Skip to content

Commit 9655589

Browse files
committed
Update
Add Reset() function to clears `pTerm`, `iTerm`, `dTerm` and `outputSum` values.
1 parent f8e912f commit 9655589

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ void QuickPID::Initialize();
6565

6666
Does all the things that need to happen to ensure a bump-less transfer from manual to automatic mode.
6767

68+
#### Reset
69+
70+
```c++
71+
void QuickPID::Reset();
72+
```
73+
74+
Clears `pTerm`, `iTerm`, `dTerm` and `outputSum` values.
75+
6876
#### PID Query Functions
6977

7078
These functions query the internal state of the PID.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "QuickPID",
3-
"version": "3.1.7",
3+
"version": "3.1.8",
44
"description": "A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.",
55
"keywords": "PID, controller, signal, autotune, tuner, stune",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=QuickPID
2-
version=3.1.7
2+
version=3.1.8
33
author=David Lloyd
44
maintainer=David Lloyd <dlloydev@testcor.ca>
55
sentence=A fast PID controller with multiple options. Various Integral anti-windup, Proportional and Derivative control modes.

src/QuickPID.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 3.1.7
2+
QuickPID Library for Arduino - Version 3.1.8
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID_v1 Library. Licensed under the MIT License.
55
**********************************************************************************/
@@ -253,6 +253,15 @@ void QuickPID::SetAntiWindupMode(uint8_t IawMode) {
253253
iawmode = (iAwMode)IawMode;
254254
}
255255

256+
void QuickPID::Reset() {
257+
lastTime = micros() - sampleTimeUs;
258+
lastInput = 0;
259+
outputSum = 0;
260+
pTerm = 0;
261+
iTerm = 0;
262+
dTerm = 0;
263+
}
264+
256265
/* Status Functions************************************************************
257266
These functions query the internal state of the PID.
258267
******************************************************************************/
@@ -274,6 +283,9 @@ float QuickPID::GetIterm() {
274283
float QuickPID::GetDterm() {
275284
return dTerm;
276285
}
286+
float QuickPID::GetOutputSum() {
287+
return outputSum;
288+
}
277289
uint8_t QuickPID::GetMode() {
278290
return static_cast<uint8_t>(mode);
279291
}

src/QuickPID.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class QuickPID {
7373
void SetAntiWindupMode(iAwMode iAwMode);
7474
void SetAntiWindupMode(uint8_t IawMode);
7575

76-
// Ensure a bumpless transfer from manual to automatic mode
77-
void Initialize();
76+
void Initialize(); // Ensure a bumpless transfer from manual to automatic mode
77+
void Reset(); // Clears pTerm, iTerm, dTerm and outputSum values
7878

7979
// PID Query functions ****************************************************************************************
8080
float GetKp(); // proportional gain
@@ -83,6 +83,7 @@ class QuickPID {
8383
float GetPterm(); // proportional component of output
8484
float GetIterm(); // integral component of output
8585
float GetDterm(); // derivative component of output
86+
float GetOutputSum(); // summation of all pid term components
8687
uint8_t GetMode(); // manual (0), automatic (1), timer (2) or toggle manual/automatic (3)
8788
uint8_t GetDirection(); // direct (0), reverse (1)
8889
uint8_t GetPmode(); // pOnError (0), pOnMeas (1), pOnErrorMeas (2)

0 commit comments

Comments
 (0)