modeling hybrid systems yerang hur cis 640, october 10, 2002 department of computer and information...
Post on 20-Dec-2015
216 views
TRANSCRIPT
Modeling Hybrid Systems
Yerang Hur CIS 640, October 10, 2002Department of Computer and Information Science University of Pennsylvania
Code generation demo: Jesung KimSome slides are edited from previous slides made together with others in Hybrid Systems Group.
Outline
Hybrid Systems Simulink State-machine-based Representation CHARON Framework CHARON Language Examples Tool Demo
Hybrid Systems
Differential equations Algebraic equations Invariant constraints
CollisionsDecision logicDiscrete communication (send/receive)
Guarded transitions between modes
Represented with
Physical processes in control system e.g. robots, aircraft, ...
Continuous Behaviors Discrete Events
Hybrid Systems - two views
Control engineering-oriented view
discretecontrol command
generator
dynamicalsystem
reference
output
Hybrid Systems - two views (con’t)
Computer scientist-oriented view
- State machine embedding dynamics
dx/dt=f(x) dx/dt=g(x)guard
reset x
- Continuous state variables with discrete state variables
guard
reset x
cont xdisc y
dx/dt=f(x,y)
Y=1 update y
cont xdisc y
dx/dt=g(x,y)
Simulink
system blockdiagramsources sinks
Elements of Simulink model
Simulink is block diagram-based notations for modeling dynamical systems.
Simulink (cont’d)
Blocks for representing continuous components
State-Space Block
Gain Blockk yx : algebraic equation
y=kx
Sum Block
Derivative Block
Integrator Block
ab c: algebraic equation
c=a-b
+-
du/dtx y: differential equation y=dx/dt
x Y: Y =y0 + x(t)dt
X=Ax+BuY=Cx+Du
yu
.
Simulink (cont’d)
Hybrid system representation
-
+
Kp
Ki
Kd
zero orderholder
discrete timeintegrator
derivativeapproximation
+
++
physicalplant
reference
State-machine-based Representation
x > 80.0
x < 70.0
x := 73.0
Thermostat
On
x>=82.0dx/dt=-x+100
Off
68.0<=xdx/dt=-x
Framework for Developing Hybrid System
1. High-level modeling
• platform independent
• hierarchical and modular– parallel composition of agents– specify modes and constraints – sequential composition of modes
2. Simulation, analysis, and automatic code generation
3. Deploy the code on actual target platform
CHARON FrameworkCHARON Code(High level language)
Java Code
CHARON to Java TranslatorCHARON to Java Translator
Control Code GeneratorControl Code Generator
Java Libraries
Human InterfaceHuman InterfaceAnalysis
Simulator GeneratorSimulator Generator
Drivers
CHARON Language
Individual components described as agents Composition, Instantiation, and Hiding
Individual behaviors described as modes Encapsulation, Instantiation, and Scoping of
variables
Shared variables as well as message passing Support for discrete and continuous behavior Well-defined formal semantics
Example: TwoAgent
mode0
mode1
Mode
choppyATop
a1
a2
Agent
TwoAgent A
top(10.0,0.0)
(9.0,-1.0)
Architectural Hierarchy
Behavioral Hierarchy
Example: TwoAgent
mode0
mode1
Mode
choppyATop
a1
a2
Agent
TwoAgent A
top(10.0,0.0)
(9.0,-1.0)
agent TwoAgent() {
private analog real v1,v2;agent a1 = A (10.0, 0.0) [vIn, vOut := v2, v1] ;agent a2 = A (9.0, -1.0)
[vIn, vOut := v1, v2] ; }
agent A(real initValue, real c) {read analog real vIn ;
write analog real vOut ; mode top=Atop(initValue,c) ; }
mode Atop(real iVal, real c) {read analog real vIn ;write analog real vOut ; mode mode0=choppy(2.0,-50.0,c);mode mode1=choppy(2.0,1.0,c) ;
trans initTrans from default to mode0 when true do {vOut=iVal}
…
Modes of Agent A1
ATop
write analog real v1 write discrete int p1
inv invChoppy {v1>0.0}
diff fv1 {d(v1)==2.0*v1-50.0+c}
mode0 mode1
write analog real v1 write discrete int p1
inv invChoppy {v1>0.0}
diff fv1 {d(v1)==2.0*v1+1.0+c}
v1<8.0 &&|v1-v2|>1.1
v1>12.0 &&|v1-v2|>1.0
transition guard: g1
mode name
variabledeclaration
dynamics
invariant:flow constraint
do {p1:=1}
do {p1:=0}
Architectural Hierarchy
Robots
Monitor
pos1 pos2
write analog position pos1, pos2
class position {double x; double y;}
Variable Specifiers
Update: discrete/analog
I/O interface: read/write/private
Architectural Hierarchy
Robot1
Robots
Robot2
pos1 pos2
r1Est1
r1Est2
r2Est1
r2Est2
Robots
Monitor
pos1 pos2
Behavioral Hierarchy
pos
r2Est1
r2Est2
r1Est1
r1Est2
Robot1
dTimer
timer == 1.
private analog real timer
awTargetdPlaniAway
atTargetdStopiAt
arrive
pos == target
movingdSteeraOmegaiFreq
sensingdStopiConst
sense
move
arrive
timer/updateFreq == 0
omega == k * (theta – phi)
pos.x == v * cos(phi)
pos.y == v * sin(phi)
.
.
Example: the Simplex Architecture-based Inverted Pendulum
Safety Controller
Baseline Controller
Experimental Controller
DecisionModule
PhysicalSystem
us
ub
ue
xu
Safety ControllerBaseline Controller
Experimental Controllerx0
Equilibrium state
The Inverted Pendulum
m
l
x
g
Muf
Control Task and CHARON Description Control objective: to move the cart from one position to a
desired target position xt maintaining the pendulum at the upright position.
Planner: generates a set point xs every T seconds with rate c until the generated set point reaches the target position.
Lower level: stabilizes the system about [xs, 0, 0, 0 ]
Controllers
Physical System
Decision Module
Simulation Results
-1
0
1
2
3
4
5
-2 0 2 4 6 8
time
ctrlCmd
angle
VaBC
VaSC
position
VaEC
cVelocity
aVelocity
Sampling Frequency 50Hz
Maximum Position Tracking Error : 0.17m < 0.2m Initial Position : 0.0Initial Cart Velocity : 0.0 m/sInitial Angle : 5.0 degInitial Angular Velocity : 0.0 deg/s
Maximum Control Value : 3.78V < 4.96V
Maximum Cart Velocity : 0.32m/s < 1.0m/s
Maximum Angle : 5.0 deg< 10.0 deg
CHARON Simulator Generation Process
CHARON
model
Agent and Mode generator
Simulator maingenerator
Agents
Modes
Simulatormain
TracePlotter
Tracegenerator
User-definedexternal classes
Numerical integrator
Differential Equations
Invariants
Algebraic Equations
Guards
Actions
Assertions
Wrap-up:Two Worlds Affect Each Other
- Simulink is augemented with a hierarchical state machine. We call it Simulink/Stateflow.
- Among other design tools of interest are Ptolemy II with continuous time domain, SHIFT/Teja, Modelica, and RT-UML.
- Controllers/Decision Module/Physical system case studyin CHARON: E.g. the Simplex-Architecture-based inverted pendulum controller[RTSSWIP 2000] andautonomous distributed multi-robots.
Wrap-up: Features of CHARON
- Discrete event/discrete state representation: discrete int/bool
- Discrete event/continuous state representation: discrete real
- Continuous time/continuous state representation: analog real
- Behavior description: mode with hierarchy
- Architecture description: agent with hierarchy
-Structured modern programming language : variable scoping, type-checking rules, formal semantics
Wrap-up: Features of CHARON (cont’d)
- Software engineering tool : reusable agent/mode definition, : simulator generator, verification tool box, code generator
- Non-determinism : non-deterministic execution of agents when more than one agent observe enabled transitions at once, currently interleaving semantics : non-deterministic choice of transitions when more than one transitions are enabled at once, currently randomly selected or user-guided : non-deterministic non-urgent jump when a guard is enabled while the invariant is not violated, currently probabilistically taken and 80/20 rule is embedded : non-deterministic differential and algebraic constraints with inequalities, currently only front-end supports this
Wrap-up: Interface Qualifiers of Agent Variables Input from environment:
input (v0.1) --> read (v0.37) Output to environment:
output (v0.1) --> write (v0.37) --> write/readwrite (v0.4) --> write exclusive/write shared (v0.7)
Local private (v0.1) --> hiding operation (v0.12)
--> private (v0.6)
Wrap-up: Other Type Qualifiers Update Qualifiers:
analog for continuous update or reset discrete for discrete update
Channel Qualifiers: buffered non-blocking communication
channel combined with buffer size, message type,
buffer management policy Example: write channel [2] of real cold chan1;
Tool Demo
For manuals and more examples, visit http://www.cis.upenn.edu/mobies/experiments.php3.