2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file table_helper.h
|
|
|
|
*
|
|
|
|
* @date Jul 6, 2014
|
2015-12-31 13:02:30 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2016
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
#ifndef TABLE_HELPER_H_
|
|
|
|
#define TABLE_HELPER_H_
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "error_handling.h"
|
|
|
|
#include "interpolation.h"
|
2015-12-27 09:01:53 -08:00
|
|
|
#include "efilib.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-18 09:03:32 -08:00
|
|
|
/**
|
|
|
|
* this helper class brings together 3D table with two 2D axis curves
|
|
|
|
*/
|
2016-06-29 19:03:26 -07:00
|
|
|
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
2015-07-10 06:01:56 -07:00
|
|
|
class Map3D {
|
|
|
|
public:
|
2015-12-27 09:01:53 -08:00
|
|
|
Map3D(const char*name);
|
2016-06-30 19:02:49 -07:00
|
|
|
Map3D(const char*name, float multiplier);
|
|
|
|
void create(const char*name, float multiplier);
|
2016-06-29 19:03:26 -07:00
|
|
|
void init(vType table[RPM_BIN_SIZE][LOAD_BIN_SIZE], float loadBins[LOAD_BIN_SIZE], float rpmBins[RPM_BIN_SIZE]);
|
2016-03-11 12:01:58 -08:00
|
|
|
float getValue(float xRpm, float y);
|
2016-06-29 19:03:26 -07:00
|
|
|
void setAll(vType value);
|
2015-07-10 06:01:56 -07:00
|
|
|
private:
|
2016-06-29 19:03:26 -07:00
|
|
|
vType *pointers[LOAD_BIN_SIZE];
|
2015-07-10 06:01:56 -07:00
|
|
|
float *loadBins;
|
|
|
|
float *rpmBins;
|
2016-01-18 09:03:32 -08:00
|
|
|
bool initialized;
|
2015-12-27 09:01:53 -08:00
|
|
|
const char *name;
|
2016-06-30 19:02:49 -07:00
|
|
|
float multiplier;
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template<int SIZE>
|
|
|
|
class Table2D {
|
|
|
|
public:
|
|
|
|
Table2D();
|
|
|
|
void preCalc(float *bin, float *values);
|
|
|
|
float aTable[SIZE];
|
|
|
|
float bTable[SIZE];
|
|
|
|
float *bin;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int SIZE>
|
|
|
|
Table2D<SIZE>::Table2D() {
|
|
|
|
bin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<int SIZE>
|
|
|
|
void Table2D<SIZE>::preCalc(float *bin, float *values) {
|
|
|
|
this->bin = bin;
|
|
|
|
for (int i = 0; i < SIZE - 1; i++) {
|
|
|
|
float x1 = bin[i];
|
|
|
|
float x2 = bin[i + 1];
|
|
|
|
if (x1 == x2) {
|
|
|
|
warning(OBD_PCM_Processor_Fault, "preCalc: 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-29 19:03:26 -07:00
|
|
|
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],
|
2015-07-10 06:01:56 -07:00
|
|
|
float loadBins[LOAD_BIN_SIZE],
|
|
|
|
float rpmBins[RPM_BIN_SIZE]) {
|
2016-04-15 20:01:40 -07:00
|
|
|
// 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
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
for (int k = 0; k < LOAD_BIN_SIZE; k++) {
|
|
|
|
pointers[k] = table[k];
|
|
|
|
}
|
2016-01-18 09:03:32 -08:00
|
|
|
initialized = true;
|
2015-07-10 06:01:56 -07:00
|
|
|
this->loadBins = loadBins;
|
|
|
|
this->rpmBins = rpmBins;
|
|
|
|
}
|
|
|
|
|
2016-06-29 19:03:26 -07:00
|
|
|
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) {
|
2016-01-18 09:03:32 -08:00
|
|
|
efiAssert(initialized, "map not initialized", NAN);
|
2016-03-11 12:01:58 -08:00
|
|
|
if (cisnan(y)) {
|
|
|
|
warning(OBD_PCM_Processor_Fault, "%s: y is NaN", name);
|
2015-12-27 09:01:53 -08:00
|
|
|
return NAN;
|
|
|
|
}
|
2016-03-11 12:01:58 -08:00
|
|
|
// todo: we have a bit of a mess: in TunerStudio, RPM is X-axis
|
2016-06-30 19:02:49 -07:00
|
|
|
return multiplier * interpolate3d<vType>(y, loadBins, LOAD_BIN_SIZE, xRpm, rpmBins, RPM_BIN_SIZE, pointers);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-06-29 19:03:26 -07:00
|
|
|
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
|
|
|
Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::Map3D(const char *name) {
|
2016-06-30 19:02:49 -07:00
|
|
|
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) {
|
|
|
|
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) {
|
2015-12-27 09:01:53 -08:00
|
|
|
this->name = name;
|
2016-06-30 19:02:49 -07:00
|
|
|
this->multiplier = multiplier;
|
2016-04-15 20:01:40 -07:00
|
|
|
initialized = false;
|
2015-07-10 06:01:56 -07:00
|
|
|
memset(&pointers, 0, sizeof(pointers));
|
|
|
|
loadBins = NULL;
|
|
|
|
rpmBins = NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-29 19:03:26 -07:00
|
|
|
template<int RPM_BIN_SIZE, int LOAD_BIN_SIZE, typename vType>
|
|
|
|
void Map3D<RPM_BIN_SIZE, LOAD_BIN_SIZE, vType>::setAll(vType value) {
|
2016-01-18 09:03:32 -08:00
|
|
|
efiAssertVoid(initialized, "map not initialized");
|
2015-07-10 06:01:56 -07:00
|
|
|
for (int l = 0; l < LOAD_BIN_SIZE; l++) {
|
|
|
|
for (int r = 0; r < RPM_BIN_SIZE; r++) {
|
2016-06-30 19:02:49 -07:00
|
|
|
pointers[l][r] = value / multiplier;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 22:01:38 -07:00
|
|
|
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float> afr_Map3D_t;
|
2016-06-29 19:03:26 -07:00
|
|
|
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;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-21 18:03:08 -08:00
|
|
|
void setRpmBin(float array[], int size, float idleRpm, float topRpm);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
void setTableBin(float array[], int size, float l, float r);
|
|
|
|
void setTableBin2(float array[], int size, float l, float r, float precision);
|
|
|
|
void setRpmTableBin(float array[], int size);
|
|
|
|
|
|
|
|
#endif /* TABLE_HELPER_H_ */
|