From 1f64754b57b00ee45ba24e509730a6bf6400edb4 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 10 Aug 2020 21:41:03 -0700 Subject: [PATCH] consume --- firmware/console/status_loop.cpp | 1 - firmware/controllers/algo/fuel_math.cpp | 14 +++++----- firmware/controllers/algo/fuel_math.h | 1 - unit_tests/tests/test_speed_density.cpp | 34 ------------------------- unit_tests/tests/tests.mk | 1 - 5 files changed, 7 insertions(+), 44 deletions(-) delete mode 100644 unit_tests/tests/test_speed_density.cpp diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a085b1cb32..064f7cb2f5 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -290,7 +290,6 @@ static void showFuelInfo2(float rpm, float engineLoad) { float magicAir = SpeedDensityBase::getAirmassImpl(1, 100, convertCelsiusToKelvin(20) PASS_ENGINE_PARAMETER_SUFFIX); - scheduleMsg(&logger, "SD magic fuel %.2f", getInjectionDurationForAirmass(magicAir, 14.7 PASS_ENGINE_PARAMETER_SUFFIX)); scheduleMsg(&logger, "inj flow %.2fcc/min displacement %.2fL", engineConfiguration->injector.flow, engineConfiguration->specs.displacement); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 06d01fc034..bccd9f01b7 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -27,6 +27,7 @@ #include "maf_airmass.h" #include "speed_density_airmass.h" #include "fuel_math.h" +#include "fuel_computer.h" #include "interpolation.h" #include "engine_configuration.h" #include "allsensors.h" @@ -163,10 +164,10 @@ constexpr float convertToGramsPerSecond(float ccPerMinute) { /** * @return per cylinder injection time, in seconds */ -float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PARAMETER_SUFFIX) { +static float getInjectionDurationForFuelMass(float fuelMass DECLARE_ENGINE_PARAMETER_SUFFIX) { float gPerSec = convertToGramsPerSecond(CONFIG(injector.flow)); - return airMass / (afr * gPerSec); + return fuelMass / gPerSec; } static SpeedDensityAirmass sdAirmass(veMap); @@ -185,6 +186,8 @@ AirmassModelBase* getAirmassModel(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } } +static FuelComputer fuelComputer(afrMap); + /** * per-cylinder fuel amount * todo: rename this method since it's now base+TPSaccel @@ -202,17 +205,14 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { 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); - // 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; - float baseFuel = getInjectionDurationForAirmass(airmass.CylinderAirmass, targetAfr PASS_ENGINE_PARAMETER_SUFFIX) * 1000; + float baseFuelMass = fuelComputer.getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent); + float baseFuel = getInjectionDurationForFuelMass(baseFuelMass PASS_ENGINE_PARAMETER_SUFFIX) * 1000; efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN baseFuel", 0); engine->engineState.baseFuel = baseFuel; diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index d39f226229..e424369a41 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -39,4 +39,3 @@ float getStandardAirCharge(DECLARE_ENGINE_PARAMETER_SIGNATURE); // convert injection duration (Ms/Nt) to fuel rate (L/h) float getFuelRate(floatms_t totalInjDuration, efitick_t timePeriod DECLARE_ENGINE_PARAMETER_SUFFIX); -float getInjectionDurationForAirmass(float airMass, float afr DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/tests/test_speed_density.cpp b/unit_tests/tests/test_speed_density.cpp deleted file mode 100644 index a212a93bb2..0000000000 --- a/unit_tests/tests/test_speed_density.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @file test_speed_density.cpp - * - * @date Jun 26, 2014 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "engine_test_helper.h" -#include "speed_density.h" -#include "fuel_math.h" - -TEST(big, testSpeedDensity) { - printf("*************************************************** testSpeedDensity\r\n"); - WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995); - - engineConfiguration->trigger.customTotalToothCount = 8; - eth.applyTriggerWaveform(); - - eth.fireTriggerEvents(36); - ASSERT_EQ( 1500, GET_RPM()) << "RPM"; - - // 427 cubic inches, that's a LOT of engine - engineConfiguration->specs.displacement = 6.99728; - engineConfiguration->specs.cylindersCount = 8; - - engineConfiguration->injector.flow = gramm_second_to_cc_minute(5.303); - - float airMass = SpeedDensityBase::getAirmassImpl(0.92, 98, 293.16 PASS_ENGINE_PARAMETER_SUFFIX); - - ASSERT_FLOAT_EQ(0.9371106624, airMass); - - // 0.01414 sec or 14.14 ms - EXPECT_NEAR(0.014137, getInjectionDurationForAirmass(airMass, 12.5 PASS_ENGINE_PARAMETER_SUFFIX), EPS4D); -} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 2051f8fc50..bac33b4443 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -29,7 +29,6 @@ TESTS_SRC_CPP = \ tests/test_one_cylinder_logic.cpp \ tests/test_pwm_generator.cpp \ tests/test_logic_expression.cpp \ - tests/test_speed_density.cpp \ tests/test_signal_executor.cpp \ tests/test_cpp_memory_layout.cpp \ tests/test_sensors.cpp \