Software > Software

My first little PID: please comment

<< < (2/5) > >>

jkerns:

--- Quote from: obiwanjacobi on May 14, 2013, 01:24:23 AM ---Thank you. It's all about (tweaking) constants, I see  :P

In

--- Quote from: jkerns on May 12, 2013, 10:19:57 AM ---filtered_error = (1 - filter_constant)*filtered_error + filter_constant*error

--- End quote ---


Is the bold 'filtered_error' a previous filtered_error value or...?
--- End quote ---


Yes. Your software is running in a loop so the variable "filtered_error" has a value from last time and now you use the old value in the calculation and it ends up in the new value. Much like using ++i or similar in C.


--- Quote ---Also: is it likely you would dynamically (at runtime) switch using P, I or D terms for a single controller process? I mean do I need to take into account that all methods update the delta-time, I-accumulator and last-error variables in order to allow mixed calling of the P, PI, PD and PID methods?

--- End quote ---


I've never switched controller types in mid stream. It isn't uncommon to modify the gains as a function of operating conditions (referred to as gain scheduling) but switching between PI and PD or whatever would be unusual.

OH! I forgot to look! Do you have anti-windup on the I term? You need that. Really.  If the output of your controller is at the limit of the physical variable that you are sending to the actuator (e.g. 100% duty cycle)
you need to freeze the integrator so it doesn't keep integrating to some unobtainable value that has to be un-integraged some time later on - that is very destabilizing.  Typically you would compare the output of the controller with the actual limits of whatever your physical output is and either not call the integrator sub-function or just substitute zero for the error in the input to the integrator. I guess you could consider that a dynamic switch but that is not a common terminology.

If you are having trouble sleeping, I drone on and on for about an hour on PID control here... http://www.youtube.com/playlist?list=PL3ea3YrO-K5gxpOrrgKytFBvIzBv_WsXs

obiwanjacobi:
Yes, I wondered about that (about I).

It keeps building up and up and you would have to undo all that. To my naive mind that would cause overshoot and oscillation.

So if the I-term reaches the max value it just stops accumulating? Or when the combined output (return value from my methods) reaches max value? I would need some value range management in my class anyway, especially when mulitple P/I/D Terms are added together...

Thinking on the I-term some more, I would even say that if your error is 0 (or within the acceptable error-band) I would simply stop using the I-term altogether and perhaps reset it (to what value I don't know - some % of its current value?) for when it is used later on (when we travel outside the error band) it would otherwise make the system 'jerk'.

Does that make sense?

PS: Had already found your YT channel and I have no trouble sleeping ;-)  Thanx.

jkerns:
 
--- Quote from: obiwanjacobi on May 14, 2013, 08:21:21 AM ---Yes, I wondered about that (about I).

It keeps building up and up and you would have to undo all that. To my naive mind that would cause overshoot and oscillation.

So if the I-term reaches the max value it just stops accumulating? Or when the combined output (return value from my methods) reaches max value? I would need some value range management in my class anyway, especially when mulitple P/I/D Terms are added together...
--- End quote ---

Stop the integrator when the combined output reaches it's limit.



--- Quote ---Thinking on the I-term some more, I would even say that if your error is 0 (or within the acceptable error-band) I would simply stop using the I-term altogether and perhaps reset it (to what value I don't know - some % of its current value?) for when it is used later on (when we travel outside the error band) it would otherwise make the system 'jerk'.
--- End quote ---

Leave it running. The point of using the I is pretty much to drive the error to zero.  Turning it off or resetting it will just introduce some error to the sytem.


--- Quote ---PS: Had already found your YT channel and I have no trouble sleeping ;-)  Thanx.

--- End quote ---
;D

jwatte:
Another option to deal with constantly accumulating I error is to use a leaky integrator for the I term, just like you do for the D term. Except for the D term, it's a single-pole low-pass filter; for the I term it's a single-term high-pass filter.

Also, yes, with an I term you will almost always get a little bit of overshoot. The point of the D term is to limit the slew rate of the response, so that the overshoot can be dampened. With a well tuned system, your I/D control terms will end up being "critically damped" which is a nice place to start from by way of trading responsiveness and damping.

obiwanjacobi:

--- Quote from: jwatte on May 14, 2013, 10:45:26 AM ---Another option to deal with constantly accumulating I error is to use a leaky integrator for the I term, just like you do for the D term. Except for the D term, it's a single-pole low-pass filter; for the I term it's a single-term high-pass filter.

--- End quote ---

I understand what low-pass and high-pass mean (from audio) but I have no idea how to build code for it...


Another thing I noticed is that I see people mix up the way the delta error is calculated. Some do
--- Code: ---previousError - newError
--- End code ---
Others do

--- Code: ---newError - previousError
--- End code ---

Is this something that you will trim/tune out of the controller (using gains) or is one correct and the other one not?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version