Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #29691 > unrolled thread
| Started by | pozz <pozzugno@gmail.com> |
|---|---|
| First post | 2020-06-25 19:55 +0200 |
| Last post | 2020-06-28 13:10 -0400 |
| Articles | 20 on this page of 28 — 9 participants |
Back to article view | Back to comp.arch.embedded
PID controller: dummy questions pozz <pozzugno@gmail.com> - 2020-06-25 19:55 +0200
Re: PID controller: dummy questions Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2020-06-25 21:14 +0200
Re: PID controller: dummy questions DJ Delorie <dj@delorie.com> - 2020-06-25 15:29 -0400
Re: PID controller: dummy questions David Brown <david.brown@hesbynett.no> - 2020-06-26 08:43 +0200
Re: PID controller: dummy questions Richard Damon <Richard@Damon-Family.org> - 2020-06-25 22:21 -0400
Re: PID controller: dummy questions pozz <pozzugno@gmail.com> - 2020-06-26 10:59 +0200
Re: PID controller: dummy questions David Brown <david.brown@hesbynett.no> - 2020-06-26 11:07 +0200
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-26 09:10 -0700
Re: PID controller: dummy questions Richard Damon <Richard@Damon-Family.org> - 2020-06-26 12:29 -0400
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-26 12:00 -0700
Re: PID controller: dummy questions Richard Damon <Richard@Damon-Family.org> - 2020-06-26 22:24 -0400
Re: PID controller: dummy questions Paul Rubin <no.email@nospam.invalid> - 2020-06-26 21:41 -0700
Re: PID controller: dummy questions DJ Delorie <dj@delorie.com> - 2020-06-27 01:15 -0400
Re: PID controller: dummy questions Paul Rubin <no.email@nospam.invalid> - 2020-06-26 23:12 -0700
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-27 00:07 -0700
Re: PID controller: dummy questions pozz <pozzugno@gmail.com> - 2020-06-27 16:53 +0200
Re: PID controller: dummy questions David Brown <david.brown@hesbynett.no> - 2020-06-27 17:31 +0200
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-27 10:09 -0700
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-27 15:44 -0700
Re: PID controller: dummy questions Richard Damon <Richard@Damon-Family.org> - 2020-06-27 12:34 -0400
Re: PID controller: dummy questions DJ Delorie <dj@delorie.com> - 2020-06-27 11:51 -0400
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-26 23:06 -0700
Re: PID controller: dummy questions Paul Rubin <no.email@nospam.invalid> - 2020-06-26 23:18 -0700
Re: PID controller: dummy questions Rick C <gnuarm.deletethisbit@gmail.com> - 2020-06-27 00:23 -0700
Re: PID controller: dummy questions Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2020-06-27 10:28 +0300
Re: PID controller: dummy questions Richard Damon <Richard@Damon-Family.org> - 2020-06-27 18:13 -0400
Re: PID controller: dummy questions Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2020-06-26 22:30 +0200
Re: PID controller: dummy questions Phil Martel <pomartel@comcast.net> - 2020-06-28 13:10 -0400
Page 1 of 2 [1] 2 Next page →
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2020-06-25 19:55 +0200 |
| Subject | PID controller: dummy questions |
| Message-ID | <rd2odq$oiv$1@dont-email.me> |
I'm trying to implement a PID controller in C for an embbeded system. This is the first time. I think I haven't fully understand the theory. For the proportional term, we have an output from PID controller that is P = Kp*err Suppose I have a power supply with a variable output voltage. The power supply output is connected to a low-value resistor that dissipates power and transfer heat to some water. I need to reach and maintain a temperature of the water by increasing/decreasing voltage across the resistor (i.e., the dissipated power). The loop is closed by the temperature measurement. Goal = 80°C. Kp = 0.1V/°C. FIRST STEP T = 20°C. Error = 60°C. P = 6V. Should I set the power supply output voltage to 6V? I think so. SECOND STEP T = 30°C. Error = 50°C. P = 5V. Should I set Vout=5V or increase Vout by 5V so setting it to 11V? The mathematics say the output of PID controller *is* Kp*err, but I'm not sure. With the increase of temperature, the errore decreases to a minimum, so the Vout. At the steady state the error should be zero, but the voltage from the power supply can't be zero. So I'm thinking to implement the proportional term as: Vout += kp*err (note +=) but this isn't what I found in literature.
[toc] | [next] | [standalone]
| From | Hans-Bernhard Bröker <HBBroeker@t-online.de> |
|---|---|
| Date | 2020-06-25 21:14 +0200 |
| Message-ID | <hlkbd5Fkd9kU1@mid.dfncis.de> |
| In reply to | #29691 |
Am 25.06.2020 um 19:55 schrieb pozz: > Goal = 80°C. Kp = 0.1V/°C. > > FIRST STEP > T = 20°C. Error = 60°C. P = 6V. > Should I set the power supply output voltage to 6V? I think so. > > SECOND STEP > T = 30°C. Error = 50°C. P = 5V. > Should I set Vout=5V or increase Vout by 5V so setting it to 11V? 5 V > The mathematics say the output of PID controller *is* Kp*err, but I'm > not sure. With the increase of temperature, the errore decreases to a > minimum, so the Vout. At the steady state the error should be zero, but > the voltage from the power supply can't be zero. It can be, if your heater overshoots --- for a while. Then your water will begin to loose heat, and the P controller will reactivate your heater. Lather, rinse, repeat. Voila, oscillation: your P controller devolved into the even simpler 2-point controller: Apply heat when too cold, otherwise don't. That's it But more likely, it'll just reach a state a couple degrees below your target, where Kp times that difference yields a heating power that just about compensates the heat loss. In the absence of actual disturbances, that's the state this system will remain at indefinitely. In other words: congratulations, you've just understood what they mean when they say a pure P controller will never actually reach a steady zero-error state. And if the control is sign-constrained (you only have a heater, but you cannot cool), that may apply even more strongly. One somewhat hand-wavy possibility to avoid the latter trap is to artificially bias your control. E.g. define that "control output zero" means "50% of the actual swing of the output", so negative control outputs can have an effect, too. That 50% point may later profit from some more strategic positioning, a.k.a. tweaking.
[toc] | [prev] | [next] | [standalone]
| From | DJ Delorie <dj@delorie.com> |
|---|---|
| Date | 2020-06-25 15:29 -0400 |
| Message-ID | <xnlfkbc5ah.fsf@delorie.com> |
| In reply to | #29691 |
I'm not an expert, but I've gone through this puzzle in the past, so... pozz <pozzugno@gmail.com> writes: > For the proportional term, we have an output from PID controller that is > > P = Kp*err Yup! > FIRST STEP > T = 20°C. Error = 60°C. P = 6V. > Should I set the power supply output voltage to 6V? I think so. Yup! > SECOND STEP > T = 30°C. Error = 50°C. P = 5V. > Should I set Vout=5V or increase Vout by 5V so setting it to 11V? 5V. > The mathematics say the output of PID controller *is* Kp*err, As a first step, yes. You're not done though. Even with a pure P controller, you can just set Kp high enough that the error is small. I.e. if your Kp was 10V/V, you'd get a 10V swing from 79C to 81C, which may be enough. If you set Kp REALLY high, you effectively get an on-off control like a mechanical thermostat. Ideally, you'd set Kp as high as you can get away with, but not so high that you get runaway oscillations in the output. > but I'm not sure. With the increase of temperature, the errore > decreases to a minimum, so the Vout. At the steady state the error > should be zero, but the voltage from the power supply can't be zero. P = Kp * err (note = not += ) Vout = P So far you've done the "P" part of PID. Next you need to do the "I" part of PID. The P portion quickly (hopefully) gets you close to the goal, with some steady-state error. The next step is to integrate the remaining error over time, which undoes any "offset" in the system. I += Ki * err (note += not = ) Vout = P + I So now, if the Kp isn't enough to get you to goal, the system will slowly boost the output to remove the offset. This is a PI controller. Note that the accumulated I value is often limited in magnitude to prevent runaway. Now for the "D" term. The D term is designed to prevent overshoot by "putting on the brakes" if you're approaching the goal too quickly. D = Kd * (err[t] - err[t-1]) (i.e. how fast is the error changing) Vout = P + I + D; Now you have a PID controller :-) There's one more term that's often used to optimize the system - a "feed forward" term. F = Kf * Tgoal I.e. if your system is of the type where (approximately) input voltage = output temperature, you can estimate this with an F term, and use the PID control just for precision.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2020-06-26 08:43 +0200 |
| Message-ID | <rd45dp$uci$1@dont-email.me> |
| In reply to | #29693 |
On 25/06/2020 21:29, DJ Delorie wrote: > > I'm not an expert, but I've gone through this puzzle in the past, so... > > pozz <pozzugno@gmail.com> writes: >> For the proportional term, we have an output from PID controller that is >> >> P = Kp*err > > Yup! > >> FIRST STEP >> T = 20°C. Error = 60°C. P = 6V. >> Should I set the power supply output voltage to 6V? I think so. > > Yup! > >> SECOND STEP >> T = 30°C. Error = 50°C. P = 5V. >> Should I set Vout=5V or increase Vout by 5V so setting it to 11V? > > 5V. > > >> The mathematics say the output of PID controller *is* Kp*err, > > As a first step, yes. You're not done though. Even with a pure P > controller, you can just set Kp high enough that the error is small. > I.e. if your Kp was 10V/V, you'd get a 10V swing from 79C to 81C, which > may be enough. If you set Kp REALLY high, you effectively get an on-off > control like a mechanical thermostat. > > Ideally, you'd set Kp as high as you can get away with, but not so high > that you get runaway oscillations in the output. > >> but I'm not sure. With the increase of temperature, the errore >> decreases to a minimum, so the Vout. At the steady state the error >> should be zero, but the voltage from the power supply can't be zero. > > P = Kp * err (note = not += ) > > Vout = P > > So far you've done the "P" part of PID. Next you need to do the "I" > part of PID. > > The P portion quickly (hopefully) gets you close to the goal, with some > steady-state error. The next step is to integrate the remaining error > over time, which undoes any "offset" in the system. > > I += Ki * err (note += not = ) > > Vout = P + I > > So now, if the Kp isn't enough to get you to goal, the system will > slowly boost the output to remove the offset. This is a PI controller. > Note that the accumulated I value is often limited in magnitude to > prevent runaway. > > Now for the "D" term. The D term is designed to prevent overshoot by > "putting on the brakes" if you're approaching the goal too quickly. > > D = Kd * (err[t] - err[t-1]) > (i.e. how fast is the error changing) > > Vout = P + I + D; > > Now you have a PID controller :-) > > There's one more term that's often used to optimize the system - a "feed > forward" term. > > F = Kf * Tgoal > > I.e. if your system is of the type where (approximately) input voltage = > output temperature, you can estimate this with an F term, and use the > PID control just for precision. > There's a few clarifications I'd like to add to this. Sometimes in examples or literature you'll see a different form of the integral term. Instead of writing: I += Ki * err you write: S += err I = Ki * S This makes more sense to me, and many people - you integrate the error over time, and then apply a scale factor when you use it. It also means your windup limits are consistent while you play with different Ki factors to get a nice regulation. It's worth noting that Kd here is negative, while Kp and Ki are positive. And sometimes the scaling is written with a single K and time factors for the I and D parts. Ultimately this is all the same in the end, but it can be useful for the OP to understand when he reads about it online. Finally, the F term you have here can be a function, not just a simple scale. You might base it on a table, or from a linear function (scale and offset).
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2020-06-25 22:21 -0400 |
| Message-ID | <mYcJG.24912$bQ4.23175@fx04.iad> |
| In reply to | #29691 |
On 6/25/20 1:55 PM, pozz wrote: > I'm trying to implement a PID controller in C for an embbeded system. > This is the first time. I think I haven't fully understand the theory. > > For the proportional term, we have an output from PID controller that is > > P = Kp*err > Basic bit of terminology, You used the Term PID controller, but you only have a P term. The equation for a PID controlloer would be more like: P = Kp*err + Ki*Integral(err) + Kd*Derivative(err) I.E. have a P, and I, and a D term. Often, you will use the I term to eliminate the DC error, but with a cost of needing to control oscillations, as integral loops have a habit of wanting to overshoot. And the D term can provide damping to reduce overshoot. You example of the loop where P became the sum of the previous P and the new Kp*err was basically just an integral loop, where you took the sum of the errors times the control constant (using the distributive property).
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2020-06-26 10:59 +0200 |
| Message-ID | <rd4dct$9dc$1@dont-email.me> |
| In reply to | #29691 |
Il 25/06/2020 19:55, pozz ha scritto: > I'm trying to implement a PID controller in C for an embbeded system. > This is the first time. I think I haven't fully understand the theory. I read all your answers, but I didn't get the point. I'm thinking of a system where a process variable (PV, such as a liquid flow) must match a desired set point (SP, such as 1 lt/min). The controller can change a control variable (CV, such as a voltage applied to an electronic valve). If we need 1 lt/min we start opening the valve increasing the voltage control. When we see 1 lt/min on a flowmeter, we stop increasing the voltage that stay indefinitely at, for example, 1.0V. At the steady state, when the error is zero, the control voltage *is not* zero, but 1.0V. The proportional term (P) of a PID controller can't mimic this "manual control", because when the error is zero (we found the right voltage on the valve), the P term drops to zero and the valve would close. When I use my brain, I will do: - the error is high, rotate the knob fast - the error is low (we are approaching the desidered value), rotate the knob slowly - the error is zero, ok stop rotating the knob The P term of a PID controller works in a different way: - the error is high, high voltage control, open the valve high - the error decreases, low voltage control, the valve starts closing - the error is zero, close the valve completely (P=0) Maybe my brain works as an integrative-only controller?
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2020-06-26 11:07 +0200 |
| Message-ID | <rd4dsp$c79$1@dont-email.me> |
| In reply to | #29696 |
On 26/06/2020 10:59, pozz wrote: > Il 25/06/2020 19:55, pozz ha scritto: >> I'm trying to implement a PID controller in C for an embbeded >> system. This is the first time. I think I haven't fully understand >> the theory. > > I read all your answers, but I didn't get the point. > > I'm thinking of a system where a process variable (PV, such as a > liquid flow) must match a desired set point (SP, such as 1 lt/min). > The controller can change a control variable (CV, such as a voltage > applied to an electronic valve). > > If we need 1 lt/min we start opening the valve increasing the > voltage control. When we see 1 lt/min on a flowmeter, we stop > increasing the voltage that stay indefinitely at, for example, 1.0V. > At the steady state, when the error is zero, the control voltage *is > not* zero, but 1.0V. You are describing an "I" controller, not a "P" controller. For long-term steady state regulation, the "I" bit of "PID" is typically the most important. But lacking a "P" part means you will react slowly to changes. And if you lack the "D" part, you need to keep the "I" part slow to avoid oscillations. > > The proportional term (P) of a PID controller can't mimic this > "manual control", because when the error is zero (we found the right > voltage on the valve), the P term drops to zero and the valve would > close. That is correct. That is why a pure "P" controller is often not a suitable choice. It can never achieve a zero-error steady state. > > When I use my brain, I will do: > > - the error is high, rotate the knob fast - the error is low (we are > approaching the desidered value), rotate the knob slowly - the error > is zero, ok stop rotating the knob > > The P term of a PID controller works in a different way: > > - the error is high, high voltage control, open the valve high - the > error decreases, low voltage control, the valve starts closing - the > error is zero, close the valve completely (P=0) > > > Maybe my brain works as an integrative-only controller? Brains are not consistent enough to be classified as PID controllers of any kind.
[toc] | [prev] | [next] | [standalone]
| From | Rick C <gnuarm.deletethisbit@gmail.com> |
|---|---|
| Date | 2020-06-26 09:10 -0700 |
| Message-ID | <bebac300-f620-4999-b9ac-5ad63ebbf5a0o@googlegroups.com> |
| In reply to | #29696 |
On Friday, June 26, 2020 at 4:59:13 AM UTC-4, pozz wrote: > Il 25/06/2020 19:55, pozz ha scritto: > > I'm trying to implement a PID controller in C for an embbeded system. > > This is the first time. I think I haven't fully understand the theory. > > I read all your answers, but I didn't get the point. > > I'm thinking of a system where a process variable (PV, such as a liquid > flow) must match a desired set point (SP, such as 1 lt/min). The > controller can change a control variable (CV, such as a voltage applied > to an electronic valve). > > If we need 1 lt/min we start opening the valve increasing the voltage > control. When we see 1 lt/min on a flowmeter, we stop increasing the > voltage that stay indefinitely at, for example, 1.0V. > At the steady state, when the error is zero, the control voltage *is > not* zero, but 1.0V. > > The proportional term (P) of a PID controller can't mimic this "manual > control", because when the error is zero (we found the right voltage on > the valve), the P term drops to zero and the valve would close. > > When I use my brain, I will do: > > - the error is high, rotate the knob fast > - the error is low (we are approaching the desidered value), rotate the > knob slowly > - the error is zero, ok stop rotating the knob > > The P term of a PID controller works in a different way: > > - the error is high, high voltage control, open the valve high > - the error decreases, low voltage control, the valve starts closing > - the error is zero, close the valve completely (P=0) > > > Maybe my brain works as an integrative-only controller? You seem to be only talking about the proportional control function while the PID controller has also an integral term and a differential term. To reach a point where the error is zero regardless of the setting requires the addition of the integral term. This term can cause oscillations however. Keeping it small relative to the proportional term will reduce that. Judicious use of the differential term will also help to give an even response with minimal over shoot. PID controlers are simple in concept, but difficult to use in practice because of stability issues. Is your application a real design or is this just for learning? -- Rick C. - Get 1,000 miles of free Supercharging - Tesla referral code - https://ts.la/richard11209
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2020-06-26 12:29 -0400 |
| Message-ID | <DnpJG.46868$5_4.33259@fx40.iad> |
| In reply to | #29696 |
On 6/26/20 4:59 AM, pozz wrote: > Il 25/06/2020 19:55, pozz ha scritto: >> I'm trying to implement a PID controller in C for an embbeded system. >> This is the first time. I think I haven't fully understand the theory. > > I read all your answers, but I didn't get the point. > > I'm thinking of a system where a process variable (PV, such as a liquid > flow) must match a desired set point (SP, such as 1 lt/min). The > controller can change a control variable (CV, such as a voltage applied > to an electronic valve). > > If we need 1 lt/min we start opening the valve increasing the voltage > control. When we see 1 lt/min on a flowmeter, we stop increasing the > voltage that stay indefinitely at, for example, 1.0V. > At the steady state, when the error is zero, the control voltage *is > not* zero, but 1.0V. > > The proportional term (P) of a PID controller can't mimic this "manual > control", because when the error is zero (we found the right voltage on > the valve), the P term drops to zero and the valve would close. > > When I use my brain, I will do: > > - the error is high, rotate the knob fast > - the error is low (we are approaching the desidered value), rotate the > knob slowly > - the error is zero, ok stop rotating the knob > > The P term of a PID controller works in a different way: > > - the error is high, high voltage control, open the valve high > - the error decreases, low voltage control, the valve starts closing > - the error is zero, close the valve completely (P=0) > > > Maybe my brain works as an integrative-only controller? It makes a big difference in what you think of as the 'Plant' and the 'Control Variable'. If your input is 'The speed I am turning the knob', then your control law is a Proportional control system. If you input is 'How much the valve is open', then you control law in an Integral control system. Note, the difference is because position is the integral of Velocity. One important aspect of a system is how many poles (or zeros) it has at zero (or near zero). These will vastly affect what type of control loop you want to put around the system.
[toc] | [prev] | [next] | [standalone]
| From | Rick C <gnuarm.deletethisbit@gmail.com> |
|---|---|
| Date | 2020-06-26 12:00 -0700 |
| Message-ID | <559b8f50-7e32-4e92-8d2d-7cad53f19095o@googlegroups.com> |
| In reply to | #29700 |
On Friday, June 26, 2020 at 12:29:27 PM UTC-4, Richard Damon wrote: > On 6/26/20 4:59 AM, pozz wrote: > > Il 25/06/2020 19:55, pozz ha scritto: > >> I'm trying to implement a PID controller in C for an embbeded system. > >> This is the first time. I think I haven't fully understand the theory. > > > > I read all your answers, but I didn't get the point. > > > > I'm thinking of a system where a process variable (PV, such as a liquid > > flow) must match a desired set point (SP, such as 1 lt/min). The > > controller can change a control variable (CV, such as a voltage applied > > to an electronic valve). > > > > If we need 1 lt/min we start opening the valve increasing the voltage > > control. When we see 1 lt/min on a flowmeter, we stop increasing the > > voltage that stay indefinitely at, for example, 1.0V. > > At the steady state, when the error is zero, the control voltage *is > > not* zero, but 1.0V. > > > > The proportional term (P) of a PID controller can't mimic this "manual > > control", because when the error is zero (we found the right voltage on > > the valve), the P term drops to zero and the valve would close. > > > > When I use my brain, I will do: > > > > - the error is high, rotate the knob fast > > - the error is low (we are approaching the desidered value), rotate the > > knob slowly > > - the error is zero, ok stop rotating the knob > > > > The P term of a PID controller works in a different way: > > > > - the error is high, high voltage control, open the valve high > > - the error decreases, low voltage control, the valve starts closing > > - the error is zero, close the valve completely (P=0) > > > > > > Maybe my brain works as an integrative-only controller? > > It makes a big difference in what you think of as the 'Plant' and the > 'Control Variable'. If your input is 'The speed I am turning the knob', > then your control law is a Proportional control system. If you input is > 'How much the valve is open', then you control law in an Integral > control system. Note, the difference is because position is the integral > of Velocity. > > One important aspect of a system is how many poles (or zeros) it has at > zero (or near zero). These will vastly affect what type of control loop > you want to put around the system. The realities of thermal control are complex with the heating device introducing an element of integrated response in addition to the thing being heated. Formal analysis is often impossible. So the resulting design process is to twiddle the PID coefficients until you get a feel for the optimum settings. Alternatively the "plant" response can be measured by applying inputs and analyzing the outputs. Complex to do in practice for many systems. -- Rick C. + Get 1,000 miles of free Supercharging + Tesla referral code - https://ts.la/richard11209
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2020-06-26 22:24 -0400 |
| Message-ID | <R5yJG.196$cc1.128@fx29.iad> |
| In reply to | #29701 |
On 6/26/20 3:00 PM, Rick C wrote: > On Friday, June 26, 2020 at 12:29:27 PM UTC-4, Richard Damon wrote: >> On 6/26/20 4:59 AM, pozz wrote: >>> Il 25/06/2020 19:55, pozz ha scritto: >>>> I'm trying to implement a PID controller in C for an embbeded system. >>>> This is the first time. I think I haven't fully understand the theory. >>> >>> I read all your answers, but I didn't get the point. >>> >>> I'm thinking of a system where a process variable (PV, such as a liquid >>> flow) must match a desired set point (SP, such as 1 lt/min). The >>> controller can change a control variable (CV, such as a voltage applied >>> to an electronic valve). >>> >>> If we need 1 lt/min we start opening the valve increasing the voltage >>> control. When we see 1 lt/min on a flowmeter, we stop increasing the >>> voltage that stay indefinitely at, for example, 1.0V. >>> At the steady state, when the error is zero, the control voltage *is >>> not* zero, but 1.0V. >>> >>> The proportional term (P) of a PID controller can't mimic this "manual >>> control", because when the error is zero (we found the right voltage on >>> the valve), the P term drops to zero and the valve would close. >>> >>> When I use my brain, I will do: >>> >>> - the error is high, rotate the knob fast >>> - the error is low (we are approaching the desidered value), rotate the >>> knob slowly >>> - the error is zero, ok stop rotating the knob >>> >>> The P term of a PID controller works in a different way: >>> >>> - the error is high, high voltage control, open the valve high >>> - the error decreases, low voltage control, the valve starts closing >>> - the error is zero, close the valve completely (P=0) >>> >>> >>> Maybe my brain works as an integrative-only controller? >> >> It makes a big difference in what you think of as the 'Plant' and the >> 'Control Variable'. If your input is 'The speed I am turning the knob', >> then your control law is a Proportional control system. If you input is >> 'How much the valve is open', then you control law in an Integral >> control system. Note, the difference is because position is the integral >> of Velocity. >> >> One important aspect of a system is how many poles (or zeros) it has at >> zero (or near zero). These will vastly affect what type of control loop >> you want to put around the system. > > The realities of thermal control are complex with the heating device introducing an element of integrated response in addition to the thing being heated. Formal analysis is often impossible. So the resulting design process is to twiddle the PID coefficients until you get a feel for the optimum settings. > > Alternatively the "plant" response can be measured by applying inputs and analyzing the outputs. Complex to do in practice for many systems. > Defining the plant doesn't necessarily mean fully knowing its dynamics, but more importantly, what the controls actually mean. Am I controlling how fast I am turning the valve know, or am I controlling the valve position. The shift from position to speed effectively added an integrator into the system. Yes, thermal systems tend to be fairly heavily low pass filter systems, and you often don't have a detailed provided response (and it might easily change over time and ambilant conditions). What isn't hard to get is an idea of your zero frequency pole/zero situation. Imagine a constant, small signal excitiation to the system. The system is likely to do one of three things (assuming a system that is at least somewhat linear): 1) It can go unstable and run off to infinity. This is indicative that you have a pole at zero (or very near it) and means you may not need an integrator in your controller. 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. 3) It can go to a zero output response. This indicates that you have a zero in the plant at DC (basically something is AC Coupled). Such systems can't maintain a DC output condition (at least not with that input).
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2020-06-26 21:41 -0700 |
| Message-ID | <875zbd15oo.fsf@nightsong.com> |
| In reply to | #29703 |
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.
[toc] | [prev] | [next] | [standalone]
| From | DJ Delorie <dj@delorie.com> |
|---|---|
| Date | 2020-06-27 01:15 -0400 |
| Message-ID | <xnwo3tccnd.fsf@delorie.com> |
| In reply to | #29704 |
Paul Rubin <no.email@nospam.invalid> writes: > 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? 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. > 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. 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.
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2020-06-26 23:12 -0700 |
| Message-ID | <871rm111h9.fsf@nightsong.com> |
| In reply to | #29706 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Rick C <gnuarm.deletethisbit@gmail.com> |
|---|---|
| Date | 2020-06-27 00:07 -0700 |
| Message-ID | <1a04bc83-d541-4210-8959-7ad8562f6224o@googlegroups.com> |
| In reply to | #29708 |
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. Try drawing this circuit in LTspice or a similar program. You will need to get creative to model the thermal properties, but you can do it with capacitors and resistors. Have a resistor in line with the output voltage from your controller feeding the capacitor and add a resistor to ground to represent the heat losses in the water tank. Add a second resistor with a switch to represent drawing water out of the tank. Then you can watch the voltage on the capacitor rise and fall as the circuit charges it up and the switched resistor empties it out. The controller can be made of op amps. One with an integrator cap to be the... integrator. One with a series cap on the input to be the differentiator and one with no cap to be the proportional term. A fourth op amp will combine the three inputs to produce the control output. It would be an interesting circuit to watch operate. -- Rick C. -+ Get 1,000 miles of free Supercharging -+ Tesla referral code - https://ts.la/richard11209
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2020-06-27 16:53 +0200 |
| Message-ID | <rd7mh9$81b$1@dont-email.me> |
| In reply to | #29711 |
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°C starting from 20°C. It's very import to avoid overshoots, because some strange and very dangerous chemical reactions happen when the temperature is over 82°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.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2020-06-27 17:31 +0200 |
| Message-ID | <rd7opb$7vl$1@dont-email.me> |
| In reply to | #29717 |
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. > > 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°C starting from > 20°C. It's very import to avoid overshoots, because some strange and > very dangerous chemical reactions happen when the temperature is over 82°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.
[toc] | [prev] | [next] | [standalone]
| From | Rick C <gnuarm.deletethisbit@gmail.com> |
|---|---|
| Date | 2020-06-27 10:09 -0700 |
| Message-ID | <4a4f779d-cd65-4ef5-9f4c-e56f67fb4d54o@googlegroups.com> |
| In reply to | #29720 |
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. -- Rick C. ++ Get 1,000 miles of free Supercharging ++ Tesla referral code - https://ts.la/richard11209
[toc] | [prev] | [next] | [standalone]
| From | Rick C <gnuarm.deletethisbit@gmail.com> |
|---|---|
| Date | 2020-06-27 15:44 -0700 |
| Message-ID | <0b932a95-99db-42ef-bf1d-180f602f7169o@googlegroups.com> |
| In reply to | #29723 |
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
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2020-06-27 12:34 -0400 |
| Message-ID | <GyKJG.52780$AN2.20100@fx46.iad> |
| In reply to | #29717 |
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). 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°C starting from > 20°C. It's very import to avoid overshoots, because some strange and > very dangerous chemical reactions happen when the temperature is over 82°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.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.arch.embedded
csiph-web