Skip to content

Commit 061b903

Browse files
committed
Update Readme, add new function
1 parent e2c5d6c commit 061b903

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

QuickPID.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 2.0.2
2+
QuickPID Library for Arduino - Version 2.0.3
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID Library by Brett Beauregard
55
@@ -219,15 +219,18 @@ float QuickPID::GetKi() {
219219
float QuickPID::GetKd() {
220220
return dispKd;
221221
}
222-
int16_t QuickPID::GetError() {
223-
return error;
224-
}
225222
bool QuickPID::GetMode() {
226223
return inAuto ? AUTOMATIC : MANUAL;
227224
}
228225
bool QuickPID::GetDirection() {
229226
return controllerDirection;
230227
}
228+
int16_t QuickPID::GetError() {
229+
return error;
230+
}
231+
bool QuickPID::GetpOnE() {
232+
return pOnE;
233+
}
231234

232235
// Utility functions **********************************************************
233236

QuickPID.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ class QuickPID
5757
float GetKp(); // These functions query the pid for interal values. They were created mainly for
5858
float GetKi(); // the pid front-end, where it's important to know what is actually inside the PID.
5959
float GetKd();
60-
int16_t GetError();
6160
bool GetMode();
6261
bool GetDirection();
62+
int16_t GetError();
63+
bool GetpOnE();
6364

6465
// Utility functions ******************************************************************************************
6566
int analogReadFast(int);

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# QuickPID
22

3-
This API (version 2.02) follows the [ArduinoPID](https://github.com/br3ttb/Arduino-PID-Library) library, however there have been some significant updates as follows:
3+
This API (version 2.03) follows the [ArduinoPID](https://github.com/br3ttb/Arduino-PID-Library) library, however there have been some significant updates as follows:
44

5-
- Library named as **QuickPID** and can run concurrently with Arduino **PID**
6-
- Quicker fixed point math in compute function
5+
- This library named as **QuickPID** and can run alongside with Arduino **PID** if needed
6+
- Quicker fixed point math in compute function for small tuning values, floating point math used for large tuning values
77
- Reorganized and more efficient PID algorithm
88
- micros() timing resolution
99
- Faster analog read function
10-
- `GetError()`function added for diagnostics
10+
- `GetError()`and `GetpOnE()`functions added for diagnostics and control benefits
11+
- Runs a complete PID cycle (*read-compute-write*) faster than just an `analogRead()` command in Arduino
1112

1213
### Performance
1314

@@ -19,9 +20,18 @@ This API (version 2.02) follows the [ArduinoPID](https://github.com/br3ttb/Ardui
1920
| QuickPID | 2.0 | 5.0 | 0.2 | 96 |
2021
| Arduino PID | 2.0 | 5.0 | 0.2 | 224 |
2122

22-
#### Self Test Example (RC Filter): P_ON_M
23+
#### Self Test Example (RC Filter):
2324

24-
![pid_self_test_pom](https://user-images.githubusercontent.com/63488701/104115407-2cee5900-52dd-11eb-9b24-ff06d39fd2d6.gif)
25+
This example allows you to set an output voltage, then view the result of your tuning parameters. The mode of the P-Term automatically toggles from Proportional on Error to [Proportional on Measurement.](http://brettbeauregard.com/blog/2017/06/introducing-proportional-on-measurement/)
26+
27+
![pid_self_test_pom](https://user-images.githubusercontent.com/63488701/104389509-a66a8f00-5509-11eb-927b-1190231a1ee9.gif)
28+
29+
### Simplified PID Algorithm
30+
31+
| Proportional Term Mode | Algorithm |
32+
| --------------------------- | --------------------------------------------- |
33+
| Proportional on Error | `outputSum += (kpi * error) - (kd * dInput);` |
34+
| Proportional on Measurement | `outputSum += (ki * error) - (kpd * dInput);` |
2535

2636
### Variables
2737

examples/QuickPID_Self_Test/QuickPID_Self_Test.ino

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,40 @@ QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
2525

2626
void setup()
2727
{
28-
myQuickPID.SetTunings(Kp, Ki, Kd, P_ON_M);
2928
Serial.begin(115200);
30-
analogWrite(PIN_OUTPUT, 0);
31-
delay(1000); // discharge capacitor
32-
Input = myQuickPID.analogReadFast(PIN_INPUT);
29+
myQuickPID.SetTunings(Kp, Ki, Kd, P_ON_E);
3330
myQuickPID.SetMode(AUTOMATIC);
31+
analogWrite(PIN_OUTPUT, 0); // discharge capacitor
32+
delay(1000);
3433
}
3534

3635
void loop()
3736
{
38-
//Serial.println("Min:0,Max:1000"); // set scale
39-
40-
// Stretch the plot x2
41-
for (int i = 0; i <= 1; i++) {
42-
Serial.print("Setpoint:");
43-
Serial.print(Setpoint);
44-
Serial.print(",");
45-
Serial.print("Input:");
46-
Serial.print(Input);
47-
Serial.print(",");
48-
Serial.print("Output:");
49-
Serial.print(Output);
50-
Serial.print(",");
51-
Serial.print("Runtime:");
52-
Serial.print(after - before);
53-
Serial.println(",");
54-
}
37+
Serial.print("Setpoint:");
38+
Serial.print(Setpoint);
39+
Serial.print(",");
40+
Serial.print("Input:");
41+
Serial.print(Input);
42+
Serial.print(",");
43+
Serial.print("Output:");
44+
Serial.print(Output);
45+
Serial.print(",");
46+
Serial.print("Runtime:");
47+
Serial.print(after - before);
48+
Serial.println(",");
5549

5650
Input = myQuickPID.analogReadFast(PIN_INPUT);
5751
before = micros();
5852
myQuickPID.Compute();
5953
after = micros();
6054
analogWrite(PIN_OUTPUT, Output);
6155

62-
delay(40);
56+
delay(10);
6357
cnt++;
64-
if (cnt == 100) {
58+
if (cnt == 250) {
6559
analogWrite(PIN_OUTPUT, 0);
6660
delay(1000); // discharge capacitor
6761
cnt = 0;
62+
myQuickPID.SetTunings(Kp, Ki, Kd, !(myQuickPID.GetpOnE())); //toggle P-Term mode
6863
}
6964
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ GetKi KEYWORD2
2323
GetKd KEYWORD2
2424
GetMode KEYWORD2
2525
GetError KEYWORD2
26+
GetpOnE KEYWORD2
2627
GetDirection KEYWORD2
2728
analogReadFast KEYWORD2
2829

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.0.2
2+
version=2.0.3
33
author=dlloydev
44
maintainer=dlloydev
55
sentence=QuickPID controller

0 commit comments

Comments
 (0)