From 15d5c872c2f99337189ba1ecc6a9b5a0d2561d3a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 31 Oct 2020 14:52:07 -0700 Subject: [PATCH] log afr in addition to lambda (#1920) * log afr * log it * weird double commas --- firmware/console/binary/tunerstudio_outputs.h | 3 ++- firmware/console/binary_log/binary_logging.cpp | 1 + firmware/console/status_loop.cpp | 4 +++- firmware/controllers/algo/engine_state.h | 1 + firmware/controllers/algo/fuel/fuel_computer.cpp | 1 + firmware/integration/rusefi_config.txt | 1 + firmware/tunerstudio/rusefi.input | 11 +++++++---- 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/firmware/console/binary/tunerstudio_outputs.h b/firmware/console/binary/tunerstudio_outputs.h index 81c0a93005..1ecbff1385 100644 --- a/firmware/console/binary/tunerstudio_outputs.h +++ b/firmware/console/binary/tunerstudio_outputs.h @@ -257,8 +257,9 @@ typedef struct { scaled_high_pressure highFuelPressure; // 278 scaled_lambda targetLambda; // 280 + scaled_afr airFuelRatio; // 282 - uint8_t unusedAtTheEnd[6]; // we have some unused bytes to allow compatible TS changes + uint8_t unusedAtTheEnd[4]; // we have some unused bytes to allow compatible TS changes // Temporary - will remove soon TsDebugChannels* getDebugChannels() { diff --git a/firmware/console/binary_log/binary_logging.cpp b/firmware/console/binary_log/binary_logging.cpp index ec94c48ab2..f8b4cce980 100644 --- a/firmware/console/binary_log/binary_logging.cpp +++ b/firmware/console/binary_log/binary_logging.cpp @@ -30,6 +30,7 @@ static const LogField fields[] = { {tsOutputChannels.throttle2Position, GAUGE_NAME_TPS2, "%", 2}, {tsOutputChannels.pedalPosition, GAUGE_NAME_THROTTLE_PEDAL, "%", 2}, {tsOutputChannels.manifoldAirPressure, GAUGE_NAME_MAP, "kPa", 1}, + {tsOutputChannels.airFuelRatio, GAUGE_NAME_AFR, "afr", 2}, {tsOutputChannels.lambda, GAUGE_NAME_LAMBDA, "", 3}, {tsOutputChannels.vBatt, GAUGE_NAME_VBAT, "v", 2}, {tsOutputChannels.oilPressure, GAUGE_NAME_OIL_PRESSURE, GAUGE_NAME_FUEL_PRESSURE_HIGH_UNITS, 0}, diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index ca40b01992..8d38138e0e 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -526,7 +526,9 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0; // offset 20 - tsOutputChannels->lambda = Sensor::get(SensorType::Lambda).value_or(0); + float lambdaValue = Sensor::get(SensorType::Lambda).value_or(0); + tsOutputChannels->lambda = lambdaValue; + tsOutputChannels->airFuelRatio = lambdaValue * ENGINE(engineState.stoichiometricRatio); // offset 24 tsOutputChannels->engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index 9fbaf3e55a..243ce4d20e 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -81,4 +81,5 @@ public: multispark_state multispark; float targetLambda = 0.0f; + float stoichiometricRatio = 0.0f; }; diff --git a/firmware/controllers/algo/fuel/fuel_computer.cpp b/firmware/controllers/algo/fuel/fuel_computer.cpp index 4bda358d6f..061263faf5 100644 --- a/firmware/controllers/algo/fuel/fuel_computer.cpp +++ b/firmware/controllers/algo/fuel/fuel_computer.cpp @@ -13,6 +13,7 @@ mass_t FuelComputerBase::getCycleFuel(mass_t airmass, int rpm, float load) const ENGINE(engineState.currentAfrLoad) = load; ENGINE(engineState.targetLambda) = lambda; ENGINE(engineState.targetAFR) = afr; + ENGINE(engineState.stoichiometricRatio) = stoich; return airmass / afr; } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index d22e37b828..3e384bb57c 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1621,6 +1621,7 @@ end_struct #define GAUGE_NAME_TCHARGE "fuel: SD tCharge" #define GAUGE_NAME_TARGET_AFR "fuel: target AFR" #define GAUGE_NAME_TARGET_LAMBDA "fuel: target lambda" +#define GAUGE_NAME_AFR "Air/Fuel Ratio" #define GAUGE_NAME_LAMBDA "Lambda" #define GAUGE_NAME_IAC "Idle Air Valve" diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 0037074bf7..70987e4a41 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -210,15 +210,15 @@ enable2ndByteCanID = false tpsADC = scalar, U16, 24, "ADC", 1, 0.0; ; air flow/mass measurments - MAFValue = scalar, U16, 26, "V",,{1/@@PACK_MULT_VOLTAGE@@},, 0 + MAFValue = scalar, U16, 26, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0 massAirFlowValue= scalar, U16, 28, "Kg/h", {1/@@PACK_MULT_MASS_FLOW@@}, 0 MAPValue = scalar, U16, 30, "kPa",{1/@@PACK_MULT_PRESSURE@@}, 0.0 baroPressure = scalar, U16, 32, "kPa",{1/@@PACK_MULT_PRESSURE@@}, 0.0 - lambdaValue = scalar, U16, 34, "",,{1/@@PACK_MULT_LAMBDA@@},, 0.0 + lambdaValue = scalar, U16, 34, "",{1/@@PACK_MULT_LAMBDA@@}, 0.0 engineLoad = scalar, U16, 36, "%",{1/@@PACK_MULT_PERCENT@@}, 0.0 ; Blend of MAP and TPS, depends on algorithm ; misc sensors - VBatt = scalar, U16, 38, "V",,{1/@@PACK_MULT_VOLTAGE@@},, 0.0 + VBatt = scalar, U16, 38, "V",{1/@@PACK_MULT_VOLTAGE@@}, 0.0 oilPressure = scalar, U16, 40, "kPa",{1/@@PACK_MULT_PRESSURE@@}, 0.0 vvtPosition = scalar, U16, 42, "deg",{1/@@PACK_MULT_ANGLE@@}, 0 @@ -228,7 +228,7 @@ enable2ndByteCanID = false ; fuel math chargeAirMass = scalar, U16, 44, "g",0.001, 0 crankingFuelMs = scalar, U16, 46, "mg",{1/@@PACK_MULT_FUEL_MASS@@}, 0.0 - currentTargetAfr= scalar, U16, 48, "ratio",,{1/@@PACK_MULT_AFR@@},, 0 + currentTargetAfr= scalar, U16, 48, "ratio",{1/@@PACK_MULT_AFR@@}, 0 baseFuel = scalar, U16, 50, "mg",{1/@@PACK_MULT_FUEL_MASS@@}, 0 fuelRunning = scalar, U16, 52, "mg",{1/@@PACK_MULT_FUEL_MASS@@}, 0 actualLastInjection=scalar,U16, 54, "ms",{1/@@PACK_MULT_MS@@}, 0.0 @@ -370,6 +370,7 @@ enable2ndByteCanID = false lowFuelPressure = scalar, S16, 276, "kpa", {1/@@PACK_MULT_PRESSURE@@}, 0 highFuelPressure = scalar, S16, 278, "bar", {1/@@PACK_MULT_HIGH_PRESSURE@@}, 0 targetLambda = scalar, U16, 280, "",{1/@@PACK_MULT_LAMBDA@@}, 0.0 + AFRValue = scalar, U16, 282, "AFR",{1/@@PACK_MULT_AFR@@}, 0.0 ; ; see TunerStudioOutputChannels struct @@ -939,6 +940,7 @@ gaugeCategory = Sensors - Basic RPMGauge = RPMValue, "RPM - engine speed", "RPM", 0, 15000, 200, 500, 6000, 6000, 0, 0 CLTGauge = coolant, "Coolant temp", "deg C", -40, 140, -15, 1, 95, 110, 1, 1 IATGauge = intake, "Intake air temp", "deg C", -40, 140, -15, 1, 95, 110, 1, 1 + afr1Gauge = AFRValue, "Air fuel ratio", "", 10, 19.4, 12, 13, 15, 16, 2, 2 lambda1Gauge = lambdaValue, "Lambda", "", 0.65, 1.2, 0.7, 0.75, 1.1, 1.15, 3, 2 MAFGauge = MAFValue, "Mass air flow", "v", 0, 5, 0, 1, 3, 4, 1, 1 VBattGauge = VBatt, "Battery voltage", "V", 8, 21, 9, 10, 17, 19, 1, 1 @@ -1130,6 +1132,7 @@ gaugeCategory = Knock entry = TPS2Value, @@GAUGE_NAME_TPS2@@, float, "%.2f" entry = MAFValue, @@GAUGE_NAME_MAF@@, float, "%.2f" entry = MAPValue, @@GAUGE_NAME_MAP@@, float, "%.1f" + entry = AFRValue, @@GAUGE_NAME_AFR@@, float, "%.2f" entry = lambdaValue, @@GAUGE_NAME_LAMBDA@@, float, "%.2f" entry = VBatt, @@GAUGE_NAME_VBAT@@, float, "%.2f" entry = engineLoad, @@GAUGE_NAME_ENGINE_LOAD@@, float, "%.1f"