Skip to content

Commit 15e8f89

Browse files
committed
Update
Update documentation, Wiki and examples
1 parent 2a6f8aa commit 15e8f89

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ This is an open loop PID autotuner using a novel s-curve inflection point test m
44

55
#### Reaction Curve Inflection Point Tuning Method
66

7-
This tuning method determines the process gain, dead time and time constant by doing a shortened step test that ends just after the [inflection point](http://en.wikipedia.org/wiki/Inflection_point) has been reached. From here, the apparent maximum PV (input) is mathematically determined and the controller's tuning parameters are calculated. Test duration is typically only ½Tau.
7+
This tuning method determines the process gain, dead time and time constant by doing a shortened step test that ends just after the [inflection point](http://en.wikipedia.org/wiki/Inflection_point) has been reached. From here, the apparent maximum PV (input) is mathematically determined and the controller's tuning parameters are calculated. Test duration is typically only ½Tau.
8+
9+
- See [**WiKi**](https://github.com/Dlloydev/sTune/wiki) for test results and more.
810

911
#### Inflection Point Discovery
1012

examples/Autotune_PID_v1/Autotune_PID_v1.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ sTune tuner = sTune(&input, &output, tuner.zieglerNicholsPID, tuner.directIP, tu
3838
noOvershootPID
3939
*/
4040
void setup() {
41-
analogReference(EXTERNAL);
41+
analogReference(EXTERNAL); // AVR
4242
Serial.begin(115200);
4343
analogWrite(outputPin, outputStart);
4444
tuner.Configure(outputStart, outputStep, testTimeSec, settleTimeSec, samples);
4545
}
4646

4747
void loop() {
4848

49-
switch (tuner.Run()) {
49+
switch (tuner.Run()) { // active while sTune is testing (non-blocking)
5050
case tuner.inOut:
5151
input = (analogRead(inputPin) / mvResolution) - bias;
5252
analogWrite(outputPin, output);
5353
break;
5454

55-
case tuner.tunings:
56-
tuner.SetAutoTunings(&kp, &ki, &kd);
57-
myPID.SetMode(AUTOMATIC);
58-
myPID.SetSampleTime((testTimeSec * 1000) / samples);
59-
myPID.SetTunings(kp, ki, kd);
55+
case tuner.tunings: // active just once when sTune is done
56+
tuner.SetAutoTunings(&kp, &ki, &kd); // sketch variables are updated by sTune
57+
myPID.SetMode(AUTOMATIC); // the PID is turned on (automatic)
58+
myPID.SetSampleTime((testTimeSec * 1000) / samples); // PID sample rate
59+
myPID.SetTunings(kp, ki, kd); // update PID with the new tunings
6060
break;
6161

6262
case tuner.runPid:
@@ -65,4 +65,5 @@ void loop() {
6565
analogWrite(outputPin, Output);
6666
break;
6767
}
68+
// put your main code here, to run repeatedly
6869
}

examples/Autotune_QuickPID/Autotune_QuickPID.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,31 @@ sTune tuner = sTune(&Input, &Output, tuner.zieglerNicholsPID, tuner.directIP, tu
4141
noOvershootPID
4242
*/
4343
void setup() {
44-
analogReference(EXTERNAL);
44+
analogReference(EXTERNAL); // AVR
4545
Serial.begin(115200);
4646
analogWrite(outputPin, outputStart);
4747
tuner.Configure(outputStart, outputStep, testTimeSec, settleTimeSec, samples);
4848
}
4949

5050
void loop() {
51-
52-
switch (tuner.Run()) {
51+
switch (tuner.Run()) { // active while sTune is testing (non-blocking)
5352
case tuner.inOut:
5453
Input = (analogRead(inputPin) / mvResolution) - bias;
5554
analogWrite(outputPin, Output);
5655
break;
5756

58-
case tuner.tunings:
59-
tuner.SetAutoTunings(&Kp, &Ki, &Kd);
60-
myPID.SetMode(myPID.Control::automatic);
61-
myPID.SetSampleTimeUs((testTimeSec * 1000000) / samples);
62-
myPID.SetTunings(Kp, Ki, Kd);
57+
case tuner.tunings: // active just once when sTune is done
58+
tuner.SetAutoTunings(&Kp, &Ki, &Kd); // sketch variables are updated by sTune
59+
myPID.SetMode(myPID.Control::automatic); // the PID is turned on (automatic)
60+
myPID.SetSampleTimeUs((testTimeSec * 1000000) / samples); // PID sample rate
61+
myPID.SetTunings(Kp, Ki, Kd); // update PID with the new tunings
6362
break;
6463

65-
case tuner.runPid:
64+
case tuner.runPid: // this case runs continuously after case "tunings" (non-blocking)
6665
Input = (analogRead(inputPin) / mvResolution) - bias;
6766
myPID.Compute();
6867
analogWrite(outputPin, Output);
6968
break;
7069
}
70+
// put your main code here, to run repeatedly
7171
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sTune",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Open loop PID autotuner using a novel s-curve inflection point test method. Tuning parameters are determined in about ½Tau on a first-order system with time delay. Full 5Tau testing and multiple serial output options are provided.",
55
"keywords": "PID, autotune, autotuner, tuner, tune, stune, inflection, step",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=sTune
2-
version=1.0.2
2+
version=1.0.3
33
author=David Lloyd
44
maintainer=David Lloyd <[email protected]>
55
sentence=Open loop PID autotuner using a novel s-curve inflection point test method.

src/sTune.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************************
2-
sTune Library for Arduino - Version 1.0.2
2+
sTune Library for Arduino - Version 1.0.3
33
by dlloydev https://github.com/Dlloydev/sTune
44
Licensed under the MIT License.
55
@@ -85,6 +85,7 @@ uint8_t sTune::Run() {
8585
if (pvDiff > epsilon && pvDiff < pvRes) pvRes = pvDiff; // check buffered input resolution
8686

8787
if (sampleCount == 0) { // initialize at first sample
88+
*_output = _outputStart;
8889
tangent.init(pvInst);
8990
pvAvg = pvInst;
9091
pvStart = pvInst;
@@ -198,6 +199,7 @@ uint8_t sTune::Run() {
198199
}
199200
} else { // settling
200201
if (usElapsed >= _samplePeriodUs) {
202+
*_output = _outputStart;
201203
usPrev = usNow;
202204
pvInst = *_input;
203205
if (_serialMode == printALL || _serialMode == printDEBUG) {

0 commit comments

Comments
 (0)