From b84df3dda82e05f1f002ed7cdfddaca34bfb1993 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 4 Oct 2021 15:33:10 -0700 Subject: [PATCH] dead map (#3316) --- firmware/console/status_loop.cpp | 7 +-- .../engine_cycle/map_averaging.cpp | 44 +-------------- .../controllers/gauges/lcd_controller.cpp | 2 +- firmware/controllers/sensors/map.cpp | 56 +------------------ firmware/controllers/sensors/map.h | 7 --- firmware/integration/rusefi_config.txt | 2 +- simulator/simulator/rusEfiFunctionalTest.cpp | 4 -- 7 files changed, 10 insertions(+), 112 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 2d0721b398..f8228afb4d 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -727,10 +727,9 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ #endif /* EFI_HIP_9011 */ tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich; - // engine load acceleration - if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / Sensor::get(SensorType::Map).value_or(0); - } + + tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / Sensor::get(SensorType::Map).value_or(0); + tsOutputChannels->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta(); tsOutputChannels->checkEngine = hasErrorCodes(); diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index f5b6d806eb..f37c49c58d 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -70,11 +70,6 @@ static float v_averagedMapValue; static float averagedMapRunningBuffer[MAX_MAP_BUFFER_LENGTH]; int mapMinBufferLength = 0; static int averagedMapBufIdx = 0; -// we need this 'NO_VALUE_YET' to properly handle transition from engine not running to engine already running -// but prior to first processed result -#define NO_VALUE_YET -100 -// this is 'minimal averaged' MAP within avegaging window -static float currentPressure = NO_VALUE_YET; /** * here we have averaging start and averaging end points for each cylinder @@ -132,7 +127,7 @@ void mapAveragingAdcCallback(adcsample_t adcValue) { if (measurementsPerRevolutionCounter % FAST_MAP_CHART_SKIP_FACTOR == 0) { float voltage = adcToVoltsDivided(adcValue); - float currentPressure = getMapByVoltage(voltage); + float currentPressure = convertMap(voltage).value_or(0); scAddData( getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX), currentPressure); @@ -174,8 +169,6 @@ static void endAveraging(void*) { } onMapAveraged(minPressure, getTimeNowNt()); - - currentPressure = minPressure; } } else { warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); @@ -199,7 +192,7 @@ static void applyMapMinBufferLength(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void postMapState(TunerStudioOutputChannels *tsOutputChannels) { tsOutputChannels->debugFloatField1 = v_averagedMapValue; tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration; - tsOutputChannels->debugFloatField3 = currentPressure; + tsOutputChannels->debugFloatField3 = Sensor::get(SensorType::MapFast).value_or(0); tsOutputChannels->debugIntField1 = mapMeasurementsCounter; } #endif /* EFI_TUNER_STUDIO */ @@ -304,26 +297,6 @@ static void showMapStats(void) { efiPrintf("per revolution %d", measurementsPerRevolution); } -#if EFI_PROD_CODE - -/** - * Because of MAP window averaging, MAP is only available while engine is spinning - * @return Manifold Absolute Pressure, in kPa - */ -float getMap(void) { - if (!isAdcChannelValid(engineConfiguration->map.sensor.hwChannel)) - return 0; - -#if EFI_ANALOG_SENSORS - if (!isValidRpm(GET_RPM()) || currentPressure == NO_VALUE_YET) - return validateMap(getRawMap()); // maybe return NaN in case of stopped engine? - return validateMap(currentPressure); -#else - return 100; -#endif -} -#endif /* EFI_PROD_CODE */ - void initMapAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if !EFI_UNIT_TEST addConsoleAction("faststat", showMapStats); @@ -332,17 +305,4 @@ void initMapAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) { applyMapMinBufferLength(PASS_ENGINE_PARAMETER_SIGNATURE); } -#else - -#if EFI_PROD_CODE - -float getMap(void) { -#if EFI_ANALOG_SENSORS - return getRawMap(); -#else - return NAN; -#endif /* EFI_ANALOG_SENSORS */ -} -#endif /* EFI_PROD_CODE */ - #endif /* EFI_MAP_AVERAGING */ diff --git a/firmware/controllers/gauges/lcd_controller.cpp b/firmware/controllers/gauges/lcd_controller.cpp index 844477dbb5..986344964f 100644 --- a/firmware/controllers/gauges/lcd_controller.cpp +++ b/firmware/controllers/gauges/lcd_controller.cpp @@ -212,7 +212,7 @@ static void showLine(lcd_line_e line, int /*screenY*/) { } return; case LL_MAP: - if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { + if (Sensor::hasSensor(SensorType::Map)) { lcdPrintf("MAP %.2f", Sensor::get(SensorType::Map).value_or(0)); } else { lcdPrintf("MAP: none"); diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index bd2435291a..8bf8f42fe3 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -73,12 +73,6 @@ static FastInterpolation mazda1bar(0 /* volts */, 2.5 /* kPa */, 5 /* volts */ , */ static FastInterpolation bosch2_5(0.4 /* volts */, 20 /* kPa */, 4.65 /* volts */ , 250 /* kPa */); -/** - * We hold a reference to current decoder to reduce code branching - * to lookup decoder each time we need to decode - */ -static FastInterpolation *mapDecoder; - static FastInterpolation *getDecoder(air_pressure_sensor_type_e type); float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -108,18 +102,6 @@ float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DEC } } -/** - * This function adds an error if MAP sensor value is outside of expected range - * @return unchanged mapKPa parameter - */ -float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) { - if (cisnan(mapKPa) || mapKPa < CONFIG(mapErrorDetectionTooLow) || mapKPa > CONFIG(mapErrorDetectionTooHigh)) { - warning(OBD_Manifold_Absolute_Pressure_Circuit_Malfunction, "unexpected MAP value: %.2f", mapKPa); - return 0; - } - return mapKPa; -} - /** * This function checks if Baro/MAP sensor value is inside of expected range * @return unchanged mapKPa parameter or NaN @@ -134,34 +116,6 @@ static float validateBaroMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) { return mapKPa; } -/** - * @brief MAP value decoded according to current settings - * @returns kPa value - */ -float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) { -#if EFI_ENABLE_MOCK_ADC - int mapChannel = engineConfiguration->map.sensor.hwChannel; - if (engine->engineState.mockAdcState.hasMockAdc[mapChannel]) - voltage = adcToVolts(engine->engineState.mockAdcState.getMockAdcValue(mapChannel) * engineConfiguration->analogInputDividerCoefficient); -#endif - - // todo: migrate to mapDecoder once parameter listeners are ready - air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor; - return decodePressure(voltage, apConfig PASS_ENGINE_PARAMETER_SUFFIX); -} - -/** - * @return Manifold Absolute Pressure, in kPa - */ -float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX); - return getMapByVoltage(voltage PASS_ENGINE_PARAMETER_SUFFIX); -} - -bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - return isAdcChannelValid(engineConfiguration->map.sensor.hwChannel); -} - float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // Override the real Baro sensor with the stored initial MAP value, if the option is set. if (CONFIG(useFixedBaroCorrFromMap)) @@ -172,8 +126,6 @@ float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) { switch (type) { - case MT_CUSTOM: - return &customMap; case MT_DENSO183: return &denso183; case MT_MPX4250: @@ -211,7 +163,6 @@ static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) { static void applyConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor; customMap.init(0, apConfig->lowValue, 5, apConfig->highValue); - mapDecoder = getDecoder(engineConfiguration->map.sensor.type); } #if EFI_PROD_CODE @@ -220,12 +171,12 @@ extern int mapMinBufferLength; static void printMAPInfo(void) { #if EFI_ANALOG_SENSORS - efiPrintf("instant value=%.2fkPa", getRawMap()); + efiPrintf("instant value=%.2fkPa", Sensor::get(SensorType::Map).value_or(0)); #if EFI_MAP_AVERAGING efiPrintf("map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type, getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type), - getMap(), + Sensor::get(SensorType::Map).value_or(0), mapMinBufferLength); #endif // EFI_MAP_AVERAGING @@ -259,11 +210,10 @@ static void printMAPInfo(void) { void initMapDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE) { applyConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE); - //engine->configurationListeners.registerCallback(applyConfiguration); if (CONFIG(useFixedBaroCorrFromMap)) { // Read initial MAP sensor value and store it for Baro correction. - storedInitialBaroPressure = getRawMap(PASS_ENGINE_PARAMETER_SIGNATURE); + storedInitialBaroPressure = Sensor::get(SensorType::MapSlow).value_or(101.325); efiPrintf("Get initial baro MAP pressure = %.2fkPa", storedInitialBaroPressure); // validate if it's within a reasonable range (the engine should not be spinning etc.) storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/sensors/map.h b/firmware/controllers/sensors/map.h index 58380c02fc..51ba17b6bc 100644 --- a/firmware/controllers/sensors/map.h +++ b/firmware/controllers/sensors/map.h @@ -17,15 +17,8 @@ void initMapDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE); */ float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE); -bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE); -/** - * @return MAP value averaged within a window of measurement - */ -float getMap(DECLARE_ENGINE_PARAMETER_SIGNATURE); -float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX); float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DECLARE_ENGINE_PARAMETER_SUFFIX); -float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX); #define KPA_PER_PSI 6.89475728f diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 94c3a27cd1..6e97c63137 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -613,7 +613,7 @@ float primingSquirtDurationMs;;"*C", 1, 0, -40, 200, 1 uint16_t etbRevLimitStart;+Once engine speed passes this value, start reducing ETB angle.;"rpm", 1, 0, 0, 15000, 0 uint16_t etbRevLimitRange;+This far above 'Soft limiter start', fully close the throttle. At the bottom of the range, throttle control is normal. At the top of the range, the throttle is fully closed.;"rpm", 1, 0, 0, 2000, 0 -MAP_sensor_config_s map;@see hasMapSensor\n@see isMapAveragingEnabled +MAP_sensor_config_s map;@see isMapAveragingEnabled ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here! diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index 0e31595c49..7354758adf 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -34,10 +34,6 @@ int getRemainingStack(thread_t *otp) { return 99999; } -float getMap(void) { - return getRawMap(); -} - static void assertString(const char*actual, const char *expected) { if (strcmp(actual, expected) != 0) { firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected);