From 2e1d5523969b83a2a570b430275fcaa02549e208 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 13 Jan 2019 01:53:58 -0500 Subject: [PATCH] MAF2MAP convestion #538 --- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/math/speed_density.cpp | 2 ++ firmware/controllers/sensors/maf2map.cpp | 15 +++++++++-- firmware/controllers/sensors/maf2map.h | 7 ++++- firmware/controllers/sensors/sensors.mk | 1 + unit_tests/test.mk | 1 + .../tests/test_fasterEngineSpinningUp.cpp | 1 - unit_tests/tests/test_fuelCut.cpp | 1 - unit_tests/tests/test_fuel_map.cpp | 2 +- unit_tests/tests/test_maf2map.cpp | 26 +++++++++++++++++++ .../test_startOfCrankingPrimingPulse.cpp | 1 - 11 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 unit_tests/tests/test_maf2map.cpp diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 61e5b57abc..1395898f0c 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -770,7 +770,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) #endif /* EFI_PROD_CODE */ } -static char UNUSED_RAM_SIZE[10300]; +static char UNUSED_RAM_SIZE[10200]; static char UNUSED_CCM_SIZE[7100] CCM_OPTIONAL; diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 93fea4b66b..c48aa5ef4b 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -13,6 +13,7 @@ #include "rpm_calculator.h" #include "engine_math.h" #include "engine_state.h" +#include "maf2map.h" #define rpmMin 500 #define rpmMax 8000 @@ -172,4 +173,5 @@ void initSpeedDensity(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // ve2Map.init(engineConfiguration->ve2Table, engineConfiguration->ve2LoadBins, engineConfiguration->ve2RpmBins); afrMap.init(config->afrTable, config->afrLoadBins, config->afrRpmBins); baroCorrMap.init(engineConfiguration->baroCorrTable, engineConfiguration->baroCorrPressureBins, engineConfiguration->baroCorrRpmBins); + initMaf2Map(); } diff --git a/firmware/controllers/sensors/maf2map.cpp b/firmware/controllers/sensors/maf2map.cpp index e5786dc377..19975d4e51 100644 --- a/firmware/controllers/sensors/maf2map.cpp +++ b/firmware/controllers/sensors/maf2map.cpp @@ -1,11 +1,11 @@ /* * @file maf2map.cpp * - * @author Andrey Belomutskiy, (c) 2012-2018 + * @author Andrey Belomutskiy, (c) 2012-2019 * @date Jan 20, 2018 */ -#define ASIZE 16 +#include "maf2map.h" /* rpm bins */ static const float rpmBins[ASIZE] = {500.0, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0, 6500.0, 7000.0, 7500.0, 8000.0}; @@ -35,3 +35,14 @@ static const float maf2map16[ASIZE][ASIZE] = { /*v=0.230000 kpa=*/ 225.399979, /*v=0.300000 kpa=*/ 165.699997, /*v=0.400000 kpa=*/ 102.175003, /*v=0.500000 kpa=*/ 76.000000, /*v=0.600000 kpa=*/ 61.100002, /*v=0.700000 kpa=*/ 52.335297, /*v=0.800000 kpa=*/ 41.700005, /*v=1.000000 kpa=*/ 20.438889, /*v=1.100000 kpa=*/ 12.161111, /*v=1.200000 kpa=*/ 3.883333, /*v=1.500000 kpa=*/ 1.400000, /*v=2.000000 kpa=*/ 1.400000, /*v=2.500000 kpa=*/ 1.400000, /*v=3.000000 kpa=*/ 1.400000, /*v=3.500000 kpa=*/ 1.400000, /*v=4.500000 kpa=*/ 1.400000, }; +maf2map_Map3D_t maf2MapMap("maf2map"); + +void initMaf2Map() { + // RPM and load are flipped in this table, that's just the way we have data + maf2MapMap.init((float (*)[ASIZE])maf2map16, rpmBins, voltageBins); +} + +float estimateMapByRpmAndMaf(int rpm, float maf) { + // RPM and load are flipped in this table, that's just the way we have data + return maf2MapMap.getValue(maf, rpm); +} diff --git a/firmware/controllers/sensors/maf2map.h b/firmware/controllers/sensors/maf2map.h index 4d51c93aa3..511199260d 100644 --- a/firmware/controllers/sensors/maf2map.h +++ b/firmware/controllers/sensors/maf2map.h @@ -1,15 +1,20 @@ /* * @file maf2map.h * - * @author Andrey Belomutskiy, (c) 2012-2018 + * @author Andrey Belomutskiy, (c) 2012-2019 * @date Jan 20, 2018 */ #ifndef CONTROLLERS_SENSORS_MAF2MAP_H_ #define CONTROLLERS_SENSORS_MAF2MAP_H_ +#include "table_helper.h" +#define ASIZE 16 +typedef Map3D maf2map_Map3D_t; +void initMaf2Map(); +float estimateMapByRpmAndMaf(int rpm, float maf); #endif /* CONTROLLERS_SENSORS_MAF2MAP_H_ */ diff --git a/firmware/controllers/sensors/sensors.mk b/firmware/controllers/sensors/sensors.mk index dc905b7cd4..c9b4c3d1fa 100644 --- a/firmware/controllers/sensors/sensors.mk +++ b/firmware/controllers/sensors/sensors.mk @@ -8,6 +8,7 @@ CONTROLLERS_SENSORS_SRC_CPP = $(PROJECT_DIR)/controllers/sensors/thermistors.cp $(PROJECT_DIR)/controllers/sensors/maf.cpp \ $(PROJECT_DIR)/controllers/sensors/tps.cpp \ $(PROJECT_DIR)/controllers/sensors/ego.cpp \ + $(PROJECT_DIR)/controllers/sensors/maf2map.cpp \ $(PROJECT_DIR)/controllers/sensors/hip9011_lookup.cpp \ $(PROJECT_DIR)/controllers/sensors/flex_fuel.cpp \ $(PROJECT_DIR)/controllers/sensors/oil_pressure.cpp diff --git a/unit_tests/test.mk b/unit_tests/test.mk index 8c58ff38d7..a51d1f8158 100644 --- a/unit_tests/test.mk +++ b/unit_tests/test.mk @@ -16,6 +16,7 @@ TEST_SRC_CPP = unit_test_framework.cpp \ tests/test_trigger_decoder.cpp \ tests/test_trigger_noiseless.cpp \ tests/test_fuel_map.cpp \ + tests/test_maf2map.cpp \ tests/test_fuelCut.cpp \ tests/test_pwm_generator.cpp \ tests/test_logic_expression.cpp \ diff --git a/unit_tests/tests/test_fasterEngineSpinningUp.cpp b/unit_tests/tests/test_fasterEngineSpinningUp.cpp index 9ec40aca52..99de35495f 100644 --- a/unit_tests/tests/test_fasterEngineSpinningUp.cpp +++ b/unit_tests/tests/test_fasterEngineSpinningUp.cpp @@ -7,7 +7,6 @@ #include "engine_math.h" #include "test_fasterEngineSpinningUp.h" #include "test_trigger_decoder.h" -#include "unit_test_framework.h" extern int timeNowUs; diff --git a/unit_tests/tests/test_fuelCut.cpp b/unit_tests/tests/test_fuelCut.cpp index 12275036a8..d811fe0c16 100644 --- a/unit_tests/tests/test_fuelCut.cpp +++ b/unit_tests/tests/test_fuelCut.cpp @@ -7,7 +7,6 @@ #include "engine_math.h" #include "test_trigger_decoder.h" #include "event_queue.h" -#include "unit_test_framework.h" #include "tps.h" extern int timeNowUs; diff --git a/unit_tests/tests/test_fuel_map.cpp b/unit_tests/tests/test_fuel_map.cpp index 2267c6605e..3cf386455d 100644 --- a/unit_tests/tests/test_fuel_map.cpp +++ b/unit_tests/tests/test_fuel_map.cpp @@ -2,7 +2,7 @@ * @file test_fuel_map.cpp * * @date Nov 6, 2013 - * @author Andrey Belomutskiy, (c) 2012-2018 + * @author Andrey Belomutskiy, (c) 2012-2019 */ #include "test_fuel_map.h" diff --git a/unit_tests/tests/test_maf2map.cpp b/unit_tests/tests/test_maf2map.cpp new file mode 100644 index 0000000000..887d6ad9df --- /dev/null +++ b/unit_tests/tests/test_maf2map.cpp @@ -0,0 +1,26 @@ +/* + * test_maf2map.cpp + * + * Created on: Jan 13, 2019 + * @author Andrey Belomutskiy, (c) 2012-2019 + */ + +#include "engine_test_helper.h" +#include "maf2map.h" + +#define round_2d(x) efiRound(x, 0.01) +// todo: this should be improved to use relative 6 digit precision not just digits after decimal point +#define ASSERT_FLOAT_EQ(x, y) ASSERT_DOUBLE_EQ(round_2d(x), round_2d(y)) + +TEST(fuel, maf2map) { + + EngineTestHelper eth(FORD_ASPIRE_1996); + EXPAND_EngineTestHelper; + + engineConfiguration->fuelAlgorithm = LM_REAL_MAF; + + ASSERT_FLOAT_EQ(61.1, estimateMapByRpmAndMaf(8000, 0.6)); + + ASSERT_FLOAT_EQ(1.4, estimateMapByRpmAndMaf(2000, 5.6)); + +} diff --git a/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp b/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp index d2126f70ae..e4b9c8f818 100644 --- a/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp +++ b/unit_tests/tests/test_startOfCrankingPrimingPulse.cpp @@ -7,7 +7,6 @@ #include "test_startOfCrankingPrimingPulse.h" #include "test_trigger_decoder.h" -#include "unit_test_framework.h" extern int timeNowUs; extern EnginePins enginePins;