Skip to content

Commit 1626eef

Browse files
committed
Update
- autoTune parameters `outputStep`, `hysteresis`, `Setpoint` and `Output` are now float - minimum `outputStep` is now 0 (previously 5).
1 parent a8cf244 commit 1626eef

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# QuickPID ![arduino-library-badge](https://camo.githubusercontent.com/989057908f34abd0c8bc2a8d762f86ccebbe377ed9ffef8c3dfdf27a09c6dac9/68747470733a2f2f7777772e617264752d62616467652e636f6d2f62616467652f517569636b5049442e7376673f)
1+
# QuickPID [![arduino-library-badge](https://www.ardu-badge.com/badge/QuickPID.svg?)](https://www.ardu-badge.com/QuickPID)
22

33
QuickPID is an updated implementation of the Arduino PID library with a built-in [AutoTune](https://github.com/Dlloydev/QuickPID/wiki/AutoTune) class as a dynamic object to reduce memory if not used, thanks to contributions by [gnalbandian (Gonzalo)](https://github.com/gnalbandian). This controller can automatically determine and set parameters `Kp, Ki, Kd`. Additionally the Ultimate Gain `Ku`, Ultimate Period `Tu`, Dead Time `td` and determine how easy the process is to control. There are 10 tuning rules available to choose from. Also available are POn and DOn settings where POn controls the mix of Proportional on Error to Proportional on Measurement and DOn controls the mix of Derivative on Error to Derivative on Measurement.
44

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "QuickPID",
3-
"version": "2.4.4",
3+
"version": "2.4.5",
44
"description": "A fast PID controller with AutoTune dynamic object, 10 tuning rules, Integral anti-windup, TIMER Mode and mixing of Proportional and Derivative on Error to Measurement. Also includes analogWrite compatibility for ESP32 and ESP32-S2.",
55
"keywords": "PID, controller, signal",
66
"repository":
@@ -20,7 +20,7 @@
2020
"license": "MIT",
2121
"homepage": "https://github.com/Dlloydev/QuickPID",
2222
"dependencies": {
23-
"QuickPID": "~2.4.4"
23+
"QuickPID": "~2.4.5"
2424
},
2525
"frameworks": "*",
2626
"platforms": "*"

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.4.4
2+
version=2.4.5
33
author=David Lloyd
44
maintainer=David Lloyd <[email protected]>
55
sentence=A fast PID controller with AutoTune dynamic object, 10 tuning rules, Integral anti-windup, TIMER Mode and mixing of Proportional and Derivative on Error to Measurement.

src/QuickPID.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************************
2-
QuickPID Library for Arduino - Version 2.4.4
2+
QuickPID Library for Arduino - Version 2.4.5
33
by dlloydev https://github.com/Dlloydev/QuickPID
44
Based on the Arduino PID Library and work on AutoTunePID class
55
by gnalbandian (Gonzalo). Licensed under the MIT License.
@@ -95,8 +95,8 @@ void QuickPID::SetTunings(float Kp, float Ki, float Kd, float POn = 1.0, float D
9595
kd = Kd / SampleTimeSec;
9696
kpe = kp * pOn;
9797
kpm = kp * (1 - pOn);
98-
kde = kp * dOn;
99-
kdm = kp * (1 - dOn);
98+
kde = kd * dOn;
99+
kdm = kd * (1 - dOn);
100100
}
101101

102102
/* SetTunings(...)************************************************************
@@ -234,8 +234,8 @@ void AutoTunePID::reset() {
234234
_autoTuneStage = 0;
235235
}
236236

237-
void AutoTunePID::autoTuneConfig(const byte outputStep, const byte hysteresis, const int atSetpoint,
238-
const int atOutput, const bool dir, const bool printOrPlotter, uint32_t sampleTimeUs)
237+
void AutoTunePID::autoTuneConfig(const float outputStep, const float hysteresis, const float atSetpoint,
238+
const float atOutput, const bool dir, const bool printOrPlotter, uint32_t sampleTimeUs)
239239
{
240240
_outputStep = outputStep;
241241
_hysteresis = hysteresis;
@@ -262,7 +262,7 @@ byte AutoTunePID::autoTuneLoop() {
262262
_t0 = millis();
263263
_peakHigh = _atSetpoint;
264264
_peakLow = _atSetpoint;
265-
(!_direction) ? *_output = 0 : *_output = _atOutput + _outputStep + 5;
265+
(!_direction) ? *_output = 0 : *_output = _atOutput + (_outputStep * 2);
266266
_autoTuneStage = COARSE;
267267
return AUTOTUNE;
268268
break;
@@ -272,7 +272,7 @@ byte AutoTunePID::autoTuneLoop() {
272272
break;
273273
}
274274
if (*_input < (_atSetpoint - _hysteresis)) {
275-
(!_direction) ? *_output = _atOutput + _outputStep + 5 : *_output = _atOutput - _outputStep - 5;
275+
(!_direction) ? *_output = _atOutput + (_outputStep * 2) : *_output = _atOutput - (_outputStep * 2);
276276
_autoTuneStage = FINE;
277277
}
278278
return AUTOTUNE;

src/QuickPID.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AutoTunePID {
2323
~AutoTunePID() {};
2424

2525
void reset();
26-
void autoTuneConfig(const byte outputStep, const byte hysteresis, const int setpoint, const int output,
26+
void autoTuneConfig(const float outputStep, const float hysteresis, const float setpoint, const float output,
2727
const bool dir = false, const bool printOrPlotter = false, uint32_t sampleTimeUs = 10000);
2828
byte autoTuneLoop();
2929
void setAutoTuneConstants(float* kp, float* ki, float* kd);
@@ -37,13 +37,10 @@ class AutoTunePID {
3737

3838
byte _autoTuneStage = 1;
3939
tuningMethod _tuningRule;
40-
byte _outputStep;
41-
byte _hysteresis;
42-
int _atSetpoint; // 1/3 of 10-bit ADC range for symetrical waveform
43-
int _atOutput;
4440
bool _direction = false;
4541
bool _printOrPlotter = false;
4642
uint32_t _tLoop, _tLast, _t0, _t1, _t2, _t3;
43+
float _outputStep, _hysteresis, _atSetpoint, _atOutput;
4744
float _Ku, _Tu, _td, _kp, _ki, _kd, _rdAvg, _peakHigh, _peakLow;
4845

4946
const uint16_t RulesContants[10][3] =

0 commit comments

Comments
 (0)