Beruflich Dokumente
Kultur Dokumente
HandsOn Tutorial
HS/PDEEC20100304
Jos Pinto zepinto@fe.up.pt
Session Outline
Simulink andStateflow
NumericalSimulationofODEs
InitialValueProblem(Handson)
ODEs withresets(Handson)
FiniteStateMachines
FSMs inStateflow (Handson)
DiscreteEventSystems
DESs inStateflow (Handson)
HybridAutomata
HybridSystemsinStateflow (Handson)
Simulink and Stateflow
1.
Simulink
Canbeusedtomodelandsimulatedynamical
systemsinacomprehensiveandgraphicalway
Modelsaredescribedasblockdiagrams(boxeswith
inputs/outputs)
Simulink (2)
Modelsarecomposedhierarchicallyallowing:
Modelingofcomplexsystemsinamodularandorganized
way
Differentdetailperspectivesoverthesamemodelat
designandsimulationtime
Simulink and Stateflow
Simulink includes several builtin
block types (Model Library)
Additionally,extensions tothis
library can be created by users
and companies (toolboxes)
Stateflow is one such toolbox
Stateflow canbeusedtomodel
thebehaviour ofFSMs
Numerical Simulation of ODEs
2.
The Initial Value Problem
Example:
? ) (
2 ) 0 (
1
t x
x
x x
=
+ =
&
[Hespanha, J. P. 05]
ODENumerical Simulation Euler method
[Hespanha, J. P. 05]
ODESimulation RangeKutta method
[Hespanha, J. P. 05]
ODESimulation Variablestep methods
[Hespanha, J. P. 05]
Solving the IVPin Simulink
Simulink has an inbuilt ODEsolver(Integrator)
Different integration methods (including variable step)
Example:
2 ) 0 ( 1 = + = x x x
&
(Integrator toolbox accepts initial value)
ODEs with resets
x
1
: speed
x
2
: acceleration
g: gravity force
c: ball elasticity constant
Integrator Block in Simulink
Integratorblockacceptsaresetport
Wheneveraresetistriggered,itsnewvaluewillbe
takenfromtheinitialvalue(x
0
)port
Stateportholdspreviousvalueofx
Statecanbeusedtodetermineiftheintegrator
needstobereset(x
)
ODEs with resetsin Simulink
ODEs with resetsin Simulink (3)
Simulink ODEsolverdetects zerocrossing behaviour
When aresetis detected,the solvergoes back in
time todeterminewhere the resetoccurred
(zero-crossing detection disabled)
(with zero-crossing detection enabled)
Finite State Machines
3.
Finite State Machines (FSMs)
Modelofsystemswhosebehaviorcanbemodeled
asasetofstatesandtransitionsbetweenstates.This
systemsaresometimescalledreactivesystems.
Finitenumberofstates
SystemsmodeledbyFSMs:
Patternrecognition
ATMs
Computationalprocesses
Humanintelligence?
t t
t
Mathematical Model of FSMs
& &
Simulation of Hybrid Automata
[Hespanha, J. P. 05]
Bouncing Ball in StateFlow
Bouncing Ball in Stateflow SIMPLER
Go toFile>Chart properties
Select Continuous update method
Bouncing Ball in Stateflow SIMPLER
In Model Exploreryou can now localvariables of
type double ascontinuous variables (update
method)
Bouncing Ball in Stateflow SIMPLER
Foreach continuous local
variable x
stateflow automatically
definesx_dot
which is derivative of x
Exercise 1:Thermostat Hybrid System
1. Define the HS formally
2. Simulate Hybrid System
[Hespanha, J. P. 05]
Exercise 2:Tank Hybrid System
[Hespanha, J. P. 05]
Exercise 3:Billiard Hybrid System
Ballinsidea10x10box
Ballstartsatunknownposition(x,y)andwith
unknownvelocityvector(v
x
,v
y
)
Ballbouncesinanyofthe4walls
Constantenergydissipationfactorbetween0and1
10
END
References:
http://www.ece.ucsb.edu/~hespanha/ece229/
http://www.mathworks.com/access/helpdesk/help/pdf_doc/stateflow/sf_ug.pdf