40
EE392m - Winter 2003 Control Engineering 2-1 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

Lecture 2 - Modeling and Simulationweb.stanford.edu/class/archive/ee/ee392m/ee392m.1034/Lecture2... · Lecture 2 - Modeling and Simulation • Model types: ODE, ... Orbital mechanics

  • Upload
    vodien

  • View
    221

  • Download
    1

Embed Size (px)

Citation preview

EE392m - Winter 2003 Control Engineering 2-1

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-2

Goals

• Review dynamical modeling approaches used for controlanalysis and simulation

• Most of the material us assumed to be known• Target audience

– people specializing in controls - practical

EE392m - Winter 2003 Control Engineering 2-3

Modeling in Control Engineering• Control in a

systemperspective

Physical systemMeasurementsystemSensors

Controlcomputing

Controlhandles

Actuators

Physicalsystem

• Control analysisperspective

Controlcomputing

System model Controlhandlemodel

Measurementmodel

EE392m - Winter 2003 Control Engineering 2-4

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-5

),,(),,(

tuxgytuxfx

==&

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

• Space flight: add control inputs u and measured outputs y),( txfx =&

EE392m - Winter 2003 Control Engineering 2-6

vr

tFrrmv pert

=

+⋅−=

&

& )(3γ

Orbital mechanics example

• Newton’s mechanics– fundamental laws– dynamics

=

3

2

1

3

2

1

vvvrrr

x),( txfx =&

• Laplace– computational dynamics

(pencil & paper computations)– deterministic model-based

prediction1749-1827

1643-1736rv

EE392m - Winter 2003 Control Engineering 2-7

Orbital mechanics example

• Space flight mechanics

• Control problems: u - ?

=

3

2

1

3

2

1

vvvrrr

x

),,(),,(

tuxgytuxfx

==&

=)()(

rr

yϕθ

vr

tutFrrmv pert

=

++⋅−=

&

& )()(3γThrust

state

modelobservations /measurements control

EE392m - Winter 2003 Control Engineering 2-8

Geneexpressionmodel

EE392m - Winter 2003 Control Engineering 2-9

),,(),,()(

tuxgytuxfdtx

==+

Sampled Time Models• Time is often sampled because of the digital computer use

– computations, numerical integration of continuous-time ODE

– digital (sampled time) control system

• 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

• Unit delay operator z-1: z-1 x(t) = x(t-1)

( ) kdttuxfdtxdtx =⋅+≈+ ),,,()(

xytutxtx

=+=+ )()()1(

EE392m - Winter 2003 Control Engineering 2-10

Finite statemachines

• TCP/IP State Machine

EE392m - Winter 2003 Control Engineering 2-11

Hybrid systems• Combination of continuous-time dynamics and a state machine• Thermostat example• Tools are not fully established yet

off on72=x

75=x

70=x

70≥−=

xKxx&

75)(

≤−=

xxxhKx&

EE392m - Winter 2003 Control Engineering 2-12

PDE models• Include functions of spatial variables

– electromagnetic fields– mass and heat transfer– fluid dynamics– structural deformations

• Example: sideways heat equation

1

2

2

0)1(;)0(

=∂∂=

==∂∂=

∂∂

xxTy

TuTxTk

tT

yheat flux

x

Toutside=0Tinside=u

EE392m - Winter 2003 Control Engineering 2-13

Black-box models

• Black-box models - describe P as an operator

– AA, ME, Physics - state space, ODE and PDE– EE - black-box,– ChE - use anything– CS - state machines, probablistic models, neural networks

Px

uinput data

youtput data

internal state

EE392m - Winter 2003 Control Engineering 2-14

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-15

Linear System (black-box)

• Linearity

• Linear Time-Invariant systems - LTI

)()( 11 ⋅→⋅ yu P

)()( TyTu P −⋅→−⋅

)()()()( 2121 ⋅+⋅→⋅+⋅ byaybuau P

)()( 22 ⋅→⋅ yu P

→ Pu

t

y

t

EE392m - Winter 2003 Control Engineering 2-16

Impulse response• Response to an input impulse

• Sampled time: t = 1, 2, ...• Control history = linear combination of the impulses ⇒

system response = linear combination of the impulse responses

( ) )(*)()()(

)()()(

0

0

tuhkukthty

kukttu

k

k

=−=

−=

∑∞

=

=

δ

)()( ⋅→⋅ hPδu

t

y

t

EE392m - Winter 2003 Control Engineering 2-17

Linear PDE System Example

• Heat transfer equation,– boundary temperature input u– heat flux output y

• Pulse response and step response

00.2

0.40.6

0.81 0

0.20 .4

0.60 .8

10

0.2

0.4

0.6

0.8

1

TIME

TEMPERATURE

COORDINATE

0)1()0(

2

2

==∂∂=

∂∂

TTuxTk

tT

1=∂∂=

xxTy

0 20 40 60 80 1000

2

4

6x 10

-2

TIME

HE

AT

FLU

X

PULSE RESPONSE

0 20 40 60 80 1000

0.2

0.4

0.6

0.8

1

TIME

HE

AT

FLU

X

STEP RESPONSE

EE392m - Winter 2003 Control Engineering 2-18

FIR model

• FIR = Finite Impulse Response• Cut off the trailing part of the pulse response to obtain FIR• FIR filter state x. Shift register

),(),()1(

uxgyuxftx

==+

h0

h1

h2

h3

u(t)

x1=u(t-1)

y(t)

x2=u(t-2)

x3=u(t-3)

z-1

z-1

z-1

( ) )(*)()()(0

tuhkukthty FIR

N

kFIR =−=∑

=

EE392m - Winter 2003 Control Engineering 2-19

IIR model• IIR model:

• Filter states: y(t-1), …, y(t-na ), u(t-1), …, u(t-nb )

∑∑==

−+−−=ba n

kk

n

kk ktubktyaty

01

)()()(

u(t) b0

b1

b2

u(t-1)

u(t-2)

u(t-3)

z-1

z-1

z-1

-a1

-a2

y(t-1)

y(t-2)

y(t-3)

z-1

z-1

z-1

y(t)

b3-a3

EE392m - Winter 2003 Control Engineering 2-20

IIR model• Matlab implementation of an IIR model: filter• Transfer function realization: unit delay operator z-1

( ) ( ) )(...)(...1

......

...1...

)()()(

)()()(

)(

110

)(

11

11

110

11

110

tuzbzbbtyzazaazazbzbzb

zazazbzbb

zAzBzH

tuzHty

zB

NN

zA

NN

NNN

NNN

NN

NN

4444 34444 21444 3444 21−−−−

−−

−−

+++=+++

++++++=

++++++==

=

• FIR model is a special case of an IIR with A(z) =1 (or zN )

EE392m - Winter 2003 Control Engineering 2-21

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 ]

