auto-sync
This commit is contained in:
parent
5810fb61d5
commit
04f6e3f024
|
@ -38,7 +38,6 @@ float FastInterpolation::getValue(float x) {
|
||||||
return a * x + b;
|
return a * x + b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief Linear interpolation by two points
|
/** @brief Linear interpolation by two points
|
||||||
*
|
*
|
||||||
* @param x1 key of the first point
|
* @param x1 key of the first point
|
||||||
|
@ -69,6 +68,30 @@ float interpolate(float x1, float y1, float x2, float y2, float x) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int findIndex2(const float array[], unsigned size, float value) {
|
||||||
|
efiAssert(!cisnan(value), "NaN in findIndex", 0);
|
||||||
|
efiAssert(size > 1, "NaN in findIndex", 0);
|
||||||
|
// if (size <= 1)
|
||||||
|
// return size && *array <= value ? 0 : -1;
|
||||||
|
|
||||||
|
signed i = 0;
|
||||||
|
//unsigned b = 1 << int(log(float(size) - 1) / 0.69314718055994530942);
|
||||||
|
unsigned b = size >> 1; // in our case size is always a power of 2
|
||||||
|
efiAssert(b + b == size, "Size not power of 2", -1);
|
||||||
|
for (; b; b >>= 1) {
|
||||||
|
unsigned j = i | b;
|
||||||
|
/**
|
||||||
|
* it should be
|
||||||
|
* "if (j < size && array[j] <= value)"
|
||||||
|
* but in our case size is always power of 2 thus size is always more then j
|
||||||
|
*/
|
||||||
|
// efiAssert(j < size, "size", 0);
|
||||||
|
if (array[j] <= value)
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
return i || *array <= value ? i : -1;
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Binary search
|
/** @brief Binary search
|
||||||
* @returns the highest index within sorted array such that array[i] is greater than or equal to the parameter
|
* @returns the highest index within sorted array such that array[i] is greater than or equal to the parameter
|
||||||
* @note If the parameter is smaller than the first element of the array, -1 is returned.
|
* @note If the parameter is smaller than the first element of the array, -1 is returned.
|
||||||
|
@ -143,13 +166,13 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
int xIndex = findIndex(xBin, xBinSize, x);
|
int xIndex = findIndex(xBin, xBinSize, x);
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
printf("X index=%d\r\n", xIndex);
|
printf("X index=%d\r\n", xIndex);
|
||||||
#endif
|
#endif
|
||||||
int yIndex = findIndex(yBin, yBinSize, y);
|
int yIndex = findIndex(yBin, yBinSize, y);
|
||||||
if (xIndex < 0 && yIndex < 0) {
|
if (xIndex < 0 && yIndex < 0) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
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 map[0][0];
|
return map[0][0];
|
||||||
}
|
}
|
||||||
|
@ -157,7 +180,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (xIndex < 0) {
|
if (xIndex < 0) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
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
|
||||||
// no interpolation should be fine here.
|
// no interpolation should be fine here.
|
||||||
return map[0][yIndex];
|
return map[0][yIndex];
|
||||||
|
@ -166,7 +189,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (yIndex < 0) {
|
if (yIndex < 0) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
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 map[xIndex][0];
|
return map[xIndex][0];
|
||||||
|
@ -175,7 +198,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) {
|
if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
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 map[xBinSize - 1][yBinSize - 1];
|
return map[xBinSize - 1][yBinSize - 1];
|
||||||
}
|
}
|
||||||
|
@ -183,7 +206,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (xIndex == xBinSize - 1) {
|
if (xIndex == xBinSize - 1) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
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 map[xBinSize - 1][yIndex];
|
return map[xBinSize - 1][yIndex];
|
||||||
|
@ -192,7 +215,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (yIndex == yBinSize - 1) {
|
if (yIndex == yBinSize - 1) {
|
||||||
#if DEBUG_INTERPOLATION
|
#if DEBUG_INTERPOLATION
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
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 map[xIndex][yBinSize - 1];
|
return map[xIndex][yBinSize - 1];
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
|
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
|
||||||
|
|
||||||
int findIndex(const float array[], int size, float value);
|
int findIndex(const float array[], int size, float value);
|
||||||
|
int findIndex2(const float array[], unsigned size, float value);
|
||||||
float interpolate(float x1, float y1, float x2, float y2, float x);
|
float interpolate(float x1, float y1, float x2, float y2, float x);
|
||||||
float interpolate2d(float value, float bin[], float values[], int size);
|
float interpolate2d(float value, float bin[], float values[], int size);
|
||||||
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]);
|
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]);
|
||||||
|
|
|
@ -21,36 +21,51 @@ float getRealMaf(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
return engine->mafDecodingLookup[mafAdc >> 4];
|
return engine->mafDecodingLookup[mafAdc >> 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBosch0280218037(engine_configuration_s *engineConfiguration) {
|
static void fillTheRest(engine_configuration_s *e, int i) {
|
||||||
int i = 0;
|
|
||||||
engineConfiguration->mafDecoding[i] = -34.5;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 0;
|
|
||||||
|
|
||||||
engineConfiguration->mafDecoding[i] = -6;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 0.78125;
|
|
||||||
|
|
||||||
engineConfiguration->mafDecoding[i] = 10.5;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 1.38671875;
|
|
||||||
|
|
||||||
engineConfiguration->mafDecoding[i] = 105.3;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 2.91015625;
|
|
||||||
|
|
||||||
engineConfiguration->mafDecoding[i] = 387.5;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 4.2578125;
|
|
||||||
|
|
||||||
engineConfiguration->mafDecoding[i] = 738;
|
|
||||||
engineConfiguration->mafDecodingBins[i++] = 4.98046875;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unrealistic values just to make binary search happy
|
* unrealistic values just to make binary search happy
|
||||||
*/
|
*/
|
||||||
while (i < MAF_DECODING_COUNT) {
|
while (i < MAF_DECODING_COUNT) {
|
||||||
engineConfiguration->mafDecoding[i] = 200;
|
e->mafDecoding[i] = 200;
|
||||||
engineConfiguration->mafDecodingBins[i] = 10 + i;
|
e->mafDecodingBins[i] = 10 + i;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBosch0280218004(engine_configuration_s *engineConfiguration) {
|
static int addMafPoint(engine_configuration_s *e, int i, float kgHrValue, float voltage) {
|
||||||
|
e->mafDecoding[i] = kgHrValue;
|
||||||
|
e->mafDecodingBins[i] = voltage;
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBosch0280218037(engine_configuration_s *e) {
|
||||||
|
int i = 0;
|
||||||
|
i = addMafPoint(e, i, -34.5, 0);
|
||||||
|
i = addMafPoint(e, i, -6, 0.78125);
|
||||||
|
|
||||||
|
e->mafDecoding[i] = 10.5;
|
||||||
|
e->mafDecodingBins[i++] = 1.38671875;
|
||||||
|
|
||||||
|
e->mafDecoding[i] = 105.3;
|
||||||
|
e->mafDecodingBins[i++] = 2.91015625;
|
||||||
|
|
||||||
|
e->mafDecoding[i] = 387.5;
|
||||||
|
e->mafDecodingBins[i++] = 4.2578125;
|
||||||
|
|
||||||
|
e->mafDecoding[i] = 738;
|
||||||
|
e->mafDecodingBins[i++] = 4.98046875;
|
||||||
|
|
||||||
|
fillTheRest(e, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBosch0280218004(engine_configuration_s *e) {
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
fillTheRest(e, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDensoTODO(engine_configuration_s *e) {
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
fillTheRest(e, i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,6 @@ float getRealMaf(DECLARE_ENGINE_PARAMETER_F);
|
||||||
void setBosch0280218037(engine_configuration_s *engineConfiguration);
|
void setBosch0280218037(engine_configuration_s *engineConfiguration);
|
||||||
void setBosch0280218004(engine_configuration_s *engineConfiguration);
|
void setBosch0280218004(engine_configuration_s *engineConfiguration);
|
||||||
|
|
||||||
|
void setDensoTODO(engine_configuration_s *engineConfiguration);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,66 +11,59 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
|
|
||||||
|
static int testIndex(const int expected, const float array[], int size, float value) {
|
||||||
|
assertEquals(expected, findIndex(array, size, value));
|
||||||
|
assertEquals(expected, findIndex2(array, size, value));
|
||||||
|
}
|
||||||
|
|
||||||
void testFindIndex(void) {
|
void testFindIndex(void) {
|
||||||
printf("*************************************************** testFindIndex\r\n");
|
printf("*************************************************** testFindIndex\r\n");
|
||||||
int result;
|
/*
|
||||||
|
|
||||||
{
|
{
|
||||||
// in real life we only use powers of 2 for sizes
|
// in real life we only use powers of 2 for sizes
|
||||||
float array5[] = { 1, 2, 3, 4, 5 };
|
float array5[] = { 1, 2, 3, 4, 5 };
|
||||||
const int size5 = 5;
|
const int size5 = 5;
|
||||||
printf("To the right5\r\n");
|
printf("To the right5\r\n");
|
||||||
result = findIndex(array5, size5, 10.0);
|
testIndex(4, array5, size5, 10.0);
|
||||||
assertEquals(4, result);
|
|
||||||
|
|
||||||
printf("Middle2\r\n");
|
printf("Middle2\r\n");
|
||||||
result = findIndex(array5, size5, 4);
|
testIndex(3, array5, size5, 4);
|
||||||
assertEquals(3, result);
|
|
||||||
|
|
||||||
printf("Middle2\r\n");
|
printf("Middle2\r\n");
|
||||||
result = findIndex(array5, size5, 3.1);
|
testIndex(2, array5, size5, 3.1);
|
||||||
assertEquals(2, result);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
float array4[] = { 1, 2, 3, 4 };
|
float array4[] = { 1, 2, 3, 4 };
|
||||||
const int size4 = 4;
|
const int size4 = 4;
|
||||||
|
|
||||||
printf("To the left\r\n");
|
printf("To the left\r\n");
|
||||||
result = findIndex(array4, size4, -1.0);
|
testIndex(-1, array4, size4, -1.0);
|
||||||
assertEquals(-1, result);
|
|
||||||
|
|
||||||
printf("To the right4\r\n");
|
printf("To the right4\r\n");
|
||||||
result = findIndex(array4, size4, 10.0);
|
testIndex(3, array4, size4, 10.0);
|
||||||
assertEquals(3, result);
|
|
||||||
|
|
||||||
printf("On the edge\r\n");
|
printf("On the edge\r\n");
|
||||||
result = findIndex(array4, size4, 4.0);
|
testIndex(3, array4, size4, 4.0);
|
||||||
assertEquals(3, result);
|
|
||||||
|
|
||||||
printf("Another1\r\n");
|
printf("Another1\r\n");
|
||||||
result = findIndex(array4, size4, 3.9);
|
testIndex(2, array4, size4, 3.9);
|
||||||
assertEquals(2, result);
|
|
||||||
|
|
||||||
printf("Another2\r\n");
|
printf("Another2\r\n");
|
||||||
result = findIndex(array4, size4, 4.1);
|
testIndex(3, array4, size4, 4.1);
|
||||||
assertEquals(3, result);
|
|
||||||
|
|
||||||
printf("Another3\r\n");
|
printf("Another3\r\n");
|
||||||
result = findIndex(array4, size4, 2);
|
testIndex(1, array4, size4, 2);
|
||||||
assertEquals(1, result);
|
|
||||||
|
|
||||||
printf("Left edge1\r\n");
|
printf("Left edge1\r\n");
|
||||||
result = findIndex(array4, size4, 1);
|
testIndex(0, array4, size4, 1);
|
||||||
assertEquals(0, result);
|
|
||||||
|
|
||||||
printf("Left edge2\r\n");
|
printf("Left edge2\r\n");
|
||||||
result = findIndex(array4, size4, 1.1);
|
testIndex(0, array4, size4, 1.1);
|
||||||
assertEquals(0, result);
|
|
||||||
|
|
||||||
printf("Middle\r\n");
|
printf("Middle\r\n");
|
||||||
result = findIndex(array4, size4, 3);
|
testIndex(2, array4, size4, 3);
|
||||||
assertEquals(2, result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue