From 5a5320e7e68857ea23776297fc7c23aacec19f52 Mon Sep 17 00:00:00 2001 From: David Forrest Date: Thu, 2 Mar 2023 16:13:29 -0500 Subject: [PATCH] Add GetIntegral() and SetIntegral(double) for user-space anti-windup --- PID_v1.cpp | 14 ++++++++++++++ PID_v1.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/PID_v1.cpp b/PID_v1.cpp index cb6637c..6a5bcf8 100644 --- a/PID_v1.cpp +++ b/PID_v1.cpp @@ -182,6 +182,20 @@ void PID::SetMode(int Mode) inAuto = newAuto; } +/* GetIntegral(...)************************************************************* + * Get Integral term for user access to anti-windup schemes + ******************************************************************************/ +double PID::GetIntegral(){ + return outputSum; +} + +/* SetIntegral(...)************************************************************* + * Set Integral term for user access to anti-windup schemes + ******************************************************************************/ +void PID::SetIntegral(double Integral){ + outputSum = Integral; +} + /* Initialize()**************************************************************** * does all the things that need to happen to ensure a bumpless transfer * from manual to automatic mode. diff --git a/PID_v1.h b/PID_v1.h index 9cba046..2be4723 100644 --- a/PID_v1.h +++ b/PID_v1.h @@ -50,6 +50,7 @@ class PID // once it is set in the constructor. void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which // the PID calculation is performed. default is 100 + void SetIntegral(double); // * sets the internal Integral term, in output units @@ -59,6 +60,7 @@ class PID double GetKd(); // where it's important to know what is actually int GetMode(); // inside the PID. int GetDirection(); // + double GetIntegral(); // private: void Initialize();