From 9a961fd0c26936b760aa0802adfc9c7a04e16a94 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 29 Sep 2019 09:58:29 -0400 Subject: [PATCH] do not let "Use fixed baro corr from MAP" kill VE fix #960 --- firmware/controllers/algo/fuel_math.cpp | 7 ++++++- firmware/controllers/algo/obd_error_codes.h | 4 ++-- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/math/speed_density.cpp | 10 ++++++---- firmware/controllers/sensors/map.cpp | 6 ++++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index a807bb0d62..ae15deb5d0 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -381,7 +381,12 @@ floatms_t getBaseTableFuel(int rpm, float engineLoad) { float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (hasBaroSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - return baroCorrMap.getValue(GET_RPM(), getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE)); + float correction = baroCorrMap.getValue(GET_RPM(), getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE)); + if (cisnan(correction) || correction < 0.01) { + warning(OBD_Barometric_Press_Circ_Range_Perf, "Invalid baro correction %f", correction); + return 1; + } + return correction; } else { return 1; } diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index 018ca1bf68..035342bd2b 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -1155,8 +1155,8 @@ typedef enum { //P2223 NOx Sensor Heater Sense Circ Low Bank2 //P2224 NOx Sensor Heater Sense Circ High Bank2 //P2225 NOx Sensor Heater Sense Circ Interm Bank2 - //P2226 Barometric Press Circ - //P2227 Barometric Press Circ Range/Perf + OBD_Barometric_Press_Circ = 2226, + OBD_Barometric_Press_Circ_Range_Perf = 2227, //P2228 Barometric Press Circ Low //P2229 Barometric Press Circ High //P2230 Barometric Press Circ Interm diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index b37cddec34..d0967f4dfd 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -832,6 +832,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20190928; + return 20190929; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 93acab4129..a1b892daf4 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -166,9 +166,6 @@ floatms_t getSpeedDensityFuel(float map DECLARE_GLOBAL_SUFFIX) { return sdMath(airMass, ENGINE(engineState.targetAFR) PASS_GLOBAL_SUFFIX) * 1000; } -// Default baro table is all 1.0, we can't recommend a reasonable default here -static const baro_corr_table_t default_baro_corr = {1}; - void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE) { setRpmTableBin(config->veRpmBins, FUEL_RPM_COUNT); veMap.setAll(80); @@ -182,7 +179,12 @@ void setDefaultVETable(DECLARE_ENGINE_PARAMETER_SIGNATURE) { setRpmTableBin(engineConfiguration->baroCorrRpmBins, BARO_CORR_SIZE); setLinearCurve(engineConfiguration->baroCorrPressureBins, BARO_CORR_SIZE, 75, 105, 1); - memcpy(engineConfiguration->baroCorrTable, default_baro_corr, sizeof(default_baro_corr)); + for (int i = 0; i < BARO_CORR_SIZE;i++) { + for (int j = 0; j < BARO_CORR_SIZE;j++) { + // Default baro table is all 1.0, we can't recommend a reasonable default here + engineConfiguration->baroCorrTable[i][j] = 1; + } + } } void initSpeedDensity(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index d7065cb2af..e1f9a9d93e 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -116,11 +116,13 @@ float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) { * This function checks if Baro/MAP sensor value is inside of expected range * @return unchanged mapKPa parameter or NaN */ -float validateBaroMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) { +static float validateBaroMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) { const float atmoPressure = 100.0f; const float atmoPressureRange = 15.0f; // 85..115 - if (cisnan(mapKPa) || absF(mapKPa - atmoPressure) > atmoPressureRange) + if (cisnan(mapKPa) || absF(mapKPa - atmoPressure) > atmoPressureRange) { + warning(OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa); return NAN; + } return mapKPa; }