Lecture 2 - Modeling and Simulation

advertisement
Lecture 2 - Modeling and Simulation
• Model types: ODE, PDE, State Machines, Hybrid
• Modeling approaches:
– physics based (white box)
– input-output models (black box)
• Linear systems
• Simulation
• Modeling uncertainty
EE392m - Winter 2003
Control Engineering
2-1
Goals
• Review dynamical modeling approaches used for control
analysis and simulation
• Most of the material us assumed to be known
• Target audience
– people specializing in controls - practical
EE392m - Winter 2003
Control Engineering
2-2
Modeling in Control Engineering
• Control in a
system
perspective
Physical system
Measurement
system
Sensors
• Control analysis
perspective
Control
computing
Control
handles
Actuators
Physical
system
Control
computing
Measurement
model
System model
EE392m - Winter 2003
Control
handle
model
Control Engineering
2-3
Models
• Model is a mathematical representations of a system
– Models allow simulating and analyzing the system
– Models are never exact
• Modeling depends on your goal
–
–
–
–
A single system may have many models
Always understand what is the purpose of the model
Large ‘libraries’ of standard model templates exist
A conceptually new model is a big deal
• Main goals of modeling in control engineering
– conceptual analysis
– detailed simulation
EE392m - Winter 2003
Control Engineering
2-4
Modeling approaches
• Controls analysis uses deterministic models. Randomness and
uncertainty are usually not dominant.
• White box models: physics described by ODE and/or PDE
• Dynamics, Newton mechanics
x& = f ( x, t )
• Space flight: add control inputs u and measured outputs y
x& = f ( x, u, t )
y = g ( x , u, t )
EE392m - Winter 2003
Control Engineering
2-5
Orbital mechanics example
• Newton’s mechanics
– fundamental laws
– dynamics
v& = −γm ⋅
1643-1736
r
r
3
+ Fpert (t )
v
r& = v
r
• Laplace
– computational dynamics
(pencil & paper computations)
– deterministic model-based
prediction
1749-1827
EE392m - Winter 2003
Control Engineering
x& = f ( x, t )
 r1 
r 
 2
 r3 
x= 
 v1 
 v2 
2-6  
 v3 
Orbital mechanics example
• Space flight mechanics
Thrust
r
v& = −γm ⋅ 3 + Fpert (t ) + u(t )
r
r& = v
• Control problems: u - ?
observations /
measurements
θ ( r ) 
y=

ϕ
r
(
)


EE392m - Winter 2003
 r1 
r 
 2
state
 r3 
x= 
 v1 
 v2 
 
 v3 
Control Engineering
model
control
x& = f ( x, u, t )
y = g ( x , u, t )
2-7
Gene
expression
model
EE392m - Winter 2003
Control Engineering
2-8
Sampled Time Models
• Time is often sampled because of the digital computer use
– computations, numerical integration of continuous-time ODE
x (t + d ) ≈ x (t ) + d ⋅ f ( x, u, t ),
t = kd
– digital (sampled time) control system
x ( t + d ) = f ( x , u, t )
y = g ( x , u, t )
• Time can be sampled because this is how a system works
• Example: bank account balance
– x(t) - balance in the end of day t
– u(t) - total of deposits and withdrawals that day
– y(t) - displayed in a daily statement
x (t + 1) = x (t ) + u (t )
y=x
• Unit delay operator z-1: z-1 x(t) = x(t-1)
EE392m - Winter 2003
Control Engineering
2-9
Finite state
machines
• TCP/IP State Machine
EE392m - Winter 2003
Control Engineering
2-10
Hybrid systems
• Combination of continuous-time dynamics and a state machine
• Thermostat example
• Tools are not fully established yet
off
x = 72
EE392m - Winter 2003
x& = − Kx
x ≥ 70
Control Engineering
x = 70
on
x& = K ( h − x ) x
x ≤ 75
x = 75
2-11
PDE models
• Include functions of spatial variables
–
–
–
–
electromagnetic fields
mass and heat transfer
fluid dynamics
structural deformations
• Example: sideways heat equation
∂T
∂ 2T
=k 2
∂t
∂x
T (0) = u;
∂T
y=
∂x
x
Tinside=u
Toutside=0
T (1) = 0
y
heat flux
x =1
EE392m - Winter 2003
Control Engineering
2-12
Black-box models
• Black-box models - describe P as an operator
u
input data
P
y
output data
x
internal state
–
–
–
–
AA, ME, Physics - state space, ODE and PDE
EE - black-box,
ChE - use anything
CS - state machines, probablistic models, neural networks
EE392m - Winter 2003
Control Engineering
2-13
Linear Systems
•
•
•
•
•
•
•
•
Impulse response
FIR model
IIR model
State space model
Frequency domain
Transfer functions
Sampled vs. continuous time
Linearization
EE392m - Winter 2003
Control Engineering
2-14
Linear System (black-box)
• Linearity
P
u1 (⋅) 
→
y1 (⋅)
P
u2 (⋅) 
→
y2 (⋅)
P
au1 (⋅) + bu2 (⋅) 
→
ay1 (⋅) + by2 (⋅)
• Linear Time-Invariant systems - LTI
P
u(⋅ − T ) 
→
y (⋅ − T )
u

