Put map in the sensor model (#2161)

* hook up map

* check for init

* switch some consumers

* don't do limp for now

* oops

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-12-30 05:43:49 -08:00 committed by GitHub
parent 8492f99b91
commit 83266c904b
12 changed files with 52 additions and 27 deletions

View File

@ -611,11 +611,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
tsOutputChannels->currentTargetAfr = ENGINE(engineState.targetAFR);
tsOutputChannels->targetLambda = ENGINE(engineState.targetLambda);
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
// offset 40
tsOutputChannels->manifoldAirPressure = mapValue;
}
tsOutputChannels->manifoldAirPressure = Sensor::get(SensorType::Map).value_or(0);
#if EFI_DYNO_VIEW
tsOutputChannels->VssAcceleration = getDynoviewAcceleration(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -14,7 +14,6 @@
#include "engine.h"
#include "boost_control.h"
#include "sensor.h"
#include "map.h"
#include "pin_repository.h"
#include "pwm_generator_logic.h"
#include "pid_auto_tune.h"
@ -57,13 +56,7 @@ int BoostController::getPeriodMs() {
}
expected<float> BoostController::observePlant() const {
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
if (cisnan(map)) {
return unexpected;
}
return map;
return Sensor::get(SensorType::Map);
}
expected<float> BoostController::getSetpoint() const {

View File

@ -6,7 +6,6 @@
#include "table_helper.h"
#include "expected.h"
#include "sensor.h"
#include "map.h"
#include "engine_math.h"
EXTERN_ENGINE;
@ -16,13 +15,7 @@ expected<float> readGppwmChannel(gppwm_channel_e channel DECLARE_ENGINE_PARAMETE
case GPPWM_Tps:
return Sensor::get(SensorType::Tps1);
case GPPWM_Map: {
float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
if (cisnan(map)) {
return unexpected;
}
return map;
return Sensor::get(SensorType::Map);
}
case GPPWM_Clt:
return Sensor::get(SensorType::Clt);

View File

@ -1,6 +1,5 @@
#include "airmass.h"
#include "sensor.h"
#include "map.h"
EXTERN_ENGINE;
@ -9,7 +8,7 @@ AirmassModelBase::AirmassModelBase(const ValueProvider3D& veTable) : m_veTable(&
float AirmassModelBase::getVeLoadAxis(float passedLoad) const {
switch(CONFIG(veOverrideMode)) {
case VE_None: return passedLoad;
case VE_MAP: return getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
case VE_MAP: return Sensor::get(SensorType::Map).value_or(0);
case VE_TPS: return Sensor::get(SensorType::Tps1).value_or(0);
default: return 0;
}

View File

@ -97,7 +97,7 @@ struct Sensors1 {
};
static void populateFrame(Sensors1& msg) {
msg.map = getMap();
msg.map = Sensor::get(SensorType::Map).value_or(0);
msg.clt = Sensor::get(SensorType::Clt).value_or(0) + PACK_ADD_TEMPERATURE;
msg.iat = Sensor::get(SensorType::Iat).value_or(0) + PACK_ADD_TEMPERATURE;

View File

@ -6,7 +6,10 @@
#pragma once
#include "engine_configuration.h"
#include "engine_ptr.h"
class Logging;
struct air_pressure_sensor_config_s;
void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -19,6 +19,7 @@ void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Internal init functions for individual systems
// Sensor init/config
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void initOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void initThermistors(DECLARE_CONFIG_PARAMETER_SIGNATURE);

View File

@ -5,3 +5,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
$(PROJECT_DIR)/init/sensor/init_can_sensors.cpp \
$(PROJECT_DIR)/init/sensor/init_thermistors.cpp \
$(PROJECT_DIR)/init/sensor/init_lambda.cpp \
$(PROJECT_DIR)/init/sensor/init_map.cpp \

View File

@ -0,0 +1,26 @@
#include "map.h"
#include "function_pointer_sensor.h"
#include "engine.h"
EXTERN_ENGINE;
struct GetMapWrapper {
DECLARE_ENGINE_PTR;
float getMap() {
return ::getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
}
};
static GetMapWrapper mapWrapper;
static FunctionPointerSensor mapSensor(SensorType::Map,
[]() {
return mapWrapper.getMap();
});
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
INJECT_ENGINE_REFERENCE(&mapWrapper);
mapSensor.Register();
}

View File

@ -13,6 +13,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
initCanSensors();
#endif
initMap(PASS_ENGINE_PARAMETER_SIGNATURE);
initTps(PASS_CONFIG_PARAMETER_SIGNATURE);
initOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
initThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);

View File

@ -218,3 +218,15 @@ TEST(SensorInit, Lambda) {
auto s = Sensor::getSensorOfType(SensorType::Lambda1);
ASSERT_NE(nullptr, s);
}
TEST(SensorInit, Map) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
initMap(PASS_ENGINE_PARAMETER_SIGNATURE);
auto s = Sensor::getSensorOfType(SensorType::Map);
ASSERT_NE(nullptr, s);
engine->mockMapValue = 55;
EXPECT_FLOAT_EQ(55.0f, Sensor::get(SensorType::Map).value_or(0));
}

View File

@ -40,12 +40,12 @@ TEST(BoostControl, ObservePlant) {
BoostController bc;
INJECT_ENGINE_REFERENCE(&bc);
engine->mockMapValue = NAN;
Sensor::resetMockValue(SensorType::Map);
// Check that invalid MAP returns unexpected
EXPECT_EQ(bc.observePlant(), unexpected);
// Test valid MAP value
engine->mockMapValue = 150.0f;
Sensor::setMockValue(SensorType::Map, 150);
EXPECT_FLOAT_EQ(bc.observePlant().value_or(0), 150.0f);
}