second lambda (x-series CAN only, for now) (#2048)

* add sensor

* second sensor

* switch sensor name

* gobblin up your memory

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-12-09 19:26:23 -06:00 committed by GitHub
parent 82e7f3435d
commit ba1ba1452d
12 changed files with 25 additions and 18 deletions

View File

@ -512,11 +512,14 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
// offset 16 // offset 16
tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0; tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0;
// offset 20 float lambdaValue = Sensor::get(SensorType::Lambda1).value_or(0);
float lambdaValue = Sensor::get(SensorType::Lambda).value_or(0);
tsOutputChannels->lambda = lambdaValue; tsOutputChannels->lambda = lambdaValue;
tsOutputChannels->airFuelRatio = lambdaValue * ENGINE(engineState.stoichiometricRatio); tsOutputChannels->airFuelRatio = lambdaValue * ENGINE(engineState.stoichiometricRatio);
float lambda2Value = Sensor::get(SensorType::Lambda2).value_or(0);
tsOutputChannels->lambda2 = lambda2Value;
tsOutputChannels->airFuelRatio2 = lambda2Value * ENGINE(engineState.stoichiometricRatio);
// offset 24 // offset 24
tsOutputChannels->engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE); tsOutputChannels->engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -118,7 +118,7 @@ struct Sensors2 {
}; };
static void populateFrame(Sensors2& msg) { static void populateFrame(Sensors2& msg) {
msg.afr = Sensor::get(SensorType::Lambda).value_or(0) * 14.7f; msg.afr = Sensor::get(SensorType::Lambda1).value_or(0) * 14.7f;
msg.oilPressure = Sensor::get(SensorType::OilPressure).value_or(-1); msg.oilPressure = Sensor::get(SensorType::OilPressure).value_or(-1);
msg.vvtPos = engine->triggerCentral.getVVTPosition(); msg.vvtPos = engine->triggerCentral.getVVTPosition();
msg.vbatt = getVBatt(); msg.vbatt = getVBatt();

View File

@ -157,7 +157,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * ODB_TPS_BYTE_PERCENT); // (A*100/255) obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * ODB_TPS_BYTE_PERCENT); // (A*100/255)
break; break;
case PID_FUEL_AIR_RATIO_1: { case PID_FUEL_AIR_RATIO_1: {
float lambda = Sensor::get(SensorType::Lambda).value_or(0); float lambda = Sensor::get(SensorType::Lambda1).value_or(0);
// phi = 1 / lambda // phi = 1 / lambda
float phi = clampF(0, 1 / lambda, 1.99f); float phi = clampF(0, 1 / lambda, 1.99f);

View File

@ -710,7 +710,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
* UNUSED_SIZE constants. * UNUSED_SIZE constants.
*/ */
#ifndef RAM_UNUSED_SIZE #ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 3400 #define RAM_UNUSED_SIZE 3300
#endif #endif
#ifndef CCM_UNUSED_SIZE #ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 2800 #define CCM_UNUSED_SIZE 2800

View File

@ -220,8 +220,8 @@ static void showLine(lcd_line_e line, int /*screenY*/) {
return; return;
#endif #endif
case LL_AFR: case LL_AFR:
if (Sensor::hasSensor(SensorType::Lambda)) { if (Sensor::hasSensor(SensorType::Lambda1)) {
lcdPrintf("AFR: %.2f", Sensor::get(SensorType::Lambda).value_or(0)); lcdPrintf("AFR: %.2f", Sensor::get(SensorType::Lambda1).value_or(0));
} else { } else {
lcdPrintf("AFR: none"); lcdPrintf("AFR: none");
} }

View File

@ -71,7 +71,7 @@ bool shouldUpdateCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// Pause (but don't reset) correction if the AFR is off scale. // Pause (but don't reset) correction if the AFR is off scale.
// It's probably a transient and poorly tuned transient correction // It's probably a transient and poorly tuned transient correction
auto afr = Sensor::get(SensorType::Lambda).value_or(0) * 14.7f; auto afr = Sensor::get(SensorType::Lambda1).value_or(0) * 14.7f;
if (!afr || afr < (cfg.minAfr * 0.1f) || afr > (cfg.maxAfr * 0.1f)) { if (!afr || afr < (cfg.minAfr * 0.1f) || afr > (cfg.maxAfr * 0.1f)) {
return false; return false;
} }

View File

@ -49,7 +49,7 @@ float ClosedLoopFuelCellBase::getAdjustment() const {
} }
float ClosedLoopFuelCellImpl::getLambdaError(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { float ClosedLoopFuelCellImpl::getLambdaError(DECLARE_ENGINE_PARAMETER_SIGNATURE) const {
auto lambda = Sensor::get(SensorType::Lambda); auto lambda = Sensor::get(SensorType::Lambda1);
// Failed sensor -> no error // Failed sensor -> no error
if (!lambda) { if (!lambda) {

View File

@ -34,7 +34,8 @@ static const char* s_sensorNames[] = {
"Aux Temp 1", "Aux Temp 1",
"Aux Temp 2", "Aux Temp 2",
"Lambda", "Lambda 1",
"Lambda 2",
"Wastegate Position", "Wastegate Position",
"Idle Valve Position", "Idle Valve Position",

View File

@ -52,7 +52,8 @@ enum class SensorType : unsigned char {
AuxTemp1, AuxTemp1,
AuxTemp2, AuxTemp2,
Lambda, Lambda1,
Lambda2,
WastegatePosition, WastegatePosition,
IdlePosition, IdlePosition,

View File

@ -18,14 +18,15 @@ struct GetAfrWrapper {
static GetAfrWrapper afrWrapper; static GetAfrWrapper afrWrapper;
static FunctionPointerSensor lambdaSensor(SensorType::Lambda, static FunctionPointerSensor lambdaSensor(SensorType::Lambda1,
[]() { []() {
return afrWrapper.getLambda(); return afrWrapper.getLambda();
}); });
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
#include "AemXSeriesLambda.h" #include "AemXSeriesLambda.h"
static AemXSeriesWideband aem(0, SensorType::Lambda); static AemXSeriesWideband aem1(0, SensorType::Lambda1);
static AemXSeriesWideband aem2(1, SensorType::Lambda2);
#endif #endif
void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
@ -33,7 +34,8 @@ void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
if (CONFIG(enableAemXSeries)) { if (CONFIG(enableAemXSeries)) {
registerCanSensor(aem); registerCanSensor(aem1);
registerCanSensor(aem2);
return; return;
} }

View File

@ -215,6 +215,6 @@ TEST(SensorInit, Lambda) {
initLambda(PASS_ENGINE_PARAMETER_SIGNATURE); initLambda(PASS_ENGINE_PARAMETER_SIGNATURE);
auto s = Sensor::getSensorOfType(SensorType::Lambda); auto s = Sensor::getSensorOfType(SensorType::Lambda1);
ASSERT_NE(nullptr, s); ASSERT_NE(nullptr, s);
} }

View File

@ -87,12 +87,12 @@ TEST(ClosedLoopFuel, afrLimits) {
engineConfiguration->stft.minAfr = 100; // 10.0 AFR engineConfiguration->stft.minAfr = 100; // 10.0 AFR
engineConfiguration->stft.maxAfr = 180; // 18.0 AFR engineConfiguration->stft.maxAfr = 180; // 18.0 AFR
Sensor::setMockValue(SensorType::Lambda, 0.1f); Sensor::setMockValue(SensorType::Lambda1, 0.1f);
EXPECT_FALSE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE)); EXPECT_FALSE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE));
Sensor::setMockValue(SensorType::Lambda, 1.0f); Sensor::setMockValue(SensorType::Lambda1, 1.0f);
EXPECT_TRUE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE)); EXPECT_TRUE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE));
Sensor::setMockValue(SensorType::Lambda, 2.0f); Sensor::setMockValue(SensorType::Lambda1, 2.0f);
EXPECT_FALSE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE)); EXPECT_FALSE(shouldUpdateCorrection(PASS_ENGINE_PARAMETER_SIGNATURE));
} }