→
y
P
t
EE392m - Winter 2003
Control Engineering
t
2-15
Impulse response
• Response to an input impulse
u
y
t
P
δ (⋅) →
h(⋅)
t
• Sampled time: t = 1, 2, ...
• Control history = linear combination of the impulses ⇒
system response = linear combination of the impulse responses
∞
u(t ) = ∑ δ (t − k )u( k )
k =0
∞
y (t ) = ∑ h(t − k )u( k ) = (h * u )(t )
k =0
EE392m - Winter 2003
Control Engineering
2-16
Linear PDE System Example
∂T
∂ 2T
=k 2
∂t
∂x
u = T ( 0)
T (1) = 0
• Heat transfer equation,
– boundary temperature input u
– heat flux output y
• Pulse response and step response
-2
HEAT FLUX
6
∂T
y=
∂x
P ULS E RES P ONS E
x 10
TEMP ERATURE
4
2
x =1
1
0.8
HEAT FLUX
0
0
20
40
60
TIME
S TEP RES P ONS E
80
100
0.6
1
0.4
0.8
0.2
0.6
0
0
1
0.4
0 .8
0.6
0.2
0.4
0 .4
0.6
0.8
0.2
0
0.2
1
0
TIME
COORDINATE
0
20
EE392m - Winter 2003
40
60
TIME
80
100
Control Engineering
2-17
FIR model
N
y (t ) = ∑ hFIR (t − k )u (k ) = (hFIR * u )(t )
k =0
• FIR = Finite Impulse Response
• Cut off the trailing part of the pulse response to obtain FIR
• FIR filter state x. Shift register
u(t)
x (t + 1) = f ( x, u )
y = g ( x, u )
y(t)
z-1
h0
z-1
h1
z-1
h2
x1=u(t-1)
x2=u(t-2)
x3=u(t-3)
EE392m - Winter 2003
Control Engineering
h3
2-18
IIR model
na
nb
k =1
k =0
• IIR model: y (t ) = − ∑ ak y (t − k ) + ∑ bk u (t − k )
• Filter states: y(t-1), …, y(t-na ), u(t-1), …, u(t-nb )
u(t)
z-1
b0
z-1
u(t-1)
z-1
-a1
b1
u(t-2)
z-1
-a2
b2
u(t-3)
-a3
b3
EE392m - Winter 2003
Control Engineering
y(t)
y(t-1)
z-1
y(t-2)
z-1
y(t-3)
2-19
IIR model
• Matlab implementation of an IIR model: filter
• Transfer function realization: unit delay operator z-1
y ( t ) = H ( z )u ( t )
B ( z ) b0 + b1 z −1 + ... + bN z − N b0 z N + b1 z N −1 + ... + bN
H ( z) =
=
= N
−1
−N
A( z ) 1 + a1 z + ... + a N z
z + a1 z N −1 + ... + a N
(1
1 + a z + ... + a z )y ( t ) = (b + b z + ... + b z )u ( t )
44424443
14 4 4
424444
3
−1
−N
1
N
−1
0
−N
1
A( z )
N
B( z)
• FIR model is a special case of an IIR with A(z) =1 (or zN )
EE392m - Winter 2003
Control Engineering
2-20
IIR approximation example
• Low order IIR approximation of impulse response:
(prony in Matlab Signal Processing Toolbox)
• Fewer parameters than a FIR model
• Example: sideways heat transfer
– pulse response h(t)
– approximation with IIR filter a = [a1 a2 ], b=[b0 b1 b2 b3 b4 ]
IMP ULS E RES P ONS E
0.06
0.04
b0 + b1 z −1 + b2 z −2 + b3 z −3 + b4 z −4
H ( z) =
1 + a1 z −1 + a 2 z − 2
0.02
0
0
20
40
60
80
100
TIME
EE392m - Winter 2003
Control Engineering
2-21
Linear state space model
• Generic state space model:
x (t + 1) = f ( x, u, t )
y = g ( x , u, t )
• LTI state space model
– another form of IIR model
– physics-based linear system model
x ( t + 1)
y (t )
= Ax ( t ) + Bu ( t )
= Cx ( t ) + Du ( t )
[
]
• Transfer function of an LTI model y = (Iz − A )−1 B + D ⋅ u
– defines an IIR representation
H ( z ) = (Iz − A ) B + D
−1
• Matlab commands for model conversion: help ltimodels
EE392m - Winter 2003
Control Engineering
2-22
Frequency domain description
• Sinusoids are eigenfunctions of an LTI system:
y = H ( z )u
LTI
Plant
z −1eiωt = eiω ( t −1) = e − iω eiωt
• Frequency domain analysis
u = ∫ u~(ω )eiωt dω ⇒ y = ∫ H (eiω )u~(ω )eiωt dω
14243
Packet
u
of
sinusoids
EE392m - Winter 2003
eiωt
u~(ω )
~
y (ω )
iω
H (e )
Packet
of
sinusoids
Control Engineering
eiωt
~
y (ω )
y
2-23
Frequency domain description
M (ω ) = H ( eiω )
• Bode plots:
iωt
Bode Diagra m
iω
y = H ( e )e
iωt
• Example:
1
H ( z) =
z − 0.7
15
Magnitude (dB)
u=e
ϕ (ω ) = arg H (eiω )
10
5
0
-5
0
• |H| is often measured
in dB
Phas e (deg)
-45
-90
-135
-180
-2
10
EE392m - Winter 2003
Control Engineering
10
-1
Frequency (rad/sec)
10
0
2-24
Black-box model from data
• Linear black-box model can be determined from the data,
e.g., step response data
• This is called model identification
• Lecture 8
EE392m - Winter 2003
Control Engineering
2-25
z-transform, Laplace transform
• Formal description of the transfer function:
– function of complex variable z
H ( z) =
– analytical outside the circle |z|≥r
– for a stable system r ≤ 1
∑ h(k )z
• Laplace transform:
∞
– function of complex variable s
– analytical in a half plane Re s ≤ a
– for a stable system a ≤ 1
EE392m - Winter 2003
Control Engineering
∞
−k
k =0
H ( s ) = ∫ h(t )e st dt
−∞
yˆ ( s ) = H ( s )uˆ ( s )
2-26
Stability analysis
• Transfer function poles tell you everything about stability
• Model-based analysis for a simple feedback example:
y = H ( z )u
u = − K ( y − yd )
H ( z)K
y=
y d = L( z ) y d
1 + H ( z)K
• If H(z) is a rational transfer function describing an IIR
model
• Then L(z) also is a rational transfer function describing an
IIR model
EE392m - Winter 2003
Control Engineering
2-27
Poles and Zeros <=> System
Impulse Re sponse
1
• …not quite so!
• Example:
Amplitude
0.8
z
y = H ( z )u =
z − 0.7
0.6
0.4
0.2
0
0
5
10
15
20
25
Time (sec)
• FIR model - truncated IIR
z19 + 0.7 z18 + 0.49 z17 + ... + 0.001628 z + 0.00114
y = H FIR ( z )u =
z19
Impulse Re sponse
1
Amplitude
0.8
0.6
0.4
0.2
0
0
5
10
15
20
Time (sec)
EE392m - Winter 2003
Control Engineering
2-28
25
IIR/FIR example - cont’d
• Feedback control:
z
z − 0.7
u = − K ( y − yd ) = −( y − yd )
y = H ( z )u =
• Closed loop:
Impulse Re sponse
0.8
H FIR ( z )
y=
u = LFIR ( z )u
1 + H FIR ( z )
EE392m - Winter 2003
Control Engineering
0.6
Amplitude
H ( z)
y=
u = L ( z )u
1 + H ( z)
0.4
0.2
0
0
5
10
15
20
25
Time (sec)
2-29
IIR/FIR example - cont’d
Poles and zeros
• Blue: Loop
with IIR
model poles x
and zeros o
0.8
0.6
0.4
0.2
• Red: Loop
with FIR
model poles x
and zeros o
0
-0.2
-0.4
-0.6
-0.8
-0.8
EE392m - Winter 2003
-0.6
-0.4
-0.2
Control Engineering
0
0.2
0.4
0.6
0.8
2-30
LTI models - summary
• Linear system can be described by impulse response
• Linear system can be described by frequency response =
Fourier transform of the impulse response
• FIR, IIR, State-space models can be used to obtain close
approximations of a linear system
• A pattern of poles and zeros can be very different for a
small change in approximation error.
• Approximation error <=> model uncertainty
EE392m - Winter 2003
Control Engineering
2-31
Nonlinear map linearization
• Nonlinear - detailed
model
• Linear - conceptual
design model
• Static map, gain
range, sector
linearity
• Differentiation,
secant method
∆f
y = f (u ) ≈
(u − u0 )
∆u
EE392m - Winter 2003
Control Engineering
2-32
Nonlinear state space model
linearization
• Linearize the r.h.s. map x& = f ( x, u ) ≈
∆f
∆f
( x − x0 ) +
(u − u0 )
1
4
2
4
3
424
3
∆x
∆u 1
q
v
q& = Aq + Bv
• Secant method
j
f (x + sj )
∆
f
 
 ∆x  =
