Skip to content

Commit f134ad8

Browse files
committed
Version 2.02
1 parent f1987c5 commit f134ad8

File tree

5 files changed

+24
-36
lines changed

5 files changed

+24
-36
lines changed

QuickPID.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 2.0.1
2+
QuickPID Library for Arduino - Version 2.0.2
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID Library by Brett Beauregard
55
@@ -67,17 +67,13 @@ bool QuickPID::Compute()
6767

6868
/*Working error, Proportional on Measurement and Remaining PID output*/
6969
if (!pOnE) {
70-
if (ki < 31) outputSum += FX_INT(FX_MUL(FL_FX(ki), INT_FX(error)));
71-
else outputSum += (ki * error);
72-
if (kpd < 31) outputSum -= FX_INT(FX_MUL(FL_FX(kpd), INT_FX(dInput)));
73-
else outputSum -= (kpd * dInput);
70+
outputSum += (ki * error);
71+
outputSum -= (kpd * dInput);
7472
}
7573
/*Working error, Proportional on Error and remaining PID output*/
7674
if (pOnE) {
77-
if (kpi < 31) outputSum += FX_INT(FX_MUL(FL_FX(kpi), INT_FX(error)));
78-
else outputSum += (kpi * error);
79-
if (kd < 31) outputSum -= FX_INT(FX_MUL(FL_FX(kd), INT_FX(dInput)));
80-
else outputSum -= (kd * dInput);
75+
outputSum += (kpi * error);
76+
outputSum -= (kd * dInput);
8177
}
8278
if (outputSum > outMax) outputSum = outMax;
8379
if (outputSum < outMin) outputSum = outMin;

QuickPID.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ class QuickPID
1414
#define P_ON_M 0
1515
#define P_ON_E 1
1616

17-
// fixed point defines
18-
#define FL_FX(a) (int32_t)(a*256.0) // float to fixed point
19-
#define FX_FL(a) (float)(a/256.0) // fixed point to float
20-
#define INT_FX(a) (a<<8) // integer to fixed point
21-
#define FX_INT(a) (int32_t)(a>>8) // fixed point to integer
22-
#define FX_MUL(a,b) ((a*b)>>8) // fixed point multiply
23-
#define FX_DIV(a,b) ((a/b)<<8) // fixed point divide
24-
2517

2618
// commonly used functions ************************************************************************************
2719

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# QuickPID
22

3-
This API (version 2.01) 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.02) follows the [ArduinoPID](https://github.com/br3ttb/Arduino-PID-Library) library, however there have been some significant updates as follows:
44

55
- Library named as **QuickPID** and can run concurrently with Arduino **PID**
66
- Reorganized and more efficient PID algorithms
7-
- Fast fixed-point calculations for smaller coefficients, floating point calculations for larger coefficients
7+
- micros() timing resolution
88
- Faster analog read function
99
- `GetError()`function added for diagnostics
1010

@@ -21,19 +21,19 @@ This API (version 2.01) follows the [ArduinoPID](https://github.com/br3ttb/Ardui
2121
### Variables
2222

2323

24-
| Variable | Arduino PID | QuickPID | Data Type | Resolution | Bits Used | Min | Max |
25-
| ------------ | ----------- | -------------- | ------------ | -------------------- | --------- | ----------- | ----------- |
26-
| Setpoint | double | int16_t | Binary | 1 | 10 | 0 | 1023 |
27-
| Input | double | int16_t | Binary | 1 | 10 | 0 | 1023 |
28-
| Output | double | uint8_t | Binary | 1 | 8 | 0 | 255 |
29-
| Kp | double | int32_t, float | s23.8, float | 6-7 digits precision | 4 bytes | | |
30-
| Ki | double | int32_t, float | s23.8, float | 6-7 digits precision | 4 bytes | | |
31-
| Kd | double | int32_t, float | s23.8, float | 6-7 digits precision | 4 bytes | | |
32-
| ratio | double | float | float | 6-7 digits precision | 4 bytes | | |
33-
| SampleTimeUs | double | uint32_t | Binary | 1 | 32 | 0 | 4294967295 |
34-
| outputSum | double | int16_t | Binary | 1 | 8 | 0 (limit) | 255 (limit) |
35-
| error | double | int32_t | Binary | 1 | 32 | -2147483648 | 2147483647 |
36-
| dInput | double | int32_t | Binary | 1 | 32 | -2147483648 | 2147483647 |
24+
| Variable | Arduino PID | QuickPID | Data Type | Min | Max |
25+
| :----------- | :---------- | :------- | :-------- | :--------- | :--------- |
26+
| Setpoint | double | int16_t | Binary | 0 | 1023 |
27+
| Input | double | int16_t | Binary | 0 | 1023 |
28+
| Output | double | uint8_t | Binary | 0 | 255 |
29+
| Kp | double | float | float | -3.402E+38 | 3.402E+38 |
30+
| Ki | double | float | float | -3.402E+38 | 3.402E+38 |
31+
| Kd | double | float | float | -3.402E+38 | 3.402E+38 |
32+
| ratio | double | float | float | -3.402E+38 | 3.402E+38 |
33+
| SampleTimeUs | double | uint32_t | Binary | 0 | 4294967295 |
34+
| outputSum | double | int16_t | Binary | 0 | 255 |
35+
| error | double | int32_t | Binary | -1023 | 1023 |
36+
| dInput | double | int32_t | Binary | -1023 | 1023 |
3737

3838
### Original README
3939

examples/QuickPID_Self_Test/QuickPID_Self_Test.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ void loop()
5353
Serial.println(",");
5454
}
5555

56-
before = micros();
5756
Input = myQuickPID.analogReadFast(PIN_INPUT);
57+
before = micros();
5858
myQuickPID.Compute();
59-
analogWrite(PIN_OUTPUT, Output);
6059
after = micros();
60+
analogWrite(PIN_OUTPUT, Output);
6161

62-
delay(50);
62+
delay(20);
6363
cnt++;
6464
if (cnt == 100) {
6565
analogWrite(PIN_OUTPUT, 0);

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

0 commit comments

Comments
 (0)