diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 03cad6a76c..5f3902155c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -145,6 +145,8 @@ void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { cylinderCleanupControl(PASS_ENGINE_PARAMETER_SIGNATURE); + standardAirCharge = getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE); + #if (BOARD_TLE8888_COUNT > 0) if (CONFIG(useTLE8888_cranking_hack) && ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE)) { efitick_t nowNt = getTimeNowNt(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 88238e2473..dabc4526be 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -216,6 +216,9 @@ public: */ floatms_t actualLastInjection = 0; + // Standard cylinder air charge - 100% VE at standard temperature, grams per cylinder + float standardAirCharge = 0; + void periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); void periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); void updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 0561c5c1e0..4c13d6d1a0 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -163,11 +163,9 @@ float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { float halfCylCount = CONFIG(specs.cylindersCount) / 2.0f; float cylinderAirmass = airPerRevolution / halfCylCount; - - //Calculation of 100% VE air mass in g/rev - 1 cylinder filling at 1.2929g/L - float StandardAirCharge = CONFIG(specs.displacement) / CONFIG(specs.cylindersCount) * 1.2929; + //Create % load for fuel table using relative naturally aspiratedcylinder filling - float airChargeLoad = 100 * cylinderAirmass/StandardAirCharge; + float airChargeLoad = 100 * cylinderAirmass / ENGINE(standardAirCharge); //Correct air mass by VE table float corrCylAirmass = cylinderAirmass * veMap.getValue(rpm, airChargeLoad) / 100; @@ -452,6 +450,15 @@ floatms_t getCrankingFuel(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return getCrankingFuel3(Sensor::get(SensorType::Clt).value_or(20), engine->rpmCalculator.getRevolutionCounterSinceStart() PASS_ENGINE_PARAMETER_SUFFIX); } + +float getStandardAirCharge(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + float totalDisplacement = CONFIG(specs.displacement); + float cylDisplacement = totalDisplacement / CONFIG(specs.cylindersCount); + + // Calculation of 100% VE air mass in g/cyl - 1 cylinder filling at 1.204/L - air density at 20C + return cylDisplacement * 1.204f; +} + #endif float getFuelRate(floatms_t totalInjDuration, efitick_t timePeriod DECLARE_ENGINE_PARAMETER_SUFFIX) { diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index 2680a94be3..6fe04eb355 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -37,5 +37,7 @@ floatms_t getCrankingFuel3(float coolantTemperature, uint32_t revolutionCounterS floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX); +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); diff --git a/unit_tests/tests/test_fuel_math.cpp b/unit_tests/tests/test_fuel_math.cpp new file mode 100644 index 0000000000..4b2da7e964 --- /dev/null +++ b/unit_tests/tests/test_fuel_math.cpp @@ -0,0 +1,31 @@ +#include "engine_test_helper.h" +#include "fuel_math.h" + +#include "gtest/gtest.h" + +TEST(FuelMath, getStandardAirCharge) { + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + + // Miata 1839cc 4cyl + CONFIG(specs.displacement) = 1.839f; + CONFIG(specs.cylindersCount) = 4; + + EXPECT_FLOAT_EQ(0.553539f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE)); + + // LS 5.3 liter v8 + CONFIG(specs.displacement) = 5.327f; + CONFIG(specs.cylindersCount) = 8; + + EXPECT_FLOAT_EQ(0.80171353f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE)); + + // Chainsaw - single cylinder 32cc + CONFIG(specs.displacement) = 0.032f; + CONFIG(specs.cylindersCount) = 1; + EXPECT_FLOAT_EQ(0.038528003, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE)); + + // Leopard 1 47.666 liter v12 + CONFIG(specs.displacement) = 47.666f; + CONFIG(specs.cylindersCount) = 12; + + EXPECT_FLOAT_EQ(4.782489f, getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE)); +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index b48dfb3882..847a45cb59 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -50,4 +50,5 @@ TESTS_SRC_CPP = \ tests/sensor/test_sensor_init.cpp \ tests/test_closed_loop_controller.cpp \ tests/test_gppwm.cpp \ + tests/test_fuel_math.cpp \