auto-sync

This commit is contained in:
rusEfi 2016-06-29 22:03:26 -04:00
parent 3bf97c624a
commit dc1a8f3859
4 changed files with 30 additions and 43 deletions

View File

@ -14,7 +14,7 @@
#include "cyclic_buffer.h" #include "cyclic_buffer.h"
#include "table_helper.h" #include "table_helper.h"
typedef Map3D<TPS_TPS_ACCEL_TABLE, TPS_TPS_ACCEL_TABLE> tps_tps_Map3D_t; typedef Map3D<TPS_TPS_ACCEL_TABLE, TPS_TPS_ACCEL_TABLE, float> tps_tps_Map3D_t;
/** /**
* this object is used for MAP rate-of-change and TPS rate-of-change corrections * this object is used for MAP rate-of-change and TPS rate-of-change corrections

View File

@ -13,7 +13,7 @@
#include "engine.h" #include "engine.h"
#include "table_helper.h" #include "table_helper.h"
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8> fsio8_Map3D_t; typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, float> fsio8_Map3D_t;
/** /**
* In human language that's * In human language that's

View File

@ -207,12 +207,10 @@ float interpolate2d(float value, float bin[], float values[], int size) {
return interpolateMsg("2d", bin[index], values[index], bin[index + 1], values[index + 1], value); return interpolateMsg("2d", bin[index], values[index], bin[index + 1], values[index + 1], value);
} }
typedef float (*getTableValue_t)(int x, int y, void *table);
/** /**
* @brief Two-dimensional table lookup with linear interpolation * @brief Two-dimensional table lookup with linear interpolation
*/ */
float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, void* map, getTableValue_t getTableValue) { float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]) {
if (cisnan(x)) { if (cisnan(x)) {
warning(OBD_PCM_Processor_Fault, "%f: x is NaN in interpolate3d", x); warning(OBD_PCM_Processor_Fault, "%f: x is NaN in interpolate3d", x);
return NAN; return NAN;
@ -233,7 +231,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
if (needInterpolationLogging) if (needInterpolationLogging)
printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex); printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex);
#endif #endif
return getTableValue(0, 0, map); return map[0][0];
} }
if (xIndex < 0) { if (xIndex < 0) {
@ -242,11 +240,11 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
printf("X is smaller than smallest cell in table: %dr\n", xIndex); printf("X is smaller than smallest cell in table: %dr\n", xIndex);
#endif #endif
if (yIndex == yBinSize - 1) if (yIndex == yBinSize - 1)
return getTableValue(0, yIndex, map); return map[0][yIndex];
float keyMin = yBin[yIndex]; float keyMin = yBin[yIndex];
float keyMax = yBin[yIndex + 1]; float keyMax = yBin[yIndex + 1];
float rpmMinValue = getTableValue(0, yIndex, map); float rpmMinValue = map[0][yIndex];
float rpmMaxValue = getTableValue(0, yIndex + 1, map); float rpmMaxValue = map[0][yIndex + 1];
return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y); return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
} }
@ -257,7 +255,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
printf("Y is smaller than smallest cell in table: %d\r\n", yIndex); printf("Y is smaller than smallest cell in table: %d\r\n", yIndex);
#endif #endif
// no interpolation should be fine here. // no interpolation should be fine here.
return getTableValue(xIndex, 0, map); return map[xIndex][0];
} }
if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) { if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) {
@ -265,7 +263,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
if (needInterpolationLogging) if (needInterpolationLogging)
printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex); printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex);
#endif #endif
return getTableValue(xBinSize - 1, yBinSize - 1, map); return map[xBinSize - 1][yBinSize - 1];
} }
if (xIndex == xBinSize - 1) { if (xIndex == xBinSize - 1) {
@ -274,7 +272,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex); printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex);
#endif #endif
// todo: implement better handling - y interpolation // todo: implement better handling - y interpolation
return getTableValue(xBinSize - 1, yIndex, map); return map[xBinSize - 1][yIndex];
} }
if (yIndex == yBinSize - 1) { if (yIndex == yBinSize - 1) {
@ -283,7 +281,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
printf("Y is larger than largest cell in table: %d\r\n", yIndex); printf("Y is larger than largest cell in table: %d\r\n", yIndex);
#endif #endif
// todo: implement better handling - x interpolation // todo: implement better handling - x interpolation
return getTableValue(xIndex, yBinSize - 1, map); return map[xIndex][yBinSize - 1];
} }
/* /*
@ -293,8 +291,8 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
float xMin = xBin[xIndex]; float xMin = xBin[xIndex];
float xMax = xBin[xIndex + 1]; float xMax = xBin[xIndex + 1];
float rpmMinKeyMinValue = getTableValue(xIndex, yIndex, map); float rpmMinKeyMinValue = map[xIndex][yIndex];
float rpmMaxKeyMinValue = getTableValue(xIndex + 1, yIndex, map); float rpmMaxKeyMinValue = map[xIndex + 1][yIndex];
float keyMinValue = interpolate(xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x); float keyMinValue = interpolate(xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x);
@ -308,8 +306,8 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
int keyMaxIndex = yIndex + 1; int keyMaxIndex = yIndex + 1;
float keyMin = yBin[yIndex]; float keyMin = yBin[yIndex];
float keyMax = yBin[keyMaxIndex]; float keyMax = yBin[keyMaxIndex];
float rpmMinKeyMaxValue = getTableValue(xIndex, keyMaxIndex, map); float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
float rpmMaxKeyMaxValue = getTableValue(rpmMaxIndex, keyMaxIndex, map); float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x); float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
@ -324,17 +322,6 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
return result; return result;
} }
float getFloatTableValue(int x, int y, void* pointer) {
float** map = (float**)pointer;
return map[x][y];
}
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]) {
return interpolate3d_g(x, xBin, xBinSize, y, yBin, yBinSize, map, getFloatTableValue);
}
void setTableValue(float bins[], float values[], int size, float key, float value) { void setTableValue(float bins[], float values[], int size, float key, float value) {
int index = findIndex(bins, size, key); int index = findIndex(bins, size, key);
if (index == -1) if (index == -1)

View File

@ -15,15 +15,15 @@
/** /**
* this helper class brings together 3D table with two 2D axis curves * this helper class brings together 3D table with two 2D axis curves
*/ */
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE> template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
class Map3D { class Map3D {
public: public:
Map3D(const char*name); Map3D(const char*name);
void init(float table[RPM_BIN_SIZE][LOAD_BIN_SIZE], float loadBins[LOAD_BIN_SIZE], float rpmBins[RPM_BIN_SIZE]); void init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE], float loadBins[LOAD_BIN_SIZE], float rpmBins[RPM_BIN_SIZE]);
float getValue(float xRpm, float y); float getValue(float xRpm, float y);
void setAll(float value); void setAll(vType value);
private: private:
float *pointers[LOAD_BIN_SIZE]; vType *pointers[LOAD_BIN_SIZE];
float *loadBins; float *loadBins;
float *rpmBins; float *rpmBins;
bool initialized; bool initialized;
@ -66,8 +66,8 @@ void Table2D<SIZE>::preCalc(float *bin, float *values) {
} }
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE> template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::init(float table[RPM_BIN_SIZE][LOAD_BIN_SIZE], void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE],
float loadBins[LOAD_BIN_SIZE], float loadBins[LOAD_BIN_SIZE],
float rpmBins[RPM_BIN_SIZE]) { float rpmBins[RPM_BIN_SIZE]) {
// this method cannot use logger because it's invoked before everything // this method cannot use logger because it's invoked before everything
@ -82,8 +82,8 @@ void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::init(float table[RPM_BIN_SIZE][LOAD_BIN
this->rpmBins = rpmBins; this->rpmBins = rpmBins;
} }
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE> template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::getValue(float xRpm, float y) { float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::getValue(float xRpm, float y) {
efiAssert(initialized, "map not initialized", NAN); efiAssert(initialized, "map not initialized", NAN);
if (cisnan(y)) { if (cisnan(y)) {
warning(OBD_PCM_Processor_Fault, "%s: y is NaN", name); warning(OBD_PCM_Processor_Fault, "%s: y is NaN", name);
@ -93,8 +93,8 @@ float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::getValue(float xRpm, float y) {
return interpolate3d(y, loadBins, LOAD_BIN_SIZE, xRpm, rpmBins, RPM_BIN_SIZE, pointers); return interpolate3d(y, loadBins, LOAD_BIN_SIZE, xRpm, rpmBins, RPM_BIN_SIZE, pointers);
} }
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE> template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::Map3D(const char *name) { Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::Map3D(const char *name) {
this->name = name; this->name = name;
initialized = false; initialized = false;
memset(&pointers, 0, sizeof(pointers)); memset(&pointers, 0, sizeof(pointers));
@ -102,8 +102,8 @@ Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::Map3D(const char *name) {
rpmBins = NULL; rpmBins = NULL;
} }
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE> template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::setAll(float value) { void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::setAll(vType value) {
efiAssertVoid(initialized, "map not initialized"); efiAssertVoid(initialized, "map not initialized");
for (int l = 0; l < LOAD_BIN_SIZE; l++) { for (int l = 0; l < LOAD_BIN_SIZE; l++) {
for (int r = 0; r < RPM_BIN_SIZE; r++) { for (int r = 0; r < RPM_BIN_SIZE; r++) {
@ -112,9 +112,9 @@ void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::setAll(float value) {
} }
} }
typedef Map3D<IGN_RPM_COUNT, IGN_LOAD_COUNT> ign_Map3D_t; typedef Map3D<IGN_RPM_COUNT, IGN_LOAD_COUNT, float> ign_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT> fuel_Map3D_t; typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float> fuel_Map3D_t;
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE> baroCorr_Map3D_t; typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE, float> baroCorr_Map3D_t;
void setRpmBin(float array[], int size, float idleRpm, float topRpm); void setRpmBin(float array[], int size, float idleRpm, float topRpm);