Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- Changed Input, Output and Setpoint parameters to float.
- Fix recent compile issue for AVR boards
  • Loading branch information
Dlloydev committed May 6, 2021
1 parent f408d87 commit 755867b
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 23 deletions.
7 changes: 4 additions & 3 deletions QuickPID.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************************
QuickPID Library for Arduino - Version 2.2.5
QuickPID Library for Arduino - Version 2.2.6
by dlloydev https://github.com/Dlloydev/QuickPID
Based on the Arduino PID Library, licensed under the MIT License
**********************************************************************************/
Expand All @@ -9,13 +9,14 @@
#else
#include "WProgram.h"
#endif

#include "QuickPID.h"

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

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

Expand Down
12 changes: 6 additions & 6 deletions QuickPID.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ static const byte TRY_AUTOMATIC = 1;
// commonly used functions ************************************************************************************

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

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

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

uint8_t controllerDirection;

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

uint32_t sampleTimeUs, lastTime;
int outMin, outMax, error;
Expand All @@ -112,7 +112,7 @@ static const byte TRY_AUTOMATIC = 1;
};

#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
#include "utility/analogWrite.h"
#include "analogWrite.h"
#endif

#endif // QuickPID.h
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The new `kpi` and `kpd` parameters are calculated in the `SetTunings()` function
#### QuickPID_Constructor

```c++
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
float Kp, float Ki, float Kd, float POn, uint8_t ControllerDirection);
```
Expand All @@ -65,7 +65,7 @@ QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
- `ControllerDirection` Either DIRECT or REVERSE determines which direction the output will move for a given error. DIRECT is most common.
```c++
QuickPID::QuickPID(int* Input, int* Output, int* Setpoint,
QuickPID::QuickPID(float* Input, float* Output, float* Setpoint,
float Kp, float Ki, float Kd, uint8_t ControllerDirection);
```

Expand Down Expand Up @@ -180,11 +180,10 @@ Use this link for reference. Note that if you're using QuickPID, there's no need
#### [![arduino-library-badge](https://www.ardu-badge.com/badge/QuickPID.svg?)](https://www.ardu-badge.com/QuickPID)
- Added ESP32-S2 support
#### Version 2.2.6
#### Version 2.2.3
- Updated compatibility with the ESP32 Arduino framework
- Changed Input, Output and Setpoint parameters to float.
- Updated compatibility with the ESP32 AnalogWrite
#### Version 2.2.2
Expand Down
5 changes: 4 additions & 1 deletion utility/analogWrite.cpp → analogWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
by dlloydev https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite
This Library is licensed under the MIT License
**********************************************************************************/

#include <Arduino.h>

#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
#include "analogWrite.h"

namespace aw {
Expand All @@ -18,6 +19,7 @@ pinStatus_t pinsStatus[8] = {
};
const uint8_t chd = 1;
#else //ESP32

pinStatus_t pinsStatus[8] = {
{ 0, -1, 980, 8, 0, 0 }, { 2, -1, 980, 8, 0, 0 },
{ 4, -1, 980, 8, 0, 0 }, { 6, -1, 980, 8, 0, 0 },
Expand Down Expand Up @@ -291,3 +293,4 @@ void printPinsStatus() {
Serial.println();
}
}
#endif //ESP32
File renamed without changes.
7 changes: 5 additions & 2 deletions examples/AutoTune_RC_Filter/AutoTune_RC_Filter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ int tuningRule = 1; // see above table
float POn = 1.0; // mix of PonE to PonM (0.0-1.0)
unsigned long timeout = 120; // AutoTune timeout (sec)

int Input, Output, Setpoint;
float Input, Output, Setpoint;
float Kp = 0, Ki = 0, Kd = 0;

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

void setup()
{
Serial.begin(115200);
Serial.println();

myQuickPID.AutoTune(inputPin, outputPin, tuningRule, Print, timeout);
myQuickPID.SetTunings(myQuickPID.GetKp(), myQuickPID.GetKi(), myQuickPID.GetKd());
myQuickPID.SetSampleTimeUs(5000); // recommend 5000µs (5ms) minimum
Expand All @@ -52,7 +54,8 @@ void setup()
Serial.print(" Kp: "); Serial.print(myQuickPID.GetKp());
Serial.print(" Ki: "); Serial.print(myQuickPID.GetKi());
Serial.print(" Kd: "); Serial.println(myQuickPID.GetKd());
delay(3000);
Serial.println();
delay(5000); //view results
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define PIN_OUTPUT 3

//Define Variables we'll be connecting to
int Setpoint, Input, Output;
float Setpoint, Input, Output;

//Define the aggressive and conservative and POn Tuning Parameters
float aggKp = 4, aggKi = 0.2, aggKd = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/QuickPID_Basic/QuickPID_Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define PIN_OUTPUT 3

//Define Variables we'll be connecting to
int Setpoint, Input, Output;
float Setpoint, Input, Output;

//Specify the links and initial tuning parameters
float Kp = 2, Ki = 5, Kd = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/QuickPID_PonM/QuickPID_PonM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "QuickPID.h"

//Define Variables we'll be connecting to
int Setpoint, Input, Output;
float Setpoint, Input, Output;
float POn = 0.0; // Range is 0.0 to 1.0 (0.0 is 0% P on Error, 100% P on Measurement)

//Specify the links and initial tuning parameters
Expand Down
2 changes: 1 addition & 1 deletion examples/QuickPID_RelayOutput/QuickPID_RelayOutput.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define RELAY_PIN 6

//Define Variables we'll be connecting to
int Setpoint, Input, Output;
float Setpoint, Input, Output;

//Specify the links and initial tuning parameters
float Kp = 2, Ki = 5, Kd = 1;
Expand Down
2 changes: 2 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"name": "QuickPID",
"keywords": "PID, controller, signal",
"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.",
"license": "MIT",
"version": "2.2.6",
"url": "https://github.com/Dlloydev/QuickPID",
"include": "QuickPID",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=QuickPID
version=2.2.5
version=2.2.6
author=David Lloyd
maintainer=David Lloyd <dlloydev@testcor.ca>
sentence=A fast fixed/floating point PID controller with AutoTune and 9 tuning rules to choose from.
Expand Down

0 comments on commit 755867b

Please sign in to comment.