On Sep 21, 3:53 pm, "Peter Nachtwey" <pnacht...@comcast.net> wrote:> <shiitsh...@yahoo.co.uk> wrote in message > > news:1190320399.608982.305930@v23g2000prn.googlegroups.com... > > > On Sep 21, 6:24 am, pnacht...@gmail.com wrote: > >> On Sep 20, 10:26 am, Vladimir Vassilevsky <antispam_bo...@hotmail.com> > >> wrote:> cincy...@gmail.com wrote: > >> > >>>>I have read some article and book on control design and PID. But I > >> > >>>>never found how to implement it in software or how to derive an > >> > >>>>algorithm for it. Can someone help me at this? I just want to code > >> > >>>>an > >> > >>>>algorithm from a block diagram of a controller. > > >> > >>>f32 PID(f32 x) > > >> > >>What's an "f32"? > >> > >>-- > > >> > > I would guess a "32-bit float." > > >> > Yes. And PID is a short for "pidor", which is the Russuan bad word for > >> > "pederast". > > >> This reminds of Chekhov in Star Trek where Chekhov thinks everything > >> was 'inwented' in Russia. > > >> > Now you know all about PIDs; use them with care. > > >> So far this thread looks like a case of the blind leading the blind. > > >> The OP should have done a search for PID code. He would have found > >> John Shaw's and Tim Wescott's sites with PID examples. What is wrong > >> with people that they can't do a simple search? > > >> Randy, remember this > >> thread?http://groups.google.com/group/comp.dsp/browse_thread/thread/e34f1fde... > >> If one can't get or give decent answers then why bother? > > >> Here is a simple PID for a DSP. I first saw this MANY years ago in a > >> TI DSP book. I think the example this code was written TMS320C14 > >> appnote. > >> e(n)=Target(n)-Actual(n) > >> u(n) = u(n-1)+K0*e(n)+K1*e(n-1)+K2*e(n-2) > >> K0 = Ki*T+Kp+Kd/T > >> K1=-Kp-2*Kd/2 > >> K2=Kd/T > > >> There are implementation problems. If the sample period T is very > >> short then Kd/T can be a very big number and Ki*T very small so that > >> the range of numbers required to accurately represent K0,K1 and K2 > >> exceeds 16 bits. > > >> I recommend that people read the appnotes in the TI, Freescale and AD > >> libraries. The DSP chip maker are trying to make using their chips as > >> easy possible. Get the hint? > > >> I know I am a fuddy duddy, stick and the mud etc. > > >> Peter Nachtwey > > > A pure differentiator is never good - you need a filter on it or a > > phase-lead. > > Why? Never is a big word. I am not saying I disagree, I just think you > should justify your statement. > > > Often you can use more than one integrator provided you > > stabilise the loop properly. > > Can you provide an example? > > > PID is just a quick fix but not the best > > solution. > > Why? I still use PIDs very effiectively. I sometimes add feed forwards, a > 2nd derivative and/or an output filter. I would love to see your solution > for the Bode plot below. > > > For the best solution you need a Bode plot and design lag- > > lead compensators along with integrators. > > Fine, where is your example filter? I provided one. > How do you get the Bode plot? Don't worry, I have one.ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtf > What do you do with the Bode plot? > How do you use it to determine the filter and the coefficients? > What is your best solution? > > Peter NachtweyOk where to start! First consider what is an ideal Bode plot. It must be very steep (open loop of course) and then a steep roll-off. In fact a vertical line. This is in fact impossible since the closed -loop system would be unstable. Therefore you must pass through unity gain at (normally) -20dB/decade or in rare cases asymptotically flat ie a horixontal line! This is possible since the exact Bode plot will scrape through if you draw it. Anyway, for a given frequency say w1 the open loop gain is given from the Bode plot and the higher it is means the better disturbance rejection. This is because the response to a disturbance is given by the disturbance divided by mag(1+KGH) where the symbols have their usual meaning. The higher the open loop gain means better disturbance rejection. Hence more than one integrator means more disturbance rejection. Of course we need to stabilise the loop with one or maybe two phase advances over a limited frequency range around unity gain (to give a good phase margin) and then have a steep roll-off to attenuate structural resonances. There is a lot more to this but this is the rough idea - two integrators are always better than one and sometimes two phase advances. This is a bit like having PI^2D^2 control!! It's used in servos such as hard disk drives. Not so much in process control because often the plant model is unknown in the first place. It's a fact that the vast majority of servos around the world in process control are not 'tight' enough. It's like tightening a violin string. Moving the bandwidth up at each step of design and having a phase margin 'buget'. Digitizing things ie with z transforms is similar. Only trouble is you must sample at least ten time higher than the closing bandwidth. This because of the extra time-delay (negative phase shift) introduced with the zero-order hold. The simple rules are... Bandwidth should be as high as physically possible Open loop gain as high as possible Decent phase margin (55-60 degrees) Steep roll-off after unity gain. When you design in the time-domain using Ki,Kp,Kd twiddle factors all these things are invisible of course and that's why PID has it's limitations - you need to work in teh freq domain where possible. Pure differentiation is not good for several reasons. First it amplifies noise and secondly it amplifies any resonances in the system (if you have an electro-mech system). Therefore differentiators must be band-limited and that is just a fancy way of saying that instead of s we use (1+sT1)/(1+sT2) T1>T2. Similarly integrators must normally (not always) be band limited ie they must have an upper limit (1+sT)/ s and this is of course PI control as you will know it. I need to write a book... Fitlike
PID Controller
Started by ●September 20, 2007
Reply by ●September 21, 20072007-09-21
Reply by ●September 21, 20072007-09-21
Peter Nachtwey wrote:>>>>Yes. And PID is a short for "pidor", which is the Russuan bad word for >>>>"pederast". >>> >>>This reminds of Chekhov in Star Trek where Chekhov thinks everything >>>was 'inwented' in Russia.Star Trek - Red Neck. A. P. Chekhov is a classic dramatist. http://en.wikipedia.org/wiki/Anton_Chekhov>>Often you can use more than one integrator provided you >>stabilise the loop properly. > Can you provide an example?Well, not a pure double integrator, of course. The double integrator can't be stable. The regulator action should be the integrator + lowpass filter, so the phase shift at DC will be 90, not 180.>>PID is just a quick fix but not the best >>solution. > > Why?Because there is no such things like the ideal LTI systems in reality. Because PID is inefficient for the systems with big amount of plain delay.> I still use PIDs very effiectively.No doubt about that. However PID approach has its limitations.> I sometimes add feed forwards, a > 2nd derivative and/or an output filter. I would love to see your solution > for the Bode plot below. > ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtfIsn't a compensation of a single peak by zero in PID loop a scholar problem?>>For the best solution you need a Bode plot and design lag- >>lead compensators along with integrators.Unfortunately, the Bode plot makes sense only for LTI systems with the monotonic response.> Fine, where is your example filter? I provided one. > How do you get the Bode plot? Don't worry, I have one. > What do you do with the Bode plot? > How do you use it to determine the filter and the coefficients? > What is your best solution?I would try to notch out the peak and then apply a PID, may be with a higher order loop. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●September 21, 20072007-09-21
cincydsp@gmail.com writes:> On Sep 20, 12:23 pm, Randy Yates <ya...@ieee.org> wrote: >> Vladimir Vassilevsky <antispam_bo...@hotmail.com> writes: >> > reginald.lo...@gmail.com wrote: >> >> >> Hi >> >> I have read some article and book on control design and PID. But I >> >> never found how to implement it in software or how to derive an >> >> algorithm for it. Can someone help me at this? I just want to code an >> >> algorithm from a block diagram of a controller. >> >> > f32 PID(f32 x) >> > { >> > const f32 P = FOO, I = BAR, D = BLABLABLA; >> > static f32 i, d; >> >> > i += x; >> > f32 dx = x - d; >> > d = x; >> >> > return x*P + i*I + dx*D; >> > } >> >> What's an "f32"? >> -- >> % Randy Yates % "So now it's getting late, >> %% Fuquay-Varina, NC % and those who hesitate >> %%% 919-577-9882 % got no one..." >> %%%% <ya...@ieee.org> % 'Waterfall', *Face The Music*, ELOhttp://home.earthlink.net/~yatescr > > I would guess a "32-bit float."I C. -- % Randy Yates % "The dreamer, the unwoken fool - %% Fuquay-Varina, NC % in dreams, no pain will kiss the brow..." %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Eldorado Overture', *Eldorado*, ELO http://home.earthlink.net/~yatescr
Reply by ●September 21, 20072007-09-21
On Sep 22, 4:02 am, Vladimir Vassilevsky <antispam_bo...@hotmail.com> wrote:> Peter Nachtwey wrote: > >>>>Yes. And PID is a short for "pidor", which is the Russuan bad word for > >>>>"pederast". > > >>>This reminds of Chekhov in Star Trek where Chekhov thinks everything > >>>was 'inwented' in Russia. > > Star Trek - Red Neck. > A. P. Chekhov is a classic dramatist.http://en.wikipedia.org/wiki/Anton_Chekhov > > >>Often you can use more than one integrator provided you > >>stabilise the loop properly. > > Can you provide an example? > > Well, not a pure double integrator, of course. The double integrator > can't be stable. The regulator action should be the integrator + lowpass > filter, so the phase shift at DC will be 90, not 180. > > >>PID is just a quick fix but not the best > >>solution. > > > Why? > > Because there is no such things like the ideal LTI systems in reality. > Because PID is inefficient for the systems with big amount of plain delay. > > > I still use PIDs very effiectively. > > No doubt about that. However PID approach has its limitations. > > > I sometimes add feed forwards, a > > 2nd derivative and/or an output filter. I would love to see your solution > > for the Bode plot below. > >ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtf > > Isn't a compensation of a single peak by zero in PID loop a scholar problem? > > >>For the best solution you need a Bode plot and design lag- > >>lead compensators along with integrators. > > Unfortunately, the Bode plot makes sense only for LTI systems with the > monotonic response. > > > Fine, where is your example filter? I provided one.As I said above the double integrator needs a phase-advance for stability and sometimes two phase advances depending on whatever there is in there. There are a number of applications where this can work. One simple one is a phase-locked loop where there is one integrator(the VCO) and a lag-lead. The lag is like another integrator over a limited frequency range and the lead gives stbility. So the Bode plot is -20,-40,-20 (through unity gain) then finally -40dB/ decade. The first roll-off can be -40 instead of -20 but this would decreas the phase margin. Fitlike
Reply by ●September 22, 20072007-09-22
minfitlike@yahoo.co.uk wrote: <snip>> > As I said above the double integrator needs a phase-advance for > stability and sometimes two phase advances depending on whatever there > is in there.Is your double integrator two pure integrators? I thought we were talking about a PID with a low pass filter. Are you sure you need phase advance? I must be doing something wrong :) Peter Nachtwey
Reply by ●September 22, 20072007-09-22
Vladimir Vassilevsky wrote: > > > Peter Nachtwey wrote: > > >>>>> Yes. And PID is a short for "pidor", which is the Russuan bad word for >>>>> "pederast". >>>> >>>> This reminds of Chekhov in Star Trek where Chekhov thinks everything >>>> was 'inwented' in Russia. > > Star Trek - Red Neck. > A. P. Chekhov is a classic dramatist. > http://en.wikipedia.org/wiki/Anton_Chekhov Who? Never heard of him. Was he on TV? I watched Chekhov on Star Trek many times. A.P. Chekhov should have got a better publicist. > > >>> Often you can use more than one integrator provided you >>> stabilise the loop properly. >> Can you provide an example? > > Well, not a pure double integrator, of course. The double integrator > can't be stable. The regulator action should be the integrator + lowpass > filter, so the phase shift at DC will be 90, not 180. So you really mean a pure integrator with a low pass filter. > >>> PID is just a quick fix but not the best >>> solution. >> >> Why? > > Because there is no such things like the ideal LTI systems in reality. I haven't seen your better solution yet. > Because PID is inefficient for the systems with big amount of plain delay. Who mentioned delay or dead time? My Bode plot doesn't show any hint of dead time. You do know what dead time looks like on a Bode plot? Those that do process control can use the methods shown on www.controlguru.com to tune their plants that have dead time. How would your Vladi-filter be better? I haven't seen you mention anything about delay queues or predicting the future. Does the Vladi-filter do that? How? > >> I still use PIDs very effiectively. > > No doubt about that. However PID approach has its limitations. Sure but like I said just below, I augment my PIDs so they work well. > >> I sometimes add feed forwards, a 2nd derivative and/or an output >> filter. I would love to see your solution for the Bode plot below. >> ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtf > > Isn't a compensation of a single peak by zero in PID loop a scholar > problem? Who needs a zero? This is not a scholar problem. I must control these kinds of systems every day. No problem for me but I haven't seen anybody else find a solution. It isn't really that hard. > > >>> For the best solution you need a Bode plot and design lag- >>> lead compensators along with integrators. > > Unfortunately, the Bode plot makes sense only for LTI systems with the > monotonic response. Well, what is it, are Bode plots useful or not? > >> Fine, where is your example filter? I provided one. >> How do you get the Bode plot? Don't worry, I have one. >> What do you do with the Bode plot? >> How do you use it to determine the filter and the coefficients? >> What is your best solution? > > I would try to notch out the peak and then apply a PID, may be with a > higher order loop. Notch? Who needs a notch filter for something so trivial? It just takes some calculations for a small PID augmentation. A higher order loop? Hmmm. Can't you see from the Bode plot that this is a type 0 under damp system? A PID should be able to handle this easily. I can make it harder though. Listening to you one would think that industry would come to a halt because PIDs are NOT good enough. I think it is people that aren't good enough. Anton Chekhov should have had a quote about if you talk the talk you better be able to walk the walk. I am waiting for the Vladi-filter. :) At least show us a transfer function. I will admit A.p. Chekhov gets more hits on the internet than the Chekhov character on Star Trek but in the '60s there was TV and no internet. Peter Nachtwey
Reply by ●September 23, 20072007-09-23
On Fri, 21 Sep 2007 16:02:18 +0000, Vladimir Vassilevsky wrote:> Peter Nachtwey wrote: > > >>>>>Yes. And PID is a short for "pidor", which is the Russuan bad word for >>>>>"pederast". >>>> >>>>This reminds of Chekhov in Star Trek where Chekhov thinks everything >>>>was 'inwented' in Russia. > > Star Trek - Red Neck. > A. P. Chekhov is a classic dramatist. > http://en.wikipedia.org/wiki/Anton_Chekhov > > >>>Often you can use more than one integrator provided you >>>stabilise the loop properly. >> Can you provide an example? > > Well, not a pure double integrator, of course. The double integrator > can't be stable. The regulator action should be the integrator + lowpass > filter, so the phase shift at DC will be 90, not 180. >Eh? By that token, a single integrator isn't stable, at least if you're talking about BIBO stability. Any plant that can be stabilized with a PID can be stabilized with a PIID; you lose some transient performance but you gain the ability to reject a ramp disturbance. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Reply by ●September 23, 20072007-09-23
Peter Nachtwey wrote:> >> I sometimes add feed forwards, a 2nd derivative and/or an output > >> filter. I would love to see your solution for the Bode plot below. > >> ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtfPeter, Your Bode plot does not make any sense because it is a response of the *ideal* LTI system of the 2nd order. A properly designed PID can compensate the 2nd order system to any accuracy. Which means that you can choose whatever control loop parameters you like. For example: P = 0.5 Ti = 5ms, Td = 50ms This provides for the control bandwidth of mere 32Hz with the overdumped response. If you ask me for good, I will design the PID function which compensates your plant up to any given frequency :) Sure, this is nonsense. In practice, there are other limitations such as the accuracy of the model, the tolerances, etc. etc. Also, the control systems theory says nothing about the engine oil getting tough in winter.> > Isn't a compensation of a single peak by zero in PID loop a scholar > > problem? > Who needs a zero? This is not a scholar problem.Ok, not a scholar problem, but rather tedious exersize in math. Solving of the algebraic equations of the 3rd order.> I must control these > kinds of systems every day. No problem for me but I haven't seen > anybody else find a solution. It isn't really that hard.Reinventing the wheel?> > Unfortunately, the Bode plot makes sense only for LTI systems with the > > monotonic response. > > Well, what is it, are Bode plots useful or not?Bode plots give some idea. However you should not overestimate their validity.> >> Fine, where is your example filter? I provided one.See the explanations above.> >> How do you get the Bode plot? Don't worry, I have one. > >> What do you do with the Bode plot? > >> How do you use it to determine the filter and the coefficients? > >> What is your best solution?I don't like the shamanism and prefer the analytic approach.> > I would try to notch out the peak and then apply a PID, may be with a > > higher order loop. > > Notch? Who needs a notch filter for something so trivial? It just > takes some calculations for a small PID augmentation. A higher order > loop? Hmmm. Can't you see from the Bode plot that this is a type 0 > under damp system?No idea what is type 0. H(s) = 1/(S^2 + QS + 1) perhaps?> A PID should be able to handle this easily.Not just easily, but *ideally*. There is no point of using the heavy methods intended for more complex cases.> I can > make it harder though.What statement are you trying to prove or disprove?> Listening to you one would think that industry would come to a halt > because PIDs are NOT good enough.Eh?> I think it is people that aren't good > enough.The mass ignorance is a blessing for the shamans AKA consultants :-)> I am waiting for the Vladi-filter. :) At least show us a transfer > function.Here we go, Chekhov :) Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●September 23, 20072007-09-23
Tim Wescott wrote:>>>>Often you can use more than one integrator provided you >>>>stabilise the loop properly. >>> >>>Can you provide an example? >> >>Well, not a pure double integrator, of course. The double integrator >>can't be stable. The regulator action should be the integrator + lowpass >>filter, so the phase shift at DC will be 90, not 180. >> > > Eh? By that token, a single integrator isn't stable, at least if you're > talking about BIBO stability. > > Any plant that can be stabilized with a PID can be stabilized with a PIID; > you lose some transient performance but you gain the ability to reject a > ramp disturbance.Tim, You got into the middle of the thread. The talk is about compensating a system by a dominant pole, i.e. integrator. You can do it with the integrator of the 1st order, but not with the 2nd. The 2nd order will require a function like (S+a)/[S(S+b)]. The point of using of the higher order integrators is having more feedback at the low frequencies; this is a valid approach. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ●September 23, 20072007-09-23
On Sep 23, 8:28 am, Vladimir Vassilevsky <antispam_bo...@hotmail.com> wrote:> Peter Nachtwey wrote: > > >> I sometimes add feed forwards, a 2nd derivative and/or an output > > >> filter. I would love to see your solution for the Bode plot below. > > >>ftp://ftp.deltacompsys.com/public/NG/Bode%20Plot.rtf > > Peter, > > Your Bode plot does not make any sense because it is a response of the > *ideal* LTI system of the 2nd order. A properly designed PID can > compensate the 2nd order system to any accuracy. Which means that you > can choose whatever control loop parameters you like. > > For example: > > P = 0.5 Ti = 5ms, Td = 50ms > > This provides for the control bandwidth of mere 32Hz with the overdumped > response. > > If you ask me for good, I will design the PID function which compensates > your plant up to any given frequency :) > > Sure, this is nonsense. In practice, there are other limitations such as > the accuracy of the model, the tolerances, etc. etc. Also, the control > systems theory says nothing about the engine oil getting tough in winter. > > > > Isn't a compensation of a single peak by zero in PID loop a scholar > > > problem? > > Who needs a zero? This is not a scholar problem. > > Ok, not a scholar problem, but rather tedious exersize in math. Solving > of the algebraic equations of the 3rd order. > > > I must control these > > kinds of systems every day. No problem for me but I haven't seen > > anybody else find a solution. It isn't really that hard. > > Reinventing the wheel? > > > > Unfortunately, the Bode plot makes sense only for LTI systems with the > > > monotonic response. > > > Well, what is it, are Bode plots useful or not? > > Bode plots give some idea. However you should not overestimate their > validity. > > > >> Fine, where is your example filter? I provided one. > > See the explanations above. > > > >> How do you get the Bode plot? Don't worry, I have one. > > >> What do you do with the Bode plot? > > >> How do you use it to determine the filter and the coefficients? > > >> What is your best solution? > > I don't like the shamanism and prefer the analytic approach. > > > > I would try to notch out the peak and then apply a PID, may be with a > > > higher order loop. > > > Notch? Who needs a notch filter for something so trivial? It just > > takes some calculations for a small PID augmentation. A higher order > > loop? Hmmm. Can't you see from the Bode plot that this is a type 0 > > under damp system? > > No idea what is type 0. H(s) = 1/(S^2 + QS + 1) perhaps? > > > A PID should be able to handle this easily. > > Not just easily, but *ideally*. There is no point of using the heavy > methods intended for more complex cases. > > > I can > > make it harder though. > > What statement are you trying to prove or disprove? > > > Listening to you one would think that industry would come to a halt > > because PIDs are NOT good enough. > > Eh? > > > I think it is people that aren't good > > enough. > > The mass ignorance is a blessing for the shamans AKA consultants :-) > > > I am waiting for the Vladi-filter. :) At least show us a transfer > > function. > > Here we go, Chekhov :) > > Vladimir Vassilevsky > DSP and Mixed Signal Design Consultanthttp://www.abvolt.comOK, why did you provide such a miserable example of a PID in your first reply and suggest that is all one needs to know. You know better. Notch filters, lead compensators, double integrators, bashing PIDs, dead time, none of this is necessary and is just a distraction that cluttered up the answer to an example of PID code. If the noise or quantizing is too great then add a low pass filter to the PID. The PID is still valid. Higher order system will require extra derivative gains but that is just an augmentation to the PID. Tuning a PID is hard enough for most people. Throwing distractions like those mentioned above makes things even more confusing. If you designed your Vladi-filter into a product then how do you expect the customers to tune it? How many customers can tune a lead lag filter with an extra integrator? One may be able to tune a PI controller with a low pass filter. It works out to the same thing as the (s+a)/ (s*(s+b)) you posted below so how can you bash a PI with a low pass filter? I will stick to the PID for my products because it is what the customers are familiar with. That doesn't mean I don't have all the augmentations I mentioned above. The customers don't need to use them if they don't need them or are comfortable with them. Peter Nachtwey






