40m QIL Cryo_Lab CTN SUS_Lab TCS_Lab OMC_Lab CRIME_Lab FEA ENG_Labs OptContFac Mariner WBEEShop
 PSL Not logged in
 Sat Feb 17 00:23:38 2018, Craig, awade, DailyProgress, BEAT, Beatnote Stabilization PID results from today Fri Mar 16 13:09:35 2018, awade, Craig, DailyProgress, TempCtrl, Beatnote Stabilization: Relay tuning of PID feedback coefficients Mon Apr 9 20:44:41 2018, awade, DailyProgress, TempCtrl, Beatnote Stabilization: Configuring heaters to actuate differentially
Message ID: 2142     Entry time: Fri Mar 16 13:09:35 2018     In reply to: 2095     Reply to this: 2167
 Author: awade, Craig Type: DailyProgress Category: TempCtrl Subject: Beatnote Stabilization: Relay tuning of PID feedback coefficients

Beat note slewing is still a problem and it will be some time before Shruti (this year's summer SURF) is here to tackle it with some intelligent controls: i.e. neural networks/machine learning, Kalman filters, Wiener filters (?) etc.

This post is an intermediate one, I will post something in more detail about using relay tests to find PID parameters at some later time.

## PID controlling beat note still not well tuned

In a previous test of controlling the beat note frequency with PID feedback to the north cavity heat shield I guessed P, I and D values.  Reaching optimal values based on the usual human methods of driving the loop close to instability and then backing off prove to be very difficult.  For the cavity-heater system the time constants for settling to thermal equilibrium are very long.  The critical dampening period appears to be on the order of 20 minutes (see below).  However, with the loop engaged and very close to point of inducing instability the oscillations can extend out to many hours. Its difficult to keep track of movements of the various gains and their impact, especially when many other parts of the experiment are dropping lock, drifting, ringing, etc. I found it difficult to discriminate the goodness of the last adjustment when there are a bunch of spurious step functions induced from humans interacting in the lab and outside.

It is also really difficult to assess whether one has truly hit the optimal critically dampened condition with no long term instability causing oscillations.  Lots of people offer advice and rules of thumb on how to tune to 'good enough'.  If tolerances are relatively loose then it might be ok. But we can do better. Ideally we would actively drive the system to probe the plant's properties and come up with an optimization that set the values in an objective way.  An active optimization will maximize the useful information for the given integration time and remove the human biases in tuning PID for plants with very large time lag.

You can see an example of one set of values I chose in PSL:2095.  It took some 12 hours to fully dampen down, this was a bad choice of values.  After this I gave up on manual tuning to work on other things.

## The Relay Test

There is a way of probing the plant under control to estimate appropriate values for P, I and D values: a relay test.  There is some information for this auto tuning method in [1]. It basically consists of switching out the PID block for a relay function.  The relay does a hard switch from +a to -a depending on the sign of the error signal: it is a step function set about some mean operating point.  This active feedback induces an oscillation in the plant and, once the system settles into regular oscillations, the relay function leads the plant by 90°.  Although the square wave hard switch will induce Fourier components at higher harmonics of the lowest natural frequency of the plant, in almost all non-pathological plants there is a dominant pole that filters these frequency components out.  Thus, the dominant oscillations induced during a relay test give some clear information about the characteristic response of the plant in a relatively robust way.

This method is similar to the step function test that people sometimes do.  That is a much older method from the 1940's.  You provide a step kick in the actuation and fit the impulse response to retrieve the critical period and amplitude of the plant's response.  The disadvantage of this method is that one is only getting information from a single kick, you also have to fit the plant response along with any sensor noise etc.  It is much better to integrate for a longer period and lock-in on the frequency of interest.

From the induced relay oscillations we can extract a critical dampening period (Tc) and critical dampening coefficient (Kc) from the ratio of the relay amplitude and induced peak-to-peak error signal amplitude. These values give the frequency at which the plant's Nyquist curve first cuts the real axis. This represents the first frequency at which the plant lags the driving signal by -180°.  This is all the information we need to make a critically dampen PID loop (in principle). There is a standard lookup table for choices of Kp, Ki and Kd gain values for Tc and Kc given in most text books.  It turns out these 'standard' values are well known to be bad and frequently give a loop tuning that have excessive oscillations.  They get copied from textbook to textbook as part of the canon of PID tuning wisdom. Values that I found to work well with initial test on the laser slow controls were that given in Table 1 of [2]. For clarity I've tabulated these values below (in case the link dies).

Improved Zeigler-Nichols tuning constants
Type Kp Ti Td
Original textbook values 0.6Kc Tc/2 Tc/8
Little overshoot 0.33Kc Tc/2 Tc/3
No overshoot 0.2Kc Tc/2 Tc/3

Where Ti and Td are integral and derivative terms in the 'standard' form of the PID controller, hence

$K_i = \frac{K_p}{T_i}; \qquad K_d = K_pT_d$

## Initial tests

I did an initial test of this auto tuning method on the laser slow controls.  It pretty much guessed first time the PID values that we had set manually with only 120 seconds of integration time. The typical characteriztic impulse response time is on the order of 4.5 seconds in that case.  That isn't a bad effort.

In my initial test on the cavity shield-beat note feedback I chose a relay amplidue of 0.05 W, an average actuator offset of 0.775 W and a setpoint of 26.5 MHz and triggered the autotune function for 4 hours.  See attachment 1 for what happened (sorry no proper plot, not worth it at this stage).  Basically the initial average actuator point was set a little too high for the set point (producing an asymmetric response) and the whole system was below the critical dampening amplitude and converges on the set point. The relay amplitude needs to be turned up to induce a much larger response.  I would also guess that there should be an extremely slow feedback to the actuator mean value to keep the plant response symmetric.

This initial test was a failure.   For reference the suggested loop adjustment based on median period and amplitude was  kp, ki, kd = 0.76544, 0.01486, 26.28024. Bad.F

## Gradient descent on PID values

This was a failure in my initial tests on laser slow controls.  For a cost function I integrated the error function over the course of a step test that was roughly 10 times the characteristic response time of the plant (laser slow frequency input). I sampled two values for the proportional term and performed a step test on each.  I then computed a local gradient of the cost function.  This cost function I was using was too susceptible to sensor noise and gave more or less 50:50 guesses in either direction for the next move in tuning parameters even when it was clear it needed to be moved down.  So it was as good as a random walk simulation.

Might get back to this later.  There might be more time efficient ways that extract information more efficiently.

## Integration into the PIDLocker_beta.py python script

I have integrated the relay test into the beta version of our python locker.  Its called with the --autotune flag, use age is something like

>  python PIDLocker_beta.py PIDConfig_NCAVHeater.ini --autotune -d 0.05 -t 14400

> python PIDLocker_beta.py --help

You can get the script from our ctn_scripts git repo here: https://git.ligo.org/cit-ctnlab/ctn_scripts, its called PIDLocker_beta.py.  I have also attached a snapshot of the current version below for future reference. All the auto tune functionality is contained within a function called RelayAutoTune.  It isn't truely 'auto' as you can see from above section, but with a bit of playing around with offset and relay amplitude you can get it to work.

More to come later. For some future reading, mostly for interesting ideas, see [3].

## References

[1]  Åström, K. J. & Murray, R. M. Feedback Systems: An Introduction for Scientists and Engineers, Control And Cybernetics 36, (2008) (link). There many versions, they are not equal.

[2]  Wilson, D. I. Relay-based PID Tuning, Autom. Control Feb/March, 10–12 (2005) (link).

[3]  Hornsey, S., A Review of Relay Auto-tuning Methods for the Tuning of PID-type Controllers, Reinvention: an International Journal of Undergraduate Research 2, issue 2 (2012) (link)

 Attachment 1: RelayTest_BNtoCavShieldHeater_Failure2018-03-16_at_3.05.48_PM.png  40 kB  Uploaded Fri Mar 16 17:23:27 2018
 Attachment 2: PIDLocker_beta_snapshot20180316.tar.gz  4 kB  Uploaded Fri Mar 16 17:25:54 2018
ELOG V3.1.3-