fix double deadtime (#1904)

* move global correction factor to fuel mass

* tests

* the fix
This commit is contained in:
Matthew Kennedy 2020-10-24 21:12:05 -07:00 committed by GitHub
parent 15363e9a41
commit f37ed597c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 27 deletions

View File

@ -205,9 +205,16 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
float baseFuelMass = ENGINE(fuelComputer)->getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent);
// Fudge it by the global correction factor
baseFuelMass *= CONFIG(globalFuelCorrection);
ENGINE(injectorModel)->prepare();
float baseFuel = ENGINE(injectorModel)->getInjectionDuration(baseFuelMass);
// Ugh, there's a bug that means we have to cancel out the deadtime.
// See https://github.com/rusefi/rusefi/issues/1903
baseFuel -= engine->engineState.running.injectorLag;
if (cisnan(baseFuel)) {
// todo: we should not have this here but https://github.com/rusefi/rusefi/issues/1690
return 0;
@ -330,7 +337,7 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
warning(CUSTOM_ERR_INJECTOR_LAG, "injectorLag not ready");
return 0; // we can end up here during configuration reset
}
return theoreticalInjectionLength * engineConfiguration->globalFuelCorrection + injectorLag;
return theoreticalInjectionLength + injectorLag;
#else
return 0;
#endif

View File

@ -138,3 +138,51 @@ TEST(AirmassModes, VeOverride) {
dut.getAirmass(0);
EXPECT_FLOAT_EQ(ENGINE(engineState.currentVeLoad), 30.0f);
}
void setInjectionMode(int value DECLARE_ENGINE_PARAMETER_SUFFIX);
extern WarningCodeState unitTestWarningCodeState;
TEST(FuelMath, testDifferentInjectionModes) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1.3440001f, 50.0f}));
setInjectionMode((int)IM_BATCH PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 20, engine->injectionDuration) << "injection while batch";
setInjectionMode((int)IM_SIMULTANEOUS PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 10, engine->injectionDuration) << "injection while simultaneous";
setInjectionMode((int)IM_SEQUENTIAL PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 40, engine->injectionDuration) << "injection while IM_SEQUENTIAL";
setInjectionMode((int)IM_SINGLE_POINT PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 40, engine->injectionDuration) << "injection while IM_SINGLE_POINT";
EXPECT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testDifferentInjectionModes";
}
TEST(FuelMath, deadtime) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1.3440001f, 50.0f}));
// First test with no deadtime
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 20, engine->injectionDuration);
// Now add some deadtime
setArrayValues(engineConfiguration->injector.battLagCorr, 2.0f);
// Should have deadtime now!
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 20 + 2, engine->injectionDuration);
}

View File

@ -921,7 +921,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0));
}
static void setInjectionMode(int value DECLARE_ENGINE_PARAMETER_SUFFIX) {
void setInjectionMode(int value DECLARE_ENGINE_PARAMETER_SUFFIX) {
engineConfiguration->injectionMode = (injection_mode_e) value;
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
}
@ -986,31 +986,6 @@ TEST(big, testSequential) {
assertInjectionEvent("inj#3@", &t->elements[3], 1, 0, 126 + 180); // Cyl 2
}
TEST(big, testDifferentInjectionModes) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{1.3440001f, 50.0f}));
setInjectionMode((int)IM_BATCH PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 20, engine->injectionDuration) << "injection while batch";
setInjectionMode((int)IM_SIMULTANEOUS PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 10, engine->injectionDuration) << "injection while simultaneous";
setInjectionMode((int)IM_SEQUENTIAL PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 40, engine->injectionDuration) << "injection while IM_SEQUENTIAL";
setInjectionMode((int)IM_SINGLE_POINT PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
EXPECT_FLOAT_EQ( 40, engine->injectionDuration) << "injection while IM_SINGLE_POINT";
EXPECT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testDifferentInjectionModes";
}
TEST(big, testFuelSchedulerBug299smallAndLarge) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
setTestBug299(&eth);