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). 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.
> >
> > 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