From 96555896cb6a4e01acab0aaf0ef92aa59cb1e32e Mon Sep 17 00:00:00 2001 From: Dlloydev Date: Fri, 5 May 2023 18:04:49 -0400 Subject: [PATCH] Update Add Reset() function to clears `pTerm`, `iTerm`, `dTerm` and `outputSum` values. --- README.md | 8 ++++++++ library.json | 2 +- library.properties | 2 +- src/QuickPID.cpp | 14 +++++++++++++- src/QuickPID.h | 5 +++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9036a9a..ba8c4ec 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,14 @@ void QuickPID::Initialize(); Does all the things that need to happen to ensure a bump-less transfer from manual to automatic mode. +#### Reset + +```c++ +void QuickPID::Reset(); +``` + +Clears `pTerm`, `iTerm`, `dTerm` and `outputSum` values. + #### PID Query Functions These functions query the internal state of the PID. diff --git a/library.json b/library.json index 2625072..3a8ff31 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "QuickPID", - "version": "3.1.7", + "version": "3.1.8", "description": "A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.", "keywords": "PID, controller, signal, autotune, tuner, stune", "repository": diff --git a/library.properties b/library.properties index 3ca8921..cb41dbc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=QuickPID -version=3.1.7 +version=3.1.8 author=David Lloyd maintainer=David Lloyd sentence=A fast PID controller with multiple options. Various Integral anti-windup, Proportional and Derivative control modes. diff --git a/src/QuickPID.cpp b/src/QuickPID.cpp index e77c6ad..fd1792d 100644 --- a/src/QuickPID.cpp +++ b/src/QuickPID.cpp @@ -1,5 +1,5 @@ /********************************************************************************** - QuickPID Library for Arduino - Version 3.1.7 + QuickPID Library for Arduino - Version 3.1.8 by dlloydev https://github.com/Dlloydev/QuickPID Based on the Arduino PID_v1 Library. Licensed under the MIT License. **********************************************************************************/ @@ -253,6 +253,15 @@ void QuickPID::SetAntiWindupMode(uint8_t IawMode) { iawmode = (iAwMode)IawMode; } +void QuickPID::Reset() { + lastTime = micros() - sampleTimeUs; + lastInput = 0; + outputSum = 0; + pTerm = 0; + iTerm = 0; + dTerm = 0; +} + /* Status Functions************************************************************ These functions query the internal state of the PID. ******************************************************************************/ @@ -274,6 +283,9 @@ float QuickPID::GetIterm() { float QuickPID::GetDterm() { return dTerm; } +float QuickPID::GetOutputSum() { + return outputSum; +} uint8_t QuickPID::GetMode() { return static_cast(mode); } diff --git a/src/QuickPID.h b/src/QuickPID.h index 38d1419..5f327ac 100644 --- a/src/QuickPID.h +++ b/src/QuickPID.h @@ -73,8 +73,8 @@ class QuickPID { void SetAntiWindupMode(iAwMode iAwMode); void SetAntiWindupMode(uint8_t IawMode); - // Ensure a bumpless transfer from manual to automatic mode - void Initialize(); + void Initialize(); // Ensure a bumpless transfer from manual to automatic mode + void Reset(); // Clears pTerm, iTerm, dTerm and outputSum values // PID Query functions **************************************************************************************** float GetKp(); // proportional gain @@ -83,6 +83,7 @@ class QuickPID { float GetPterm(); // proportional component of output float GetIterm(); // integral component of output float GetDterm(); // derivative component of output + float GetOutputSum(); // summation of all pid term components uint8_t GetMode(); // manual (0), automatic (1), timer (2) or toggle manual/automatic (3) uint8_t GetDirection(); // direct (0), reverse (1) uint8_t GetPmode(); // pOnError (0), pOnMeas (1), pOnErrorMeas (2)