From 109b30f063ba1074a1247d6fd20be7421ead26a9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 5 Jun 2024 21:43:09 -0400 Subject: [PATCH] only:stftCorrection vs fuelPidCorrection vs engine --- firmware/console/status_loop.cpp | 7 ++++--- firmware/controllers/algo/engine.h | 3 --- firmware/controllers/algo/engine2.cpp | 5 +++-- firmware/controllers/algo/engine_state.h | 2 ++ firmware/controllers/can/can_dash_ms.cpp | 2 +- firmware/controllers/can/can_verbose.cpp | 4 ++-- firmware/controllers/can/obd2.cpp | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index ec2ec93c9c..ca49a085e8 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -553,9 +553,10 @@ static void updateSensors() { } static void updateFuelCorrections() { - engine->outputChannels.fuelPidCorrection[0] = 100.0f * (engine->stftCorrection[0] - 1.0f); - engine->outputChannels.fuelPidCorrection[1] = 100.0f * (engine->stftCorrection[1] - 1.0f); - engine->outputChannels.Gego = 100.0f * engine->stftCorrection[0]; + for (size_t i = 0; i < STFT_BANK_COUNT; i++) { + engine->outputChannels.fuelPidCorrection[i] = 100.0f * (engine->engineState.stftCorrection[i] - 1.0f); + } + engine->outputChannels.Gego = 100.0f * engine->engineState.stftCorrection[0]; } static void updateFuelResults() { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 81c42f2dd0..a0fecd9914 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -287,9 +287,6 @@ public: #endif // EFI_SHAFT_POSITION_INPUT - float stftCorrection[STFT_BANK_COUNT] = {0}; - - /** * See FAST_CALLBACK_PERIOD_MS */ diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 95ee8adfb3..54ab6d52ce 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -176,13 +176,14 @@ void EngineState::periodicFastCallback() { // compute per-bank fueling for (size_t i = 0; i < STFT_BANK_COUNT; i++) { float corr = clResult.banks[i]; - engine->stftCorrection[i] = corr; + // todo: move to engine_state.txt and get rid of fuelPidCorrection in output_channels.txt? + engine->engineState.stftCorrection[i] = corr; } // Now apply that to per-cylinder fueling and timing for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) { uint8_t bankIndex = engineConfiguration->cylinderBankSelect[i]; - auto bankTrim = engine->stftCorrection[bankIndex]; + auto bankTrim = engine->engineState.stftCorrection[bankIndex]; auto cylinderTrim = getCylinderFuelTrim(i, rpm, fuelLoad); // Apply both per-bank and per-cylinder trims diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index 2cfaeac5e0..ce1b67d634 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -33,6 +33,8 @@ public: // Per-injection fuel mass, including TPS accel enrich float injectionMass[MAX_CYLINDER_COUNT] = {0}; + // todo: move to .txt or even better extract injection.txt? + float stftCorrection[STFT_BANK_COUNT] = {0}; float injectionStage2Fraction = 0; diff --git a/firmware/controllers/can/can_dash_ms.cpp b/firmware/controllers/can/can_dash_ms.cpp index 65d6da7143..18c9878b1d 100644 --- a/firmware/controllers/can/can_dash_ms.cpp +++ b/firmware/controllers/can/can_dash_ms.cpp @@ -72,7 +72,7 @@ static void populateFrame(ms1514& msg) msg.afrtgt1 = (float)engine->fuelComputer.targetLambda * STOICH_RATIO; msg.AFR1 = Sensor::getOrZero(SensorType::Lambda1) * STOICH_RATIO; /* TODO: banks? */ - msg.EGOcor1 = engine->stftCorrection[0]; + msg.EGOcor1 = engine->engineState.stftCorrection[0]; /* TODO */ msg.egt1 = 0; msg.pwseq1 = engine->engineState.injectionDuration; diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index f64a6426be..17c8a98586 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -165,8 +165,8 @@ static void populateFrame(Fueling2& msg) { msg.fuelConsumedGram = engine->module()->getConsumedGrams(); msg.fuelFlowRate = engine->module()->getConsumptionGramPerSecond(); - for (size_t i = 0; i < 2; i++) { - msg.fuelTrim[i] = 100.0f * (engine->stftCorrection[i] - 1.0f); + for (size_t i = 0; i < STFT_BANK_COUNT; i++) { + msg.fuelTrim[i] = 100.0f * (engine->engineState.stftCorrection[i] - 1.0f); } } diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index d4cf90a86d..2ca3a5d83f 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -126,10 +126,10 @@ static void handleGetDataRequest(const CANRxFrame& rx, size_t busIndex) { obdSendValue(_1_MODE, pid, 1, Sensor::getOrZero(SensorType::Clt) + ODB_TEMP_EXTRA, busIndex); break; case PID_STFT_BANK1: - obdSendValue(_1_MODE, pid, 1, 128 * engine->stftCorrection[0], busIndex); + obdSendValue(_1_MODE, pid, 1, 128 * engine->engineState.stftCorrection[0], busIndex); break; case PID_STFT_BANK2: - obdSendValue(_1_MODE, pid, 1, 128 * engine->stftCorrection[1], busIndex); + obdSendValue(_1_MODE, pid, 1, 128 * engine->engineState.stftCorrection[1], busIndex); break; case PID_INTAKE_MAP: obdSendValue(_1_MODE, pid, 1, Sensor::getOrZero(SensorType::Map), busIndex);