diff --git a/firmware/config/engines/dodge_neon.cpp b/firmware/config/engines/dodge_neon.cpp index 92424c8a7d..efc31fdae0 100644 --- a/firmware/config/engines/dodge_neon.cpp +++ b/firmware/config/engines/dodge_neon.cpp @@ -369,7 +369,6 @@ void setDodgeNeonNGCEngineConfiguration() { engineConfiguration->canNbcType = CAN_BUS_NBC_BMW; // engineConfiguration->canNbcType = CAN_BUS_MAZDA_RX8; - engineConfiguration->tpsAccelLength = 12; engineConfiguration->tpsAccelEnrichmentThreshold = 10; engineConfiguration->wwaeTau = 1.0f; diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index b5cfcf5183..6d8273f8d0 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -29,14 +29,11 @@ static tps_tps_Map3D_t tpsTpsMap; floatms_t TpsAccelEnrichment::getTpsEnrichment() { ScopePerf perf(PE::GetTpsEnrichment); - int maxDeltaIndex = getMaxDeltaIndex(); + if (engineConfiguration->tpsAccelLookback == 0) { + // If disabled, return 0. + return 0; + } - tpsTo = cb.get(maxDeltaIndex); - tpsFrom = cb.get(maxDeltaIndex - 1); - deltaTps = tpsTo - tpsFrom; - - isAboveAccelThreshold = deltaTps > engineConfiguration->tpsAccelEnrichmentThreshold; - isBelowDecelThreshold = deltaTps < -engineConfiguration->tpsDecelEnleanmentThreshold; if (isAboveAccelThreshold) { valueFromTable = tpsTpsMap.getValue(tpsFrom, tpsTo); extraFuel = valueFromTable; @@ -119,7 +116,6 @@ void TpsAccelEnrichment::onEngineCycleTps() { } int TpsAccelEnrichment::getMaxDeltaIndex() { - int len = minI(cb.getSize(), cb.getCount()); tooShort = len < 2; if (tooShort) @@ -166,7 +162,20 @@ void TpsAccelEnrichment::setLength(int length) { } void TpsAccelEnrichment::onNewValue(float currentValue) { + // Push new value in to the history buffer cb.add(currentValue); + + // Update deltas + int maxDeltaIndex = getMaxDeltaIndex(); + tpsFrom = cb.get(maxDeltaIndex - 1); + tpsTo = cb.get(maxDeltaIndex); + deltaTps = tpsTo - tpsFrom; + + // Update threshold detection + isAboveAccelThreshold = deltaTps > engineConfiguration->tpsAccelEnrichmentThreshold; + + // TODO: can deltaTps actually be negative? Will this ever trigger? + isBelowDecelThreshold = deltaTps < -engineConfiguration->tpsDecelEnleanmentThreshold; } TpsAccelEnrichment::TpsAccelEnrichment() { @@ -208,7 +217,8 @@ void setTpsAccelLen(int length) { } void updateAccelParameters() { - setTpsAccelLen(engineConfiguration->tpsAccelLength); + constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f; + setTpsAccelLen(engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond); } #endif /* ! EFI_UNIT_TEST */ diff --git a/firmware/controllers/algo/defaults/default_fuel.cpp b/firmware/controllers/algo/defaults/default_fuel.cpp index 69ea67868b..d562eb5560 100644 --- a/firmware/controllers/algo/defaults/default_fuel.cpp +++ b/firmware/controllers/algo/defaults/default_fuel.cpp @@ -231,7 +231,6 @@ void setDefaultFuel() { // Decel fuel cut setDefaultFuelCutParameters(); - engineConfiguration->tpsAccelLength = 12; engineConfiguration->tpsAccelEnrichmentThreshold = 40; // TPS % change, per engine cycle #if !EFI_UNIT_TEST diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 1d675a2db7..62b5a3e2cf 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -221,6 +221,8 @@ void Engine::periodicSlowCallback() { updateSlowSensors(); checkShutdown(); + tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1)); + updateVrPwm(); #if EFI_FSIO diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 0c055c85ec..a3171a28e4 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -285,7 +285,6 @@ static void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm, efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3"); efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index"); - engine->tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1)); if (trgEventIndex == 0) { engine->tpsAccelEnrichment.onEngineCycleTps(); } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index eadb949655..d21f2c7c77 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -70,7 +70,7 @@ ! Any time an incompatible change is made to the configuration format stored in flash, ! update this string to the current date! It is required to also update TS_SIGNATURE above ! when this happens. -#define FLASH_DATA_VERSION 10008 +#define FLASH_DATA_VERSION 10009 #define LOG_DELIMITER "`" @@ -1171,7 +1171,8 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\ brain_pin_e LIS302DLCsPin; - int tpsAccelLength;+This is the number of engine cycles that the TPS position change can occur over, a longer duration will make the enrichment more active but too long may affect steady state driving, a good default is 30-60 cycles. ;"cycles", 1, 0, 1, 200, 0 + uint8_t tpsAccelLookback;+How long to look back for TPS-based acceleration enrichment. Increasing this time will trigger enrichment for longer when a throttle position change occurs.;"sec", 0.05, 0, 0, 5, 2 + uint8_t[3] unused1689;;"", 1,0,0,0,0 float tpsAccelEnrichmentThreshold;+Maximum change delta of TPS percentage over the 'length'. Actual TPS change has to be above this value in order for TPS/TPS acceleration to kick in.;"roc", 1, 0, 0, 200, 3 int engineLoadAccelLength;;"cycles", 1, 0, 1, 200, 0 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 5e02fbc27a..68ebf26a20 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -3220,7 +3220,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" dialog = TpsAccelPanel, "TPS" field = "Set 'Debug Mode' to see detailed 'TPS acceleration enrichment' diagnostics" - field = "Length", tpsAccelLength + field = "Length", tpsAccelLookback field = "Accel Threshold", tpsAccelEnrichmentThreshold field = "Decel Threshold", tpsDecelEnleanmentThreshold ; field = "Decel Multiplier", tpsDecelEnleanmentMultiplier diff --git a/unit_tests/tests/test_accel_enrichment.cpp b/unit_tests/tests/test_accel_enrichment.cpp index f17b8ad6c0..b6d355a5fb 100644 --- a/unit_tests/tests/test_accel_enrichment.cpp +++ b/unit_tests/tests/test_accel_enrichment.cpp @@ -45,9 +45,16 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) { setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); engineConfiguration->useOnlyRisingEdgeForTrigger = true; + engineConfiguration->tpsAccelEnrichmentThreshold = 5; + engineConfiguration->tpsAccelLookback = 2; + eth.setTriggerType(TT_ONE); + + Sensor::setMockValue(SensorType::Tps1, 0); + engine->periodicSlowCallback(); Sensor::setMockValue(SensorType::Tps1, 7); + engine->periodicSlowCallback(); eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */); ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM"; @@ -57,7 +64,7 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) { Sensor::setMockValue(SensorType::Tps1, 70); eth.fireTriggerEvents2(/* count */ 1, 25 /* ms */); - float expectedAEValue = 29.2; + float expectedAEValue = 7; // it does not matter how many times we invoke 'getTpsEnrichment' - state does not change for (int i = 0; i <20;i++) { ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D); @@ -95,6 +102,7 @@ TEST(fuel, testAccelEnrichmentFractionalTps) { // setup engineConfiguration->tpsAccelEnrichmentThreshold = 5; + engineConfiguration->tpsAccelLookback = 2; // fill tps2tps map (todo: there should be a better way?) static const float tpsTpsConst = 1.0f;