Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Add Reset() function to clears `pTerm`, `iTerm`, `dTerm` and `outputSum` values.
  • Loading branch information
Dlloydev committed May 5, 2023
1 parent f8e912f commit 9655589
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=QuickPID
version=3.1.7
version=3.1.8
author=David Lloyd
maintainer=David Lloyd <dlloydev@testcor.ca>
sentence=A fast PID controller with multiple options. Various Integral anti-windup, Proportional and Derivative control modes.
Expand Down
14 changes: 13 additions & 1 deletion src/QuickPID.cpp
Original file line number Diff line number Diff line change
@@ -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.
**********************************************************************************/
Expand Down Expand Up @@ -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.
******************************************************************************/
Expand All @@ -274,6 +283,9 @@ float QuickPID::GetIterm() {
float QuickPID::GetDterm() {
return dTerm;
}
float QuickPID::GetOutputSum() {
return outputSum;
}
uint8_t QuickPID::GetMode() {
return static_cast<uint8_t>(mode);
}
Expand Down
5 changes: 3 additions & 2 deletions src/QuickPID.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9655589

Please sign in to comment.