diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 9b47605ad3..b749b557c8 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -175,7 +175,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { currentAfr = getAfr(PASS_ENGINE_PARAMETER_F); // todo: move this into slow callback, no reason for IAT corr to be here - iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER); + iatFuelCorrection = getIatFuelCorrection(iat PASS_ENGINE_PARAMETER); // todo: move this into slow callback, no reason for CLT corr to be here if (boardConfiguration->useWarmupPidAfr && clt < engineConfiguration->warmupAfrThreshold) { if (rpm < 200) { @@ -192,10 +192,10 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { #endif } else { - cltFuelCorrection = getCltFuelCorrection(clt PASS_ENGINE_PARAMETER); + cltFuelCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_F); } - cltTimingCorrection = getCltTimingCorrection(clt PASS_ENGINE_PARAMETER); + cltTimingCorrection = getCltTimingCorrection(PASS_ENGINE_PARAMETER_F); engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins, engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 2667da434c..240250f565 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -178,20 +178,19 @@ void prepareFuelMap(DECLARE_ENGINE_PARAMETER_F) { /** * @brief Engine warm-up fuel correction. */ -float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { - if (cisnan(clt)) +float getCltFuelCorrection(DECLARE_ENGINE_PARAMETER_F) { + if (cisnan(engine->engineState.clt)) return 1; // this error should be already reported somewhere else, let's just handle it - return interpolate2d(clt, config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE) / PERCENT_MULT; + return interpolate2d(engine->engineState.clt, config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE) / PERCENT_MULT; } -angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S) { - if (cisnan(clt)) +angle_t getCltTimingCorrection(DECLARE_ENGINE_PARAMETER_F) { + if (cisnan(engine->engineState.clt)) return 0; // this error should be already reported somewhere else, let's just handle it - return interpolate2d(clt, engineConfiguration->cltTimingBins, engineConfiguration->cltTimingExtra, CLT_TIMING_CURVE_SIZE); + return interpolate2d(engine->engineState.clt, engineConfiguration->cltTimingBins, engineConfiguration->cltTimingExtra, CLT_TIMING_CURVE_SIZE); } - -float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S) { +float getIatFuelCorrection(float iat DECLARE_ENGINE_PARAMETER_S) { if (cisnan(iat)) return 1; // this error should be already reported somewhere else, let's just handle it return interpolate2d(iat, config->iatFuelCorrBins, config->iatFuelCorr, IAT_CURVE_SIZE); diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index e2832d6bfc..3755a218b5 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -28,10 +28,10 @@ floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F); int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); angle_t getinjectionOffset(float rpm DECLARE_ENGINE_PARAMETER_S); -float getIatCorrection(float iat DECLARE_ENGINE_PARAMETER_S); +float getIatFuelCorrection(float iat DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_S); -float getCltFuelCorrection(float clt DECLARE_ENGINE_PARAMETER_S); -angle_t getCltTimingCorrection(float clt DECLARE_ENGINE_PARAMETER_S); +float getCltFuelCorrection(DECLARE_ENGINE_PARAMETER_F); +angle_t getCltTimingCorrection(DECLARE_ENGINE_PARAMETER_F); floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_F); floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_S); floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S); diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index de8666230a..1a95b4f66f 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -88,10 +88,10 @@ void testFuelMap(void) { setInjectorLag(0 PASS_ENGINE_PARAMETER); assertEquals(NAN, getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F)); - float iatCorrection = getIatCorrection(-KELV PASS_ENGINE_PARAMETER); + float iatCorrection = getIatFuelCorrection(-KELV PASS_ENGINE_PARAMETER); assertEqualsM("IAT", 2, iatCorrection); engine->engineState.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_F); - float cltCorrection = getCltFuelCorrection(engine->engineState.clt PASS_ENGINE_PARAMETER); + float cltCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_F); assertEqualsM("CLT", 1, cltCorrection); float injectorLag = getInjectorLag(getVBatt(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); assertEqualsM("injectorLag", 0, injectorLag);