diff --git a/firmware/controllers/algo/ec2.h b/firmware/controllers/algo/ec2.h index cb5b5bfc17..04c32ab15b 100644 --- a/firmware/controllers/algo/ec2.h +++ b/firmware/controllers/algo/ec2.h @@ -16,6 +16,7 @@ #include "engine_configuration.h" #include "event_registry.h" #include "trigger_structure.h" +#include "table_helper.h" class FuelSchedule { public: @@ -49,6 +50,12 @@ public: FuelSchedule crankingInjectionEvents; FuelSchedule injectionEvents; + float sparkAtable[DWELL_CURVE_SIZE]; + float sparkBtable[DWELL_CURVE_SIZE]; + + Table2D sparkTable; + void precalc(); + /** * We are alternating two event lists in order to avoid a potential issue around revolution boundary * when an event is scheduled within the next revolution. diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index bb42ed0562..c12f79293f 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -572,6 +572,12 @@ engine_configuration2_s::engine_configuration2_s() { engineConfiguration = NULL; } +void engine_configuration2_s::precalc() { + //sparkTable.init() + //engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE); + +} + void applyNonPersistentConfiguration(Logging * logger, Engine *engine) { engine_configuration_s *engineConfiguration = engine->engineConfiguration; engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; diff --git a/firmware/controllers/core/interpolation.cpp b/firmware/controllers/core/interpolation.cpp index d8aaa87357..ab14ced34f 100644 --- a/firmware/controllers/core/interpolation.cpp +++ b/firmware/controllers/core/interpolation.cpp @@ -15,11 +15,8 @@ #include "main.h" #include "interpolation.h" -#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2)) - int needInterpolationLogging = TRUE; - FastInterpolation::FastInterpolation(float x1, float y1, float x2, float y2) { init(x1, y1, x2, y2); } diff --git a/firmware/controllers/core/interpolation.h b/firmware/controllers/core/interpolation.h index 856705830b..3defad1ac4 100644 --- a/firmware/controllers/core/interpolation.h +++ b/firmware/controllers/core/interpolation.h @@ -8,6 +8,8 @@ #ifndef INTERPOLATION_3D_H_ #define INTERPOLATION_3D_H_ +#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2)) + int findIndex(float array[], int size, float value); float interpolate(float x1, float y1, float x2, float y2, float x); float interpolate2d(float value, float bin[], float values[], int size); diff --git a/firmware/controllers/core/table_helper.cpp b/firmware/controllers/core/table_helper.cpp index 71615930ff..a2d98210a9 100644 --- a/firmware/controllers/core/table_helper.cpp +++ b/firmware/controllers/core/table_helper.cpp @@ -20,6 +20,29 @@ void setTableBin2(float array[], int size, float l, float r, float precision) { } } +void Table2D::init(int size, float *aTable, float *bTable) { + this->size = size; + this->aTable = aTable; + this->bTable = bTable; +} + +void Table2D::preCalc(float *bin, float *values) { + for (int i = 0; i < size - 1; i++) { + float x1 = bin[i]; + float x2 = bin[i + 1]; + if (x1 == x2) { + firmwareError("Same x1 and x2 in interpolate: %f/%f", x1, x2); + return; + } + + float y1 = values[i]; + float y2 = values[i + 1]; + + aTable[i] = INTERPOLATION_A(x1, y1, x2, y2); + bTable[i] = y1 - aTable[i] * x1; + } +} + void setTableBin(float array[], int size, float l, float r) { setTableBin2(array, size, l, r, 0.01); } diff --git a/firmware/controllers/core/table_helper.h b/firmware/controllers/core/table_helper.h index c4367fdec6..e2291adfd6 100644 --- a/firmware/controllers/core/table_helper.h +++ b/firmware/controllers/core/table_helper.h @@ -9,6 +9,7 @@ #include #include "error_handling.h" +#include "interpolation.h" // 'random' value to be sure we are not treating any non-zero trash as TRUE #define MAGIC_TRUE_VALUE 153351512 @@ -24,6 +25,15 @@ private: int initialized; }; +class Table2D { +public: + void init(int size, float *aTable, float *bTable); + void preCalc(float *bin, float *values); + int size; + float *aTable; + float *bTable; +}; + template void Map3D::init(float table[RPM_BIN_SIZE][LOAD_BIN_SIZE]) { for (int k = 0; k < LOAD_BIN_SIZE; k++) {