fome-fw/firmware/controllers/core/table_helper.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file table_helper.cpp
* @brief Helper methods related to 3D & 2D tables manipulation (maps and curves)
*
* @date Jul 6, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#include "table_helper.h"
#include "efilib.h"
#include "interpolation.h"
void setTableBin2(float array[], int size, float l, float r, float precision) {
for (int i = 0; i < size; i++) {
float value = interpolate(0, l, size - 1, r, i);
/**
* rounded values look nicer, also we want to avoid precision mismatch with Tuner Studio
*/
array[i] = efiRound(value, precision);
}
}
2014-11-24 10:04:56 -08:00
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) {
2014-11-24 11:03:17 -08:00
this->bin = bin;
2014-11-24 10:04:56 -08:00
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;
}
}
2014-08-29 07:52:33 -07:00
void setTableBin(float array[], int size, float l, float r) {
setTableBin2(array, size, l, r, 0.01);
}
void setRpmTableBin(float array[], int size) {
setTableBin2(array, size, 800, 7000, 1);
}