switch more map to read from sensor model (#2162)

* hook up map

* check for init

* switch some consumers

* that's the rest of them

* test

* tests

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-01-02 16:13:10 -08:00 committed by GitHub
parent c06fea083e
commit 92ea09b0a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 31 additions and 22 deletions

View File

@ -638,7 +638,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich;
// engine load acceleration
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / Sensor::get(SensorType::Map).value_or(0);
}
tsOutputChannels->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta();

View File

@ -1,7 +1,6 @@
#include "global.h"
#include "engine.h"
#include "speed_density_airmass.h"
#include "map.h"
#include "perf_trace.h"
EXTERN_ENGINE;
@ -18,15 +17,15 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
return {};
}
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
if (cisnan(map)) {
auto map = Sensor::get(SensorType::Map);
if (!map) {
warning(CUSTOM_ERR_TCHARGE_NOT_READY2, "map not ready"); // this could happen during HW CI during configuration reset
return {};
}
engine->engineState.sd.manifoldAirPressureAccelerationAdjustment = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
float adjustedMap = engine->engineState.sd.adjustedManifoldAirPressure = map.Value + engine->engineState.sd.manifoldAirPressureAccelerationAdjustment;
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(adjustedMap), "NaN adjustedMap", {});
float ve = getVe(rpm, adjustedMap);
@ -43,6 +42,6 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) {
return {
airMass,
map, // AFR/VE table Y axis
map.Value, // AFR/VE table Y axis
};
}

View File

@ -45,7 +45,8 @@ float FuelComputer::getTargetLambdaLoadAxis(float defaultLoad) const {
float getLoadOverride(float defaultLoad, afr_override_e overrideMode DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch(overrideMode) {
case AFR_None: return defaultLoad;
case AFR_MAP: return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
// MAP default to 200kpa - failed MAP goes rich
case AFR_MAP: return Sensor::get(SensorType::Map).value_or(200);
// TPS/pedal default to 100% - failed TPS goes rich
case AFR_Tps: return Sensor::get(SensorType::Tps1).value_or(100);
case AFR_AccPedal: return Sensor::get(SensorType::AcceleratorPedal).value_or(100);

View File

@ -43,10 +43,15 @@ float InjectorModel::getInjectorFlowRatio() const {
return 1.0f;
}
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
auto map = Sensor::get(SensorType::Map);
// Map has failed, assume nominal pressure
if (!map) {
return 1.0f;
}
// TODO: what to do when pressureDelta is less than 0?
float pressureDelta = absRailPressure.Value - map;
float pressureDelta = absRailPressure.Value - map.Value;
float pressureRatio = pressureDelta / referencePressure;
float flowRatio = sqrtf(pressureRatio);

View File

@ -406,8 +406,11 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_
return 1.0f;
}
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
const auto [mapValid, map] = Sensor::get(SensorType::Map);
if (!mapValid) {
return 1.0f;
}
// gather events
bool mapDeactivate = (map >= CONFIG(coastingFuelCutMap));
bool tpsDeactivate = (tpsPos >= CONFIG(coastingFuelCutTps));

View File

@ -133,7 +133,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
obdSendValue(_1_MODE, pid, 1, 128 * ENGINE(engineState.running.pidCorrection));
break;
case PID_INTAKE_MAP:
obdSendValue(_1_MODE, pid, 1, getMap(PASS_ENGINE_PARAMETER_SIGNATURE));
obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Map).value_or(0));
break;
case PID_RPM:
obdSendValue(_1_MODE, pid, 2, GET_RPM() * ODB_RPM_MULT); // rotation/min. (A*256+B)/4

View File

@ -134,7 +134,7 @@ FsioResult getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
case LE_METHOD_MAF:
return getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE);
case LE_METHOD_MAP:
return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
return Sensor::get(SensorType::Map).value_or(0);
#if EFI_SHAFT_POSITION_INPUT
case LE_METHOD_INTAKE_VVT:
case LE_METHOD_EXHAUST_VVT:

View File

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

View File

@ -1,6 +1,5 @@
#include "limp_manager.h"
#include "engine.h"
#include "map.h"
#include "efilib.h"
EXTERN_ENGINE;
@ -20,7 +19,7 @@ void LimpManager::updateState(int rpm) {
// Limit fuel only on boost pressure (limiting spark bends valves)
if (CONFIG(boostCutPressure) != 0) {
if (getMap(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(boostCutPressure)) {
if (Sensor::get(SensorType::Map).value_or(0) > CONFIG(boostCutPressure)) {
limitFuel = true;
}
}

View File

@ -66,7 +66,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiAssert(CUSTOM_ERR_ASSERT, engineConfiguration!=NULL, "engineConfiguration 2NULL", NAN);
switch (engineConfiguration->fuelAlgorithm) {
case LM_SPEED_DENSITY:
return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
return Sensor::get(SensorType::Map).value_or(0);
case LM_ALPHA_N:
return Sensor::get(SensorType::Tps1).value_or(0);
case LM_REAL_MAF:

View File

@ -31,6 +31,8 @@ TEST(fuelCut, coasting) {
// basic engine setup
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
Sensor::setMockValue(SensorType::Map, 0);
// mock CLT - just above threshold ('hot engine')
float hotClt = engineConfiguration->coastingFuelCutClt + 1;
Sensor::setMockValue(SensorType::Clt, hotClt);

View File

@ -109,7 +109,7 @@ TEST_P(FlowRateFixture, PressureRatio) {
engineConfiguration->fuelReferencePressure = 400.0f;
// MAP sensor always reads 35 kpa
engine->mockMapValue = fakeMap;
Sensor::setMockValue(SensorType::Map, fakeMap);
// Should return the expected ratio
EXPECT_FLOAT_EQ(expectedFlowRatio, dut.getInjectorFlowRatio());

View File

@ -54,23 +54,23 @@ TEST(limp, boostCut) {
INJECT_ENGINE_REFERENCE(&dut);
// Below threshold, injection allowed
engine->mockMapValue = 80;
Sensor::setMockValue(SensorType::Map, 80);
dut.updateState(1000);
EXPECT_TRUE(dut.allowInjection());
// Above threshold, injection cut
engine->mockMapValue = 120;
Sensor::setMockValue(SensorType::Map, 120);
dut.updateState(1000);
EXPECT_FALSE(dut.allowInjection());
// Below threshold, should recover
engine->mockMapValue = 80;
Sensor::setMockValue(SensorType::Map, 80);
dut.updateState(1000);
EXPECT_TRUE(dut.allowInjection());
// SPECIAL CASE: threshold of 0 means never boost cut
engineConfiguration->boostCutPressure = 0;
engine->mockMapValue = 500;
Sensor::setMockValue(SensorType::Map, 500);
dut.updateState(1000);
EXPECT_TRUE(dut.allowInjection());
}