From c8fb6993ac8010c8c2318fbeb62edc4642520a8e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 18 Jun 2020 05:54:02 -0700 Subject: [PATCH 1/2] simplify cranking corrections (#1510) --- firmware/controllers/algo/fuel_math.cpp | 17 ++++++++++++----- firmware/controllers/algo/fuel_math.h | 2 +- unit_tests/tests/test_fuel_map.cpp | 17 +++++++++++------ .../tests/test_startOfCrankingPrimingPulse.cpp | 2 -- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 0bb84e1f2f..442b3e2b0b 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -52,7 +52,6 @@ DISPLAY_TEXT(eol); DISPLAY(DISPLAY_IF(isCrankingState)) floatms_t getCrankingFuel3( floatms_t baseFuel, - float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_SUFFIX) { // these magic constants are in Celsius float baseCrankingFuel; @@ -71,10 +70,12 @@ DISPLAY(DISPLAY_IF(isCrankingState)) floatms_t getCrankingFuel3( /** * Cranking fuel is different depending on engine coolant temperature + * If the sensor is failed, use 20 deg C */ + auto clt = Sensor::get(SensorType::Clt); DISPLAY_TEXT(Coolant_coef); - engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(coolantTemperatureCoefficient) = cisnan(coolantTemperature) ? 1 : interpolate2d("crank", coolantTemperature, config->crankingFuelBins, - config->crankingFuelCoef); + engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(coolantTemperatureCoefficient) = + interpolate2d("crank", clt.value_or(20), config->crankingFuelBins, config->crankingFuelCoef); DISPLAY_SENSOR(CLT); DISPLAY_TEXT(eol); @@ -83,6 +84,13 @@ DISPLAY(DISPLAY_IF(isCrankingState)) floatms_t getCrankingFuel3( DISPLAY_TEXT(TPS_coef); engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(tpsCoefficient) = tps.Valid ? 1 : interpolate2d("crankTps", tps.Value, engineConfiguration->crankingTpsBins, engineConfiguration->crankingTpsCoef); + + + /* + engine->engineState.DISPLAY_PREFIX(cranking).DISPLAY_FIELD(tpsCoefficient) = + tps.Valid + ? interpolate2d("crankTps", tps.Value, engineConfiguration->crankingTpsBins, engineConfiguration->crankingTpsCoef) + : 1; // in case of failed TPS, don't correct.*/ DISPLAY_SENSOR(TPS); DISPLAY_TEXT(eol); @@ -489,8 +497,7 @@ float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * @return Duration of fuel injection while craning */ floatms_t getCrankingFuel(float baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) { - return getCrankingFuel3(baseFuel, Sensor::get(SensorType::Clt).value_or(20), - engine->rpmCalculator.getRevolutionCounterSinceStart() PASS_ENGINE_PARAMETER_SUFFIX); + return getCrankingFuel3(baseFuel, engine->rpmCalculator.getRevolutionCounterSinceStart() PASS_ENGINE_PARAMETER_SUFFIX); } float getStandardAirCharge(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index 630001f2cc..4bd979900a 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -34,7 +34,7 @@ float getCltFuelCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); angle_t getCltTimingCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE); floatms_t getCrankingFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX); -floatms_t getCrankingFuel3(floatms_t baseFuel, float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_SUFFIX); +floatms_t getCrankingFuel3(floatms_t baseFuel, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_SUFFIX); floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/tests/test_fuel_map.cpp b/unit_tests/tests/test_fuel_map.cpp index 3dbb926082..efcbe3971b 100644 --- a/unit_tests/tests/test_fuel_map.cpp +++ b/unit_tests/tests/test_fuel_map.cpp @@ -112,13 +112,18 @@ TEST(misc, testFuelMap) { engineConfiguration->cranking.baseFuel = 4; - // NAN in case we have issues with the CLT sensor - EXPECT_NEAR( 6.0, getCrankingFuel3(2, NAN, 0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + // Should use 20 degree correction in case of failed sensor + Sensor::resetMockValue(SensorType::Clt); + EXPECT_NEAR( 9.71999, getCrankingFuel3(2, 0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); - EXPECT_NEAR(11.6, getCrankingFuel3(2, 0, 4 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); - EXPECT_NEAR(5.82120, getCrankingFuel3(2, 8, 15 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); - EXPECT_NEAR(6.000, getCrankingFuel3(2, 70, 0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); - EXPECT_NEAR(2.41379, getCrankingFuel3(2, 70, 50 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + Sensor::setMockValue(SensorType::Clt, 0); + EXPECT_NEAR(11.6, getCrankingFuel3(2, 4 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + Sensor::setMockValue(SensorType::Clt, 8); + EXPECT_NEAR(5.82120, getCrankingFuel3(2, 15 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + Sensor::setMockValue(SensorType::Clt, 70); + EXPECT_NEAR(6.000, getCrankingFuel3(2, 0 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); + Sensor::setMockValue(SensorType::Clt, 70); + EXPECT_NEAR(2.41379, getCrankingFuel3(2, 50 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); } diff --git a/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp b/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp index b07688d261..407f2e3a6b 100644 --- a/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp +++ b/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp @@ -8,8 +8,6 @@ #include "engine_test_helper.h" TEST(engine, testPlainCrankingWithoutAdvancedFeatures) { - printf("*************************************************** testPlainCrankingWithoutAdvancedFeatures\r\n"); - WITH_ENGINE_TEST_HELPER(TEST_ENGINE); setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð); From 54f55595d7fe353902f535153aa08cc7099bfcfa Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 18 Jun 2020 09:02:43 -0400 Subject: [PATCH 2/2] Fresh generated - auto --- .../ui/src/main/java/com/rusefi/ldmp/generated/FuelMathMeta.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java_console/ui/src/main/java/com/rusefi/ldmp/generated/FuelMathMeta.java b/java_console/ui/src/main/java/com/rusefi/ldmp/generated/FuelMathMeta.java index 1b3d9a0633..d7d5710867 100644 --- a/java_console/ui/src/main/java/com/rusefi/ldmp/generated/FuelMathMeta.java +++ b/java_console/ui/src/main/java/com/rusefi/ldmp/generated/FuelMathMeta.java @@ -19,6 +19,7 @@ public class FuelMathMeta { new TextRequest("eol"), new TextRequest("TPS_coef"), new FieldRequest("Engine", "cranking_tpsCoefficient"), + new FieldRequest("Engine", "cranking_tpsCoefficient"), new SensorRequest("TPS"), new TextRequest("eol"), new TextRequest("Cranking_fuel"),