diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 879a7979b3..98f84a32cb 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -45,10 +45,35 @@ EXTERN_ENGINE; static Map3D1616 fuelMap; static Map3D1616 fuelPhaseMap; +extern Map3D1616 ve2Map; +extern Map3D1616 afrMap; + +/** + * @return total duration of fuel injection per engine cycle, in milliseconds + */ +float getRealMafFuel(float airSpeed, int rpm DECLARE_ENGINE_PARAMETER_S) { + // duration of engine cycle, in hours + float engineCycleDurationHr = 1.0 / 60 / rpm; + + float airMassKg = airSpeed * engineCycleDurationHr; + + /** + * todo: pre-calculate gramm/second injector flow to save one multiplication + * open question if that's needed since that's just a multiplication + */ + float injectorFlowRate = cc_minute_to_gramm_second(engineConfiguration->injector.flow); + + float afr = afrMap.getValue(airSpeed, rpm); + float fuelMassGramm = airMassKg / afr * 1000; + + return 1000 * fuelMassGramm / injectorFlowRate; +} float getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S) { if (engine->engineConfiguration->algorithm == LM_SPEED_DENSITY) { return getSpeedDensityFuel(engine, rpm); + } else if (engine->engineConfiguration->algorithm == LM_REAL_MAF) { + return getRealMafFuel(getRealMaf(PASS_ENGINE_PARAMETER_F), rpm PASS_ENGINE_PARAMETER); } else { float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F); return getBaseTableFuel(engine->engineConfiguration, rpm, engineLoad); diff --git a/firmware/controllers/algo/fuel_math.h b/firmware/controllers/algo/fuel_math.h index ad0c9be784..5eae9d78c0 100644 --- a/firmware/controllers/algo/fuel_math.h +++ b/firmware/controllers/algo/fuel_math.h @@ -12,6 +12,7 @@ void prepareFuelMap(engine_configuration_s *engineConfiguration); +float getRealMafFuel(float airMass, int rpm DECLARE_ENGINE_PARAMETER_S); float getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S); float getInjectionAngle(int rpm DECLARE_ENGINE_PARAMETER_S); float getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float engineLoad); diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index a2b9a319fc..f3556bb302 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -23,7 +23,8 @@ #define rpmMax 8000 static Map3D1616 veMap; -static Map3D1616 afrMap; +Map3D1616 ve2Map; +Map3D1616 afrMap; #define tpMin 0 #define tpMax 100 @@ -94,16 +95,19 @@ float getSpeedDensityFuel(Engine *engine, int rpm) { void setDetaultVETable(engine_configuration_s *engineConfiguration) { setRpmTableBin(engineConfiguration->veRpmBins, FUEL_RPM_COUNT); setTableBin2(engineConfiguration->veLoadBins, FUEL_LOAD_COUNT, 10, 300, 1); + veMap.setAll(0.8); + + setRpmTableBin(engineConfiguration->ve2RpmBins, FUEL_RPM_COUNT); + setTableBin2(engineConfiguration->ve2LoadBins, FUEL_LOAD_COUNT, 10, 300, 1); + ve2Map.setAll(0.8); setRpmTableBin(engineConfiguration->afrRpmBins, FUEL_RPM_COUNT); setTableBin2(engineConfiguration->afrLoadBins, FUEL_LOAD_COUNT, 10, 300, 1); - - veMap.setAll(0.8); afrMap.setAll(14.7); } void initSpeedDensity(engine_configuration_s *e) { veMap.init(e->veTable, e->veLoadBins, e->veRpmBins); - veMap.init(e->ve2Table, e->ve2LoadBins, e->ve2RpmBins); + ve2Map.init(e->ve2Table, e->ve2LoadBins, e->ve2RpmBins); afrMap.init(e->afrTable, e->afrLoadBins, e->afrRpmBins); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 0fd852725b..6bcaff2209 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -258,5 +258,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE == 0) return 1; // this is here to make the compiler happy about the unused array - return 20150212; + return 20150213; } diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 1f3005cef4..019f2b91ff 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -143,9 +143,10 @@ int main(void) { testMenuTree(); testMafLookup(); + testMafFuelMath(); // resizeMap(); - printf("Success 20150207\r\n"); + printf("Success 20150213\r\n"); return EXIT_SUCCESS; } diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 1f1772069c..415b58a0e6 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -18,6 +18,23 @@ extern float testMafValue; +void testMafFuelMath(void) { + printf("*************************************************** testMafFuelMath\r\n"); + EngineTestHelper eth(FORD_ASPIRE_1996); + + Engine *engine = ð.engine; + engine_configuration_s *engineConfiguration = engine->engineConfiguration; + + engineConfiguration->algorithm = LM_REAL_MAF; + + engineConfiguration->injector.flow = 200; + + setMap(engineConfiguration->afrTable, 13); + + float fuelMs = getRealMafFuel(300, 6000 PASS_ENGINE_PARAMETER); + assertEquals(26.7099, fuelMs); +} + void testFuelMap(void) { printf("*************************************************** testFuelMap\r\n"); diff --git a/unit_tests/test_fuel_map.h b/unit_tests/test_fuel_map.h index 331c753274..6de5fe6866 100644 --- a/unit_tests/test_fuel_map.h +++ b/unit_tests/test_fuel_map.h @@ -8,17 +8,9 @@ #ifndef TEST_FUEL_MAP_H_ #define TEST_FUEL_MAP_H_ -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - void testFuelMap(void); +void testMafFuelMath(void); void testAngleResolver(void); void testPinHelper(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* TEST_FUEL_MAP_H_ */