From 8a3727de3e04c49633e6f1e6212d47f2c783f040 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 29 Nov 2022 14:59:08 -0500 Subject: [PATCH] ETB duty cycle jitter #4833 --- firmware/controllers/actuators/electronic_throttle.cpp | 6 ++++-- firmware/controllers/actuators/electronic_throttle_impl.h | 2 ++ firmware/util/math/exp_average.h | 5 +++++ unit_tests/tests/actuators/test_etb_integrated.cpp | 4 +--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 7aecc1ff12..df43913724 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -215,6 +215,9 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara void EtbController::reset() { m_shouldResetPid = true; + etbDutyRateOfChange = etbDutyAverage = 0; + m_dutyRocAverage.reset(); + m_dutyAverage.reset(); } void EtbController::onConfigurationChange(pid_s* previousConfiguration) { @@ -740,12 +743,11 @@ static void showEtbInfo() { #endif /* EFI_PROD_CODE */ } -static void etbPidReset() { +void etbPidReset() { for (int i = 0 ; i < ETB_COUNT; i++) { if (auto controller = engine->etbControllers[i]) { controller->reset(); } - } } diff --git a/firmware/controllers/actuators/electronic_throttle_impl.h b/firmware/controllers/actuators/electronic_throttle_impl.h index 1f154e4e44..3edf3af191 100644 --- a/firmware/controllers/actuators/electronic_throttle_impl.h +++ b/firmware/controllers/actuators/electronic_throttle_impl.h @@ -119,6 +119,8 @@ private: Timer m_luaAdjustmentTimer; }; +void etbPidReset(); + class EtbController1 : public EtbController { }; class EtbController2 : public EtbController { diff --git a/firmware/util/math/exp_average.h b/firmware/util/math/exp_average.h index d2ba98afd0..0ed9ab9015 100644 --- a/firmware/util/math/exp_average.h +++ b/firmware/util/math/exp_average.h @@ -15,6 +15,11 @@ public: 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/actuators/test_etb_integrated.cpp b/unit_tests/tests/actuators/test_etb_integrated.cpp index 6ab6db299a..95bbfa6556 100644 --- a/unit_tests/tests/actuators/test_etb_integrated.cpp +++ b/unit_tests/tests/actuators/test_etb_integrated.cpp @@ -5,6 +5,7 @@ TEST(etb, integrated) { EngineTestHelper eth(TEST_ENGINE); + etbPidReset(); // ETB controlles are global shared instances :( engineConfiguration->tps1_1AdcChannel = EFI_ADC_3; engineConfiguration->tps1_2AdcChannel = EFI_ADC_3; @@ -17,15 +18,12 @@ TEST(etb, integrated) { Sensor::setMockValue(SensorType::Tps1, 25.0f, true); - initTps(); doInitElectronicThrottle(); EtbController *etb = (EtbController*)engine->etbControllers[0]; etb->update(); - - ASSERT_EQ(engine->outputChannels.etbTarget, 40); ASSERT_EQ(etb->prevOutput, 100); ASSERT_EQ(etb->etbDutyAverage, 50);