0 20 40 60 80 1000

0.02

0.04

0.06

TIME

IMPULSE RESPONSE

22

11

44

33

22

110

1)( −−

−−−−

++++++=

zazazbzbzbzbbzH

EE392m - Winter 2003 Control Engineering 2-22

Linear state space model• Generic state space model:

• LTI state space model– another form of IIR model– physics-based linear system model

• Transfer function of an LTI model– defines an IIR representation

• Matlab commands for model conversion: help ltimodels

( )[ ]( ) DBAIzzH

uDBAIzy

+−=

⋅+−=−

1

1

)(

)()()()()()1(

tDutCxtytButAxtx

+=+=+

),,(),,()1(

tuxgytuxftx

==+

EE392m - Winter 2003 Control Engineering 2-23

Frequency domain description• Sinusoids are eigenfunctions of an LTI system:

LTIPlant

tiititi eeeez ωωωω −−− == )1(1

• Frequency domain analysis

uzHy )(=

∫∫ =⇒= ωωωω ω

ω

ωω deueHydeuu ti

y

iti43421)(~

)(~)()(~

)(~ ω

ω

ue ti

uPacket

of

sinusoids )(~ ω

ω

ye tiPacket

of

sinusoids

)( ωieH y

EE392m - Winter 2003 Control Engineering 2-24

Frequency domain description• Bode plots:

tii

ti

eeHyeu

ωω

ω

)(==

• Example:

)(arg)(

)()(ω

ω

ωϕ

ωi

i

eH

eHM

=

=

7.01)(

−=

zzH

Bode Diagra m

Frequency (rad/sec)

Phas

e (d

eg)

Mag

nitu

de (d

B)

-5

0

5

10

15

10-2

10-1

100

-180

-135

-90

-45

0

• |H| is often measuredin dB

EE392m - Winter 2003 Control Engineering 2-25

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-26

z-transform, Laplace transform• Formal description of the transfer function:

– function of complex variable z– analytical outside the circle |z|≥r– for a stable system r ≤ 1

k

kzkhzH −

=∑=

0

)()(

• Laplace transform:– function of complex variable s– analytical in a half plane Re s ≤ a– for a stable system a ≤ 1

∫∞

∞−

= dtethsH st)()(

)(ˆ)()(ˆ susHsy =

EE392m - Winter 2003 Control Engineering 2-27

Stability analysis

• Transfer function poles tell you everything about stability• Model-based analysis for a simple feedback example:

)()(

dyyKuuzHy−−=

=dd yzLy

KzHKzHy )()(1

)( =+

=

• If H(z) is a rational transfer function describing an IIRmodel

• Then L(z) also is a rational transfer function describing anIIR model

EE392m - Winter 2003 Control Engineering 2-28

Poles and Zeros <=> System• …not quite so!• Example:

7.0)(

−==

zzuzHy

19

171819 0011400016280...4907.0)(z

. z.z.zzuzHy FIR+++++==

Impulse Re sponse

Time (sec)

Ampl

itude

0 5 10 15 20 250

0.2

0.4

0.6

0.8

1

Impulse Re sponse

Time (sec)

Ampl

itude

0 5 10 15 20 250

0.2

0.4

0.6

0.8

1

• FIR model - truncated IIR

EE392m - Winter 2003 Control Engineering 2-29

IIR/FIR example - cont’d• Feedback control:

• Closed loop:

)()(7.0

)(

dd yyyyKuz

zuzHy

−−=−−=−

==

Impulse Re sponse

Time (sec)

Ampl

itude

0 5 10 15 20 250

0.2

0.4

0.6

0.8

uzLuzH

zHy )()(1

)( =+

=

uzLuzH

zHy FIRFIR

FIR )()(1

)( =+

=

EE392m - Winter 2003 Control Engineering 2-30

-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

IIR/FIR example - cont’dPoles and zeros

• Blue: Loopwith IIRmodel poles xand zeros o

• Red: Loopwith FIRmodel poles xand zeros o

EE392m - Winter 2003 Control Engineering 2-31

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-32

Nonlinear map linearization• Nonlinear - detailed

model• Linear - conceptual

design model• Static map, gain

range, sectorlinearity

• Differentiation,secant method

)()( 0uuufufy −

∆∆≈=

EE392m - Winter 2003 Control Engineering 2-33

Nonlinear state space modellinearization

• Linearize the r.h.s. map

• Secant method

• Or … capture a response to small step and build animpulse response model

BvAqq

uuufxx

xfuxfx

vq

+=

−∆∆+−

∆∆≈=

&

4342143421& )()(),( 00

{ ]0...1...0[

)(

# jj

j

jj

ss

sxfxf

=

+=

∆∆

EE392m - Winter 2003 Control Engineering 2-34

Sampled time vs. continuous time

• Continuous time analysis (Digital implementation ofcontinuous time controller)– Tustin’s method = trapezoidal rule of integration for

– Matched Zero Pole: map each zero and a pole in accordance with

• Sampled time analysis (Sampling of continuous signalsand system)

+−⋅==→ −

1

1

112)()(

zz

TsHzHsH s

ssH 1)( =

sTes =

EE392m - Winter 2003 Control Engineering 2-35

Sampled and continuous time• Sampled and continuous time together• Continuous time physical system + digital controller

– ZOH = Zero Order Hold

Sensors

Controlcomputing

ActuatorsPhysicalsystem

D/A, ZOHA/D, Sample

EE392m - Winter 2003 Control Engineering 2-36

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

Digitalcomputing

D/A, ZOHA/D, SampleLowPassFilter

LowPassFilter

EE392m - Winter 2003 Control Engineering 2-37

Simulation• ODE solution

– dynamical model:– Euler integration method:– 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

),( txfx =&( )ttxfdtxdtx ),()()( ⋅+=+

EE392m - Winter 2003 Control Engineering 2-38

Simulation environment

• Block libraries

• Subsystem blocksdeveloped independently

• Engineered for developinglarge simulation models

• Supports code generation

• Simulink by Mathworks• Matlab functions and analysis• Stateflow state machines

• Ptolemeus -UC Berkeley

EE392m - Winter 2003 Control Engineering 2-39

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-40

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 wouldever 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