diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 5ac7344f15..5190be45a9 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -208,8 +208,6 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara // Ignore 3% position error before complaining m_errorAccumulator.init(3.0f, etbPeriodSeconds); - m_dutyIntegrator.init(engineConfiguration->etbDutyThreshold, etbPeriodSeconds); - reset(); return true; @@ -223,6 +221,8 @@ 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); } void EtbController::showStatus() { @@ -515,7 +515,9 @@ expected EtbController::getClosedLoop(percent_t target, percent_t obs // Normal case - use PID to compute closed loop part float output = m_pid.getOutput(target, observation, etbPeriodSeconds); - etbDutyRateOfChange = m_dutyIntegrator.accumulate(prevOutput - output); + etbDutyAverage = m_dutyAverage.average(output); + + etbDutyAverage = m_dutyRocAverage.average(prevOutput - output); prevOutput = output; // seems good enough to simply check for both TPS sensors diff --git a/firmware/controllers/actuators/electronic_throttle_impl.h b/firmware/controllers/actuators/electronic_throttle_impl.h index f0fe2d3a48..4009ebf87b 100644 --- a/firmware/controllers/actuators/electronic_throttle_impl.h +++ b/firmware/controllers/actuators/electronic_throttle_impl.h @@ -14,6 +14,7 @@ #include "efi_pid.h" #include "error_accumulator.h" #include "electronic_throttle_generated.h" +#include "exp_average.h" /** * Hard code ETB update speed. @@ -87,7 +88,8 @@ private: // todo: rename to m_targetErrorAccumulator ErrorAccumulator m_errorAccumulator; - ErrorAccumulator m_dutyIntegrator; + ExpAverage m_dutyRocAverage; + ExpAverage m_dutyAverage; float prevOutput = 0; // Pedal -> target map