PID control in SX/B
Dunnsept
Posts: 115
I'm working on the code to do PID control for my next project. I have P and D working just fine, thanks to
both the Industrial Control text and Andy Lindsay's PID text in the forums.
BUT for the integral portion, while it works fine when there is a difference between the setpoint and measured value.
When the measured value EQUALS the setpoint, the integral portion is not removed (not reset to zero).
the Integral portion so far is a mix of code from between the above mentioned sources:
intcount = 10 and sign is a value set when I calc the error, err = setpoint - theTEMP if C = 0 then sign = -1. I have a display hooked up that displays inte. at the start I can watch it count up and as time goes by it really ramps up like it should.. But when I adjust the input so that theTEMP = setpoint, the integral portion stays.
Any suggestions at which point I should reset it? Since the integral portion is treated as an accumulator, it is never reset in any of the 2 sources above. Andy's tutorial has
so, when setpoint and sensorinput are the same, error(current) = 0. so the integral drive stays at its current value and never goes away
· I was thinking of putting something in the error calc to set all drives to zero if setpoint and measured input are equal. Then only base drive is used, and if temp overshoots, the subs can return negative values.
thoughts?· better options for this? Did I just miss something in this part that would reset integral drive (probable)?
thanks
dunnsept
·
·
both the Industrial Control text and Andy Lindsay's PID text in the forums.
BUT for the integral portion, while it works fine when there is a difference between the setpoint and measured value.
When the measured value EQUALS the setpoint, the integral portion is not removed (not reset to zero).
the Integral portion so far is a mix of code from between the above mentioned sources:
int_calc: ei = ei + err intcount = intcount + 1 if intcount < ti then else ei = ei / ti ei = ei * ki inte = inte + ei inte = inte * sign intcount = 0 ei = 0 endif return
intcount = 10 and sign is a value set when I calc the error, err = setpoint - theTEMP if C = 0 then sign = -1. I have a display hooked up that displays inte. at the start I can watch it count up and as time goes by it really ramps up like it should.. But when I adjust the input so that theTEMP = setpoint, the integral portion stays.
Any suggestions at which point I should reset it? Since the integral portion is treated as an accumulator, it is never reset in any of the 2 sources above. Andy's tutorial has
do ' Calculate error. error(Current) = SetPoint - sensorInput ' Calculate integral term. error(Accumulator) = error(Accumulator) + error(Current) i = Ki * error(Accumulator) ' Calculate output. drive = i loop
so, when setpoint and sensorinput are the same, error(current) = 0. so the integral drive stays at its current value and never goes away
· I was thinking of putting something in the error calc to set all drives to zero if setpoint and measured input are equal. Then only base drive is used, and if temp overshoots, the subs can return negative values.
thoughts?· better options for this? Did I just miss something in this part that would reset integral drive (probable)?
thanks
dunnsept
·
·
Comments
One of the main functions of integral is to apply whatever pressure it takes to keep the measured value equal to the set point. We don't know what kind of conditions are present in the system. Maybe the proportional just isn't pushing hard enough to overcome those conditions. Integral, on the other hand, will keep on accumulating until the output overcomes whatever conditions are present. If the wind happens to be 5 mph faster on a given day, the integral will accumulate to offset that 5 mph. Once it has accumulated to the right level to offset the forces the system is applying to it, it stays the same, and the error stays at zero.
now I get it.. sorry about that.. I was thinking that when the system gets to the point where setpoint = input, the only drive there should be from the base.
I'm looking at it for a beer brewing system. and was thinking that since P and D would not be there, with whatever change was there integral·would then cause it to overshoot.
but then since we'd have a negative error (input > setpoint) that would bring it back down.
thanks Andy!
sure wish I had someone around here to say this stuff to outloud so I didn't post to the forum first and look dumb
Paul...
(edit) just fixed another issue in the code and now it works fine, just need to adjust it for scaling
thanks again
Post Edited (Dunnsept) : 5/5/2006 7:24:50 PM GMT
BTW...my motor is a DC brushed motor size 540, speed range from 100rpm to 7,000rpm.
Best Regards,
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com