From d4974a783d4a295b0a8b551ca8d7ae289741ff5d Mon Sep 17 00:00:00 2001 From: andreika-git Date: Fri, 3 Nov 2017 00:10:42 +0200 Subject: [PATCH] Implement postCrankingFuelCorrection (#485) --- firmware/controllers/algo/engine.cpp | 13 +++++++++++++ firmware/controllers/algo/fuel_math.cpp | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index dad408d54e..11aea26003 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -193,6 +193,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { efitick_t nowNt = getTimeNowNt(); if (ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE)) { crankingTime = nowNt; + timeSinceCranking = 0.0f; } else { timeSinceCranking = nowNt - crankingTime; } @@ -223,6 +224,18 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { cltFuelCorrection = getCltFuelCorrection(PASS_ENGINE_PARAMETER_SIGNATURE); } + // post-cranking fuel enrichment. + // for compatibility reasons, apply only if the factor is greater than zero (0.01 margin used) + if (engineConfiguration->postCrankingFactor > 0.01f) { + // convert to microsecs and then to seconds + float timeSinceCrankingInSecs = NT2US(timeSinceCranking) / 1000000.0f; + // use interpolation for correction taper + postCrankingFuelCorrection = interpolateClamped(0.0f, engineConfiguration->postCrankingFactor, + engineConfiguration->postCrankingDurationSec, 1.0f, timeSinceCrankingInSecs); + } else { + postCrankingFuelCorrection = 1.0f; + } + cltTimingCorrection = getCltTimingCorrection(PASS_ENGINE_PARAMETER_SIGNATURE); engineNoiseHipLevel = interpolate2d("knock", rpm, engineConfiguration->knockNoiseRpmBins, diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 5af437dd31..db6e0740f5 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -164,10 +164,12 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) { float iatCorrection = ENGINE(engineState.iatFuelCorrection); float cltCorrection = ENGINE(engineState.cltFuelCorrection); + float postCrankingFuelCorrection = ENGINE(engineState.postCrankingFuelCorrection); efiAssert(!cisnan(iatCorrection), "NaN iatCorrection", 0); efiAssert(!cisnan(cltCorrection), "NaN cltCorrection", 0); + efiAssert(!cisnan(postCrankingFuelCorrection), "NaN postCrankingFuelCorrection", 0); - floatms_t runningFuel = baseFuel * iatCorrection * cltCorrection + ENGINE(engineState.fuelPidCorrection); + floatms_t runningFuel = baseFuel * iatCorrection * cltCorrection * postCrankingFuelCorrection + ENGINE(engineState.fuelPidCorrection); efiAssert(!cisnan(runningFuel), "NaN runningFuel", 0); ENGINE(engineState.runningFuel) = runningFuel;