fuel math simplifications (#1485)
* simplify * fix * tweak * cleaning Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
d45e97c550
commit
531f1c63c7
|
@ -303,7 +303,7 @@ static void showFuelInfo2(float rpm, float engineLoad) {
|
|||
|
||||
#if EFI_ENGINE_CONTROL
|
||||
scheduleMsg(&logger, "base cranking fuel %.2f", engineConfiguration->cranking.baseFuel);
|
||||
scheduleMsg(&logger2, "cranking fuel: %.2f", getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE));
|
||||
scheduleMsg(&logger2, "cranking fuel: %.2f", ENGINE(engineState.cranking.fuel));
|
||||
|
||||
if (!engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||
float iatCorrection = engine->engineState.running.intakeTemperatureCoefficient;
|
||||
|
@ -696,7 +696,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
|||
tsOutputChannels->ignitionAdvance = timing > 360 ? timing - 720 : timing;
|
||||
// 60
|
||||
tsOutputChannels->sparkDwell = ENGINE(engineState.sparkDwell);
|
||||
tsOutputChannels->crankingFuelMs = engine->isCylinderCleanupMode ? 0 : getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
tsOutputChannels->crankingFuelMs = ENGINE(engineState.cranking.fuel);
|
||||
tsOutputChannels->chargeAirMass = engine->engineState.sd.airMassInOneCylinder;
|
||||
|
||||
tsOutputChannels->coilDutyCycle = getCoilDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
|
|
@ -504,12 +504,6 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
#endif
|
||||
|
||||
engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
#if EFI_ENGINE_CONTROL
|
||||
int rpm = GET_RPM();
|
||||
|
||||
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif
|
||||
}
|
||||
|
||||
void doScheduleStopEngine(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
|
|
|
@ -205,7 +205,9 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
} else {
|
||||
baseTableFuel = getBaseTableFuel(rpm, engineLoad);
|
||||
}
|
||||
#endif
|
||||
|
||||
ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif // EFI_ENGINE_CONTROL
|
||||
}
|
||||
|
||||
void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
|
|
|
@ -50,12 +50,14 @@ DISPLAY(DISPLAY_FIELD(dwellAngle))
|
|||
DISPLAY(DISPLAY_FIELD(cltTimingCorrection))
|
||||
DISPLAY_TEXT(eol);
|
||||
|
||||
DISPLAY(DISPLAY_IF(isCrankingState)) floatms_t getCrankingFuel3(float coolantTemperature,
|
||||
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;
|
||||
if (engineConfiguration->useRunningMathForCranking) {
|
||||
baseCrankingFuel = engine->engineState.running.baseFuel;
|
||||
baseCrankingFuel = baseFuel;
|
||||
} else {
|
||||
baseCrankingFuel = engineConfiguration->cranking.baseFuel;
|
||||
}
|
||||
|
@ -290,6 +292,14 @@ percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
return 100 * totalInjectiorAmountPerCycle / engineCycleDuration;
|
||||
}
|
||||
|
||||
static floatms_t getFuel(bool isCranking, floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
if (isCranking) {
|
||||
return getCrankingFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
} else {
|
||||
return getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Length of each individual fuel injection, in milliseconds
|
||||
* in case of single point injection mode the amount of fuel into all cylinders, otherwise the amount for one cylinder
|
||||
|
@ -307,19 +317,13 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
warning(CUSTOM_CONFIG_NOT_READY, "config not ready");
|
||||
return 0; // we can end up here during configuration reset
|
||||
}
|
||||
floatms_t fuelPerCycle;
|
||||
if (isCranking) {
|
||||
fuelPerCycle = getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(fuelPerCycle), "NaN cranking fuelPerCycle", 0);
|
||||
} else {
|
||||
floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
fuelPerCycle = getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(fuelPerCycle), "NaN fuelPerCycle", 0);
|
||||
#if EFI_PRINTF_FUEL_DETAILS
|
||||
printf("baseFuel=%.2f fuelPerCycle=%.2f \t\n",
|
||||
baseFuel, fuelPerCycle);
|
||||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
||||
}
|
||||
|
||||
// Always update base fuel - some cranking modes use it
|
||||
floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
floatms_t fuelPerCycle = getFuel(isCranking, baseFuel PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(fuelPerCycle), "NaN fuelPerCycle", 0);
|
||||
|
||||
if (mode == IM_SINGLE_POINT) {
|
||||
// here we convert per-cylinder fuel amount into total engine amount since the single injector serves all cylinders
|
||||
fuelPerCycle *= engineConfiguration->specs.cylindersCount;
|
||||
|
@ -484,8 +488,8 @@ float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
/**
|
||||
* @return Duration of fuel injection while craning
|
||||
*/
|
||||
floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return getCrankingFuel3(Sensor::get(SensorType::Clt).value_or(20),
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|||
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(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterSinceStart DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
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 getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
|
|
|
@ -112,13 +112,13 @@ TEST(misc, testFuelMap) {
|
|||
|
||||
engineConfiguration->cranking.baseFuel = 4;
|
||||
|
||||
printf("*************************************************** getStartingFuel\r\n");
|
||||
// NAN in case we have issues with the CLT sensor
|
||||
ASSERT_EQ( 6.0, getCrankingFuel3(NAN, 0 PASS_ENGINE_PARAMETER_SUFFIX)) << "getStartingFuel nan";
|
||||
assertEqualsM("getStartingFuel#1", 11.6, getCrankingFuel3(0, 4 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
assertEqualsM("getStartingFuel#2", 5.82120, getCrankingFuel3(8, 15 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
assertEqualsM("getStartingFuel#3", 6.000, getCrankingFuel3(70, 0 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
assertEqualsM("getStartingFuel#4", 2.41379, getCrankingFuel3(70, 50 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
EXPECT_NEAR( 6.0, getCrankingFuel3(2, NAN, 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue