From 2c33abbf7b463bf21977d36b97bd1003d59a7948 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 25 Apr 2024 15:07:21 -0700 Subject: [PATCH] use timer instead of home spun time math --- firmware/controllers/actuators/electronic_throttle.cpp | 3 +-- firmware/controllers/actuators/electronic_throttle_impl.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index f63238bdff..bf26326db7 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -413,8 +413,7 @@ expected EtbController::getClosedLoopAutotune(percent_t target, perce efitick_t now = getTimeNowNt(); // Determine period - float tu = NT2US((float)(now - m_cycleStartTime)) / 1e6; - m_cycleStartTime = now; + float tu = m_autotuneCycleStart.getElapsedSecondsAndReset(now); // Determine amplitude float a = m_maxCycleTps - m_minCycleTps; diff --git a/firmware/controllers/actuators/electronic_throttle_impl.h b/firmware/controllers/actuators/electronic_throttle_impl.h index dee1191458..543d907704 100644 --- a/firmware/controllers/actuators/electronic_throttle_impl.h +++ b/firmware/controllers/actuators/electronic_throttle_impl.h @@ -117,7 +117,7 @@ private: // Autotune helpers bool m_lastIsPositive = false; - efitick_t m_cycleStartTime = 0; + Timer m_autotuneCycleStart; float m_minCycleTps = 0; float m_maxCycleTps = 0; // Autotune measured parameters: gain and ultimate period