Skip to content

Commit f326bbb

Browse files
committed
Update
- Fixed REVERSE acting controller mode. - now using src folder for source code - replaced defines with enumerated types and inline functions
1 parent 755867b commit f326bbb

File tree

14 files changed

+88
-75
lines changed

14 files changed

+88
-75
lines changed

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Copyright 2011-2017 Brett Beauregard <[email protected]> brettbeauregard.com
21
Copyright 2021 David Lloyd <[email protected]>
32

43
Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -16,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1615
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1716
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1817
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ The new `kpi` and `kpd` parameters are calculated in the `SetTunings()` function
4747
kpd = kp * (1 - pOn) + kd;
4848
```
4949

50+
### Controller Action
51+
52+
If a positive error increases the controller's output, the controller is said to be direct acting (i.e. heating process). When a positive error decreases the controller's output, the controller is said to be reverse acting (i.e. cooling process). Since the PWM and ADC peripherals on microcontrollers only operate with positive values, QuickPID only uses positive values for Input, Output and Setpoint. When the controller is set to `REVERSE` acting, the sign of the `error` and `dInput` (derivative of Input) is internally changed. All operating ranges and limits remain the same. To simulate a `REVERSE` acting process from a process that's `DIRECT` acting, the Input value needs to be "flipped". That is, if your reading from a 10-bit ADC with 0-1023 range, the input value used is (1023 - reading). See the example [AutoTune_RC_Filter.ino](https://github.com/Dlloydev/QuickPID/blob/master/examples/AutoTune_RC_Filter/AutoTune_RC_Filter.ino) for details.
53+
5054
### Functions
5155

5256
#### QuickPID_Constructor
@@ -180,6 +184,12 @@ Use this link for reference. Note that if you're using QuickPID, there's no need
180184
181185
#### [![arduino-library-badge](https://www.ardu-badge.com/badge/QuickPID.svg?)](https://www.ardu-badge.com/QuickPID)
182186
187+
#### Version 2.2.7
188+
189+
- Fixed REVERSE acting controller mode.
190+
- now using src folder for source code
191+
- replaced defines with enumerated types and inline functions
192+
183193
#### Version 2.2.6
184194
185195
- Changed Input, Output and Setpoint parameters to float.

examples/AutoTune_RC_Filter/AutoTune_RC_Filter.ino

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ unsigned long timeout = 120; // AutoTune timeout (sec)
3030
float Input, Output, Setpoint;
3131
float Kp = 0, Ki = 0, Kd = 0;
3232

33-
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, DIRECT);
33+
// choose controller direction:
34+
// DIRECT: Input increases when the output is increased or the error is positive (heating).
35+
// REVERSE: Input decreases when the output is increased or when the error is positive (cooling).
36+
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, QuickPID::DIRECT);
37+
//QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, QuickPID::REVERSE);
3438

3539
void setup()
3640
{
@@ -39,8 +43,8 @@ void setup()
3943

4044
myQuickPID.AutoTune(inputPin, outputPin, tuningRule, Print, timeout);
4145
myQuickPID.SetTunings(myQuickPID.GetKp(), myQuickPID.GetKi(), myQuickPID.GetKd());
42-
myQuickPID.SetSampleTimeUs(5000); // recommend 5000µs (5ms) minimum
43-
myQuickPID.SetMode(AUTOMATIC);
46+
myQuickPID.SetSampleTimeUs(4000); // 4ms
47+
myQuickPID.SetMode(QuickPID::AUTOMATIC);
4448
Setpoint = 700;
4549

4650
if (Print == 1) {
@@ -66,7 +70,11 @@ void loop()
6670
Serial.print("Output:"); Serial.print(Output); Serial.print(",");
6771
Serial.println(",");
6872

69-
Input = myQuickPID.analogReadFast(inputPin);
73+
if (myQuickPID.GetDirection() == QuickPID::REVERSE) {
74+
Input = (1023 - myQuickPID.analogReadFast(inputPin)); // simulate reverse acting controller (cooling)
75+
} else {
76+
Input = (myQuickPID.analogReadFast(inputPin));
77+
}
7078
myQuickPID.Compute();
7179
analogWrite(outputPin, Output);
7280
}

examples/QuickPID_AdaptiveTunings/QuickPID_AdaptiveTunings.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ float aggPOn = 1.0; // Range is 0.0 to 1.0 (1.0 is 100% P on Error, 0% P on Meas
2424
float consPOn = 0.0; // Range is 0.0 to 1.0 (0.0 is 0% P on Error, 100% P on Measurement)
2525

2626
//Specify the links and initial tuning parameters
27-
QuickPID myQuickPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, aggPOn, DIRECT);
27+
QuickPID myQuickPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, aggPOn, QuickPID::DIRECT);
2828

2929
void setup()
3030
{
@@ -33,7 +33,7 @@ void setup()
3333
Setpoint = 100;
3434

3535
//turn the PID on
36-
myQuickPID.SetMode(AUTOMATIC);
36+
myQuickPID.SetMode(QuickPID::AUTOMATIC);
3737
}
3838

3939
void loop()

examples/QuickPID_Basic/QuickPID_Basic.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ float Setpoint, Input, Output;
1414
//Specify the links and initial tuning parameters
1515
float Kp = 2, Ki = 5, Kd = 1;
1616

17-
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
17+
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, QuickPID::DIRECT);
1818

1919
void setup()
2020
{
@@ -23,7 +23,7 @@ void setup()
2323
Setpoint = 100;
2424

2525
//turn the PID on
26-
myQuickPID.SetMode(AUTOMATIC);
26+
myQuickPID.SetMode(QuickPID::AUTOMATIC);
2727
}
2828

2929
void loop()

examples/QuickPID_PonM/QuickPID_PonM.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ float Setpoint, Input, Output;
1313
float POn = 0.0; // Range is 0.0 to 1.0 (0.0 is 0% P on Error, 100% P on Measurement)
1414

1515
//Specify the links and initial tuning parameters
16-
QuickPID myQuickPID(&Input, &Output, &Setpoint, 2, 5, 1, POn, DIRECT);
16+
QuickPID myQuickPID(&Input, &Output, &Setpoint, 2, 5, 1, POn, QuickPID::DIRECT);
1717

1818
void setup()
1919
{
@@ -22,7 +22,7 @@ void setup()
2222
Setpoint = 100;
2323

2424
//turn the PID on
25-
myQuickPID.SetMode(AUTOMATIC);
25+
myQuickPID.SetMode(QuickPID::AUTOMATIC);
2626
}
2727

2828
void loop()

examples/QuickPID_RelayOutput/QuickPID_RelayOutput.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ float Setpoint, Input, Output;
2828
float Kp = 2, Ki = 5, Kd = 1;
2929
float POn = 0.0; // Range is 0.0 to 1.0 (0.0 is 0% P on Error, 100% P on Measurement)
3030

31-
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, DIRECT);
31+
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, QuickPID::DIRECT);
3232

3333
unsigned int WindowSize = 5000;
3434
unsigned int minWindow = 500;
@@ -46,7 +46,7 @@ void setup()
4646
myQuickPID.SetOutputLimits(0, WindowSize);
4747

4848
//turn the PID on
49-
myQuickPID.SetMode(AUTOMATIC);
49+
myQuickPID.SetMode(QuickPID::AUTOMATIC);
5050
}
5151

5252
void loop()

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
##########################################
88

99
QuickPID KEYWORD1
10+
mode_t KEYWORD1
11+
direction_t KEYWORD1
1012
analog_write_channel_t KEYWORD1
1113

1214
##########################################

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"keywords": "PID, controller, signal",
44
"description": "A fast fixed/floating point PID controller with AutoTune and 9 tuning rules to choose from. This controller can automatically determine and set tuning parameters. Compatible with most Arduino and ESP32 boards.",
55
"license": "MIT",
6-
"version": "2.2.6",
6+
"version": "2.2.7",
77
"url": "https://github.com/Dlloydev/QuickPID",
88
"include": "QuickPID",
99
"authors":

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=2.2.6
2+
version=2.2.7
33
author=David Lloyd
44
maintainer=David Lloyd <[email protected]>
55
sentence=A fast fixed/floating point PID controller with AutoTune and 9 tuning rules to choose from.

0 commit comments

Comments
 (0)