From 132ee12974945ac02ec972fa7a7e20950e5179f2 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 30 Jul 2020 21:20:10 -0700 Subject: [PATCH] cleanup --- firmware/console/status_loop.cpp | 2 +- firmware/controllers/algo/fuel_math.cpp | 64 ++++--------------- firmware/controllers/algo/fuel_math.h | 1 - firmware/development/rfi_perftest.cpp | 2 - unit_tests/tests/test_fuel_map.cpp | 21 ++---- .../tests/trigger/test_trigger_decoder.cpp | 2 +- 6 files changed, 20 insertions(+), 72 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a335f20fa0..4b31b16f22 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -286,7 +286,7 @@ void updateDevConsoleState(void) { static void showFuelInfo2(float rpm, float engineLoad) { - float baseFuelMs = getBaseTableFuel((int) rpm, engineLoad); + float baseFuelMs = 0; // TODO float magicAir = SpeedDensityBase::getAirmassImpl(1, 100, convertCelsiusToKelvin(20) PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 7d60e77ea0..31ee2105d8 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -197,39 +197,24 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { efiAssert(CUSTOM_ERR_ASSERT, !cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0); ENGINE(engineState.tpsAccelEnrich) = tpsAccelEnrich; - floatms_t baseFuel; + // airmass modes - get airmass first, then convert to fuel + auto model = getAirmassModel(PASS_ENGINE_PARAMETER_SIGNATURE); + efiAssert(CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f); - if ((CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) || - (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) || - (engineConfiguration->fuelAlgorithm == LM_ALPHA_N_2) || - (engineConfiguration->fuelAlgorithm == LM_MOCK)) { - // airmass modes - get airmass first, then convert to fuel - auto model = getAirmassModel(PASS_ENGINE_PARAMETER_SIGNATURE); - efiAssert(CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f); + auto airmass = model->getAirmass(rpm); - auto airmass = model->getAirmass(rpm); + // The airmass mode will tell us how to look up AFR - use the provided Y axis value + float targetAfr = afrMap.getValue(rpm, airmass.EngineLoadPercent); - // The airmass mode will tell us how to look up AFR - use the provided Y axis value - float targetAfr = afrMap.getValue(rpm, airmass.EngineLoadPercent); + // Plop some state for others to read + ENGINE(engineState.targetAFR) = targetAfr; + ENGINE(engineState.sd.airMassInOneCylinder) = airmass.CylinderAirmass; + ENGINE(engineState.fuelingLoad) = airmass.EngineLoadPercent; + // TODO: independently selectable ignition load mode + ENGINE(engineState.ignitionLoad) = airmass.EngineLoadPercent; - // Plop some state for others to read - ENGINE(engineState.targetAFR) = targetAfr; - ENGINE(engineState.sd.airMassInOneCylinder) = airmass.CylinderAirmass; - ENGINE(engineState.fuelingLoad) = airmass.EngineLoadPercent; - // TODO: independently selectable ignition load mode - ENGINE(engineState.ignitionLoad) = airmass.EngineLoadPercent; - - baseFuel = getInjectionDurationForAirmass(airmass.CylinderAirmass, targetAfr PASS_ENGINE_PARAMETER_SUFFIX) * 1000; - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN baseFuel", 0); - } else { - float tps = Sensor::get(SensorType::Tps1).value_or(0); - ENGINE(engineState.fuelingLoad) = tps; - // TODO: independently selectable ignition load mode - ENGINE(engineState.ignitionLoad) = tps; - - baseFuel = getBaseTableFuel(rpm, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN bt baseFuel", 0); - } + float baseFuel = getInjectionDurationForAirmass(airmass.CylinderAirmass, targetAfr PASS_ENGINE_PARAMETER_SUFFIX) * 1000; + efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN baseFuel", 0); engine->engineState.baseFuel = baseFuel; @@ -446,27 +431,6 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_ return fuelCorr; } -/** - * @return Fuel injection duration injection as specified in the fuel map, in milliseconds - */ -floatms_t getBaseTableFuel(int rpm, float engineLoad) { -#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT - if (cisnan(engineLoad)) { - warning(CUSTOM_NAN_ENGINE_LOAD_2, "NaN engine load"); - return 0; - } - floatms_t result = fuelMap.getValue(rpm, engineLoad); - if (cisnan(result)) { - // result could be NaN in case of invalid table, like during initialization - result = 0; - warning(CUSTOM_ERR_FUEL_TABLE_NOT_READY, "baseFuel table not ready"); - } - return result; -#else - return 0; -#endif -} - float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (hasBaroSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { float correction = baroCorrMap.getValue(GET_RPM(), getBaroPressure(PASS_ENGINE_PARAMETER_SIGNATURE)); diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index 28a88787a5..d39f226229 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -22,7 +22,6 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); */ floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_SUFFIX); -floatms_t getBaseTableFuel(int rpm, float engineLoad); float getBaroCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE); int getNumberOfInjections(injection_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX); angle_t getInjectionOffset(float rpm, float load DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/development/rfi_perftest.cpp b/firmware/development/rfi_perftest.cpp index e63baecb47..648a31346a 100644 --- a/firmware/development/rfi_perftest.cpp +++ b/firmware/development/rfi_perftest.cpp @@ -75,8 +75,6 @@ static void testRusefiMethods(const int count) { start = currentTimeMillis(); - for (int i = 0; i < count; i++) - tempi += getBaseTableFuel(testEngine.engineConfiguration, 4020, 2.21111); time = currentTimeMillis() - start; if (tempi != 0) scheduleMsg(logger, "Finished %d iterations of getBaseFuel in %dms", count, time); diff --git a/unit_tests/tests/test_fuel_map.cpp b/unit_tests/tests/test_fuel_map.cpp index 14dbbcb386..1a6c63de95 100644 --- a/unit_tests/tests/test_fuel_map.cpp +++ b/unit_tests/tests/test_fuel_map.cpp @@ -21,23 +21,8 @@ using ::testing::FloatNear; TEST(misc, testFuelMap) { printf("Setting up FORD_ASPIRE_1996\r\n"); WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996); - engineConfiguration->fuelAlgorithm = LM_PLAIN_MAF; - - printf("Filling fuel map\r\n"); - for (int k = 0; k < FUEL_LOAD_COUNT; k++) { - for (int r = 0; r < FUEL_RPM_COUNT; r++) { - eth.engine.config->fuelTable[k][r] = k * 200 + r; - } - } - for (int i = 0; i < FUEL_LOAD_COUNT; i++) - eth.engine.config->fuelLoadBins[i] = i; - for (int i = 0; i < FUEL_RPM_COUNT; i++) - eth.engine.config->fuelRpmBins[i] = i; - - ASSERT_EQ( 1005, getBaseTableFuel(5, 5)) << "base fuel table"; printf("*** getInjectorLag\r\n"); -// engine->engineState.vb assertEqualsM("lag", 1.04, getInjectorLag(12 PASS_ENGINE_PARAMETER_SUFFIX)); for (int i = 0; i < VBAT_INJECTOR_CURVE_SIZE; i++) { @@ -53,7 +38,8 @@ TEST(misc, testFuelMap) { // because all the correction tables are zero printf("*************************************************** getRunningFuel 1\r\n"); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); - float baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); + //float baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); + float baseFuel = 1234; ASSERT_NEAR(5.3679, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER_SUFFIX), EPS4D) << "base fuel"; printf("*************************************************** setting IAT table\r\n"); @@ -88,7 +74,8 @@ TEST(misc, testFuelMap) { // 1005 * 2 for IAT correction printf("*************************************************** getRunningFuel 2\r\n"); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); - baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); + //baseFuel = getBaseTableFuel(5, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); + baseFuel = 1234; EXPECT_EQ(baseFuel, 1005); // Check that runningFuel corrects appropriately diff --git a/unit_tests/tests/trigger/test_trigger_decoder.cpp b/unit_tests/tests/trigger/test_trigger_decoder.cpp index 5aa73cccec..d6b7ebce32 100644 --- a/unit_tests/tests/trigger/test_trigger_decoder.cpp +++ b/unit_tests/tests/trigger/test_trigger_decoder.cpp @@ -592,7 +592,7 @@ static void assertInjectionEventBatch(const char *msg, InjectionEvent *ev, int i static void setTestBug299(EngineTestHelper *eth) { // TODO: switch to mock airmass - eth->persistentConfig.engineConfiguration.fuelAlgorithm = LM_PLAIN_MAF; + //eth->persistentConfig.engineConfiguration.fuelAlgorithm = LM_PLAIN_MAF; setupSimpleTestEngineWithMafAndTT_ONE_trigger(eth); Engine *engine = ð->engine; EXPAND_Engine