From a3de5fc2767ed93ee15af7e44af032336278dca9 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 12 Jul 2019 22:34:38 -0400 Subject: [PATCH] Annotations in C++ code to produce formulas in rusEfi console #807 refactoring wall wetting --- firmware/console/status_loop.cpp | 4 +-- .../controllers/algo/accel_enrichment.cpp | 29 +++++++++---------- firmware/controllers/algo/accel_enrichment.h | 10 +++++-- firmware/controllers/algo/engine.h | 4 --- .../trigger/main_trigger_callback.cpp | 2 +- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a066299ecd..aebba5c192 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -298,7 +298,7 @@ static void printSensors(Logging *log) { reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_PID_CORR, "ms", ENGINE(engineState.fuelPidCorrection), 2); reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_WALL_AMOUNT, "v", ENGINE(wallFuel).getWallFuel(0), 2); - reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_WALL_CORRECTION, "v", ENGINE(wallFuelCorrection), 2); + reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_WALL_CORRECTION, "v", ENGINE(wallFuel).wallFuelCorrection, 2); reportSensorI(log, fileFormat, GAUGE_NAME_VERSION, "#", getRusEfiVersion()); @@ -864,7 +864,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ } tsOutputChannels->wallFuelAmount = ENGINE(wallFuel).getWallFuel(0); - tsOutputChannels->wallFuelCorrection = ENGINE(wallFuelCorrection); + tsOutputChannels->wallFuelCorrection = ENGINE(wallFuel).wallFuelCorrection; // TPS acceleration tsOutputChannels->deltaTps = engine->tpsAccelEnrichment.getMaxDelta(); tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich; diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index 56e5385024..60cf486e3e 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -41,14 +41,15 @@ tps_tps_Map3D_t tpsTpsMap("tpsTps"); static Logging *logger = NULL; WallFuel::WallFuel() { - reset(); + resetWF(); } -void WallFuel::reset() { - memset(wallFuel, 0, sizeof(wallFuel)); +void WallFuel::resetWF() { + wallFuel = 0; } -floatms_t WallFuel::adjust(int injectorIndex, floatms_t M_des DECLARE_ENGINE_PARAMETER_SUFFIX) { +// +floatms_t WallFuel::adjust(int injectorIndex, floatms_t M_des DECLARE_ENGINE_PARAMETER_SUFFIX) { if (cisnan(M_des)) { return M_des; } @@ -94,15 +95,13 @@ floatms_t WallFuel::adjust(int injectorIndex, floatms_t M_des DECLARE_ENGINE_PAR // if tau is really small, we get div/0. // you probably meant to disable wwae. float tau = CONFIG(wwaeTau); - if(tau < 0.01f) - { + if (tau < 0.01f) { return M_des; } // Ignore really slow RPM int rpm = GET_RPM(); - if(rpm < 100) - { + if (rpm < 100) { return M_des; } @@ -113,32 +112,30 @@ floatms_t WallFuel::adjust(int injectorIndex, floatms_t M_des DECLARE_ENGINE_PAR // For reasonable values {tau, beta}, this should only be possible // at extremely low engine speeds (<300rpm ish) // Clamp beta to less than alpha. - if(beta > alpha) - { + if (beta > alpha) { beta = alpha; } - float M_f = wallFuel[injectorIndex]; + float M_f = wallFuel/*[injectorIndex]*/; float M_cmd = (M_des - (1 - alpha) * M_f) / (1 - beta); // We can't inject a negative amount of fuel // If this goes below zero we will be over-fueling slightly, // but that's ok. - if(M_cmd <= 0) - { + if (M_cmd <= 0) { M_cmd = 0; } // remainder on walls from last time + new from this time float M_f_next = alpha * M_f + beta * M_cmd; - wallFuel[injectorIndex] = M_f_next; - engine->wallFuelCorrection = M_cmd - M_des; + wallFuel/*[injectorIndex]*/ = M_f_next; + wallFuelCorrection = M_cmd - M_des; return M_cmd; } floatms_t WallFuel::getWallFuel(int injectorIndex) const { - return wallFuel[injectorIndex]; + return wallFuel/*[injectorIndex]*/; } int AccelEnrichmemnt::getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/algo/accel_enrichment.h b/firmware/controllers/algo/accel_enrichment.h index 326c8d1f99..6a09e23b54 100644 --- a/firmware/controllers/algo/accel_enrichment.h +++ b/firmware/controllers/algo/accel_enrichment.h @@ -66,12 +66,16 @@ public: */ floatms_t adjust(int injectorIndex, floatms_t target DECLARE_ENGINE_PARAMETER_SUFFIX); floatms_t getWallFuel(int injectorIndex) const; - void reset(); + void resetWF(); + /** + * fuel injection time correction to account for wall wetting effect, for current cycle + */ + floatms_t wallFuelCorrection = 0; private: /** - * Amount of fuel on the wall, in ms of injector open time, for specific injector. + * Amount of fuel on the wall, in ms of injector open time, for each injector. */ - floatms_t wallFuel[INJECTION_PIN_COUNT]; + floatms_t wallFuel/*[INJECTION_PIN_COUNT]*/; }; void initAccelEnrichment(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 1a742cc404..933e1d38e7 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -189,10 +189,6 @@ public: * @see getInjectionDuration() */ floatms_t injectionDuration = 0; - /** - * fuel injection time correction to account for wall wetting effect, for current cycle - */ - floatms_t wallFuelCorrection = 0; /** * This one with wall wetting accounted for, used for logging. diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 7f69545dda..785eba5755 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -214,7 +214,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE * wetting coefficient works the same way for any injection mode, or is something * x2 or /2? */ - const floatms_t injectionDuration = ENGINE(wallFuel).adjust(event->outputs[0]->injectorIndex, ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX); + const floatms_t injectionDuration = ENGINE(wallFuel).adjust(0/*event->outputs[0]->injectorIndex*/, ENGINE(injectionDuration) PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_PRINTF_FUEL_DETAILS printf("fuel injectionDuration=%.2f adjusted=%.2f\t\n", ENGINE(injectionDuration), injectionDuration); #endif /*EFI_PRINTF_FUEL_DETAILS */