Check that table axes are ascending (#2866)

* templated interpolation check

* check tables
This commit is contained in:
Matthew Kennedy 2021-06-26 12:02:25 -07:00 committed by GitHub
parent 2633c33fab
commit 219d9feaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 13 deletions

View File

@ -163,6 +163,67 @@ static bool validateConfig() {
return false;
}
// Fueling
{
ensureArrayIsAscending("VE load", config->veLoadBins);
ensureArrayIsAscending("VE RPM", config->veRpmBins);
ensureArrayIsAscending("Lambda/AFR load", config->lambdaLoadBins);
ensureArrayIsAscending("Lambda/AFR RPM", config->lambdaRpmBins);
ensureArrayIsAscending("Fuel CLT mult", config->cltFuelCorrBins);
ensureArrayIsAscending("Fuel IAT mult", config->iatFuelCorrBins);
ensureArrayIsAscending("Injection phase load", config->injPhaseLoadBins);
ensureArrayIsAscending("Injection phase RPM", config->injPhaseRpmBins);
ensureArrayIsAscending("TPS/TPS AE from", config->tpsTpsAccelFromRpmBins);
ensureArrayIsAscending("TPS/TPS AE to", config->tpsTpsAccelToRpmBins);
}
// Ignition
{
ensureArrayIsAscending("Dwell RPM", engineConfiguration->sparkDwellRpmBins);
ensureArrayIsAscending("Ignition load", config->ignitionLoadBins);
ensureArrayIsAscending("Ignition RPM", config->ignitionRpmBins);
ensureArrayIsAscending("Ignition CLT corr", engineConfiguration->cltTimingBins);
ensureArrayIsAscending("Ignition IAT corr IAT", config->ignitionIatCorrLoadBins);
ensureArrayIsAscending("Ignition IAT corr RPM", config->ignitionIatCorrRpmBins);
}
ensureArrayIsAscending("Map estimate TPS", config->mapEstimateTpsBins);
ensureArrayIsAscending("Map estimate RPM", config->mapEstimateRpmBins);
ensureArrayIsAscending("Ignition load", config->mafDecodingBins);
// Cranking tables
ensureArrayIsAscending("Cranking fuel mult", config->crankingFuelBins);
ensureArrayIsAscending("Cranking duration", config->crankingCycleBins);
ensureArrayIsAscending("Cranking TPS", engineConfiguration->crankingTpsBins);
// Idle tables
ensureArrayIsAscending("Idle target RPM", engineConfiguration->cltIdleRpmBins);
ensureArrayIsAscending("Idle warmup mult", config->cltIdleCorrBins);
ensureArrayIsAscending("Idle coasting position", engineConfiguration->iacCoastingBins);
ensureArrayIsAscending("Idle VE", config->idleVeBins);
ensureArrayIsAscending("Idle timing", config->idleAdvanceBins);
// Boost
ensureArrayIsAscending("Boost control TPS", config->boostTpsBins);
ensureArrayIsAscending("Boost control RPM", config->boostRpmBins);
// ETB
ensureArrayIsAscending("Pedal map pedal", config->pedalToTpsPedalBins);
ensureArrayIsAscending("Pedal map RPM", config->pedalToTpsRpmBins);
// VVT
ensureArrayIsAscending("VVT intake load", config->vvtTable1LoadBins);
ensureArrayIsAscending("VVT intake RPM", config->vvtTable1RpmBins);
ensureArrayIsAscending("VVT exhaust load", config->vvtTable2LoadBins);
ensureArrayIsAscending("VVT exhaust RPM", config->vvtTable2RpmBins);
return true;
}

View File

@ -165,18 +165,6 @@ int findIndex2(const float array[], unsigned size, float value) {
return i || *array <= value ? i : -1;
}
/**
* in order to use binary search we need to know that axis elements are sorted
*/
void ensureArrayIsAscending(const char *msg, const float array[], int size) {
for (int i = 0; i < size - 1; i ++) {
if (array[i] >= array[i+ 1]) {
// todo: this should become a warning under https://github.com/rusefi/rusefi/issues/440
firmwareError(CUSTOM_ERR_AXIS_ORDER, "invalid axis %s at %.2f", msg, array[i]);
}
}
}
int findIndex(const float array[], int size, float value) {
return findIndexMsg("", array, size, value);
}

View File

@ -23,11 +23,19 @@
int findIndex(const float array[], int size, float value);
#define findIndexMsg(msg, array, size, value) findIndexMsgExt<float>(msg, array, size, value)
void ensureArrayIsAscending(const char *msg, const float array[], int size);
int findIndex2(const float array[], unsigned size, float value);
float interpolateClamped(float x1, float y1, float x2, float y2, float x);
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
template<typename TValue, int TSize>
void ensureArrayIsAscending(const char* msg, const TValue (&values)[TSize]) {
for (size_t i = 0; i < TSize - 1; i++) {
if (values[i + 1] < values[i]) {
firmwareError(CUSTOM_ERR_AXIS_ORDER, "Invalid table axis (must be ascending!): %s", msg);
}
}
}
namespace priv {
struct BinResult
{