diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 74412e4953..cf36edd77c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -62,8 +62,7 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_F) { isEngineChartEnabled = CONFIG(isEngineChartEnabled) && rpm < CONFIG(engineSnifferRpmThreshold); sensorChartMode = rpm < CONFIG(sensorSnifferRpmThreshold) ? boardConfiguration->sensorChartMode : SC_OFF; - engineState.iat = getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F); - engineState.clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_F); + engineState.updateSlowSensors(PASS_ENGINE_PARAMETER_F); if (engineConfiguration->fuelLevelSensor != EFI_ADC_NONE) { float fuelLevelVoltage = getVoltageDivided("fuel", engineConfiguration->fuelLevelSensor); @@ -132,6 +131,14 @@ EngineState::EngineState() { injectorLag = 0; } +void EngineState::updateSlowSensors(DECLARE_ENGINE_PARAMETER_F) { + iat = getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F); + clt = getCoolantTemperature(PASS_ENGINE_PARAMETER_F); + + warmupTargetAfr = interpolate2d(clt, engineConfiguration->warmupTargetAfrBins, + engineConfiguration->warmupTargetAfr, WARMUP_TARGET_AFR_SIZE); +} + void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { int rpm = ENGINE(rpmCalculator.rpmValue); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 9b47123d50..d28783843f 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -100,6 +100,7 @@ class EngineState { public: EngineState(); void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F); + void updateSlowSensors(DECLARE_ENGINE_PARAMETER_F); /** * Performance optimization: @@ -154,6 +155,7 @@ public: * See useWarmupPidAfr */ Pid warmupAfrPid; + float warmupTargetAfr; float baroCorrection; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 131fab107a..7ceb4d3e48 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -430,6 +430,15 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { config->crankingCycleBins[7] = 77; + engineConfiguration->warmupTargetAfrBins[0] = -12; + engineConfiguration->warmupTargetAfr[0] = 12.3; + engineConfiguration->warmupTargetAfrBins[1] = 0; + engineConfiguration->warmupTargetAfr[1] = 13; + engineConfiguration->warmupTargetAfrBins[2] = 30; + engineConfiguration->warmupTargetAfr[2] = 13.8; + engineConfiguration->warmupTargetAfrBins[3] = 60; + engineConfiguration->warmupTargetAfr[3] = 14.5; + // todo: set bins setTableValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, -30, 1350); setTableValue(engineConfiguration->cltIdleRpmBins, engineConfiguration->cltIdleRpm, CLT_CURVE_SIZE, -20, 1300); @@ -703,6 +712,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->uartConsoleSerialSpeed = 115200; engineConfiguration->warmupAfrPid.offset = 1; + engineConfiguration->warmupAfrThreshold = 60; engineConfiguration->engineLoadAccelLength = 6; engineConfiguration->engineLoadAccelEnrichmentThreshold = 5; // kPa