auto-sync
This commit is contained in:
parent
3bf97c624a
commit
dc1a8f3859
|
@ -14,7 +14,7 @@
|
|||
#include "cyclic_buffer.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
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "engine.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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
typedef float (*getTableValue_t)(int x, int y, void *table);
|
||||
|
||||
/**
|
||||
* @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)) {
|
||||
warning(OBD_PCM_Processor_Fault, "%f: x is NaN in interpolate3d", x);
|
||||
return NAN;
|
||||
|
@ -233,7 +231,7 @@ float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[]
|
|||
if (needInterpolationLogging)
|
||||
printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex);
|
||||
#endif
|
||||
return getTableValue(0, 0, map);
|
||||
return map[0][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);
|
||||
#endif
|
||||
if (yIndex == yBinSize - 1)
|
||||
return getTableValue(0, yIndex, map);
|
||||
return map[0][yIndex];
|
||||
float keyMin = yBin[yIndex];
|
||||
float keyMax = yBin[yIndex + 1];
|
||||
float rpmMinValue = getTableValue(0, yIndex, map);
|
||||
float rpmMaxValue = getTableValue(0, yIndex + 1, map);
|
||||
float rpmMinValue = map[0][yIndex];
|
||||
float rpmMaxValue = map[0][yIndex + 1];
|
||||
|
||||
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);
|
||||
#endif
|
||||
// no interpolation should be fine here.
|
||||
return getTableValue(xIndex, 0, map);
|
||||
return map[xIndex][0];
|
||||
}
|
||||
|
||||
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)
|
||||
printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex);
|
||||
#endif
|
||||
return getTableValue(xBinSize - 1, yBinSize - 1, map);
|
||||
return map[xBinSize - 1][yBinSize - 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);
|
||||
#endif
|
||||
// todo: implement better handling - y interpolation
|
||||
return getTableValue(xBinSize - 1, yIndex, map);
|
||||
return map[xBinSize - 1][yIndex];
|
||||
}
|
||||
|
||||
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);
|
||||
#endif
|
||||
// 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 xMax = xBin[xIndex + 1];
|
||||
float rpmMinKeyMinValue = getTableValue(xIndex, yIndex, map);
|
||||
float rpmMaxKeyMinValue = getTableValue(xIndex + 1, yIndex, map);
|
||||
float rpmMinKeyMinValue = map[xIndex][yIndex];
|
||||
float rpmMaxKeyMinValue = map[xIndex + 1][yIndex];
|
||||
|
||||
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;
|
||||
float keyMin = yBin[yIndex];
|
||||
float keyMax = yBin[keyMaxIndex];
|
||||
float rpmMinKeyMaxValue = getTableValue(xIndex, keyMaxIndex, map);
|
||||
float rpmMaxKeyMaxValue = getTableValue(rpmMaxIndex, keyMaxIndex, map);
|
||||
float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
|
||||
float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
int index = findIndex(bins, size, key);
|
||||
if (index == -1)
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
/**
|
||||
* 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 {
|
||||
public:
|
||||
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);
|
||||
void setAll(float value);
|
||||
void setAll(vType value);
|
||||
private:
|
||||
float *pointers[LOAD_BIN_SIZE];
|
||||
vType *pointers[LOAD_BIN_SIZE];
|
||||
float *loadBins;
|
||||
float *rpmBins;
|
||||
bool initialized;
|
||||
|
@ -66,8 +66,8 @@ void Table2D<SIZE>::preCalc(float *bin, float *values) {
|
|||
}
|
||||
|
||||
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE>
|
||||
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::init(float table[RPM_BIN_SIZE][LOAD_BIN_SIZE],
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
||||
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE],
|
||||
float loadBins[LOAD_BIN_SIZE],
|
||||
float rpmBins[RPM_BIN_SIZE]) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE>
|
||||
float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::getValue(float xRpm, float y) {
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
||||
float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::getValue(float xRpm, float y) {
|
||||
efiAssert(initialized, "map not initialized", NAN);
|
||||
if (cisnan(y)) {
|
||||
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);
|
||||
}
|
||||
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE>
|
||||
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::Map3D(const char *name) {
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
||||
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::Map3D(const char *name) {
|
||||
this->name = name;
|
||||
initialized = false;
|
||||
memset(&pointers, 0, sizeof(pointers));
|
||||
|
@ -102,8 +102,8 @@ Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::Map3D(const char *name) {
|
|||
rpmBins = NULL;
|
||||
}
|
||||
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE>
|
||||
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE>::setAll(float value) {
|
||||
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
||||
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::setAll(vType value) {
|
||||
efiAssertVoid(initialized, "map not initialized");
|
||||
for (int l = 0; l < LOAD_BIN_SIZE; l++) {
|
||||
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<FUEL_RPM_COUNT, FUEL_LOAD_COUNT> fuel_Map3D_t;
|
||||
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE> baroCorr_Map3D_t;
|
||||
typedef Map3D<IGN_RPM_COUNT, IGN_LOAD_COUNT, float> ign_Map3D_t;
|
||||
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float> fuel_Map3D_t;
|
||||
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE, float> baroCorr_Map3D_t;
|
||||
|
||||
void setRpmBin(float array[], int size, float idleRpm, float topRpm);
|
||||
|
||||
|
|
Loading…
Reference in New Issue