PID autotuning, how to detect oscillation?
ManAtWork
Posts: 2,178
Hello,
I try to implement autotuning for a PID controller using the Ziegler–Nichols method. Has somebody already done this? What is the preferred method for detecting oscillation (finding critical gain or stability limit). If the controller has to be general-purpose it's not easy, I think. The simplest method of counting zero crossings might not work if there is noise present. Oscillation may not reach saturation level in all cases due to external limits/clipping or non-linear damping/friction. Real oscillation has to be distinguished from marginal cycles due to quantisation errors. FFT would probably be the best method but is way too much overhead.
Any ideas?
I try to implement autotuning for a PID controller using the Ziegler–Nichols method. Has somebody already done this? What is the preferred method for detecting oscillation (finding critical gain or stability limit). If the controller has to be general-purpose it's not easy, I think. The simplest method of counting zero crossings might not work if there is noise present. Oscillation may not reach saturation level in all cases due to external limits/clipping or non-linear damping/friction. Real oscillation has to be distinguished from marginal cycles due to quantisation errors. FFT would probably be the best method but is way too much overhead.
Any ideas?
Comments
I have thought these days about a similar problem. Guitar tuner. Measure the frequency.
I have not tried it yet, but I thought that you could sample the values into a buffer, then find the amplitude (scanning the buffer), then define a threshhold as for example half of the amplitude, then find the time (number of samples) for one (or n) cycle(s).
A cycle is done if value>threshhold again after it had been once value<-threshhold.
Does this help?
((Just a thought: Is the method suitable for a general-purpose controller? Is it allways allowed to oscillate?))
Christof
yes, our problems are similar but not the same. In your case only frequency is relevant and is has to be measured very accurate. In my case both frequency and amplitude are important but accuracy is not that critical.·The oscillations I'm looking for are in the range 3 to 1000Hz and amplitude can change over a 1:1000 ratio. I don't have much memory left over so I think I'll try to pack/preprocess the samples. If I only store minimum/maximum values and zero crossings and their timestamps I could estimate the frequency and amlitude later without wasting much memory even if I have to record a full second of signal data. I could stop after say 10 cycles or a 1s timeout which ever occurs first.
For the Ziegler-Nichols tuning I need to find the critical gain where oscillations starts by turning up the gain and repeatedly stimulate the controller with short pulses (some systems don't start oscillations spontanously due to friction). When oscillations starts, I backoff gain until·oscillation decays so I get something like in the "Oscillation" picture. The problem is that even overdamped systems can have some zero crossings (see picture) but amplitude decreases rapidly. So I have to find out "trends" over time instead of working with fixed thresholds.
For your quitar tuner I'd first look at some scope snapshots. If you are lucky the waveforms do not contain too much overtone components so the wave is monotonic between min/max values or at least between 20 and 80% points. The worst case would be an instrument with multiple strings per tone (e.g. piano) that can contain subharmonics due to modulations. In that case you might see the frequency difference between the strings instead of the fundamental if your algorithm is not clever.