diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 383aeb6beb..549752f220 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -608,7 +608,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->injectorLagMs = ENGINE(engineState.injectorLag); tsOutputChannels->timeSeconds = getTimeNowSeconds(); - if (engineConfiguration->debugMode == TPS_ACCEL) { + if (engineConfiguration->debugMode == DBG_TPS_ACCEL) { tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize(); } diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index 6be902f8c7..3f4ed0c15c 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -26,10 +26,17 @@ #include "engine_state.h" #include "engine_math.h" #include "signal_executor.h" +#if !EFI_UNIT_TEST +#include "tunerstudio_configuration.h" +extern TunerStudioOutputChannels tsOutputChannels; +#endif EXTERN_ENGINE ; + +tps_tps_Map3D_t tpsTpsMap("tpsTps"); + static Logging *logger = NULL; WallFuel::WallFuel() { @@ -95,9 +102,25 @@ float AccelEnrichmemnt::getMaxDelta(DECLARE_ENGINE_PARAMETER_F) { // todo: eliminate code duplication between these two methods! Some pointer magic would help. floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_F) { - float d = getMaxDelta(PASS_ENGINE_PARAMETER_F); + int index = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_F); + +// FuelSchedule *fs = engine->engineConfiguration2->injectionEvents; + float tpsTo = cb.get(index); + float tpsFrom = cb.get(index - 1); + float d = tpsTo - tpsFrom; + + float deltaMult = tpsTpsMap.getValue(tpsFrom, tpsTo); + + +#if !EFI_UNIT_TEST + if (engineConfiguration->debugMode == DBG_TPS_ACCEL) { + tsOutputChannels.debugFloatField1 = tpsFrom; + tsOutputChannels.debugFloatField2 = tpsTo; + } +#endif + if (d > engineConfiguration->tpsAccelEnrichmentThreshold) { - return d * engineConfiguration->tpsAccelEnrichmentMultiplier; + return deltaMult; } if (d < -engineConfiguration->tpsDecelEnleanmentThreshold) { return d * engineConfiguration->tpsDecelEnleanmentMultiplier; @@ -220,8 +243,14 @@ void updateAccelParameters() { setTpsAccelLen(engineConfiguration->tpsAccelLength); } -void initAccelEnrichment(Logging *sharedLogger) { +#endif /* ! EFI_UNIT_TEST */ + + +void initAccelEnrichment(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { logger = sharedLogger; + tpsTpsMap.init(config->tpsTpsAccelTable, config->tpsTpsAccelFromRpmBins, config->tpsTpsAccelToRpmBins); + +#if ! EFI_UNIT_TEST || defined(__DOXYGEN__) addConsoleActionI("set_tps_accel_len", setTpsAccelLen); addConsoleActionF("set_tps_accel_threshold", setTpsAccelThr); addConsoleActionF("set_tps_accel_multiplier", setTpsAccelMult); @@ -236,5 +265,6 @@ void initAccelEnrichment(Logging *sharedLogger) { addConsoleAction("accelinfo", accelInfo); updateAccelParameters(); -} #endif /* ! EFI_UNIT_TEST */ +} + diff --git a/firmware/controllers/algo/accel_enrichment.h b/firmware/controllers/algo/accel_enrichment.h index 59dd11fed0..e34b18b738 100644 --- a/firmware/controllers/algo/accel_enrichment.h +++ b/firmware/controllers/algo/accel_enrichment.h @@ -61,7 +61,7 @@ private: floatms_t wallFuel[INJECTION_PIN_COUNT]; }; -void initAccelEnrichment(Logging *sharedLogger); +void initAccelEnrichment(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S); void setEngineLoadAccelLen(int len); void setEngineLoadAccelThr(float value); diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 825c9cb0db..41b54875b6 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -576,7 +576,7 @@ typedef enum { typedef enum { ALTERNATOR = 0, - TPS_ACCEL = 1, + DBG_TPS_ACCEL = 1, WARMUP_ENRICH = 2, IDLE = 3, diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 52e62aa8ee..ff62b12799 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -10,6 +10,7 @@ #include "trigger_decoder.h" #include "speed_density.h" #include "fuel_math.h" +#include "accel_enrichment.h" extern int timeNow; @@ -39,6 +40,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste Engine *engine = &this->engine; prepareFuelMap(PASS_ENGINE_PARAMETER_F); + initAccelEnrichment(NULL PASS_ENGINE_PARAMETER); initSpeedDensity(PASS_ENGINE_PARAMETER_F);