sj
s j = [0 ... 1{ ... 0]
#j
• Or … capture a response to small step and build an
impulse response model
EE392m - Winter 2003
Control Engineering
2-33
Sampled time vs. continuous time
• Continuous time analysis (Digital implementation of
continuous time controller)
– Tustin’s method = trapezoidal rule of integration for H ( s ) =

2 1 − z −1 

H ( s ) → H s ( z ) = H  s = ⋅
−1 
T 1+ z 

1
s
– Matched Zero Pole: map each zero and a pole in accordance with
s = e sT
• Sampled time analysis (Sampling of continuous signals
and system)
EE392m - Winter 2003
Control Engineering
2-34
Sampled and continuous time
• Sampled and continuous time together
• Continuous time physical system + digital controller
– ZOH = Zero Order Hold
A/D, Sample
Sensors
EE392m - Winter 2003
D/A, ZOH
Control
computing
Physical
system
Control Engineering
Actuators
2-35
Signal sampling, aliasing
• Nyquist frequency:
ωN= ½ωS; ωS= 2π/T
• Frequency folding: kωS±ω map to the same frequency ω
• Sampling Theorem: sampling is OK if there are no frequency
components above ωN
• Practical approach to anti-aliasing: low pass filter (LPF)
• Sampled→continuous: impostoring
Low
Pass
Filter
A/D, Sample
EE392m - Winter 2003
Digital
computing
Control Engineering
D/A, ZOH
Low
Pass
Filter
2-36
Simulation
• ODE solution
– dynamical model: x& = f ( x, t )
– Euler integration method: x (t + d ) = x (t ) + d ⋅ f ( x (t ), t )
– Runge-Kutta: ode45 in Matlab
• Can do simple problems by integrating ODEs
• Issues:
–
–
–
–
–
–
mixture of continuous and sampled time
hybrid logic (conditions)
state machines
stiff systems, algebraic loops
systems integrated out of many subsystems
large projects, many people contribute different subsystems
EE392m - Winter 2003
Control Engineering
2-37
Simulation environment
• Simulink by Mathworks
• Matlab functions and analysis
• Stateflow state machines
• Ptolemeus UC Berkeley
• Block libraries
• Subsystem blocks
developed independently
• Engineered for developing
large simulation models
EE392m code
- Wintergeneration
2003
• Supports
Control Engineering
2-38
Model block development
• Look up around for available conceptual models
• Physics - conceptual modeling
• Science (analysis, simple conceptual abstraction) vs.
engineering (design, detailed models - out of simple blocks)
EE392m - Winter 2003
Control Engineering
2-39
Modeling uncertainty
• Modeling uncertainty:
– unknown signals
– model errors
• Controllers work with real systems:
– Signal processing: data → algorithm → data
– Control: algorithms in a feedback loop with a real system
• BIG question: Why controller designed for a model would
ever work with a real system?
– Robustness, gain and phase margins,
– Control design model, vs. control analysis model
– Monte-Carlo analysis - a fancy name for a desperate approach
EE392m - Winter 2003
Control Engineering
2-40
Download