From 66d7c2bd5dee83a185af5d51800c0a797de2e819 Mon Sep 17 00:00:00 2001 From: andreika-git Date: Tue, 23 Jan 2018 06:47:58 +0200 Subject: [PATCH] Fix advance corrections for cranking (#547) --- firmware/controllers/algo/advance_map.cpp | 40 ++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index cf24a5e3cb..e46dc74fb8 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -83,6 +83,21 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME return engineConfiguration->step1timing; } + float advanceAngle = advanceMap.getValue((float) rpm, engineLoad); + + // get advance from the separate table for Idle + if (CONFIG(useSeparateAdvanceForIdle)) { + float idleAdvance = interpolate2d("idleAdvance", rpm, config->idleAdvanceBins, config->idleAdvance, IDLE_ADVANCE_CURVE_SIZE); + // interpolate between idle table and normal (running) table using TPS threshold + float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); + advanceAngle = interpolateClamped(0.0f, idleAdvance, boardConfiguration->idlePidDeactivationTpsThreshold, advanceAngle, tps); + } + + engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance; + return advanceAngle; +} + +static angle_t getAdvanceCorrections(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { float iatCorrection; if (cisnan(engine->sensors.iat)) { iatCorrection = 0; @@ -96,26 +111,12 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME tsOutputChannels.debugFloatField3 = engine->fsioTimingAdjustment; #endif } - - float advanceAngle = advanceMap.getValue((float) rpm, engineLoad); - // get advance from the separate table for Idle - if (CONFIG(useSeparateAdvanceForIdle)) { - float idleAdvance = interpolate2d("idleAdvance", rpm, config->idleAdvanceBins, config->idleAdvance, IDLE_ADVANCE_CURVE_SIZE); - // interpolate between idle table and normal (running) table using TPS threshold - float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); - advanceAngle = interpolateClamped(0.0f, idleAdvance, boardConfiguration->idlePidDeactivationTpsThreshold, advanceAngle, tps); - } - - float result = advanceAngle - + iatCorrection - + engine->fsioTimingAdjustment - + engine->engineState.cltTimingCorrection - // todo: uncomment once we get useable knock - engine->knockCount - ; - - engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance; - return result; + return iatCorrection + + engine->fsioTimingAdjustment + + engine->engineState.cltTimingCorrection + // todo: uncomment once we get useable knock - engine->knockCount + ; } angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -133,6 +134,7 @@ angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) { } else { angle = getRunningAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER_SUFFIX); } + angle += getAdvanceCorrections(rpm PASS_ENGINE_PARAMETER_SUFFIX); angle -= engineConfiguration->ignitionOffset; fixAngle(angle, "getAdvance"); return angle;