55:036 embedded systems and systems...
TRANSCRIPT
PID Control , Slide 1 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Embedded Systems and Software
A Simple Introduction to Embedded Control Systems (PID Control)
PID Control , Slide 2 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Acknowledgements
• The material in this lecture is adapted from: – F. Vahid and T. Givargis, Embedded System Design—A Unified
Hardware/Software Introduction, John Wiley & Sons, 2002 (Chapter 9)
– T. Wescott, “PID Without a PhD” http://www.embedded.com/2000/0010/0010feat3.htm
PID Control , Slide 3 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Control System Terminology
• Control physical system (plant) output – By setting plant’ input
• Examples – Cruise control, thermostat, disk drive, chemical processes
• Difficulty due to – Disturbance: wind, road, tire, brake; opening/closing door… – Human interface: feel good, feel right…
PID Control , Slide 4 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Control System Tracking
Reference Input a.k.a. Set Point where we want the output to be
For example, here the user turned up the thermostat
This how the system tracks the reference input or set point
PID Control , Slide 5 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Control System Tracking
Reference Input a.k.a. Set Point where we want the output to be
For example, here the user turned up the thermostat
This how the system tracks the reference input or set point
PID Control , Slide 6 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Plant – Physical system to be controlled: car, plane, disk, heater,…
• Actuator – Device to control the plant: throttle, wing flap, disk motor,…
• Controller – Designed product to control the plant
Open-Loop Control Systems
PID Control , Slide 7 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Output – What we are interested in: speed, disk location, temperature
• Reference Input / Set Point – Desired output: speed, desired location, desired temperature
• Disturbance – Uncontrollable input to the plant imposed by environment
Wind, bumping the disk drive, door opening
Open-Loop Control Systems
7
PID Control , Slide 8 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Feed-forward control • Delay in actual change of the output • Controller doesn’t know how well things are going • Simple • Best use for predictable systems
– Examples?
Characteristics of Open Loop Control
PID Control , Slide 9 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Closed Loop Control Systems
Sensor measures plant output
Error detector. Can, and often is as simple as computing difference between Set Point and plant output
Use error to adjust controller
Concept: feedback control systems
Goal: minimize tracking error
PID Control , Slide 10 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Develop a model of the plant • Develop a controller • Analyze the controller • Consider Disturbance • Determine Performance • Example: Open Loop Cruise Control System
Designing Open Loop Control System
PID Control , Slide 11 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• May not be necessary – Can be done through experimenting and tuning
• But, – Can ease design, and be useful for deriving the controller
Model of the Plant
PID Control , Slide 12 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Model the car speed at t +1 as a linear combination of the speed at t (i.e., vt) and the throttle at t (i.e., ut)
vt+1 = Avt + But
Next, experimentally determine the model parameters A and B. On flat surface at 50 mph, open the throttle to 40 degrees. Then measure the speed after one time unit. Assume the speed is 55 mph. Then
55 = 50A + 40B
Repeat the experiment, but now start at 65 mph and with the throttle at 50 degrees. Assume the resulting speed after one time unit is 70.5 mph. Then
70.5 = 65A + 50B
One can now solve these two equations for the two unknowns A and B, to find A = 0.7 and B = 0.5.
One can repeat the experiment many times and determine, say, average values for A and B. (There are more optimum techniques for dealing with multiple As and Bs). Regardless, we now have model for the car (plant).
vt+1 = 0.7vt + 0.5ut
Example
PID Control , Slide 13 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Designing the Controller
Assuming we want to use a simple linear function ut = F(rt) = P × rt
(Recall that rt is the desired speed or Set Point)
Linear proportional controller vt+1 = 0.7vt + 0.5ut = 0.7vt + 0.5P×rt
Let vt+1= vt at steady state (vss) vss= 0.7vss+0.5P×rt
At steady state, we want vss= rt. To achieve this, we need P = 0.6, or ut=0.6×rt
PID Control , Slide 14 Embedded Systems and Software, 55:036. The University of Iowa, 2013 14
Analyzing the Controller Let v0 = 20 mph, rt = 50 mph vt+1 = 0.7vt + 0.5(0.6)rt = 0.7vt + 0.3×50 = 0.7vt + 15 Throttle position is 0.6×50 = 30 degrees
PID Control , Slide 15 Embedded Systems and Software, 55:036. The University of Iowa, 2013 15
Analyzing the Controller Let v0 = 20 mph, r0 = 50 mph vt+1 = 0.7vt + 0.5(0.6)rt = 0.7vt + 0.3×50 = 0.7vt + 15 Throttle position is 0.6×50 = 30 degrees
PID Control , Slide 16 Embedded Systems and Software, 55:036. The University of Iowa, 2013 16
Analyzing the Controller Let v0 = 20 mph, r0 = 50 mph vt+1 = 0.7vt + 0.5(0.6)rt = 0.7vt + 0.3×50 = 0.7vt + 15 Throttle position is 0.6×50 = 30 degrees
PID Control , Slide 17 Embedded Systems and Software, 55:036. The University of Iowa, 2013 17
Analyzing the Controller Let v0 = 20 mph, r0 = 50 mph vt+1 = 0.7vt + 0.5(0.6)rt = 0.7vt + 0.3×50 = 0.7vt + 15 Throttle position is 0.6×50 = 30 degrees
PID Control , Slide 18 Embedded Systems and Software, 55:036. The University of Iowa, 2013 18
Analyzing the Controller Let v0 = 20 mph, r0 = 50 mph vt+1 = 0.7vt + 0.5(0.6)rt = 0.7vt + 0.3×50 = 0.7vt + 15 Throttle position is 0.6×50 = 30 degrees
PID Control , Slide 19 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
19
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 20 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
20
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 21 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
21
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 22 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
22
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 23 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
23
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 24 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Considering the Disturbance
24
Assume road grade can affect the speed from –5 mph to +5 mph Recall our model: vt+1 = 0.7vt + 15 + wt With: wt = -5 and +5, the bounds are
vt+1 = 0.7×vt + 10 vt+1 = 0.7×vt + 20
PID Control , Slide 25 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Determining Performance
25
vt+1 = 0.7vt + 0.5P×r0 - w0 // Our Model
v1 = 0.7v0 + 0.5P×r0-w0 // Speed at time 0
v2 = 0.7(0.7×v0+0.5P×r0-w0) + 0.5P×r0-w0 // Speed at time 1
= 0.7×0.7×v0 + (0.7+1.0) × 0.5P×r0 -(0.7+1.0)w0
vn = (0.7n)v0 + (0.7n-1 + 0.7n-2 +…+ 0.7 + 1.0)(0.5P×r0-w0) // Speed at time n
Coefficient of vt determines rate of decay of v0. Bigger coefficient will result in slower response. >1 or <-1, vt will grow without bound <0, vt will oscillate
PID Control , Slide 26 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Designing Closed Loop Control System
PID Control , Slide 27 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Closed-Loop Control
[ ] BABBAvABBABvAABvAv +++=+++=+= 20
30
223
( ) ttt
ttttt
wPr.vP..wvrPvv−+−=
−−−=+
505070)(5.07.01
( )ttt vrPu −−=tttt wu.vv −+=+ 507.01
BvAv tt +=+1
( ) 005.0,5.07.0 wPrBPA −=−=
BvAv += 01
[ ] BABvABBvAABvAv ++=++=+= 02
012
( )BAAvAv nnnn 121
0 =+++= −−
Consider fixed set point and fixed disturbance
( ) 001 505070 wPr.vP..v tt −+−=+
( ) ( ) ( )( )( )0021
0 5.015.07.05.07.05.07.0 wPrPPvPv nnnn −+−+−+−= −−
Plant model Control Law (feedback)
PID Control , Slide 28 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Tuning Performance: Finding Proper P
( ) ( ) ( )( )( )0021
0 5.015.07.05.07.05.07.0 wPrPPvPv nnnn −+−+−+−= −−
To obtain convergence requires ( ) 15.07.0 <− P 4.36.0 <<−⇒ P
To avoid oscillation requires 05.07.0 ≥− P 4.1≤⇒ P
Reduce the effect of initial conditions (v0), make (0.7-0.5P) as small as possible 4.1=⇒ P
( ) 001 505070 wPr.vP..v tt −+−=+ ( ) 450 <−= tt vrPu
PID Control , Slide 29 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Tuning Performance: Finding Proper P
Steady state means vss = vt + 1 = vt ( ) 00505070 wPr.vP..v ssss −+−=
Pwr
PPvss 5.03.05.03.0
5.0 00 +−
+=
To get vss as close as possible to r0, (perfect tracking) let P ∞
( ) ( ) ( )( )( )0021
0 5.015.07.05.07.05.07.0 wPrPPvPv nnnn −+−+−+−= −−
( ) 001 505070 wPr.vP..v tt −+−=+ ( ) 450 <−= tt vrPu
PID Control , Slide 30 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Tuning Performance: Finding Proper P
To obtain convergence requires ( ) 15.07.0 <− P 4.36.0 <<−⇒ P
To avoid oscillation requires 05.07.0 ≥− P 4.1≤⇒ P
Reduce the effect of initial conditions (v0), make (0.7-0.5P) as small as possible 4.1=⇒ P
To get vss as close as possible to r0, (perfect tracking) let P ∞
Finally, pick 3.3=P stable, fast, good tracking, but some oscillation
PID Control , Slide 31 Embedded Systems and Software, 55:036. The University of Iowa, 2013
0 10 20 30 40 50 600
10
20
30
40
50
60
70
Control Point (i.e., time)
Spee
d (m
ph)
Analyze Controller Performance 0 mph,50 mph,20 00 === wrv t
( ) 01 505070 Pr.vP..v tt +−=+
( ) 01 )3.3(50)3.3(5070 r.v..v tt +−=+
5.8295.01 +−=+ tt vv
( )tt vrPu −= 0 ( )tt vu −= 503.3
Valid range for controller is 0-45o. Thus, with this P, the actuator saturates.
Tracking error ~ 8 mph
Significant oscillation
3.3=P
PID Control , Slide 32 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Analyze Controller Performance
0 10 20 30 40 50 600
10
20
30
40
50
60
70
Control Point (i.e., time)
Spee
d (m
ph)
Tracking error ~ 20 mph
No oscillation
Valid range for controller is 0-45o. Thus, with this P=1, the actuator does not saturate.
Set P = 1 to avoid oscillation
PID Control , Slide 33 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Analyzing the Controller
0 10 20 30 40 50 600
10
20
30
40
50
60
70
Control Point (i.e., time)
Spee
d (m
ph)
P = 1.0
P = 3.3 P = 2.5
Set point (where we want to be)
PID Control , Slide 34 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Closed-Loop Performance
0 10 20 30 40 50 600
10
20
30
40
50
60
70
Control Point (i.e., time)
Spee
d (m
ph)
P = 3.3, W =+5 P = 3.3, W =0
P = 3.3, W = - 5
0 mph,50 mph,20 000 ≠== wrv
( ) 01 505070 Pr.vP..v tt +−=+
( ) 01 )3.3(50)3.3(5070 r.v..v tt +−=+
01 5.8295.0 wvv tt ++−=+
Change is 5 mph compared to 66-33 = 33 mph for open-loop control
PID Control , Slide 35 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Objective – Causing output to track a reference even in the presence of
Measurement noise Model error Disturbances
• Metrics – Stability
Output remains bounded – Performance
How well an output tracks the reference – Disturbance rejection – Robustness
Ability to tolerate modeling error of the plant
General Control System
PID Control , Slide 36 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Performance (generally speaking)
• Rise time – Time it takes
from 10% to 90%
• Peak time • Overshoot
– Percentage by which Peak exceed final value
• Settling time – Time it takes to
reach 1% of final value
PID Control , Slide 37 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Difficult • May need to be done first • Plant is usually on continuous time
– Not discrete time. For example, car speed continuously reacts to throttle position, not at discrete interval
– Sampling period must be chosen carefully to ensure “nothing interesting” happens in between sampling intervals
• Plant is usually non-linear – For example, shock absorber response may need to be 8th order
differential equation • Iterative development of the plant model and controller
– Have a plant model that is “good enough”
Plant Modeling
PID Control , Slide 38 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Controller Design: “P”
( )tt vrPu −= 0Proportional control - multiplies the tracking error with a constant P
P affects
Stability
Tracking
Disturbance rejection
Large P can lead to overshoot and oscillation
Make P large to reduce tracking error
Make P large to improve disturbance rejection
( ) 001 505070 wPr.vP..v tt −+−=+Closed-loop model with linear plant
PID Control , Slide 39 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Controller Design: “PD”
Proportional and Derivative control - P control, and also consider error over time
Intuitively
Want to “push” more if error is not reducing fast enough
Want to “push” less if error is reducing really fast
( ) ( ) ( )( )11 −− −−−+−= ttttttt vrvrDvrPu
( )1−−+= tttt eeDPeu
PID Control , Slide 40 Embedded Systems and Software, 55:036. The University of Iowa, 2013
PD Controller
( )1−−+= tttt eeDPeu
tttt wu.vv −+=+ 507.01 Plant model
Control Law (feedback)
( ) ( ) ( )( )( ) ttttttttt wvrvrDvrP.vv −−−−+−+= −−+ 111 507.0
ttt vre −=
( )( ) ( ) ttttttt wDrrDPDvvDP.vv −−++++−= −−+ 111 5.05.05.0507.0
05.07.015.0 r
PPvss
+−=
Assume reference input and disturbance are constant, then the steady-state speed is
P can be set for best tracking and disturbance control
Then D can be set to control transient behavior
Does not depend on D
Steady state means vss = vt + 1 = vt
PID Control , Slide 41 Embedded Systems and Software, 55:036. The University of Iowa, 2013
PD Control Example
PID Control , Slide 42 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Controller Design: “PI” Proportional and Integral control P control, and also integrate (sum) error
Intuitively
Sum (integrate) error over time, and use this to “push”
Ensure that system reaches desired steady state, eventually
( ) ( ) ( )( )+−+−+−= −− 11 ttttttt vrvrIvrPu
( )++++= −− 21 ttttt eeeIPeu
P controls disturbance, I controls steady state convergence and convergence rate
PID Control , Slide 43 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Controller Design: “PID” Proportional , Integral and Derivative control - use all 3 types of control
Intuitively
P considers current error, controls disturbance
I controls long-term error, controls steady state convergence and convergence rate
( ) ( ) ( )( ) ( ) ( )( )1111 −−−− −−−++−+−+−= ttttttttttt vrvrDvrvrIvrPu
( ) ( )121 −−− −+++++= ttttttt eeDeeeIPeu
D considers how error is changing, controls transient response
PID Control , Slide 44 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Examples
PID Control , Slide 45 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• More than 90% of all controllers used in process industries are PID controllers.
• A typical chemical plant has 100s or more PID controllers.
• PID controllers are widely used in: – Chemical plants – Oil refineries – Pharmaceutical industries – Food industries – Paper mills – Electronic equipments
Application of PID Control
PID Control , Slide 46 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Off-The-Shelf PID Controllers
There are many off-the-shelf PID controllers available
PID Control , Slide 47 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Block Diagram View of PID Controller
PID Control , Slide 48 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Set desired input
PID Control , Slide 49 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Compare actual output against setpoint
PID Control , Slide 50 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Use part of the error signal
PID Control , Slide 51 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Use sum of the previous errors
PID Control , Slide 52 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Use rate of change of errors
PID Control , Slide 53 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Another Block Diagram View of PID Controller
Update the process, and repeat
PID Control , Slide 54 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Sidebar: Analog PID Controller
Integral
Proportional
Derivative
Summer
PID Control , Slide 55 Embedded Systems and Software, 55:036. The University of Iowa, 2013
PID Pseudo Code
previous_error = 0
integral = 0
start:
get actual_position
error = setpoint - actual_position
integral = integral + error*dt
derivative = (error - previous_error)/dt
output = P*error + I*integral + D*derivative
previous_error = error
wait(dt)
goto start
PID Control , Slide 56 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Main function loops forever, during each iteration – Read plant output sensor (may require ADC) – Read current desired reference input (set point) – Call a routine PidUpdate, to determine actuator value – Set actuator value (may require DAC)
Software Coding
PID Control , Slide 57 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Software Coding
( ) ( )121 −−− −+++++= ttttttt eeDeeeIPeu
PID Control , Slide 58 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Computation
( ) ( )121 −−− −+++++= ttttttt eeDeeeIPeu
PID Control , Slide 59 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Analytically deriving P, I, D may not be possible – E.g., plant not is not available, or to costly to obtain
• Ad hoc method for getting “reasonable” P, I, D – Start with a small P, I = D = 0 – Increase D, until seeing oscillation, then reduce D a bit – Increase P, until seeing oscillation, then D a bit – Increase I, until seeing oscillation
• Iterate until one can change anything without excessive oscillation
PID Tuning
PID Control , Slide 60 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• PID Without a PhD by Tim Wescott • http://www.embedded.com/2000/0010/0010feat3.htm • http://www.embedded.com/story/OEG20020726S0044
Excellent Reference for PID Control
PID Control , Slide 61 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Quantization • Overflow • Aliasing • Computation Delay
Practical Issues with Computer-Based Control
PID Control , Slide 62 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Quantization & Overflow
• Quantization – E.g., can’t store 0.36 as 4-bit fractional number – Can only store 0.75, 0.59, 0.25, 0.00, -0.25, -050,-0.75, -1.00 – Choose 0.25 – Results in quantization error of 0.11
• Sources of quantization error – Operations, e.g., 0.50*0.25=0.125
Can use more bits until input/output to the environment/memory – ADC resolution
• Overflow – Can’t store 0.75 + 0.50 = 1.25 as 4-bit fractional number
• Solutions – Use fix-point representation/operations carefully
Time-consuming – Use floating-point co-processor
Costly
PID Control , Slide 63 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Aliasing Example
The points below are the samples from a sine wave
t
Volta
ge
PID Control , Slide 64 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Aliasing Example
Reconstruction of the sine wave
t
Volta
ge
PID Control , Slide 65 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Aliasing Example
But why not this reconstruction?
t
Volta
ge
PID Control , Slide 66 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Aliasing Example
Both (an many others) are valid reconstructions if we don’t exclude higher frequencies
In other words, if we don’t eliminate (filter out) high frequencies their samples become undistinguishable from low frequency samples. The high frequencies alias as low frequency signals.
t
Volta
ge
PID Control , Slide 67 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Aliasing Example
Sampling at 2.5 Hz (period = 0.4 s) the following signals are indistinguishable
( )tty π6sin)( =
( )tty πsin)( =
Frequency f = 3 Hz
Frequency f = 0.5 Hz
In fact, with sampling frequency of 2.5 Hz one can only correctly sample signal below the Nyquist frequency 2.5/2 = 1.25 Hz.
PID Control , Slide 68 Embedded Systems and Software, 55:036. The University of Iowa, 2013
• Inherent delay in processing – Actuation occurs later than expected
• Need to characterize implementation delay to make sure it is negligible
• Hardware delay is usually easy to characterize – Synchronous design
• Software delay is harder to predict – Should organize code carefully so delay is predictable and
minimized – Write software with predictable timing behavior (be like hardware)
Time Trigger Architecture Synchronous Software Language and/or RTOS
Computation Delay
PID Control , Slide 69 Embedded Systems and Software, 55:036. The University of Iowa, 2013