Skip to content

Commit 755867b

Browse files
committed
Update
- Changed Input, Output and Setpoint parameters to float. - Fix recent compile issue for AVR boards
1 parent f408d87 commit 755867b

File tree

12 files changed

+31
-23
lines changed

12 files changed

+31
-23
lines changed

QuickPID.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 2.2.5
2+
QuickPID Library for Arduino - Version 2.2.6
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID Library, licensed under the MIT License
55
**********************************************************************************/
@@ -9,13 +9,14 @@
99
#else
1010
#include "WProgram.h"
1111
#endif
12+
1213
#include "QuickPID.h"
1314

1415
/* Constructor ********************************************************************
1516
The parameters specified here are those for for which we can't set up
1617
reliable defaults, so we need to have the user set them.
1718
**********************************************************************************/
18-
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
19+
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
1920
float Kp, float Ki, float Kd, float POn = 1, uint8_t ControllerDirection = 0) {
2021

2122
myOutput = Output;
@@ -35,7 +36,7 @@ QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
3536
To allow backwards compatability for v1.1, or for people that just want
3637
to use Proportional on Error without explicitly saying so.
3738
**********************************************************************************/
38-
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
39+
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
3940
float Kp, float Ki, float Kd, uint8_t ControllerDirection)
4041
: QuickPID::QuickPID(Input, Output, Setpoint, Kp, Ki, Kd, pOn = 1, ControllerDirection = 0) {
4142

QuickPID.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ static const byte TRY_AUTOMATIC = 1;
2121
// commonly used functions ************************************************************************************
2222

2323
// Constructor. Links the PID to Input, Output, Setpoint and initial Tuning Parameters.
24-
QuickPID(int*, int*, int*, float, float, float, float, uint8_t);
24+
QuickPID(float*, float*, float*, float, float, float, float, uint8_t);
2525

2626
// Overload constructor with proportional mode. Links the PID to Input, Output, Setpoint and Tuning Parameters.
27-
QuickPID(int*, int*, int*, float, float, float, uint8_t);
27+
QuickPID(float*, float*, float*, float, float, float, uint8_t);
2828

2929
// Sets PID to either Manual (0) or Auto (non-0).
3030
void SetMode(uint8_t Mode);
@@ -92,9 +92,9 @@ static const byte TRY_AUTOMATIC = 1;
9292

9393
uint8_t controllerDirection;
9494

95-
int *myInput; // Pointers to the Input, Output, and Setpoint variables. This creates a
96-
int *myOutput; // hard link between the variables and the PID, freeing the user from having
97-
int *mySetpoint; // to constantly tell us what these values are. With pointers we'll just know.
95+
float *myInput; // Pointers to the Input, Output, and Setpoint variables. This creates a
96+
float *myOutput; // hard link between the variables and the PID, freeing the user from having
97+
float *mySetpoint; // to constantly tell us what these values are. With pointers we'll just know.
9898

9999
uint32_t sampleTimeUs, lastTime;
100100
int outMin, outMax, error;
@@ -112,7 +112,7 @@ static const byte TRY_AUTOMATIC = 1;
112112
};
113113

114114
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
115-
#include "utility/analogWrite.h"
115+
#include "analogWrite.h"
116116
#endif
117117

118118
#endif // QuickPID.h

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The new `kpi` and `kpd` parameters are calculated in the `SetTunings()` function
5252
#### QuickPID_Constructor
5353

5454
```c++
55-
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
55+
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
5656
float Kp, float Ki, float Kd, float POn, uint8_t ControllerDirection);
5757
```
5858
@@ -65,7 +65,7 @@ QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
6565
- `ControllerDirection` Either DIRECT or REVERSE determines which direction the output will move for a given error. DIRECT is most common.
6666
6767
```c++
68-
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
68+
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
6969
float Kp, float Ki, float Kd, uint8_t ControllerDirection);
7070
```
7171

