br3ttb/Arduino-PID-AutoTune-Library — pull request #10 by t0mpr1c3 (2013-10-28 04:12:00+00:00)
Title: Peak detection overhaul, new tuning rules, etc.

Brett, There's a lot of stuff here but I realise that there are constraints on you developing this library that might be obviated by a pull request. You might want to have a look at the method of peak detection I have implemented here. I think it is a considerable improvement. There's also a bunch of new auto tune rules.

Summary of changes:
================

Changes to the peak convergence method:
* peak times and values now recorded for both minima and maxima in array peakTime[] and longer array peaks[]
* new method of assessing convergence for peaks based on amplitude over last 1.5 cycles rather than levels of recent maxima
* new variable inputCount counts number of inputs in lastInputs[] so that peaks are not called before lastInputs[] has been filled

Finite state machine:
* new private variable enum AutoTunerState state records current state of algorithm
* Runtime() initiates autotuner immediately first time around instead of waiting until next sampleTime

Enumerated types:
* tuning algorithms selected by enum Control type
* enum AutoTuneState state used instead of flag variable running to indicate autotuner state
* enum PeakType used to describe whether peaks are maxima or minima
* enum Mode used to describe whether under Automatic or Manual control
* enum Direction used to describe sign of gain

Changes to private methods and variables:
* minimum value of nLookBack set to 20 in method SetLookbackSec()
* int variables nLookBack, peakCount changed to byte
* got rid of private variable justevaled whose value was never checked
* private variables justchanged, isMin, isMax, absMax, absMin made local to Runtime()
*private method FinishUp() inlined so that phaseLag and inducedAmplitude can be local to Runtime()

New tuning rules:
* new tuning rules selectable by setting enum Control type
* new private variables Kp, Ti, Td for calculation of gain parameters
* private variables Ku, Kp made local to FinishUp();
* induced amplitude calculated as average over previous 1.5 cycles instead of difference between most extreme values ever observed

New variables and methods used by the AMIGOF_PI algorithm:
* private variable K_process estimates the process gain from the steady
state response to a step up in output
* private variable originalNoiseBand saves value of noiseBand, which is tuned by the AMIGOF_PI algorithm
* private method CheckStable() checks whether the values in lastInputs[] have converged to values within noiseBand of each other

New simulations:
* lag-dominated and delay-dominated processes. Ziegler-Nichols PI works surprisingly well, but some of the more conservative methods I have implemented are worth a look.

Dithering:
* implemented as a compile option. I haven't found this very useful.