adding support for smaller table axis

This commit is contained in:
rusefi 2019-06-10 12:38:32 -04:00
parent 4f939bbe4a
commit 30847db935
7 changed files with 63 additions and 60 deletions

View File

@ -293,7 +293,7 @@ void setDodgeNeonNGCEngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
//setWholeTimingTable_d(12 PASS_CONFIG_PARAMETER_SUFFIX);
copyTimingTable(fromODB, config->ignitionTable);
copy2DTable<FSIO_TABLE_8, FSIO_TABLE_8, float>(vBattTarget, config->fsioTable1);
copy2DTable<FSIO_TABLE_8, FSIO_TABLE_8, float, float>(vBattTarget, config->fsioTable1);
copyFuelTable(veDodgeNeon2003Table, config->veTable);
//setMap(config->veTable, 50);

View File

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

View File

@ -217,7 +217,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/
if (CONFIGB(useTPSBasedVeTable)) {
// todo: should we have 'veTpsMap' fuel_Map3D_t variable here?
currentRawVE = interpolate3d<float>(tps, CONFIG(ignitionTpsBins), IGN_TPS_COUNT, rpm, config->veRpmBins, FUEL_RPM_COUNT, veMap.pointers);
currentRawVE = interpolate3d<float, float>(tps, CONFIG(ignitionTpsBins), IGN_TPS_COUNT, rpm, config->veRpmBins, FUEL_RPM_COUNT, veMap.pointers);
} else {
currentRawVE = veMap.getValue(rpm, map);
}

View File

@ -14,8 +14,8 @@
#include "table_helper.h"
#include "system_fsio.h"
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, float> fsio8_Map3D_f32t;
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, uint8_t> fsio8_Map3D_u8t;
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, float, float> fsio8_Map3D_f32t;
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, uint8_t, float> fsio8_Map3D_u8t;
#define MAGIC_OFFSET_FOR_ENGINE_WARNING 4
#define MAGIC_OFFSET_FOR_CRITICAL_ENGINE 5

View File

@ -12,7 +12,7 @@
#define ASIZE 16
typedef Map3D<ASIZE, ASIZE, float> maf2map_Map3D_t;
typedef Map3D<ASIZE, ASIZE, float, float> maf2map_Map3D_t;
void initMaf2Map();
float estimateMapByRpmAndMaf(int rpm, float maf);

View File

