sTune PID Autotune Library

sTune

arduino-library-badge PlatformIO Registry

This is an open loop PID autotuner using a novel s-curve inflection point test method. Tuning parameters are typically determined in about Β½Tau on a first-order system with time delay. Full 5Tau testing and multiple serial output options are provided.

2 Likes

Very useful information along with the visual representation. It would be even better if you could shed some light on the inflection point.

Thanks,

Well, looking at just the small tangent line, the first derivative is the slope. As the tangent moves along the curve, at first the slope keeps increasing. Then, at some point, the slope begins to decrease. This is the point of inflection (POI).

In order to detect this point, we just keep taking the second derivative and are interested only in when the sign changes from positive to negative.

If this were a cooling process, the graph would be flipped (top to bottom). In this case, the POI would be when the sign of the second derivative changes from negative to positive.

The test completes at the POI. From here, there is enough information to calculate remaining results, rather than waiting to take measurements. The test duration is about an order of magnitude less than testing to pvMax.

Imagine getting reliable PID tuning results for a PWM step test of 1 ... or take a look here.

image

New major revision: sTune 2.0.0

  • Check out the new Get_All_Tunings example where you get results for all 10 tuning methods in just 1 quick test run. Here's the print results from my Temperature Control Lab hardware which has a time constant of 2.9 minutes and the "get all tunings" test took only 90 sec ...
 Sec: 9.39986  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 8.79969  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 8.19953  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 7.59935  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 6.99917  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 6.39902  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 5.79899  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 5.19894  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 4.59876  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 3.99858  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 3.39844  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 2.79828  pvInst: 20.1285  Settling  β€³β€³β€³β€³
 Sec: 2.19825  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 1.59814  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 0.99814  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 0.39798  pvInst: 20.4388  Settling  β€³β€³β€³β€³
 Sec: 0.00000  pvInst: 20.4388  pvAvg: 20.4388  pvTangent: 0.0000 β†’
 Sec: 0.60014  pvInst: 20.1285  pvAvg: 20.4326  pvTangent: -0.0062 β†˜
 Sec: 1.20016  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 1.80030  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 2.40034  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 3.00053  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 3.60060  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 4.20074  pvInst: 20.4388  pvAvg: 20.4326  pvTangent: -0.0062 β†’
 Sec: 4.80078  pvInst: 20.1285  pvAvg: 20.4264  pvTangent: -0.0124 β†˜
 Sec: 5.40090  pvInst: 20.4388  pvAvg: 20.4264  pvTangent: -0.0124 β†’
 Sec: 6.00104  pvInst: 20.1285  pvAvg: 20.4202  pvTangent: -0.0186 β†˜
 Sec: 6.60122  pvInst: 20.4388  pvAvg: 20.4202  pvTangent: -0.0186 β†’
 Sec: 7.20128  pvInst: 20.1285  pvAvg: 20.4140  pvTangent: -0.0248 β†˜
 Sec: 7.80136  pvInst: 20.4388  pvAvg: 20.4140  pvTangent: -0.0248 β†’
 Sec: 8.40138  pvInst: 20.1285  pvAvg: 20.4078  pvTangent: -0.0310 β†˜
 Sec: 9.00146  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 9.60151  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 10.20158  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 10.80166  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 11.40180  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 12.00190  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 12.60198  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 13.20207  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 13.80217  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 14.40226  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 15.00238  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 15.60247  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 16.20260  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 16.80272  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 17.40281  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 18.00294  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 18.60304  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 19.20322  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 19.80329  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 20.40342  pvInst: 20.4388  pvAvg: 20.4078  pvTangent: -0.0310 β†’
 Sec: 21.00356  pvInst: 20.7491  pvAvg: 20.4140  pvTangent: -0.0248 β†—
 Sec: 21.60373  pvInst: 20.4388  pvAvg: 20.4140  pvTangent: -0.0248 β†’
 Sec: 22.20387  pvInst: 20.4388  pvAvg: 20.4140  pvTangent: -0.0248 β†’
 Sec: 22.80406  pvInst: 20.4388  pvAvg: 20.4140  pvTangent: -0.0248 β†’
 Sec: 23.40423  pvInst: 20.7491  pvAvg: 20.4202  pvTangent: -0.0186 β†—
 Sec: 24.00429  pvInst: 20.4388  pvAvg: 20.4202  pvTangent: -0.0186 β†’
 Sec: 24.60438  pvInst: 20.4388  pvAvg: 20.4202  pvTangent: -0.0186 β†’
 Sec: 25.20455  pvInst: 20.4388  pvAvg: 20.4202  pvTangent: -0.0186 β†’
 Sec: 25.80457  pvInst: 20.7491  pvAvg: 20.4264  pvTangent: -0.0124 β†—
 Sec: 26.40476  pvInst: 20.7491  pvAvg: 20.4326  pvTangent: -0.0062 β†—
 Sec: 27.00478  pvInst: 20.7491  pvAvg: 20.4388  pvTangent: 0.0000 β†—
 Sec: 27.60495  pvInst: 20.7491  pvAvg: 20.4450  pvTangent: 0.0062 β†—
 Sec: 28.20497  pvInst: 20.7491  pvAvg: 20.4512  pvTangent: 0.0124 β†—
 Sec: 28.80509  pvInst: 20.7491  pvAvg: 20.4574  pvTangent: 0.0186 β†—
 Sec: 29.40522  pvInst: 20.7491  pvAvg: 20.4636  pvTangent: 0.0248 β†—
 Sec: 30.00529  pvInst: 20.7491  pvAvg: 20.4698  pvTangent: 0.3413 β†—
 Sec: 30.60538  pvInst: 20.7491  pvAvg: 20.4822  pvTangent: 0.0434 β†˜
 Sec: 31.20538  pvInst: 20.7491  pvAvg: 20.4884  pvTangent: 0.0496 β†—
 Sec: 31.80546  pvInst: 21.0594  pvAvg: 20.5008  pvTangent: 0.0621 β†—
 Sec: 32.40549  pvInst: 20.7491  pvAvg: 20.5071  pvTangent: 0.0683 β†—
 Sec: 33.00566  pvInst: 21.0594  pvAvg: 20.5195  pvTangent: 0.0807 β†—
 Sec: 33.60573  pvInst: 21.0594  pvAvg: 20.5319  pvTangent: 0.0931 β†—
 Sec: 34.20584  pvInst: 21.0594  pvAvg: 20.5443  pvTangent: 0.4158 β†—
 Sec: 34.80585  pvInst: 21.0594  pvAvg: 20.5629  pvTangent: 0.1241 β†˜
 Sec: 35.40597  pvInst: 21.0594  pvAvg: 20.5753  pvTangent: 0.4468 β†—
 Sec: 36.00607  pvInst: 21.0594  pvAvg: 20.5939  pvTangent: 0.1552 β†˜
 Sec: 36.60608  pvInst: 21.0594  pvAvg: 20.6064  pvTangent: 0.4779 β†—
 Sec: 37.20618  pvInst: 21.0594  pvAvg: 20.6250  pvTangent: 0.1862 β†˜
 Sec: 37.80623  pvInst: 21.0594  pvAvg: 20.6374  pvTangent: 0.5089 β†—
 Sec: 38.40629  pvInst: 21.0594  pvAvg: 20.6560  pvTangent: 0.2172 β†˜
 Sec: 39.00632  pvInst: 21.3697  pvAvg: 20.6746  pvTangent: 0.2358 β†—
 Sec: 39.60646  pvInst: 21.3697  pvAvg: 20.6932  pvTangent: 0.2544 β†—
 Sec: 40.20649  pvInst: 21.3697  pvAvg: 20.7119  pvTangent: 0.2731 β†—
 Sec: 40.80654  pvInst: 21.3697  pvAvg: 20.7305  pvTangent: 0.2917 β†—
 Sec: 41.40661  pvInst: 21.3697  pvAvg: 20.7491  pvTangent: 0.3103 β†—
 Sec: 42.00664  pvInst: 21.3697  pvAvg: 20.7677  pvTangent: 0.3289 β†—
 Sec: 42.60669  pvInst: 21.3697  pvAvg: 20.7863  pvTangent: 0.3475 β†—
 Sec: 43.20669  pvInst: 21.3697  pvAvg: 20.8049  pvTangent: 0.3662 β†—
 Sec: 43.80674  pvInst: 21.3697  pvAvg: 20.8236  pvTangent: 0.3848 β†—
 Sec: 44.40678  pvInst: 21.3697  pvAvg: 20.8422  pvTangent: 0.4034 β†—
 Sec: 45.00682  pvInst: 21.3697  pvAvg: 20.8608  pvTangent: 0.4220 β†—
 Sec: 45.60684  pvInst: 21.3697  pvAvg: 20.8794  pvTangent: 0.4406 β†—
 Sec: 46.20691  pvInst: 21.6800  pvAvg: 20.9042  pvTangent: 0.4655 β†—
 Sec: 46.80706  pvInst: 21.6800  pvAvg: 20.9291  pvTangent: 0.4903 β†—
 Sec: 47.40720  pvInst: 21.6800  pvAvg: 20.9539  pvTangent: 0.5151 β†—
 Sec: 48.00733  pvInst: 21.6800  pvAvg: 20.9787  pvTangent: 0.5399 β†—
 Sec: 48.60746  pvInst: 21.6800  pvAvg: 21.0035  pvTangent: 0.5648 β†—
 Sec: 49.20757  pvInst: 21.6800  pvAvg: 21.0284  pvTangent: 0.5896 β†—
 Sec: 49.80758  pvInst: 21.9903  pvAvg: 21.0594  pvTangent: 0.6206 β†—
 Sec: 50.40777  pvInst: 21.6800  pvAvg: 21.0842  pvTangent: 0.3351 β†˜
 Sec: 51.00789  pvInst: 21.6800  pvAvg: 21.1028  pvTangent: 0.6640 β†—
 Sec: 51.60802  pvInst: 21.6800  pvAvg: 21.1277  pvTangent: 0.6889 β†—
 Sec: 52.20815  pvInst: 21.6800  pvAvg: 21.1525  pvTangent: 0.7137 β†—
 Sec: 52.80819  pvInst: 21.6800  pvAvg: 21.1773  pvTangent: 0.4282 β†˜
 Sec: 53.40834  pvInst: 21.9903  pvAvg: 21.2021  pvTangent: 0.7633 β†—
 Sec: 54.00853  pvInst: 21.9903  pvAvg: 21.2332  pvTangent: 0.7944 β†—
 Sec: 54.60869  pvInst: 21.9903  pvAvg: 21.2642  pvTangent: 0.8254 β†—
 Sec: 55.20872  pvInst: 21.9903  pvAvg: 21.2952  pvTangent: 0.5461 β†˜
 Sec: 55.80879  pvInst: 21.9903  pvAvg: 21.3200  pvTangent: 0.5710 β†—
 Sec: 56.40885  pvInst: 21.9903  pvAvg: 21.3449  pvTangent: 0.5958 β†—
 Sec: 57.00900  pvInst: 21.9903  pvAvg: 21.3697  pvTangent: 0.6206 β†—
 Sec: 57.60910  pvInst: 21.9903  pvAvg: 21.3945  pvTangent: 0.6454 β†—
 Sec: 58.20913  pvInst: 21.9903  pvAvg: 21.4193  pvTangent: 0.6703 β†—
 Sec: 58.80914  pvInst: 21.9903  pvAvg: 21.4442  pvTangent: 0.6951 β†—
 Sec: 59.40924  pvInst: 22.3006  pvAvg: 21.4752  pvTangent: 0.7261 β†—
 Sec: 60.00941  pvInst: 22.3006  pvAvg: 21.5062  pvTangent: 0.7571 β†—
 Sec: 60.60950  pvInst: 22.3006  pvAvg: 21.5373  pvTangent: 0.7882 β†—
 Sec: 61.20957  pvInst: 22.3006  pvAvg: 21.5683  pvTangent: 0.5089 β†˜
 Sec: 61.80964  pvInst: 22.3006  pvAvg: 21.5931  pvTangent: 0.8440 β†—
 Sec: 62.40977  pvInst: 22.3006  pvAvg: 21.6241  pvTangent: 0.5648 β†˜
 Sec: 63.00977  pvInst: 22.3006  pvAvg: 21.6490  pvTangent: 0.5896 β†—
 Sec: 63.60993  pvInst: 22.3006  pvAvg: 21.6738  pvTangent: 0.6144 β†—
 Sec: 64.21006  pvInst: 22.3006  pvAvg: 21.6986  pvTangent: 0.6392 β†—
 Sec: 64.81022  pvInst: 22.6109  pvAvg: 21.7296  pvTangent: 0.6703 β†—
 Sec: 65.41036  pvInst: 22.6109  pvAvg: 21.7607  pvTangent: 0.7013 β†—
 Sec: 66.01044  pvInst: 22.3006  pvAvg: 21.7855  pvTangent: 0.7261 β†—
 Sec: 66.61057  pvInst: 22.6109  pvAvg: 21.8165  pvTangent: 0.7571 β†—
 Sec: 67.21070  pvInst: 22.6109  pvAvg: 21.8476  pvTangent: 0.7882 β†—
 Sec: 67.81085  pvInst: 22.6109  pvAvg: 21.8786  pvTangent: 0.8192 β†—
 Sec: 68.41094  pvInst: 22.6109  pvAvg: 21.9096  pvTangent: 0.5399 β†˜
 Sec: 69.01094  pvInst: 22.6109  pvAvg: 21.9344  pvTangent: 0.5648 β†—
 Sec: 69.61113  pvInst: 22.6109  pvAvg: 21.9593  pvTangent: 0.5896 β†—
 Sec: 70.21129  pvInst: 22.6109  pvAvg: 21.9841  pvTangent: 0.6144 β†—
 Sec: 70.81142  pvInst: 22.6109  pvAvg: 22.0089  pvTangent: 0.6392 β†—
 Sec: 71.41147  pvInst: 22.6109  pvAvg: 22.0337  pvTangent: 0.6640 β†—
 Sec: 72.01149  pvInst: 22.6109  pvAvg: 22.0586  pvTangent: 0.6889 β†—
 Sec: 72.61162  pvInst: 22.6109  pvAvg: 22.0834  pvTangent: 0.7137 β†—
 Sec: 73.21176  pvInst: 22.9212  pvAvg: 22.1144  pvTangent: 0.7447 β†—
 Sec: 73.81190  pvInst: 22.9212  pvAvg: 22.1455  pvTangent: 0.7758 β†—
 Sec: 74.41204  pvInst: 22.9212  pvAvg: 22.1765  pvTangent: 0.8068 β†—
 Sec: 75.01221  pvInst: 22.9212  pvAvg: 22.2075  pvTangent: 0.8378 β†—
 Sec: 75.61222  pvInst: 22.9212  pvAvg: 22.2385  pvTangent: 0.5585 β†˜
 Sec: 76.21239  pvInst: 22.9212  pvAvg: 22.2634  pvTangent: 0.5834 β†—
 Sec: 76.81244  pvInst: 22.9212  pvAvg: 22.2882  pvTangent: 0.6082 β†—
 Sec: 77.41249  pvInst: 22.9212  pvAvg: 22.3130  pvTangent: 0.6330 β†—
 Sec: 78.01263  pvInst: 22.9212  pvAvg: 22.3378  pvTangent: 0.6578 β†—
 Sec: 78.61273  pvInst: 23.2315  pvAvg: 22.3689  pvTangent: 0.6889 β†—
 Sec: 79.21285  pvInst: 23.2315  pvAvg: 22.3999  pvTangent: 0.4096 β†˜

 Controller Action: directIP
 Tuning Method:     ZN_PID

 Output Start:      0.00
 Output Step:       25.00
 Sample Sec:        0.60000

 Pv Start:          20.4388
 Pv Max:            25.2227
 Pv Diff:           4.7840

 Process Gain:      0.6100
 Dead Time Sec:     26.40476
 Tau Sec:           140.23580

 Tau/Dead Time:     5.3 (easy to control)
 Tau/Sample Period: 233.7 (good sample rate)

 Kp: 1.2107
 Ki: 0.1136
 Kd: 0.4544

 ZN_PID
  Kp: 1.21
  Ki: 0.11
  Kd: 0.45

 ZN_Half_PID
  Kp: 0.61
  Ki: 0.06
  Kd: 0.23

 Damped_PID
  Kp: 0.67
  Ki: 0.15
  Kd: 0.38

 NoOvershoot_PID
  Kp: 5.22
  Ki: 0.04
  Kd: 0.45

 CohenCoon_PID
  Kp: 7.25
  Ki: 0.09
  Kd: 0.65

 ZN_PI
  Kp: 0.91
  Ki: 0.07
  Kd: 0.00

 ZN_Half_PI
  Kp: 0.45
  Ki: 0.03
  Kd: 0.00

 Damped_PI
  Kp: 0.50
  Ki: 0.11
  Kd: 0.00

 NoOvershoot_PI
  Kp: 3.05
  Ki: 0.04
  Kd: 0.00

 CohenCoon_PI
  Kp: 4.82
  Ki: 0.09
  Kd: 0.00