This commit is contained in:
Matthew Kennedy 2021-10-04 15:33:10 -07:00 committed by GitHub
parent 53d20d203e
commit b84df3dda8
7 changed files with 10 additions and 112 deletions

View File

@ -727,10 +727,9 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
#endif /* EFI_HIP_9011 */ #endif /* EFI_HIP_9011 */
tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich; 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->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta();
tsOutputChannels->checkEngine = hasErrorCodes(); tsOutputChannels->checkEngine = hasErrorCodes();

View File

@ -70,11 +70,6 @@ static float v_averagedMapValue;
static float averagedMapRunningBuffer[MAX_MAP_BUFFER_LENGTH]; static float averagedMapRunningBuffer[MAX_MAP_BUFFER_LENGTH];
int mapMinBufferLength = 0; int mapMinBufferLength = 0;
static int averagedMapBufIdx = 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 * 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 if (measurementsPerRevolutionCounter % FAST_MAP_CHART_SKIP_FACTOR
== 0) { == 0) {
float voltage = adcToVoltsDivided(adcValue); float voltage = adcToVoltsDivided(adcValue);
float currentPressure = getMapByVoltage(voltage); float currentPressure = convertMap(voltage).value_or(0);
scAddData( scAddData(
getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX), getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX),
currentPressure); currentPressure);
@ -174,8 +169,6 @@ static void endAveraging(void*) {
} }
onMapAveraged(minPressure, getTimeNowNt()); onMapAveraged(minPressure, getTimeNowNt());
currentPressure = minPressure;
} }
} else { } else {
warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values");
@ -199,7 +192,7 @@ static void applyMapMinBufferLength(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void postMapState(TunerStudioOutputChannels *tsOutputChannels) { void postMapState(TunerStudioOutputChannels *tsOutputChannels) {
tsOutputChannels->debugFloatField1 = v_averagedMapValue; tsOutputChannels->debugFloatField1 = v_averagedMapValue;
tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration; tsOutputChannels->debugFloatField2 = engine->engineState.mapAveragingDuration;
tsOutputChannels->debugFloatField3 = currentPressure; tsOutputChannels->debugFloatField3 = Sensor::get(SensorType::MapFast).value_or(0);
tsOutputChannels->debugIntField1 = mapMeasurementsCounter; tsOutputChannels->debugIntField1 = mapMeasurementsCounter;
} }
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
@ -304,26 +297,6 @@ static void showMapStats(void) {
efiPrintf("per revolution %d", measurementsPerRevolution); 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) { void initMapAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
addConsoleAction("faststat", showMapStats); addConsoleAction("faststat", showMapStats);
@ -332,17 +305,4 @@ void initMapAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
applyMapMinBufferLength(PASS_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 */ #endif /* EFI_MAP_AVERAGING */

View File

@ -212,7 +212,7 @@ static void showLine(lcd_line_e line, int /*screenY*/) {
} }
return; return;
case LL_MAP: case LL_MAP:
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { if (Sensor::hasSensor(SensorType::Map)) {
lcdPrintf("MAP %.2f", Sensor::get(SensorType::Map).value_or(0)); lcdPrintf("MAP %.2f", Sensor::get(SensorType::Map).value_or(0));
} else { } else {
lcdPrintf("MAP: none"); lcdPrintf("MAP: none");

View File

@ -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 */); 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); static FastInterpolation *getDecoder(air_pressure_sensor_type_e type);
float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DECLARE_ENGINE_PARAMETER_SUFFIX) { 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 * This function checks if Baro/MAP sensor value is inside of expected range
* @return unchanged mapKPa parameter or NaN * @return unchanged mapKPa parameter or NaN
@ -134,34 +116,6 @@ static float validateBaroMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX) {
return mapKPa; 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) { float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// Override the real Baro sensor with the stored initial MAP value, if the option is set. // Override the real Baro sensor with the stored initial MAP value, if the option is set.
if (CONFIG(useFixedBaroCorrFromMap)) if (CONFIG(useFixedBaroCorrFromMap))
@ -172,8 +126,6 @@ float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) { static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) {
switch (type) { switch (type) {
case MT_CUSTOM:
return &customMap;
case MT_DENSO183: case MT_DENSO183:
return &denso183; return &denso183;
case MT_MPX4250: case MT_MPX4250:
@ -211,7 +163,6 @@ static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) {
static void applyConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void applyConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor; air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor;
customMap.init(0, apConfig->lowValue, 5, apConfig->highValue); customMap.init(0, apConfig->lowValue, 5, apConfig->highValue);
mapDecoder = getDecoder(engineConfiguration->map.sensor.type);
} }
#if EFI_PROD_CODE #if EFI_PROD_CODE
@ -220,12 +171,12 @@ extern int mapMinBufferLength;
static void printMAPInfo(void) { static void printMAPInfo(void) {
#if EFI_ANALOG_SENSORS #if EFI_ANALOG_SENSORS
efiPrintf("instant value=%.2fkPa", getRawMap()); efiPrintf("instant value=%.2fkPa", Sensor::get(SensorType::Map).value_or(0));
#if EFI_MAP_AVERAGING #if EFI_MAP_AVERAGING
efiPrintf("map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type, efiPrintf("map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type,
getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type), getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type),
getMap(), Sensor::get(SensorType::Map).value_or(0),
mapMinBufferLength); mapMinBufferLength);
#endif // EFI_MAP_AVERAGING #endif // EFI_MAP_AVERAGING
@ -259,11 +210,10 @@ static void printMAPInfo(void) {
void initMapDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void initMapDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
applyConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE); applyConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE);
//engine->configurationListeners.registerCallback(applyConfiguration);
if (CONFIG(useFixedBaroCorrFromMap)) { if (CONFIG(useFixedBaroCorrFromMap)) {
// Read initial MAP sensor value and store it for Baro correction. // 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); efiPrintf("Get initial baro MAP pressure = %.2fkPa", storedInitialBaroPressure);
// validate if it's within a reasonable range (the engine should not be spinning etc.) // validate if it's within a reasonable range (the engine should not be spinning etc.)
storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure PASS_ENGINE_PARAMETER_SUFFIX); storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -17,15 +17,8 @@ void initMapDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE);
*/ */
float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getBaroPressure(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 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 #define KPA_PER_PSI 6.89475728f

View File

@ -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 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 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! ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here!

View File

@ -34,10 +34,6 @@ int getRemainingStack(thread_t *otp) {
return 99999; return 99999;
} }
float getMap(void) {
return getRawMap();
}
static void assertString(const char*actual, const char *expected) { static void assertString(const char*actual, const char *expected) {
if (strcmp(actual, expected) != 0) { if (strcmp(actual, expected) != 0) {
firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected); firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected);