Skip to content

Commit a8cf244

Browse files
committed
Update
- Now using 2-stage integral anti-windup strategy - Better organized compute code - Some cleanup and documentation updates
1 parent 5817808 commit a8cf244

File tree

4 files changed

+15
-33
lines changed

4 files changed

+15
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Development began with a fork of the Arduino PID Library. Modifications and new
1717
- [x] Variable Proportional on Error to Proportional on Measurement parameter `POn`
1818
- [x] Variable Derivative on Error to Derivative on Measurement parameter `DOn`
1919
- [x] New PID Query Functions: `GetPterm();` `GetIterm();` `GetDterm();`
20-
- [x] Integral windup prevention when output exceeds limits
20+
- [x] 2-stage Integral windup prevention when output exceeds limits
2121
- [x] New REVERSE mode only changes sign of `error` and `dInput`
2222
- [x] Uses `float` instead of `double`
2323

library.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "QuickPID",
3-
"version": "2.4.3",
4-
"description": "A fast PID controller with an AutoTune dynamic object, 10 tunung rules, Integral anti-windup, TIMER Mode, variable Proportional and Derivative on Error to Measurement and full-featured Arduino analogWrite compatibility for ESP32 and ESP32-S2.",
3+
"version": "2.4.4",
4+
"description": "A fast PID controller with AutoTune dynamic object, 10 tuning rules, Integral anti-windup, TIMER Mode and mixing of Proportional and Derivative on Error to Measurement. Also includes analogWrite compatibility for ESP32 and ESP32-S2.",
55
"keywords": "PID, controller, signal",
66
"repository":
77
{
@@ -20,7 +20,7 @@
2020
"license": "MIT",
2121
"homepage": "https://github.com/Dlloydev/QuickPID",
2222
"dependencies": {
23-
"QuickPID": "~2.4.3"
23+
"QuickPID": "~2.4.4"
2424
},
2525
"frameworks": "*",
2626
"platforms": "*"

library.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name=QuickPID
2-
version=2.4.3
2+
version=2.4.4
33
author=David Lloyd
44
maintainer=David Lloyd <[email protected]>
5-
sentence=A fast PID controller with AutoTune, integral anti-windup and variable controls for Proportional and Derivative on Error to Measurement.
6-
paragraph=A fast PID controller with an AutoTune dynamic object, 10 tunung rules, Integral anti-windup, TIMER Mode, variable Proportional and Derivative on Error to Measurement and full-featured Arduino analogWrite compatibility for ESP32 and ESP32-S2.
5+
sentence=A fast PID controller with AutoTune dynamic object, 10 tuning rules, Integral anti-windup, TIMER Mode and mixing of Proportional and Derivative on Error to Measurement.
6+
paragraph=Also includes analogWrite compatibility for ESP32 and ESP32-S2.
77
category=Signal Input/Output
88
url=https://github.com/Dlloydev/QuickPID
99
architectures=*
10-
includes=QuickPID.h,analogWrite.h

src/QuickPID.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 2.4.3
2+
QuickPID Library for Arduino - Version 2.4.4
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID Library and work on AutoTunePID class
55
by gnalbandian (Gonzalo). Licensed under the MIT License.
@@ -65,18 +65,13 @@ bool QuickPID::Compute() {
6565
dmTerm = kdm * dInput;
6666
deTerm = -kde * error;
6767

68-
outputSum += iTerm;
69-
if (outputSum > outMax) iTerm -= outputSum - outMax; // integral anti-windup
70-
else if (outputSum < outMin) iTerm += outMin - outputSum;
68+
outputSum += iTerm; // include integral amount
69+
if (outputSum > outMax) outputSum -= outputSum - outMax; // early integral anti-windup at outMax
70+
else if (outputSum < outMin) outputSum += outMin - outputSum; // early integral anti-windup at outMin
71+
outputSum = constrain(outputSum, outMin, outMax); // integral anti-windup clamp
72+
outputSum = constrain(outputSum - pmTerm, outMin, outMax); // include pmTerm and clamp
73+
*myOutput = constrain(outputSum + peTerm + dmTerm - deTerm, outMin, outMax); // totalize, clamp and drive the output
7174

72-
float output = peTerm;
73-
outputSum -= pmTerm;
74-
outputSum = constrain(outputSum, outMin, outMax);
75-
76-
output += outputSum - deTerm + dmTerm;
77-
output = constrain(output, outMin, outMax);
78-
79-
*myOutput = output;
8075
lastInput = input;
8176
lastTime = now;
8277
return true;
@@ -399,26 +394,14 @@ void AutoTunePID::setAutoTuneConstants(float * kp, float * ki, float * kd) {
399394
}
400395

401396
/* Utility************************************************************/
402-
397+
// https://github.com/avandalen/avdweb_AnalogReadFast
403398
int QuickPID::analogReadFast(int ADCpin) {
404399
#if defined(__AVR_ATmega328P__)
405400
byte ADCregOriginal = ADCSRA;
406401
ADCSRA = (ADCSRA & B11111000) | 5; // 32 prescaler
407402
int adc = analogRead(ADCpin);
408403
ADCSRA = ADCregOriginal;
409404
return adc;
410-
#elif defined(__AVR_ATtiny_Zero_One__) || defined(__AVR_ATmega_Zero__)
411-
byte ADCregOriginal = ADC0_CTRLC;
412-
ADC0_CTRLC = 0x54; // reduced cap, Vdd ref, 32 prescaler
413-
int adc = analogRead(ADCpin);
414-
ADC0_CTRLC = ADCregOriginal;
415-
return adc;
416-
#elif defined(__AVR_DA__)
417-
byte ADCregOriginal = ADC0.CTRLC;
418-
ADC0.CTRLC = ADC_PRESC_DIV32_gc; // 32 prescaler
419-
int adc = analogRead(ADCpin);
420-
ADC0.CTRLC = ADCregOriginal;
421-
return adc;
422405
#else
423406
return analogRead(ADCpin);
424407
# endif

0 commit comments

Comments
 (0)