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 53e481b6ef
commit a08e79789d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 25 additions and 18 deletions

View File

@ -512,11 +512,14 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
// offset 16
tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0;
// offset 20
float lambdaValue = Sensor::get(SensorType::Lambda).value_or(0);
float lambdaValue = Sensor::get(SensorType::Lambda1).value_or(0);
tsOutputChannels->lambda = lambdaValue;
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
tsOutputChannels->engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -118,7 +118,7 @@ struct Sensors2 {
};
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.vvtPos = engine->triggerCentral.getVVTPosition();
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)
break;
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
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.
*/
#ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 3400
#define RAM_UNUSED_SIZE 3300
#endif
#ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 2800

View File

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

View File

@ -49,7 +49,7 @@ float ClosedLoopFuelCellBase::getAdjustment() 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
if (!lambda) {

View File

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

View File

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

View File

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

View File

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

View File

@ -87,12 +87,12 @@ TEST(ClosedLoopFuel, afrLimits) {
engineConfiguration->stft.minAfr = 100; // 10.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));
Sensor::setMockValue(SensorType::Lambda, 1.0f);
Sensor::setMockValue(SensorType::Lambda1, 1.0f);
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));
}