From 3a394dc83ac8c3efab6f53bfb75cc40b4a3310e6 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 17 Sep 2024 18:49:13 -0700 Subject: [PATCH] ETB expAverage cleanup #489 --- .../actuators/electronic_throttle.cpp | 8 +---- .../actuators/electronic_throttle_impl.h | 4 --- firmware/integration/rusefi_config.txt | 3 -- firmware/tunerstudio/tunerstudio.template.ini | 4 +-- firmware/util/math/exp_average.h | 26 -------------- unit_tests/tests/util/test_exp_average.cpp | 36 ------------------- unit_tests/tests/util/test_util.mk | 1 - 7 files changed, 3 insertions(+), 79 deletions(-) delete mode 100644 firmware/util/math/exp_average.h delete mode 100644 unit_tests/tests/util/test_exp_average.cpp diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 04d5be43a6..f740be42b8 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -206,8 +206,6 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam void EtbController::reset() { m_shouldResetPid = true; - m_dutyRocAverage.reset(); - m_dutyAverage.reset(); etbTpsErrorCounter = 0; etbPpsErrorCounter = 0; } @@ -216,8 +214,7 @@ void EtbController::onConfigurationChange(pid_s* previousConfiguration) { if (m_motor && !m_pid.isSame(previousConfiguration)) { m_shouldResetPid = true; } - m_dutyRocAverage.init(engineConfiguration->etbRocExpAverageLength); - m_dutyAverage.init(engineConfiguration->etbExpAverageLength); + doInitElectronicThrottle(); } @@ -799,9 +796,6 @@ void setBoschVNH2SP30Curve() { void setDefaultEtbParameters() { engineConfiguration->etbIdleThrottleRange = 5; - engineConfiguration->etbExpAverageLength = 50; - engineConfiguration->etbRocExpAverageLength = 50; - setLinearCurve(config->pedalToTpsPedalBins, /*from*/0, /*to*/100, 1); setLinearCurve(config->pedalToTpsRpmBins, /*from*/0, /*to*/8000, 1); diff --git a/firmware/controllers/actuators/electronic_throttle_impl.h b/firmware/controllers/actuators/electronic_throttle_impl.h index 7ee4cdfc51..93b0e2f68a 100644 --- a/firmware/controllers/actuators/electronic_throttle_impl.h +++ b/firmware/controllers/actuators/electronic_throttle_impl.h @@ -13,7 +13,6 @@ #include "sensor.h" #include "efi_pid.h" #include "electronic_throttle_generated.h" -#include "exp_average.h" /** * Hard code ETB update speed. @@ -98,9 +97,6 @@ private: return m_function == DC_Throttle1 || m_function == DC_Throttle2; } - ExpAverage m_dutyRocAverage; - ExpAverage m_dutyAverage; - Timer m_jamDetectTimer; // Pedal -> target map diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 564bdd48a3..0c6a78aa67 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1242,7 +1242,6 @@ tChargeMode_e tChargeMode; int8_t launchFuelAdderPercent;;"%", 1, 0, 0, 100, 0 uint8_t autoscale etbJamTimeout;Time required to detect a stuck throttle.;"sec", 0.02, 0, 0, 5, 2 - uint16_t etbExpAverageLength;By the way ETB PID runs at 500hz, length in 1/500 of second here. int16_t coastingFuelCutRpmHigh;This sets the RPM above which fuel cut is active.;"rpm", 1, 0, 0, 5000, 0 int16_t coastingFuelCutRpmLow;This sets the RPM below which fuel cut is deactivated, this prevents jerking or issues transitioning to idle;"rpm", 1, 0, 0, 5000, 0 @@ -1271,8 +1270,6 @@ float tChargeAirDecrLimit;Maximum allowed rate of decrease allowed for the estim pid_s idleTimingPid - int16_t etbRocExpAverageLength;By the way ETB PID runs at 500hz, length in 1/500 of second here. - int16_t tpsAccelFractionPeriod;A delay in cycles between fuel-enrich. portions;"cycles", 1, 0, 0, 500, 0 float tpsAccelFractionDivisor;A fraction divisor: 1 or less = entire portion at once, or split into diminishing fractions;"coef", 1, 0, 0, 100, 2 diff --git a/firmware/tunerstudio/tunerstudio.template.ini b/firmware/tunerstudio/tunerstudio.template.ini index 56c1e1565d..1800a6196e 100644 --- a/firmware/tunerstudio/tunerstudio.template.ini +++ b/firmware/tunerstudio/tunerstudio.template.ini @@ -4224,11 +4224,11 @@ dialog = tcuControls, "Transmission Settings" field = "PWM Frequency", etbFreq field = "Minimum ETB position", etbMinimumPosition field = "Maximum ETB position", etbMaximumPosition + field = "" field = "Jam detection error max", jamDetectThreshold field = "Jam detection timeout period", etbJamTimeout commandButton = "Temporarily disable jam detection", cmd_etb_disable_jam_detect - field = "Duty Averaging Length", etbExpAverageLength - field = "Rate of change Averaging Length", etbRocExpAverageLength + ; we need the term about stepper idle in here, because there's a bug in TS that you can't have different visibility ; criteria for the same panel when used in multiple places ; todo: report bug to TS? diff --git a/firmware/util/math/exp_average.h b/firmware/util/math/exp_average.h deleted file mode 100644 index 0ed9ab9015..0000000000 --- a/firmware/util/math/exp_average.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @file exp_average.h - */ - -#pragma once - -class ExpAverage { -public: - float average(float value) { - current = smoothingFactor * value + (1 - smoothingFactor) * current; - return current; - } - - void init(int length) { - smoothingFactor = 2 / (length + 1.0); - } - - void reset() { - current = 0; - smoothingFactor = 0.5; - } - -private: - float current = 0; - float smoothingFactor = 0.5; -}; diff --git a/unit_tests/tests/util/test_exp_average.cpp b/unit_tests/tests/util/test_exp_average.cpp deleted file mode 100644 index 66c73f4fc6..0000000000 --- a/unit_tests/tests/util/test_exp_average.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "pch.h" - -#include "exp_average.h" - -TEST(exp_average, length1) { - ExpAverage ea; - ea.init(1); - ASSERT_NEAR(ea.average(3), 3, EPS2D); - ASSERT_NEAR(ea.average(8), 8, EPS2D); - ASSERT_NEAR(ea.average(3), 3, EPS2D); - ASSERT_NEAR(ea.average(8), 8, EPS2D); -} - -TEST(exp_average, length2) { - ExpAverage ea; - ea.init(2); - ASSERT_NEAR(ea.average(3), 2, EPS2D); - ASSERT_NEAR(ea.average(8), 6, EPS2D); - ASSERT_NEAR(ea.average(3), 4, EPS2D); - ASSERT_NEAR(ea.average(8), 6.6666, EPS2D); -} - -TEST(exp_average, length12) { - ExpAverage ea; - ea.init(12); - ASSERT_NEAR(ea.average(3), 0.4615, EPS2D); - ASSERT_NEAR(ea.average(8), 1.6213, EPS2D); - ASSERT_NEAR(ea.average(3), 1.8334, EPS2D); - ASSERT_NEAR(ea.average(8), 2.7821, EPS2D); - - for (int i = 0; i < 300; i++) { - ea.average(3); - ea.average(8); - } - ASSERT_NEAR(ea.average(3), 5.2916, EPS2D); -} diff --git a/unit_tests/tests/util/test_util.mk b/unit_tests/tests/util/test_util.mk index 195af485ea..e28c3600cc 100644 --- a/unit_tests/tests/util/test_util.mk +++ b/unit_tests/tests/util/test_util.mk @@ -1,7 +1,6 @@ CPPSRC += $(PROJECT_DIR)/../unit_tests/tests/util/test_buffered_writer.cpp \ - $(PROJECT_DIR)/../unit_tests/tests/util/test_exp_average.cpp \ $(PROJECT_DIR)/../unit_tests/tests/util/test_hash.cpp \ INCDIR += $(PROJECT_DIR)/controllers/system