From fbd1eab28992ecec4aa1eccfb520bdb8cd3ac04c Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 2 Jun 2017 21:34:00 -0400 Subject: [PATCH] PID reset counter --- firmware/controllers/math/pid.cpp | 9 +++++---- firmware/controllers/math/pid.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index 64650c0c66..c2f8530d1a 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -21,9 +21,9 @@ Pid::Pid(pid_s *pid) { void Pid::init(pid_s *pid) { this->pid = pid; + resetCounter = 0; - dTerm = iTerm = 0; - prevResult = prevInput = prevTarget = prevError = 0; + reset(); } bool Pid::isSame(pid_s *pid) { @@ -74,8 +74,9 @@ void Pid::updateFactors(float pFactor, float iFactor, float dFactor) { } void Pid::reset(void) { - iTerm = 0; - prevError = 0; + dTerm = iTerm = 0; + prevResult = prevInput = prevTarget = prevError = 0; + resetCounter++; } float Pid::getP(void) { diff --git a/firmware/controllers/math/pid.h b/firmware/controllers/math/pid.h index 0bcd75d9b7..5d5037bc94 100644 --- a/firmware/controllers/math/pid.h +++ b/firmware/controllers/math/pid.h @@ -44,6 +44,7 @@ public: float dTerm; // we are remembering this only for debugging purposes void showPidStatus(Logging *logging, const char*msg); void sleep(); + int resetCounter; private: pid_s *pid;