Reply by Phil Martel June 28, 20202020-06-28
On 6/26/2020 16:30, Hans-Bernhard Br�ker wrote:
> Am 26.06.2020 um 10:59 schrieb pozz: >> >> The proportional term (P) of a PID controller can't mimic this "manual >> control", > > Nobody ever claimed it could.� A P-only controller simply won't meet > that goal. > > That's a large part of the reason why everybody routinely talks about > full PID-controllers. > > People know better than to just react linearly.� You would be doing a > good deal of D- and I-type controlling, too, and most likely some more > that doesn't fit into the PID model at all.� Especially if it's not the > first time ever you've been turning that knob.� You will have got a > "feel" for it after just a few tries. > > Nobody in their right mind ever claimed the human brain was as bluntly > stupid as a P controller.� A PID controller is still way simpler than > what you would do yourself.� We use them not because they're better at > the job than humans, but rather because they're cheaper and more > reliable in the long run. > > All said, I believe your apparent frustration at the answer you've found > has more to do with asking the wrong question than with anything else.
I've found Tim Wescott's website helpful https://www.wescottdesign.com/ Especially this: https://www.wescottdesign.com/articles/pid/pidWithoutAPhd.pdf -- Best wishes, --Phil pomartel At Comcast(ignore_this) dot net
Reply by Rick C June 27, 20202020-06-27
On Saturday, June 27, 2020 at 1:10:00 PM UTC-4, Rick C wrote:
> On Saturday, June 27, 2020 at 11:31:58 AM UTC-4, David Brown wrote: > > On 27/06/2020 16:53, pozz wrote: > > > Il 27/06/2020 09:07, Rick C ha scritto: > > >> On Saturday, June 27, 2020 at 2:12:21 AM UTC-4, Paul Rubin wrote: > > >>> DJ Delorie <dj@delorie.com> writes: > > >>>> Typical systems will limit the I term to some range so it won't go out > > >>>> of bounds (or "wind up" as they say).&nbsp; It doesn't decay on its own, but > > >>>> the system can cause its value to reduce to zero due to the Ki math. > > >>> > > >>> Do you mean it saturates (controller stops increasing it once it reaches > > >>> some maximum)?&nbsp; Ok, but won't it reach the maximum and stay there?&nbsp; The > > >>> Ki math I think was: > > >>> > > >>> &nbsp;&nbsp; I += Ki * err&nbsp;&nbsp; (note += not = ) > > >>> &nbsp;&nbsp; Vout = P + I > > >>> > > >>> So if the error is almost always positive, I will keep increasing. > > >>> > > >>>>> E.g. in a thermal system, you have to keep adding heat > > >>>> > > >>>> Yes, but the amount of extra energy you put in is constant in that > > >>>> case, > > >>>> and when the extra energy balances so that you stay at your set point, > > >>>> the I term stops increasing, because the error is now zero.&nbsp; Drain more > > >>>> hot water, the I term goes up.&nbsp; Insulate the tank, the I term goes > > >>>> down.. > > >>> > > >>> I'm imagining a tank starting with 20 degree water and you want to heat > > >>> it to 50 degrees.&nbsp; Now the error is 30 degrees, or am I interpreting the > > >>> wrong thing as the error?&nbsp; You turn on the heat and the error decreases > > >>> as the water gets hotter.&nbsp; Eventually the water reaches 50 degrees and > > >>> the error is 0, but I is some positive number (the integral of the error > > >>> over the time it took to reach 50 degrees). > > >>> > > >>> Now you draw out some hot water, say to wash dishes; you replace it with > > >>> more 20 degree water, so the system is say at 40 degrees now (error is > > >>> 10).&nbsp; You turn the heat back on, but again, I keeps increasing.&nbsp; You > > >>> might overshoot a little (say to 51 degrees, error is -1) in which case > > >>> I might decrease a little until the tank cools back down.&nbsp; But really, > > >>> the error will always be either positive or near 0.&nbsp; So I keeps > > >>> increasing. > > >>> > > >>> I have to be missing something.&nbsp; Thanks. > > >> > > >> Yes, you are missing that the error variable can be both positive and > > >> negative and by definition will balance the I variable to a value that > > >> makes error return to zero. > > >> > > >> Once the water in your heater reaches the set temperature the error > > >> will be zero but the heat sent to the water heater won't be zero.&nbsp; If > > >> water is drawn the temperature will drop and the error term will go > > >> positive again, the integral term will increase to restore the error > > >> to zero, but at that point the heat into the tank will be higher than > > >> before so that the temperature will rise above the set point and the > > >> error will go negative. > > >> > > >> It is a mistake to think there will be more positive error than > > >> negative error.&nbsp; Once the water is warmed to the appropriate > > >> temperature the integral value will be back at the value it had before > > >> cold water was added. > > > > > > I think the wrong assumption was: as soon as the error goes to zero, P > > > and I term should be zero as well, because we reached the set-point. > > > > Yes - P goes to zero, and I /stabilises/ to a value of output that > > results in a steady state. > > > > If you overshoot - perhaps I has built up too much - the error term will > > be negative, so the I term will decrease (but remain positive for a > > while), while the P term will be negative. > > Not "if" but just "how much" I will cause overshoot. The I term is an oscillator with P as a damping factor. > > > > > For example, when I need to move the optical bar of a scanner to a > > > certain position. > > > As soon as the bar reached the wanted position, the power from the > > > motors must be cut off immediately (because the bar doesn't move if the > > > motors are off). > > > This means that when the error is zero, P+I must be zero as well. > > > > That works for some kinds of systems. In other systems, you might have > > gravity or a spring that means keeping the same position requires a > > constant small force - you get that from the I term. > > > > In this case, the I term will be zero at the perfect stable spot. But > > it could well be non-zero while moving - a P term alone rarely gets you > > to the target. (Imagine you are near the target. The P term might give > > too low a force to overcome the static friction and move the bar - then > > the I term will build up until things are moving.) > > > > > However this is impossible. P is really zero, but I isn't zero, because > > > it's the sum of all the previous errors that are all positive. So the > > > power doesn't drop to zero and we have an overshoot (the bar moves after > > > the wanted position). Now the error starts being negative and I starts > > > decreasing. > > > > Yes. > > > > In any regulation system, you have a balance between reacting quickly to > > changes and minimising overshoot and oscillations. The D term can be > > helpful in reducing these unwanted effects. > > > > > > > > I think that systems similar to optical bars (where the controlled > > > signal must be stopped as soon as the set-point is reached) is best > > > controlled by a P-only algorithm. > > > > You'll never get to the target that way. > > Not correct. This design incorporates the integrator into the mechanism. Position is the integral of velocity which is proportional to the output of the controller. So the additional integrator is not required in the controller. But the P term will get to the end position because there is non-ideal behavior in moving the bar because of it's mass. So velocity is not perfectly proportional to the control output. > > This is why the theory is so hard to manage in real world situations. There are many, many nonidealities. While many of them won't have a significant impact on the controller, some may and it can be hard to know which need to be factored in. > > I'm working on a PID simulation in LTspice. I thought I'd use the "universal op amp" as an ideal device, but I guess I should have read the data sheet first... lol. I should have something working later in the day. > > Working on lunch at the moment.
I didn't like the op amp circuits too many components. Here is an LTspice simulation with voltage sources as amplifiers, simpler. The ringing of the controlled quantity can be managed by "tuning" the ratio of the proportional section to the integral section. Too little P term and ringing starts. Too much P term and the response is slow. I tried it with no P term and the ringing is all you see practically. Ramping down both together rounds the corners of the response. Ramping up both together sharpens the corners crisply. PID.asc Version 4 SHEET 1 884 740 WIRE -368 -224 -384 -224 WIRE -304 -224 -368 -224 WIRE -176 -224 -224 -224 WIRE -384 -192 -384 -224 WIRE -432 -176 -768 -176 WIRE -432 -128 -464 -128 WIRE -464 -112 -464 -128 WIRE -384 -80 -384 -112 WIRE -768 0 -768 -176 WIRE -736 0 -768 0 WIRE -624 0 -656 0 WIRE -592 0 -624 0 WIRE -480 0 -528 0 WIRE -368 0 -384 0 WIRE -304 0 -368 0 WIRE -176 0 -176 -224 WIRE -176 0 -224 0 WIRE -832 16 -912 16 WIRE -768 16 -768 0 WIRE -768 16 -832 16 WIRE -384 32 -384 0 WIRE -912 48 -912 16 WIRE -480 48 -480 0 WIRE -480 48 -560 48 WIRE -432 48 -480 48 WIRE -1024 64 -1072 64 WIRE -960 64 -1024 64 WIRE -560 64 -560 48 WIRE -624 80 -624 0 WIRE -608 80 -624 80 WIRE 80 80 64 80 WIRE 160 80 80 80 WIRE 288 80 240 80 WIRE 400 80 288 80 WIRE 496 80 400 80 WIRE 544 80 496 80 WIRE -432 96 -448 96 WIRE -1024 112 -1072 112 WIRE -960 112 -1024 112 WIRE -448 112 -448 96 WIRE 64 112 64 80 WIRE -608 128 -624 128 WIRE -384 128 -384 112 WIRE -176 128 -176 0 WIRE -112 128 -176 128 WIRE -64 128 -112 128 WIRE 16 128 -64 128 WIRE 288 128 288 80 WIRE 400 128 400 80 WIRE 544 128 544 80 WIRE -1072 144 -1072 112 WIRE -624 144 -624 128 WIRE -912 160 -912 128 WIRE -560 160 -560 144 WIRE -64 176 -64 128 WIRE 16 176 0 176 WIRE 0 192 0 176 WIRE 64 224 64 192 WIRE 672 224 592 224 WIRE 736 224 672 224 WIRE -1072 240 -1072 224 WIRE 288 240 288 192 WIRE 400 240 400 208 WIRE 544 240 544 208 WIRE 736 240 736 224 WIRE -368 256 -384 256 WIRE -304 256 -368 256 WIRE -176 256 -176 128 WIRE -176 256 -224 256 WIRE 592 256 592 224 WIRE -768 288 -768 16 WIRE -720 288 -768 288 WIRE -624 288 -656 288 WIRE -608 288 -624 288 WIRE -592 288 -608 288 WIRE -480 288 -512 288 WIRE -64 288 -64 256 WIRE -384 320 -384 256 WIRE -480 336 -480 288 WIRE -480 336 -544 336 WIRE -432 336 -480 336 WIRE 544 336 544 320 WIRE 592 336 592 304 WIRE 592 336 544 336 WIRE 736 336 736 320 WIRE 736 336 592 336 WIRE -544 352 -544 336 WIRE 544 352 544 336 WIRE -624 368 -624 288 WIRE -592 368 -624 368 WIRE -432 384 -448 384 WIRE -448 400 -448 384 WIRE -592 416 -624 416 WIRE -384 416 -384 400 WIRE -624 432 -624 416 WIRE -544 448 -544 432 FLAG 288 240 0 FLAG 400 240 0 FLAG 544 352 0 FLAG -64 288 0 FLAG 672 224 WaterDraw FLAG -624 432 0 FLAG 496 80 WaterTemp FLAG -1024 64 WaterTemp FLAG -1072 240 0 FLAG -832 16 Error FLAG -1024 112 SetPoint FLAG -112 128 SUM FLAG -368 256 DIF FLAG -368 0 INT FLAG -368 -224 PROP FLAG -608 288 D- FLAG -624 144 0 FLAG -624 0 I- FLAG -384 -80 0 FLAG -464 -112 0 FLAG -912 160 0 FLAG -560 160 0 FLAG -544 448 0 FLAG 64 224 0 FLAG 0 192 0 FLAG 80 80 Correction FLAG -448 112 0 FLAG -384 128 0 FLAG -448 400 0 FLAG -384 416 0 SYMBOL cap 272 128 R0 SYMATTR InstName HWTank SYMATTR Value 1 SYMBOL res 384 112 R0 SYMATTR InstName HeatLoss SYMATTR Value 10 SYMBOL res -208 -240 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName R2 SYMATTR Value 1 SYMBOL res 528 112 R0 SYMATTR InstName DrawPipe SYMATTR Value 1 SYMBOL sw 544 336 R180 SYMATTR InstName S1 SYMATTR Value MYSW SYMBOL voltage 736 224 R0 WINDOW 123 0 0 Left 0 WINDOW 39 0 0 Left 0 SYMATTR InstName V1 SYMATTR Value 0 SYMBOL res 256 64 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName R7 SYMATTR Value 1 SYMBOL res -208 -16 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName R3 SYMATTR Value 1 SYMBOL res -208 240 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName R4 SYMATTR Value 1 SYMBOL res -48 272 R180 WINDOW 0 36 76 Left 2 WINDOW 3 36 40 Left 2 SYMATTR InstName R1 SYMATTR Value 1 SYMBOL cap -656 272 R90 WINDOW 0 -4 60 VBottom 2 WINDOW 3 -3 2 VBottom 2 SYMATTR InstName Kd SYMATTR Value 1 SYMBOL cap -528 -16 R90 WINDOW 0 0 64 VBottom 2 WINDOW 3 1 6 VBottom 2 SYMATTR InstName Ki SYMATTR Value 1 SYMBOL res -608 304 R270 WINDOW 0 34 32 VTop 2 WINDOW 3 34 76 VTop 2 SYMATTR InstName R6 SYMATTR Value 1 SYMBOL voltage -1072 128 R0 WINDOW 123 0 0 Left 0 WINDOW 39 0 0 Left 0 SYMATTR InstName V4 SYMATTR Value PULSE(0 2 1 1 1 50) SYMBOL res -640 -16 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName R5 SYMATTR Value 1 SYMBOL e -384 -208 R0 SYMATTR InstName E2 SYMATTR Value 90.854 SYMBOL e2 -560 48 R0 SYMATTR InstName E3 SYMATTR Value 1Meg SYMBOL e2 -384 16 R0 SYMATTR InstName E4 SYMATTR Value 100 SYMBOL e 64 96 R0 SYMATTR InstName E5 SYMATTR Value 3 SYMBOL e2 -912 32 R0 SYMATTR InstName E1 SYMATTR Value 1 SYMBOL e2 -544 336 R0 SYMATTR InstName E6 SYMATTR Value 1Meg SYMBOL e2 -384 304 R0 SYMATTR InstName E7 SYMATTR Value 0 TEXT 192 424 Left 2 !.model MYSW SW(Ron=30m Roff=1G Vt=1 Vh=0.1) TEXT 192 368 Left 2 !.tran 5 RECTANGLE Normal 832 560 -1136 -336 PID.plt [Transient Analysis] { Npanes: 1 { traces: 7 {524291,0,"V(error)"} {524290,0,"V(setpoint)"} {524292,0,"V(watertemp)"} {524293,0,"V(prop)"} {524294,0,"V(int)"} {524295,0,"V(dif)"} {524296,0,"V(sum)"} X: (' ',0,0,1,10) Y[0]: (' ',1,-2,0.5,4.8) Y[1]: ('m',1,1e+308,0.0002,-1e+308) Volts: (' ',0,0,1,-2,0.5,4.8) Log: 0 0 0 } } -- Rick C. --- Get 1,000 miles of free Supercharging --- Tesla referral code - https://ts.la/richard11209
Reply by Richard Damon June 27, 20202020-06-27
On 6/27/20 12:41 AM, Paul Rubin wrote:
> Richard Damon <Richard@Damon-Family.org> writes: >> 2) It can go to some finite, non-zero state. This indicated neither a >> pole or zero near zero. A proportional controller will have a finite >> error result, so you may want an integral term in the system. > > Slightly tangential but can someone explain if the integral term is > supposed to decay? Otherwise, can't it potentially keep getting bigger > and bigger without bound? E.g. in a thermal system, you have to keep > adding heat to account for losses, or for (say) hot water being drawn > out of a water heater, and being replaced by incoming cold water. >
The integral term is supposed to be a pure integral, no decay. It will only keep getting bigger if you keep having error of the same sign. Often, limits are put on the integration, to limit the overshoot from 'windup' as the system tries to get close or special rules to hold the integrator when the P-D part of the loop is driving hard.
Reply by Rick C June 27, 20202020-06-27
On Saturday, June 27, 2020 at 11:31:58 AM UTC-4, David Brown wrote:
> On 27/06/2020 16:53, pozz wrote: > > Il 27/06/2020 09:07, Rick C ha scritto: > >> On Saturday, June 27, 2020 at 2:12:21 AM UTC-4, Paul Rubin wrote: > >>> DJ Delorie <dj@delorie.com> writes: > >>>> Typical systems will limit the I term to some range so it won't go out > >>>> of bounds (or "wind up" as they say).&nbsp; It doesn't decay on its own, but > >>>> the system can cause its value to reduce to zero due to the Ki math. > >>> > >>> Do you mean it saturates (controller stops increasing it once it reaches > >>> some maximum)?&nbsp; Ok, but won't it reach the maximum and stay there?&nbsp; The > >>> Ki math I think was: > >>> > >>> &nbsp;&nbsp; I += Ki * err&nbsp;&nbsp; (note += not = ) > >>> &nbsp;&nbsp; Vout = P + I > >>> > >>> So if the error is almost always positive, I will keep increasing. > >>> > >>>>> E.g. in a thermal system, you have to keep adding heat > >>>> > >>>> Yes, but the amount of extra energy you put in is constant in that > >>>> case, > >>>> and when the extra energy balances so that you stay at your set point, > >>>> the I term stops increasing, because the error is now zero.&nbsp; Drain more > >>>> hot water, the I term goes up.&nbsp; Insulate the tank, the I term goes > >>>> down.. > >>> > >>> I'm imagining a tank starting with 20 degree water and you want to heat > >>> it to 50 degrees.&nbsp; Now the error is 30 degrees, or am I interpreting the > >>> wrong thing as the error?&nbsp; You turn on the heat and the error decreases > >>> as the water gets hotter.&nbsp; Eventually the water reaches 50 degrees and > >>> the error is 0, but I is some positive number (the integral of the error > >>> over the time it took to reach 50 degrees). > >>> > >>> Now you draw out some hot water, say to wash dishes; you replace it with > >>> more 20 degree water, so the system is say at 40 degrees now (error is > >>> 10).&nbsp; You turn the heat back on, but again, I keeps increasing.&nbsp; You > >>> might overshoot a little (say to 51 degrees, error is -1) in which case > >>> I might decrease a little until the tank cools back down.&nbsp; But really, > >>> the error will always be either positive or near 0.&nbsp; So I keeps > >>> increasing. > >>> > >>> I have to be missing something.&nbsp; Thanks. > >> > >> Yes, you are missing that the error variable can be both positive and > >> negative and by definition will balance the I variable to a value that > >> makes error return to zero. > >> > >> Once the water in your heater reaches the set temperature the error > >> will be zero but the heat sent to the water heater won't be zero.&nbsp; If > >> water is drawn the temperature will drop and the error term will go > >> positive again, the integral term will increase to restore the error > >> to zero, but at that point the heat into the tank will be higher than > >> before so that the temperature will rise above the set point and the > >> error will go negative. > >> > >> It is a mistake to think there will be more positive error than > >> negative error.&nbsp; Once the water is warmed to the appropriate > >> temperature the integral value will be back at the value it had before > >> cold water was added. > > > > I think the wrong assumption was: as soon as the error goes to zero, P > > and I term should be zero as well, because we reached the set-point. > > Yes - P goes to zero, and I /stabilises/ to a value of output that > results in a steady state. > > If you overshoot - perhaps I has built up too much - the error term will > be negative, so the I term will decrease (but remain positive for a > while), while the P term will be negative.
Not "if" but just "how much" I will cause overshoot. The I term is an oscillator with P as a damping factor.
> > For example, when I need to move the optical bar of a scanner to a > > certain position. > > As soon as the bar reached the wanted position, the power from the > > motors must be cut off immediately (because the bar doesn't move if the > > motors are off). > > This means that when the error is zero, P+I must be zero as well. > > That works for some kinds of systems. In other systems, you might have > gravity or a spring that means keeping the same position requires a > constant small force - you get that from the I term. > > In this case, the I term will be zero at the perfect stable spot. But > it could well be non-zero while moving - a P term alone rarely gets you > to the target. (Imagine you are near the target. The P term might give > too low a force to overcome the static friction and move the bar - then > the I term will build up until things are moving.) > > > However this is impossible. P is really zero, but I isn't zero, because > > it's the sum of all the previous errors that are all positive. So the > > power doesn't drop to zero and we have an overshoot (the bar moves after > > the wanted position). Now the error starts being negative and I starts > > decreasing. > > Yes. > > In any regulation system, you have a balance between reacting quickly to > changes and minimising overshoot and oscillations. The D term can be > helpful in reducing these unwanted effects. > > > > > I think that systems similar to optical bars (where the controlled > > signal must be stopped as soon as the set-point is reached) is best > > controlled by a P-only algorithm. > > You'll never get to the target that way.
Not correct. This design incorporates the integrator into the mechanism. Position is the integral of velocity which is proportional to the output of the controller. So the additional integrator is not required in the controller. But the P term will get to the end position because there is non-ideal behavior in moving the bar because of it's mass. So velocity is not perfectly proportional to the control output. This is why the theory is so hard to manage in real world situations. There are many, many nonidealities. While many of them won't have a significant impact on the controller, some may and it can be hard to know which need to be factored in. I'm working on a PID simulation in LTspice. I thought I'd use the "universal op amp" as an ideal device, but I guess I should have read the data sheet first... lol. I should have something working later in the day. Working on lunch at the moment. -- Rick C. ++ Get 1,000 miles of free Supercharging ++ Tesla referral code - https://ts.la/richard11209
Reply by Richard Damon June 27, 20202020-06-27
On 6/27/20 10:53 AM, pozz wrote:
> Il 27/06/2020 09:07, Rick C ha scritto: >> On Saturday, June 27, 2020 at 2:12:21 AM UTC-4, Paul Rubin wrote: >>> DJ Delorie <dj@delorie.com> writes: >>>> Typical systems will limit the I term to some range so it won't go out >>>> of bounds (or "wind up" as they say).&nbsp; It doesn't decay on its own, but >>>> the system can cause its value to reduce to zero due to the Ki math. >>> >>> Do you mean it saturates (controller stops increasing it once it reaches >>> some maximum)?&nbsp; Ok, but won't it reach the maximum and stay there?&nbsp; The >>> Ki math I think was: >>> >>> &nbsp;&nbsp; I += Ki * err&nbsp;&nbsp; (note += not = ) >>> &nbsp;&nbsp; Vout = P + I >>> >>> So if the error is almost always positive, I will keep increasing. >>> >>>>> E.g. in a thermal system, you have to keep adding heat >>>> >>>> Yes, but the amount of extra energy you put in is constant in that >>>> case, >>>> and when the extra energy balances so that you stay at your set point, >>>> the I term stops increasing, because the error is now zero.&nbsp; Drain more >>>> hot water, the I term goes up.&nbsp; Insulate the tank, the I term goes >>>> down.. >>> >>> I'm imagining a tank starting with 20 degree water and you want to heat >>> it to 50 degrees.&nbsp; Now the error is 30 degrees, or am I interpreting the >>> wrong thing as the error?&nbsp; You turn on the heat and the error decreases >>> as the water gets hotter.&nbsp; Eventually the water reaches 50 degrees and >>> the error is 0, but I is some positive number (the integral of the error >>> over the time it took to reach 50 degrees). >>> >>> Now you draw out some hot water, say to wash dishes; you replace it with >>> more 20 degree water, so the system is say at 40 degrees now (error is >>> 10).&nbsp; You turn the heat back on, but again, I keeps increasing.&nbsp; You >>> might overshoot a little (say to 51 degrees, error is -1) in which case >>> I might decrease a little until the tank cools back down.&nbsp; But really, >>> the error will always be either positive or near 0.&nbsp; So I keeps >>> increasing. >>> >>> I have to be missing something.&nbsp; Thanks. >> >> Yes, you are missing that the error variable can be both positive and >> negative and by definition will balance the I variable to a value that >> makes error return to zero. >> >> Once the water in your heater reaches the set temperature the error >> will be zero but the heat sent to the water heater won't be zero.&nbsp; If >> water is drawn the temperature will drop and the error term will go >> positive again, the integral term will increase to restore the error >> to zero, but at that point the heat into the tank will be higher than >> before so that the temperature will rise above the set point and the >> error will go negative. >> >> It is a mistake to think there will be more positive error than >> negative error.&nbsp; Once the water is warmed to the appropriate >> temperature the integral value will be back at the value it had before >> cold water was added. > > I think the wrong assumption was: as soon as the error goes to zero, P > and I term should be zero as well, because we reached the set-point. > > For example, when I need to move the optical bar of a scanner to a > certain position. > As soon as the bar reached the wanted position, the power from the > motors must be cut off immediately (because the bar doesn't move if the > motors are off). > This means that when the error is zero, P+I must be zero as well. > However this is impossible. P is really zero, but I isn't zero, because > it's the sum of all the previous errors that are all positive. So the > power doesn't drop to zero and we have an overshoot (the bar moves after > the wanted position). Now the error starts being negative and I starts > decreasing. > > I think that systems similar to optical bars (where the controlled > signal must be stopped as soon as the set-point is reached) is best > controlled by a P-only algorithm. > > Now come to mind another scenario. Suppose I need to transfer heat to a > liquid to reach a set-point temperature, for example 80&deg;C starting from > 20&deg;C. It's very import to avoid overshoots, because some strange and > very dangerous chemical reactions happen when the temperature is over 82&deg;C. > I know I can tune the PID controller (i.e., find an optimal Kp, Ki, Kd) > to avoid overshoots, but I'm wondering if some other techniques can be > implemented too. > > For example, changing dynamically PID coefficients when the error is > negative.
The motor situation where you want 0 signal to hold at the desired set point, basically implies that the system has an integrator in its response. (A pole at zero). With the motor that is because the input Voltage determines the Speed of the motor, and the motor mechanics integrates that speed to become a position, which is the thing that is being controlled. Such a system may not need an integral term for 0 error (because the plant provides that integral term). On the other hand, if there is a bit of force on the motor (maybe gravity) and with zero input, the system slides of the control point, so we need to add a bit of voltage to provide some torque to counter that force, that brings back the need for the integral loop to provide that balancing voltage. One issue with your P only controller for position, is that as you get close, you slow down, so you close slower, and slower, so it takes a while to get to where you want (theoretically, forever, as you will close exponentially). You can make the loop faster by raising P, but at some point, the gain gets too high, and other dynamics or time delays get in the way and the system may mal-perform. PID loops, when properly tuned, can get you closer faster when you tune the system to be critically damped, the key being that you let the PI terms give you a higher starting gain, but then the damping term backs that off giving you more gain at slow speeds, which handles the base error, and less gain at high frequencies where the instabilities live. As to changing parameters, yes that can be done, and that gets you into the domain of non-linear control. Such system can be harder to think about or analyze, and it can introduce strange phenomenon like limit cycles. I would probably not have a sharp change of values at 0 error, as that would likely be the nominal operating point, so very apt to create limit cycles. You might either gradually adjust the parameters as you go negative, or have a break-point at a certain amount of error that you don't normally expect to reach.
Reply by DJ Delorie June 27, 20202020-06-27
Paul Rubin <no.email@nospam.invalid> writes:
> Do you mean it saturates (controller stops increasing it once it reaches > some maximum)? Ok, but won't it reach the maximum and stay there? The > Ki math I think was: > > I += Ki * err (note += not = ) > Vout = P + I > > So if the error is almost always positive, I will keep increasing.
The error is *after* all three PID factors are added. The I factor reduces the error. If it reduces the error to zero, the I term stops increasing. In real life terms, consider this: you want to heat a pot of water to a slow boil. You turn on the stove, at first a lot as a "guess" but as the pot approaches the boiling you turn the heat down (P term). Eventually you have to start tweaking the heat up a bit to bring the temperature up, this is the I term. As you approach the right temp, you tweak in smaller increments, until you're there.
> I'm imagining a tank starting with 20 degree water and you want to heat > it to 50 degrees. Now the error is 30 degrees, or am I interpreting the > wrong thing as the error?
Error is 30.
> You turn on the heat and the error decreases > as the water gets hotter. Eventually the water reaches 50 degrees and > the error is 0, but I is some positive number (the integral of the error > over the time it took to reach 50 degrees).
Better example: when the heat gets to 45 degrees (error=5) the P term has been reduced enough that the water doesn't get any warmer. If the water were to warm up, the heat would be reduced, and it would cool again. You've reached steady state, and this is as close as the P term can get you. This happens relatively quickly. Let's say the P term is providing 500 watts at this point. Now, you need a little more heat to make up the difference. The I term sees the small remaining error, and slowly adds more heat, until the temperature slowly climbs to the set point. The I term might be adding another 5 watts or so
> Now you draw out some hot water,
And the error quickly jumps up, the P term immediately reacts. The I term slowly starts rising again. More heat pours in. The temperature might rise past the set point, but then the error is *negative* and the I term slowly goes down until it's back where we started.
> But really, the error will always be either positive or near 0. So I > keeps increasing. > I have to be missing something. Thanks.
You're missing that if the I term keeps increasing, eventually the water will be too hot, the error negative, and that reduces the I term again. It's like the pot on the stove. You turn the heat up until the water is the right temperature, but if you *keep* turning the knob up, the water becomes too hot, and you have to turn the knob back down again.
Reply by David Brown June 27, 20202020-06-27
On 27/06/2020 16:53, pozz wrote:
> Il 27/06/2020 09:07, Rick C ha scritto: >> On Saturday, June 27, 2020 at 2:12:21 AM UTC-4, Paul Rubin wrote: >>> DJ Delorie <dj@delorie.com> writes: >>>> Typical systems will limit the I term to some range so it won't go out >>>> of bounds (or "wind up" as they say).&nbsp; It doesn't decay on its own, but >>>> the system can cause its value to reduce to zero due to the Ki math. >>> >>> Do you mean it saturates (controller stops increasing it once it reaches >>> some maximum)?&nbsp; Ok, but won't it reach the maximum and stay there?&nbsp; The >>> Ki math I think was: >>> >>> &nbsp;&nbsp; I += Ki * err&nbsp;&nbsp; (note += not = ) >>> &nbsp;&nbsp; Vout = P + I >>> >>> So if the error is almost always positive, I will keep increasing. >>> >>>>> E.g. in a thermal system, you have to keep adding heat >>>> >>>> Yes, but the amount of extra energy you put in is constant in that >>>> case, >>>> and when the extra energy balances so that you stay at your set point, >>>> the I term stops increasing, because the error is now zero.&nbsp; Drain more >>>> hot water, the I term goes up.&nbsp; Insulate the tank, the I term goes >>>> down.. >>> >>> I'm imagining a tank starting with 20 degree water and you want to heat >>> it to 50 degrees.&nbsp; Now the error is 30 degrees, or am I interpreting the >>> wrong thing as the error?&nbsp; You turn on the heat and the error decreases >>> as the water gets hotter.&nbsp; Eventually the water reaches 50 degrees and >>> the error is 0, but I is some positive number (the integral of the error >>> over the time it took to reach 50 degrees). >>> >>> Now you draw out some hot water, say to wash dishes; you replace it with >>> more 20 degree water, so the system is say at 40 degrees now (error is >>> 10).&nbsp; You turn the heat back on, but again, I keeps increasing.&nbsp; You >>> might overshoot a little (say to 51 degrees, error is -1) in which case >>> I might decrease a little until the tank cools back down.&nbsp; But really, >>> the error will always be either positive or near 0.&nbsp; So I keeps >>> increasing. >>> >>> I have to be missing something.&nbsp; Thanks. >> >> Yes, you are missing that the error variable can be both positive and >> negative and by definition will balance the I variable to a value that >> makes error return to zero. >> >> Once the water in your heater reaches the set temperature the error >> will be zero but the heat sent to the water heater won't be zero.&nbsp; If >> water is drawn the temperature will drop and the error term will go >> positive again, the integral term will increase to restore the error >> to zero, but at that point the heat into the tank will be higher than >> before so that the temperature will rise above the set point and the >> error will go negative. >> >> It is a mistake to think there will be more positive error than >> negative error.&nbsp; Once the water is warmed to the appropriate >> temperature the integral value will be back at the value it had before >> cold water was added. > > I think the wrong assumption was: as soon as the error goes to zero, P > and I term should be zero as well, because we reached the set-point.
Yes - P goes to zero, and I /stabilises/ to a value of output that results in a steady state. If you overshoot - perhaps I has built up too much - the error term will be negative, so the I term will decrease (but remain positive for a while), while the P term will be negative.
> > For example, when I need to move the optical bar of a scanner to a > certain position. > As soon as the bar reached the wanted position, the power from the > motors must be cut off immediately (because the bar doesn't move if the > motors are off). > This means that when the error is zero, P+I must be zero as well.
That works for some kinds of systems. In other systems, you might have gravity or a spring that means keeping the same position requires a constant small force - you get that from the I term. In this case, the I term will be zero at the perfect stable spot. But it could well be non-zero while moving - a P term alone rarely gets you to the target. (Imagine you are near the target. The P term might give too low a force to overcome the static friction and move the bar - then the I term will build up until things are moving.)
> However this is impossible. P is really zero, but I isn't zero, because > it's the sum of all the previous errors that are all positive. So the > power doesn't drop to zero and we have an overshoot (the bar moves after > the wanted position). Now the error starts being negative and I starts > decreasing.
Yes. In any regulation system, you have a balance between reacting quickly to changes and minimising overshoot and oscillations. The D term can be helpful in reducing these unwanted effects.
> > I think that systems similar to optical bars (where the controlled > signal must be stopped as soon as the set-point is reached) is best > controlled by a P-only algorithm.
You'll never get to the target that way. Maybe that's okay, and you'll get close enough. Sometimes overshoot must be avoided at all costs, other times it is merely a mild inconvenience - there is no single answer to all regulation problems. And pure PID is just one way to regulate a system. You can use variations or ad-hoc methods (such as P regulation, but using an artificial setpoint beyond the real target, or applying a break when you hit the target), or you can use completely different regulation techniques.
> > Now come to mind another scenario. Suppose I need to transfer heat to a > liquid to reach a set-point temperature, for example 80&deg;C starting from > 20&deg;C. It's very import to avoid overshoots, because some strange and > very dangerous chemical reactions happen when the temperature is over 82&deg;C. > I know I can tune the PID controller (i.e., find an optimal Kp, Ki, Kd) > to avoid overshoots, but I'm wondering if some other techniques can be > implemented too. > > For example, changing dynamically PID coefficients when the error is > negative.
Reply by pozz June 27, 20202020-06-27
Il 27/06/2020 09:07, Rick C ha scritto:
> On Saturday, June 27, 2020 at 2:12:21 AM UTC-4, Paul Rubin wrote: >> DJ Delorie <dj@delorie.com> writes: >>> Typical systems will limit the I term to some range so it won't go out >>> of bounds (or "wind up" as they say). It doesn't decay on its own, but >>> the system can cause its value to reduce to zero due to the Ki math. >> >> Do you mean it saturates (controller stops increasing it once it reaches >> some maximum)? Ok, but won't it reach the maximum and stay there? The >> Ki math I think was: >> >> I += Ki * err (note += not = ) >> Vout = P + I >> >> So if the error is almost always positive, I will keep increasing. >> >>>> E.g. in a thermal system, you have to keep adding heat >>> >>> Yes, but the amount of extra energy you put in is constant in that case, >>> and when the extra energy balances so that you stay at your set point, >>> the I term stops increasing, because the error is now zero. Drain more >>> hot water, the I term goes up. Insulate the tank, the I term goes down.. >> >> I'm imagining a tank starting with 20 degree water and you want to heat >> it to 50 degrees. Now the error is 30 degrees, or am I interpreting the >> wrong thing as the error? You turn on the heat and the error decreases >> as the water gets hotter. Eventually the water reaches 50 degrees and >> the error is 0, but I is some positive number (the integral of the error >> over the time it took to reach 50 degrees). >> >> Now you draw out some hot water, say to wash dishes; you replace it with >> more 20 degree water, so the system is say at 40 degrees now (error is >> 10). You turn the heat back on, but again, I keeps increasing. You >> might overshoot a little (say to 51 degrees, error is -1) in which case >> I might decrease a little until the tank cools back down. But really, >> the error will always be either positive or near 0. So I keeps increasing. >> >> I have to be missing something. Thanks. > > Yes, you are missing that the error variable can be both positive and negative and by definition will balance the I variable to a value that makes error return to zero. > > Once the water in your heater reaches the set temperature the error will be zero but the heat sent to the water heater won't be zero. If water is drawn the temperature will drop and the error term will go positive again, the integral term will increase to restore the error to zero, but at that point the heat into the tank will be higher than before so that the temperature will rise above the set point and the error will go negative. > > It is a mistake to think there will be more positive error than negative error. Once the water is warmed to the appropriate temperature the integral value will be back at the value it had before cold water was added.
I think the wrong assumption was: as soon as the error goes to zero, P and I term should be zero as well, because we reached the set-point. For example, when I need to move the optical bar of a scanner to a certain position. As soon as the bar reached the wanted position, the power from the motors must be cut off immediately (because the bar doesn't move if the motors are off). This means that when the error is zero, P+I must be zero as well. However this is impossible. P is really zero, but I isn't zero, because it's the sum of all the previous errors that are all positive. So the power doesn't drop to zero and we have an overshoot (the bar moves after the wanted position). Now the error starts being negative and I starts decreasing. I think that systems similar to optical bars (where the controlled signal must be stopped as soon as the set-point is reached) is best controlled by a P-only algorithm. Now come to mind another scenario. Suppose I need to transfer heat to a liquid to reach a set-point temperature, for example 80&deg;C starting from 20&deg;C. It's very import to avoid overshoots, because some strange and very dangerous chemical reactions happen when the temperature is over 82&deg;C. I know I can tune the PID controller (i.e., find an optimal Kp, Ki, Kd) to avoid overshoots, but I'm wondering if some other techniques can be implemented too. For example, changing dynamically PID coefficients when the error is negative.
Reply by Tauno Voipio June 27, 20202020-06-27
On 27.6.20 07:41, Paul Rubin wrote:
> Richard Damon <Richard@Damon-Family.org> writes: >> 2) It can go to some finite, non-zero state. This indicated neither a >> pole or zero near zero. A proportional controller will have a finite >> error result, so you may want an integral term in the system. > > Slightly tangential but can someone explain if the integral term is > supposed to decay? Otherwise, can't it potentially keep getting bigger > and bigger without bound? E.g. in a thermal system, you have to keep > adding heat to account for losses, or for (say) hot water being drawn > out of a water heater, and being replaced by incoming cold water.
The integral term is supposed to approach a stable value, to compensate for the steady-state error of pure proportional control. What is supposed to decay is the total error term. -- -TV
Reply by Rick C June 27, 20202020-06-27
On Saturday, June 27, 2020 at 2:18:44 AM UTC-4, Paul Rubin wrote:
> Rick C <gnuarm.deletethisbit@gmail.com> writes: > > In the water heater example the integral term will be ramping up the > > entire time the heater is not up to temperature. The rate of increase > > of the heat flowing in will lower until the set point is achieved at > > which point the integral term will be at a maximum, but too high with > > the water temperature continuing to rise. > > Let's say the water heater is insulated, but not perfectly (which is > impossible). That means heat steadily escapes from the system and you > have to keep adding energy to maintain the temperature. That is, the > error (difference between measured temperature and goal temperature) is > always positive or zero, except maybe for a few moments when you > overshoot slightly. Therefore, the integral of the error should keep > increasing. > > I tried reading the Wikipedia article about PID and thought I understood > it, but still come away from it with the same impression. I'm clearly > missing something.
Your mistake is thinking the integral term will only overshoot "slightly". Once the integral term rises to heat the added water it is too high to maintain the temperature of the take once it reaches the set point. So the error will shoot past the zero point and become negative quickly. The integrator doesn't make the temperature rise to gently reach the set point. At the point the temperature crosses the set point it increasing the fastest it will move. So now the error has to be negative for a while to bring it back to zero from the other direction. Increasing the gain on the proportional term and keeping the gain on the integral term low will minimize the ripples, but never eliminate them. So the error will always wing positive and negative. You need to keep in mind that if the integral term is high, the heat output will be high. Thinking the set point will only be passed a little bit is not accurate. You need to stop "feeling" the design and try looking at some real numbers. If LTspice is too complicated for you, you can use a spread sheet to make calculations in a stepwise manner. Write the equations for the three controller terms and one for the combined heat output based on the previous values. Write the equations for the heat output (losses) based on present temperature and the intermittent water draw. Write the equations for the temperature of the tank in terms of the previous temperature and the heat inputs and outputs. Copy each of these from one row to the next for many rows and watch the temperature change across the rows. I evaluate DSP algorithms this way. You can even chart the columns to see temperature and the heat flows change and watch the oscillations of temperature and heat output. -- Rick C. +- Get 1,000 miles of free Supercharging +- Tesla referral code - https://ts.la/richard11209