@ -12,31 +12,34 @@
#include "interpolation.h"
#include "efilib.h"
// popular left edge of CLT-based correction curvers
// popular left edge of CLT-based correction curves
#define CLT_CURVE_RANGE_FROM -40
/**
* this helper class brings together 3D table with two 2D axis curves
*/
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
class Map3D {
public:
explicit Map3D(const char*name);
Map3D(const char*name, float multiplier);
void init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE], const float loadBins[LOAD_BIN_SIZE], const float rpmBins[RPM_BIN_SIZE]);
void init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE], const kType loadBins[LOAD_BIN_SIZE], const kType rpmBins[RPM_BIN_SIZE]);
float getValue(float xRpm, float y);
void setAll(vType value);
vType *pointers[LOAD_BIN_SIZE];
private:
void create(const char*name, float multiplier);
const float *loadBins = NULL;
const float *rpmBins = NULL;
const kType *loadBins = NULL;
const kType *rpmBins = NULL;
bool initialized = false;
const char *name;
float multiplier;
};
/*
* this dead code is a questionable performance optimization idea: instead of division every time
* we want interpolation for a curve we can pre-calculate A and B and save the division at the cost of more RAM usage
* Realistically we probably value RAM over CPU at this time and the costs are not justified.
template<int SIZE>
class Table2D {
public:
@ -71,10 +74,10 @@ void Table2D<SIZE>::preCalc(float *bin, float *values) {
}
*/
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],
const float loadBins[LOAD_BIN_SIZE],
const float rpmBins[RPM_BIN_SIZE]) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE],
const kType loadBins[LOAD_BIN_SIZE],
const kType rpmBins[RPM_BIN_SIZE]) {
// this method cannot use logger because it's invoked before everything
// that's because this method needs to be invoked before initial configuration processing
// and initial configuration load is done prior to logging initialization
@ -87,36 +90,36 @@ void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::init(vType table[RPM_BIN_SIZE][L
this->rpmBins = rpmBins;
}
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) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
float Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::getValue(float xRpm, float y) {
efiAssert(CUSTOM_ERR_ASSERT, initialized, "map not initialized", NAN);
if (cisnan(y)) {
warning(CUSTOM_PARAM_RANGE, "%s: y is NaN", name);
return NAN;
}
// todo: we have a bit of a mess: in TunerStudio, RPM is X-axis
return multiplier * interpolate3d<vType>(y, loadBins, LOAD_BIN_SIZE, xRpm, rpmBins, RPM_BIN_SIZE, pointers);
return multiplier * interpolate3d<vType, kType>(y, loadBins, LOAD_BIN_SIZE, xRpm, rpmBins, RPM_BIN_SIZE, pointers);
}
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::Map3D(const char *name) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::Map3D(const char *name) {
create(name, 1);
}
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::Map3D(const char *name, float multiplier) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::Map3D(const char *name, float multiplier) {
create(name, multiplier);
}
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::create(const char *name, float multiplier) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::create(const char *name, float multiplier) {
this->name = name;
this->multiplier = multiplier;
memset(&pointers, 0, sizeof(pointers));
}
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::setAll(vType value) {
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType, kType>::setAll(vType value) {
efiAssertVoid(CUSTOM_ERR_6573, initialized, "map not initialized");
for (int l = 0; l < LOAD_BIN_SIZE; l++) {
for (int r = 0; r < RPM_BIN_SIZE; r++) {
@ -125,7 +128,7 @@ void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::setAll(vType value) {
}
}
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType, typename kType>
void copy2DTable(const vType source[LOAD_BIN_SIZE][RPM_BIN_SIZE], vType destination[LOAD_BIN_SIZE][RPM_BIN_SIZE]) {
for (int k = 0; k < LOAD_BIN_SIZE; k++) {
for (int rpmIndex = 0; rpmIndex < RPM_BIN_SIZE; rpmIndex++) {
@ -143,11 +146,11 @@ void copy2DTable(const vType source[LOAD_BIN_SIZE][RPM_BIN_SIZE], vType destinat
*/
#define ADVANCE_TPS_STORAGE_MULT 100
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint8_t> afr_Map3D_t;
typedef Map3D<IGN_RPM_COUNT, IGN_LOAD_COUNT, float> ign_Map3D_t;
typedef Map3D<IGN_RPM_COUNT, IGN_TPS_COUNT, int16_t> ign_tps_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;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint8_t, float> afr_Map3D_t;
typedef Map3D<IGN_RPM_COUNT, IGN_LOAD_COUNT, float, float> ign_Map3D_t;
typedef Map3D<IGN_RPM_COUNT, IGN_TPS_COUNT, int16_t, float> ign_tps_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float, float> fuel_Map3D_t;
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE, float, float> baroCorr_Map3D_t;
void setRpmBin(float array[], int size, float idleRpm, float topRpm);

View File

@ -33,8 +33,8 @@ int needInterpolationLogging(void);
/**
* @brief Two-dimensional table lookup with linear interpolation
*/
template<typename vType>
float interpolate3d(float x, const float xBin[], int xBinSize, float y, const float yBin[], int yBinSize, vType* map[]) {
template<typename vType, typename kType>
float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kType yBin[], int yBinSize, vType* map[]) {
if (cisnan(x)) {
warning(CUSTOM_INTEPOLATE_ERROR_3, "%.2f: x is NaN in interpolate3d", x);
return NAN;
@ -65,10 +65,10 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
#endif /* DEBUG_INTERPOLATION */
if (yIndex == yBinSize - 1)
return map[0][yIndex];
float keyMin = yBin[yIndex];
float keyMax = yBin[yIndex + 1];
float rpmMinValue = map[0][yIndex];
float rpmMaxValue = map[0][yIndex + 1];
kType keyMin = yBin[yIndex];
kType keyMax = yBin[yIndex + 1];
vType rpmMinValue = map[0][yIndex];
vType rpmMaxValue = map[0][yIndex + 1];
return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
}
@ -80,10 +80,10 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
#endif /* DEBUG_INTERPOLATION */
if (xIndex == xBinSize - 1)
return map[xIndex][0];
float key1 = xBin[xIndex];
float key2 = xBin[xIndex + 1];
float value1 = map[xIndex][0];
float value2 = map[xIndex + 1][0];
kType key1 = xBin[xIndex];
kType key2 = xBin[xIndex + 1];
vType value1 = map[xIndex][0];
vType value2 = map[xIndex + 1][0];
return interpolateMsg("out3d", key1, value1, key2, value2, x);
}
@ -103,10 +103,10 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
#endif /* DEBUG_INTERPOLATION */
// here yIndex is less than yBinSize - 1, we've checked that condition already
float key1 = yBin[yIndex];
float key2 = yBin[yIndex + 1];
float value1 = map[xIndex][yIndex];
float value2 = map[xIndex][yIndex + 1];
kType key1 = yBin[yIndex];
kType key2 = yBin[yIndex + 1];
vType value1 = map[xIndex][yIndex];
vType value2 = map[xIndex][yIndex + 1];
return interpolateMsg("out3d", key1, value1, key2, value2, y);
}
@ -118,10 +118,10 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
#endif /* DEBUG_INTERPOLATION */
// here xIndex is less than xBinSize - 1, we've checked that condition already
float key1 = xBin[xIndex];
float key2 = xBin[xIndex + 1];
float value1 = map[xIndex][yIndex];
float value2 = map[xIndex + 1][yIndex];
kType key1 = xBin[xIndex];
kType key2 = xBin[xIndex + 1];
vType value1 = map[xIndex][yIndex];
vType value2 = map[xIndex + 1][yIndex];
return interpolateMsg("out3d", key1, value1, key2, value2, x);
}
@ -131,12 +131,12 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
*/
int rpmMaxIndex = xIndex + 1;
float xMin = xBin[xIndex];
float xMax = xBin[xIndex + 1];
float rpmMinKeyMinValue = map[xIndex][yIndex];
float rpmMaxKeyMinValue = map[xIndex + 1][yIndex];
kType xMin = xBin[xIndex];
kType xMax = xBin[xIndex + 1];
vType rpmMinKeyMinValue = map[xIndex][yIndex];
vType rpmMaxKeyMinValue = map[xIndex + 1][yIndex];
float keyMinValue = interpolateMsg("", xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x);
vType keyMinValue = interpolateMsg("", xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x);
#if DEBUG_INTERPOLATION
if (needInterpolationLogging()) {
@ -146,12 +146,12 @@ float interpolate3d(float x, const float xBin[], int xBinSize, float y, const fl
#endif /* DEBUG_INTERPOLATION */
int keyMaxIndex = yIndex + 1;
float keyMin = yBin[yIndex];
float keyMax = yBin[keyMaxIndex];
float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
kType keyMin = yBin[yIndex];
kType keyMax = yBin[keyMaxIndex];
vType rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
vType rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
vType keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
#if DEBUG_INTERPOLATION
if (needInterpolationLogging()) {