@@ -180,11 +180,10 @@ Use this link for reference. Note that if you're using QuickPID, there's no need
180180
181181
#### [![arduino-library-badge](https://www.ardu-badge.com/badge/QuickPID.svg?)](https://www.ardu-badge.com/QuickPID)
182182
183-
- Added ESP32-S2 support
183+
#### Version 2.2.6
184184
185-
#### Version 2.2.3
186-
187-
- Updated compatibility with the ESP32 Arduino framework
185+
- Changed Input, Output and Setpoint parameters to float.
186+
- Updated compatibility with the ESP32 AnalogWrite
188187
189188
#### Version 2.2.2
190189

utility/analogWrite.cpp renamed to analogWrite.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
by dlloydev https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite
44
This Library is licensed under the MIT License
55
**********************************************************************************/
6-
76
#include <Arduino.h>
7+
8+
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
89
#include "analogWrite.h"
910

1011
namespace aw {
@@ -18,6 +19,7 @@ pinStatus_t pinsStatus[8] = {
1819
};
1920
const uint8_t chd = 1;
2021
#else //ESP32
22+
2123
pinStatus_t pinsStatus[8] = {
2224
{ 0, -1, 980, 8, 0, 0 }, { 2, -1, 980, 8, 0, 0 },
2325
{ 4, -1, 980, 8, 0, 0 }, { 6, -1, 980, 8, 0, 0 },
@@ -291,3 +293,4 @@ void printPinsStatus() {
291293
Serial.println();
292294
}
293295
}
296+
#endif //ESP32
File renamed without changes.

examples/AutoTune_RC_Filter/AutoTune_RC_Filter.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ int tuningRule = 1; // see above table
2727
float POn = 1.0; // mix of PonE to PonM (0.0-1.0)
2828
unsigned long timeout = 120; // AutoTune timeout (sec)
2929

30-
int Input, Output, Setpoint;
30+
float Input, Output, Setpoint;
3131
float Kp = 0, Ki = 0, Kd = 0;
3232

3333
QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, DIRECT);
3434

3535
void setup()
3636
{
3737
Serial.begin(115200);
38+
Serial.println();
39+
3840
myQuickPID.AutoTune(inputPin, outputPin, tuningRule, Print, timeout);
3941
myQuickPID.SetTunings(myQuickPID.GetKp(), myQuickPID.GetKi(), myQuickPID.GetKd());
4042
myQuickPID.SetSampleTimeUs(5000); // recommend 5000µs (5ms) minimum
@@ -52,7 +54,8 @@ void setup()
5254
Serial.print(" Kp: "); Serial.print(myQuickPID.GetKp());
5355
Serial.print(" Ki: "); Serial.print(myQuickPID.GetKi());
5456
Serial.print(" Kd: "); Serial.println(myQuickPID.GetKd());
55-
delay(3000);
57+
Serial.println();
58+
delay(5000); //view results
5659
}
5760
}
5861

examples/QuickPID_AdaptiveTunings/QuickPID_AdaptiveTunings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define PIN_OUTPUT 3
1616

1717
//Define Variables we'll be connecting to
18-
int Setpoint, Input, Output;
18+
float Setpoint, Input, Output;
1919

2020
//Define the aggressive and conservative and POn Tuning Parameters
2121
float aggKp = 4, aggKi = 0.2, aggKd = 1;

examples/QuickPID_Basic/QuickPID_Basic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define PIN_OUTPUT 3
1010

1111
//Define Variables we'll be connecting to
12-
int Setpoint, Input, Output;
12+
float Setpoint, Input, Output;
1313

1414
//Specify the links and initial tuning parameters
1515
float Kp = 2, Ki = 5, Kd = 1;

examples/QuickPID_PonM/QuickPID_PonM.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "QuickPID.h"
1010

1111
//Define Variables we'll be connecting to
12-
int Setpoint, Input, Output;
12+
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

examples/QuickPID_RelayOutput/QuickPID_RelayOutput.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define RELAY_PIN 6
2323

2424
//Define Variables we'll be connecting to
25-
int Setpoint, Input, Output;
25+
float Setpoint, Input, Output;
2626

2727
//Specify the links and initial tuning parameters
2828
float Kp = 2, Ki = 5, Kd = 1;

0 commit comments

Comments
 (0)