SlideShare a Scribd company logo
Hybrid Equations (HyEQ) Toolbox
A Toolbox for Simulation of
Hybrid Dynamical Systems
in MATLAB/Simulink R
Ricardo G. Sanfelice, David A. Copp, and Pablo ˜Na˜nez
Hybrid Dynamics and Control Lab (HDC Lab)
Department of Aerospace and Mechanical Engineering
University of Arizona, USA
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Systems
Hybrid systems combine behaviors that are typical of
continuous-time dynamical systems with behaviors that are
typical of discrete-time dynamical systems.
In switched electrical circuits, voltages
and currents that change continuously
according to classical electrical
network laws also change
discontinuously due to switches
opening or closing.
Embedded systems and, more
generally, systems involving both
digital and analog components,
execute software code discretely while
interacting with their physical
environments continuously.
s1
s2
s4
s3
ell, r
il
c0
vc
ic
Hybrid
VDC
DC/AC
io so vg
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Systems
Hybrid systems combine behaviors that are typical of
continuous-time dynamical systems with behaviors that are
typical of discrete-time dynamical systems.
Velocities in a multibody dynamical
system change continuously according
to Newton’s second law, but undergo
instantaneous changes in velocity and
momentum due to collisions.
The concentrations in genetic
networks grow or decay continuously
according to binary variables that
change between 1 and 0 when the
concentrations reach certain
thresholds.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Systems
Hybrid systems combine behaviors that are typical of
continuous-time dynamical systems with behaviors that are
typical of discrete-time dynamical systems.
Impulsive oscillators capture the
dynamics of certain networked
biological systems, such as fireflies and
crickets, by means of timers with
event-driven resets.
Modern control algorithms often lead
to both kinds of behavior, due to
either digital components used in
implementation or logic and decision
making encoded in the control
algorithm.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Outline
1 Hybrid Systems
Challenges to Simulation
2 A Toolbox for Simulation of Hybrid Systems
Hybrid Equations (HyEQ) Toolbox Overview
Modeling Framework and Contributions
3 Components and Usage of the HyEQ Toolbox
Simulating Hybrid Systems
Simulating Interconnections
Internals
Configuration, Initialization, Postprocessing
Simulation Procedure
4 Illustrative Example
5 Conclusion and References
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation of hybrid systems
Hybrid systems demand simulation algorithms capable of
Numerically integrate differential equations
Locate, detect, and manage events
Reset state variables discretely
Generate a time axis that jointly parameterizes continuous
and discrete behavior
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation of hybrid systems
Hybrid systems demand simulation algorithms capable of
Numerically integrate differential equations
Locate, detect, and manage events
Reset state variables discretely
Generate a time axis that jointly parameterizes continuous
and discrete behavior
Challenges to Simulation of Hybrid Systems:
Simultaneous simulation of continuous and discrete dynamics
Accurate event location and detection
Large number of events/jumps in finite time (e.g., Zeno)
Multiple events at the same time
Time sharing in simulation of interconnected hybrid systems
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Equations (HyEQ) Toolbox
A hybrid simulator for MATLAB/Simulink called Hybrid Equations
(HyEQ) Toolbox with the following capabilities is introduced and
illustrated in examples:
Simulation of autonomous and non-autonomous hybrid
systems given by hybrid equations
Modular simulation of interconnections of hybrid systems
Simulation of systems with Zeno behavior and multiple jumps
at an instant
Generation of hybrid time axis indexing jumps
The HyEQ Toolbox is designed to simulate hybrid systems written
in a hybrid system framework amenable for control theory for
which a theory of robust stability has recently been developed.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
Hybrid systems are given by the hybrid equations
H : x ∈ Rn
, u ∈ Rm ˙x = f(x, u) (x, u) ∈ C
x+ = g(x, u) (x, u) ∈ D
or H = (C, f, D, g) for short.
C
D
Rn
˙x = f(x, u)
g(x, u)
×
Solutions are functions parameterized by hybrid time (t, j):
Flows parameterized by t ∈ R≥0 := [0, +∞)
Jumps parameterized by j ∈ N≥0 := {0, 1, 2, . . .}
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
A hybrid system is a dynamical system with continuous and
discrete dynamics.
Modeling Framework: A hybrid system H on a state space Rn
and input space Rm is defined by the following objects:
A set C ⊂ Rn × Rm called the flow set.
A function f : Rn → Rn called the flow map.
A set D ⊂ Rn × Rm called the jump set.
A function g : Rn → Rn called the jump map.
The flow map f defines the continuous dynamics on the flow set C.
The jump map g defines the discrete dynamics on the jump set D.
H can be explicitly denoted as H = (C, f, D, g).
Hybrid systems may have states that evolve both continuously
and jump, in which case the boundary of the flow and jump set
intersect.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Contributions to Hybrid Systems Theory
Autonomous Hybrid Systems
Notion of Solution
Lyapunov Theory and Invariance
Robustness to Small Perturbations
Nonautonomus Hybrid Systems
Notion of Solution
Control Lyapunov Functions
ISS and I/O Stability
Interconnections
Small gain Theorems
Hybrid Control Design
Tracking Control
Passivity-based Control
Minimum-norm Control
Backstepping
Numerical Simulation
Simulation theory
Simulation toolbox
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Examples
Examples of such systems include:
a bouncing ball on a moving platform,
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Examples
a DC/AC inverter,
s1
s2
s4
s3
ell, r
il
c0
vc
ic
Hybrid
VDC
DC/AC
io so vg
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Examples
a vehicle traveling along a track with boundaries,
−2
−1
1
2
0
the synchronization of multiple fireflies flashing.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Impulsive biological oscillators
Figure 1 shows how two fireflies can be modeled as periodic
oscillators with timers. The timer in each firefly is denoted τ1 and
τ2, respectively. The stars indicate when resets of the timers occur.
The “timer threshold” defines when the timers are reset to zero,
which corresponds to the respective firefly flashing.
τ1, τ2
time
synchronizationreset
firefly1
firefly2threshold
Figure 1 : Fireflies with hybrid dynamics synchronizing
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Impulsive biological oscillators
A model for interacting fireflies can be described as a hybrid
system. The fireflies are modeled mathematically as impulsive
oscillators with timer variables exhibiting impulses due to flashes.
In this way, the oscillator in a firefly exhibits continuous and
discrete dynamics:
The flow map f enforces that the timer state counts time
during continuous evolution.
The jump map g induces jumps in the timer state as follows:
it resets the timer to zero when the firefly flashes.
it is incremented a small amount when a neighboring firefly
flashes.
The flow set C determines when the timer should count time
while the flow set D triggers the jumps of the timer.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Components and Usage of the HyEQ Toolbox
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Equations (HyEQ) Toolbox
The Hybrid Equations (HyEQ) Toolbox includes the following:
HyEQsolver.m lite simulator script for systems w/o inputs.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Equations (HyEQ) Toolbox
The Hybrid Equations (HyEQ) Toolbox includes the following:
Simulink library for systems w/inputs and interconnections.
HS with external
functions
HS with embedded
functions
HS with embedded
functions and inputs
Time
t
State
x
J umps
jHS
x
t
j
Time
t
State
x
J umps
jHS
x
t
j
u
Time
t
Terminator
State
x
J umps
j
HSu
x
t
j
x−(int)
u
u
HSu
x
t
j
x−(int)
u
HSu
x
t
j
x−(int)
u
1 2
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
A Simulink implementation in the HyEQ Toolbox is shown below.
This model simulates a hybrid system with input
x−(int)
4
j
3
t
2
x
1
u
jump set D
x
u
v
D
jump map g
x
u
xplus
g
flow set C
x
u
v
C
flow map f
x
u
xdot
f
Time
t
Terminator
State
x
Jumps
j
Integrator System
f
C
g
D
x
t
j
x−
HSu
x
t
j
x−(int)
u
u1
1
Double Click
to Initialize
Double Click to
Plot Solutions
Figure 2 : MATLAB/Simulink implementation of a hybrid system with
inputs. The blocks f and C implement the flow equation while the
blocks g and D implement the jump equation.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulating Hybrid Systems in the HyEQ Toolbox
In the HyEQ Toolbox, the hybrid equations above are implemented
in Simulink using Embedded MATLAB Functions. The data of the
hybrid system is coded as follows:
The flow set C is captured by the embedded function C
The flow map f is captured by the embedded function f
The jump set D is captured by the embedded function D
The jump map g is captured by the embedded function g
Each of the blocks in Figure 2 implement the embedded functions
above.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulating Interconnections in the HyEQ Toolbox
The simulator implementation in HyEQ with inputs uses
embedded MATLAB functions within the main Simulink file
HyEQsimulator.mdl.
This allows the user to modify the data of each hybrid system
inside the model without having to edit several files.
With such an implementation, multiple hybrid systems can be
incorporated in a single Simulink file.
Then, interconnections of N hybrid systems is possible. Each
systems can be identical, as in the case of multiple fireflies
synchronizing flashing, or they can be different, such as a
bouncing ball impacting on a moving floor, which can be
interpreted as an interconnection of two systems.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulating Interconnections in the HyEQ Toolbox
In the model shown below, the input of the second system is
defined as the output of the first system, and viceversa. Other
types of interconnections are also possible.
This model simulates interconnected hybrid systems.
time1
t2
time
t1
state1
x2
state
x1
jumps1
j2
jumps
j1
Hybrid System 2
x
t
j
x−(int)
u
Hybrid System 1
x
t
j
x−(int)
u
Double Click
to Initialize
Double Click to
Plot Solutions
Figure 3 : Implementation of interconnected hybrid systems, H1 and H2.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulating Interconnections in the HyEQ Toolbox
Figure 4 : Bouncing ball on a
moving floor
0 2 4 6 8 10 12 14 16 18
0.2
0.4
0.6
0.8
1
0 2 4 6 8 10 12 14 16 18
−1
−0.5
0
0.5
1
heightvelocity
flows [t]
flows [t]
Figure 5 : Simulation trajectories: height
and velocity
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Hybrid Equations (HyEQ) Toolbox
The Hybrid Equations (HyEQ) Toolbox includes the following:
plotflows.m, plotjumps.m, plotHybridArc.m files for
plotting solutions,
initialization.m, postprocessing.m files for
configuring the simulation and solutions,
Files for several examples of individual and interconnected
hybrid systems.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Internal Structure of Simulink Implementation
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Internals of the HyEQ Toolbox simulator
Four basic blocks are used to define
the dynamics of the hybrid system H:
Flow map f
Flow set C
Jump map g
Jump set D
x
u
v
D
jump map g
x
u
xplus
g
x
u
v
C
flow map f
x
u
xdot
f
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Integrator System
x−
4
j
3
t
2
x
1
Update logic
g(x−,u)
j−
t−
update law
Stop logic
t
j
C
D
stop
Stop
Simulation
STOP
Save
In1
In2
Jump logic
C
D
r
jump
1
s
xo
ICx0
[0; 0; x0(:)]
ICx
[x0]
Constant
save
CT dynamics
f(x,u) dot
D
4
g
3
C
2
f
1
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
CT Dynamics
dot
1
Jumps
0
Flows
1
f(x,u)
1
This block defines the continuous dynamics by assembling the time
derivative of the state [t j x ] .
States t and j are considered states of the system because
they need to be updated throughout the simulation in order to
keep track of the time and number of jumps.
The dynamics of these states is given by
˙t = 1, ˙j = 0, ˙x = f(x, u) .
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Jump Logic
rule=1: out = D
rlule=2: out = D and ~C
rule=3: out = (D and ~C) or (D and C and r>0.5)
other : out = 0
jump
1
jump
Multiport
Switch
1
2
3
*
AND
OR
NOT
AND
0
rule
Compare
To Constant
>= 0.5
r
3
D
2
C
1
The inputs are the outputs of blocks C and D indicating
whether the state is in those sets or not, and a random signal
with uniform distribution in [0, 1].
Output of 1 indicates a jump of H and triggers a reset of the
integrator.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Update Logic
update law
1
1
t−
3
j−
2
g(x−,u)
1
The update logic uses the state port information of the integrator.
This port reports the value of the state of the integrator, [t j x ] ,
at the exact instant that the reset condition becomes true.
The flow time t is kept constant at jumps and j is incremented by
one. More precisely:
t+
= t−
, j+
= j−
+ 1, x+
= g(x−
, u)
where [t− j− x− ] is the state that triggers the jump.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Stop Logic
stop
1
Logical
Operator1
OR
Logical
Operator
NOR
Jump Horizon, J
>= J
Flow Horizon, T
>= T
D
4
C
3
j
2
t
1
This block stops the simulation under any of the following events:
1. flow time ≥ maximum flow time specified by T.
2. jump time ≥ maximum number of jumps specified by J.
3. state of the hybrid system x is neither in C nor in D.
Under any of these events, the output of the logic operator
connected to the Stop block becomes one, stopping the
simulation.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Configuration
Before a simulation is started, the following parameters should be
defined
Determine the integrator scheme, zero-cross detection
settings, precision, and other tolerances. Using the default
settings does not always give the most efficient or most
accurate simulations. One way to edit these settings is to
open the Simulink Model, select
Simulation>Configuration Parameters>Solver
An easy way to adjust some settings is to include a line of
code in the initialization.m file like that given below.
% configuration of solver
RelTol = 1e-8; MaxStep = .001;
In this code, RelTol = 1e-8 and MaxStep = .001 define
variables for the relative tolerance and maximum step size of
the ODE solver, respectively.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Initialization
Double-click block labeled Double Click to Initialize to initialize
variables. This calls initialization.m which defines the initial
conditions by defining the initial values of
the state components
any necessary parameters
the maximum flow time specified by T
the maximum number of jumps specified by J, and
tolerances used when simulating.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Postprocessing and Plotting solutions
Solutions are plotted by double-clicking on Double Click to Plot
Solutions block which calls the script postprocessing.m. The
script postprocessing.m may be changed to include the desired
postprocessing and solution plots.
The following functions are available to generate plots:
plotflows(t,j,x):
plots (in blue) the projection of the trajectory x onto the flow time
axis t.
The value of the trajectory for trivial flow intervals (zero
length) is marked with ∗ (in blue).
Dashed lines (in red) connect the value of the trajectory
before and after the jump.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Postprocessing and Plotting solutions
plotjumps(t,j,x):
plots (in red) the projection of the trajectory x onto the jump time
axis j.
The initial and final value of the trajectory on each flow
interval is denoted by ∗ (in red).
The continuous evolution of the trajectory on each flow
interval is depicted with a dashed line (in blue).
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
0
0.2
0.4
0.6
0.8
1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0
0.2
0.4
0.6
0.8
1
x1
x1
flows [t]
jumps [j]
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Postprocessing and Plotting solutions
plotHybridArc(t,j,x):
plots (in blue) the trajectory x on hybrid time domains.
The flow intervals indexed by the corresponding j are depicted
in the t − j plane (in red).
0
2
4
6
8
10
12
14
16
18
200 1 2 3 4
0
0.5
1
x1
t
j
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Using the HyEQ Simulink Toolbox
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation Procedure
The following procedure is used to simulate an example:
Step 1)
The main Simulink file HyEQsimulator.mdl is opened in
MATLAB/Simulink.
Step 2)
The Embedded MATLAB function blocks f, C, g, D are edited. In
each embedded function block, global variables must be added as
input variables and defined as parameters by selecting Tools>Edit
Data/Ports>Add>Data. Name the variables the same as they are
called in the function block, and set the scope to Parameter.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation Procedure
Step 3)
The initialization script initialization.m is edited. The flow
time and jump horizons, T and J are defined as well as the initial
conditions for the state vector x0, a rule for jumps, and the
tolerances for simulation.
Step 4)
The integrator system is double-clicked and the flow time T, jump
horizon J, and initial condition x0 are defined on the window that
appears.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation Procedure
Step 5)
The simulation stop time and simulation tolerances in the Simulink
model are set to the values defined in initialization.m by
selecting Simulation>Configuration Parameters and inputing
the values T, RelTol, and MaxStep.
Step 6)
The postprocessing script postprocessing.m is to be edited.
Flows and jumps may be plotted by calling the functions
plotflows.m and plotjumps.m, respectively. The hybrid arc may
be plotted by calling the function plotHybridArc.m.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation Procedure
Step 7)
The block labeled Double Click to Initialize is double-clicked to
initialize the variables.
Step 8)
The play button is clicked in the Simulink model to run the
simulation.
Step 9)
The block labeled Double Click to Plot Solutions is
double-clicked to plot the desired solutions.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: initialization.m
%initialization for fireflies example
% initial conditions
tau1_0 = .5;
tau2_0 = 0;
%biological coefficient
e = 0.3;
% simulation horizon
T = 15; J = 15;
% rule for jumps
rule = 1; % priority for jumps
%solver tolerances
RelTol = 1e-8;
MaxStep = .005;
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Flow Map
fi(τi, ui) := 1
function taudot = f(tau, u)
% flow map
taudot = 1;
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Flow Set
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
function v = C(tau, u)
% flow set
if ((tau >= 0) && (tau <= 1)) || ((u >= 0) && (u <= 1))
v = 1; % report flow
else
v = 0; % do not report flow
end
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Jump Map
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
function out = g(tau, u, e)
% jump map
if (1+e)*tau <= 1
tauplus = (1+e)*tau;
else (1+e)*tau >= 1
tauplus = 0;
end
out = tauplus;
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Back to Synchronization of Two Fireflies
The synchronization of the fireflies can be modeled as an
interconnection of two hybrid systems where each firefly can be
modeled as a hybrid system given by
fi(τi, ui) := 1
Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1}
gi(τi, ui) :=
(1 + ε)τi if (1 + ε)τi ≤ 1
0 if (1 + ε)τi ≥ 1
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
A state value of τi = 1 corresponds to a flash, and after each
flash, the firefly automatically resets its timer to zero.
When one of the fireflies flashes, the other tries to synchronize
its flash by jumping ahead in its periodic cycle. This behavior
is captured by the coefficient ε.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Jump Set
Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1}
function v = D(tau, u)
% jump set
if (tau >= 1) || (u >= 1) % jump condition
v = 1; % report jump
else
v = 0; % do not report jump
end
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
0 2 4 6 8 10 12
0
0.5
1
1.5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0
0.5
1
1.5
τ1
τ1
flows [t]
jumps [j]
Figure 6 : Solution of firefly system
H1
0 2 4 6 8 10 12
0
0.5
1
1.5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0
0.5
1
1.5
τ2
τ2
flows [t]
jumps [j]
Figure 7 : Solution of firefly system
H2
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
0 2 4 6 8 10 12
0
0.5
1
1.5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0
0.5
1
1.5
τ1,τ2τ1,τ2
flows [t]
jumps [j]
Figure 8 : Solution of firefly systemfor interconnection of H1 and H2
A solution to the interconnection of hybrid systems H1 and H2
with T = 15, J = 15, rule = 1, ε = 0.3 is depicted in Figure 8.
The fireflies initially flash out of phase with one another and then
synchronize to flash with same phase.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation of N interconnected fireflies
The same procedure can be
used to simulate any number of
fireflies. The main system can
be copied N times, and then
those systems can be
interconnected where the input
to every system is the
maximum state value of all of
the outputs. This
interconnection is shown for 10
fireflies in Figure 9.
This model simulates the synchronization of ten fireflies.
x6
x5
x4
x3
x2
j1
j10
j9
t1
j8
j7
j6
j5
j4
j3
j2
t10
t9
t8
x1
t7
t6
t5
t4
t3
t2
x10
x9
x8
x7
Max
u y
fcn
Hybrid System 9
x
t
j
x−(int)
u
Hybrid System 8
x
t
j
x−(int)
u
Hybrid System 7
x
t
j
x−(int)
u
Hybrid System 6
x
t
j
x−(int)
u
Hybrid System 5
x
t
j
x−(int)
u
Hybrid System 4
x
t
j
x−(int)
u
Hybrid System 3
x
t
j
x−(int)
u
Hybrid System 2
x
t
j
x−(int)
u
Hybrid System 10
x
t
j
x−(int)
u
Hybrid System 1
x
t
j
x−(int)
u
Double Click
to Initialize
Double Click to
Plot Solutions
Figure 9 : Model for 10 Fireflies
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Simulation of 10 interconnected fireflies
0 5 10 15
0
0.5
1
1.5
0 1 2 3 4 5 6 7 8 9 101112131415161718192021222324252627282930313233343536373839404142434445
0
0.5
1
1.5
ττ
flows [t]
jumps [j]
Figure 10 : Solution for 10 fireflies with T = 15, J = 45, rule = 1,
ε = 0.1
It can be seen that all 10 fireflies start with different initial
conditions and eventually all synchronize.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Conclusion
HyEQ Toolbox installation files can be found at MATLAB
Central’s file exchange website by accessing
http://www.mathworks.com/matlabcentral
and searching for HyEQ Toolbox or through the “Software” tab at
the author’s website
http://www.u.arizona.edu/~sricardo/.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Conclusion
HyEQ Toolbox installation files can be found at MATLAB
Central’s file exchange website by accessing
http://www.mathworks.com/matlabcentral
and searching for HyEQ Toolbox or through the “Software” tab at
the author’s website
http://www.u.arizona.edu/~sricardo/.
We would like to thank Giampiero Campa for his thoughtful
feedback and advice as well as Torstein Ingebrigtsen Bo for his
comments and first version of the HyEQsolver script.
MATLAB/Simulink are registered trademarks of The MathWorks, Inc.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
References
[1] David A. Copp and Ricardo G. Sanfelice, Hybrid Equations
(HyEQ) Toolbox v1.0 - A Toolbox for Simulating Hybrid Systems
in MATLAB/Simulink. Hybrid Dynamics and Control Laboratory,
University of Arizona.
[2] http://control.ee.ethz.ch/~ifaatic/ex/example1.m.
Institut f¨ur Automatik - Automatic Control Laboratory, ETH
Zurich, 2011.
[3] R. Goebel, R. G. Sanfelice, and A. R. Teel, Hybrid dynamical
systems. IEEE Control Systems Magazine, 28-93, 2009.
[4] R. G. Sanfelice and A. R. Teel, Dynamical Properties of Hybrid
Systems Simulators. Automatica, 46, No. 2, 239–248, 2010.
[5] Sanfelice, R. G., Interconnections of Hybrid Systems: Some
Challenges and Recent Results Journal of Nonlinear Systems and
Applications, 111–121, 2011.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Extra Slides
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Conclusion
HyEQ Toolbox installation files can be found at MATLAB
Central’s file exchange website by accessing
http://www.mathworks.com/matlabcentral
and searching for HyEQ Toolbox or through the “Software” tab at
the author’s website
http://www.u.arizona.edu/~sricardo/.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Conclusion
HyEQ Toolbox installation files can be found at MATLAB
Central’s file exchange website by accessing
http://www.mathworks.com/matlabcentral
and searching for HyEQ Toolbox or through the “Software” tab at
the author’s website
http://www.u.arizona.edu/~sricardo/.
We would like to thank NSF and AFOSR for partially funding
this project, Giampiero Campa from The Mathworks for helpful
suggestions, and Torstein Ingebrigtsen Bo for his comments and
first version of the HyEQsolver script.
MATLAB/Simulink are registered trademarks of The MathWorks, Inc.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Examples
Sample hybrid systems simulated in the HyEQ Toolbox:
s1
s2
s4
s3
ell, r
il
c0
vc
ic
Hybrid
VDC
DC/AC
io so vg
−2
−1
1
2
0
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
Examples of dynamical systems that may be simulated in Simulink
without using an implementation like the HyEQ Toolbox are shown
below.
Systems with continuous states only, e.g.,
˙x1 = x2, ˙x2 = u,
which can be simulated by
ScopeIntegrator1
1
s
Integrator
1
s
u
1
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
Systems with discrete states only, e.g.,
q(t + 1) = q + 1,
which can be simulated by
Unit Delay
z
1
Scope
Constant
1
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
Certain systems with combined continuous and discrete
states, e.g.,
q(t + 1) = q + 1, ˙x = q
Unit Delay
z
1
Scope
Constant
Integrator
1
s
1
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Modeling Framework
Certain systems with combined continuous and discrete
states, e.g.,
q(t + 1) = q + 1, ˙x = q
Unit Delay
z
1
Scope
Constant
Integrator
1
s
1
However, if some of the system states evolve both continuously and
discretely (that is they evolve continuously but might also jump,
according to known hybrid state equations), then it might be easier
to simulate the system using the HyEQ toolbox.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: Several methods for simulation
As previously noted, there are multiple methods available in this
toolbox for simulating different hybrid systems. They include:
1. Simulink implementation with embedded functions:
for simulation of individual or interconnected hybrid systems
with or without inputs.
2. Simulink implementation with external functions:
for simulation of individual hybrid systems with or without
inputs without needing a C-compiler installed with MATLAB.
3. Lite simulator
for simulation of individual hybrid systems without inputs
straight from the command line.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
HyEQ Toolbox: No inputs
An implementation for HyEQ without inputs is as follows:
This model simulates a hybrid system.
j
3
t
2
x
1
jump set D
Interpreted
MATLAB Fcn
jump map g
Interpreted
MATLAB Fcn
flow set C
Interpreted
MATLAB Fcn
flow map f
Interpreted
MATLAB Fcn
Time
t
State
x
Jumps
j
Integrator System
f
C
g
D
x
t
j
x−
HS
x
t
j
Double Click
to Initialize
Double Click to
Plot Solutions
Figure 11 : MATLAB/Simulink implementation of a hybrid system
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
A Simulator for Hybrid Systems: No inputs
The data is implemented in using .m files. The data of the hybrid
system is coded as follows:
The flow set C is captured by the function C.m
The flow map f is captured by the function f.m
The jump set D is captured by the function D.m
The jump map g is captured by the function g.m
Each of the blocks in Figure 11 implement the .m functions above.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
A Simulator for Hybrid Systems: No inputs
The data is implemented in using .m files. The data of the hybrid
system is coded as follows:
The flow set C is captured by the function C.m
The flow map f is captured by the function f.m
The jump set D is captured by the function D.m
The jump map g is captured by the function g.m
Each of the blocks in Figure 11 implement the .m functions above.
A stand alone script called HyEQsolver.m is also available. It
evaluates these functions and finds a solution to the hybrid system
with the given dynamics.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Bouncing Ball
For the simulation of the bouncing ball system with a constant
input and regular data given by
f(x, u) :=
x2
−γ
, C := (x, u) ∈ R2
× R : x1 ≥ u
g(x, u) :=
u
−λx2
, D := (x, u) ∈ R2
× R : x1 ≤ u , x2 ≤ 0
γ > 0 is the gravity constant, u is the input constant, and
λ ∈ [0, 1) is the restitution coefficient. An input was chosen to be
u(t, j) = 0.2 for all (t, j). The constants for the bouncing ball
system are chosen to be γ = 9.81 and λ = 0.8.
Note that for this example, the jump set may be implemented
using Simulink logic blocks with Zero Cross Detection. See the
figure below.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Bouncing Ball
This model simulates a hybrid system with input
x (int)
4
j
3
t
2
x
1
u
jump map g
x
u
xplus
g
flow set C
x
u
v
C
flow map f
x
u
xdot
f
Time
t
Terminator
State
x
<=
<=
AND
Jumps
j
Integrator System
f
C
g
D
x
t
j
x
HSu
x
t
j
x (int)
u
u1
1
Double Click
to Initialize
Double Click to
Plot Solutions
Figure 12 : Implementation with Simulink logic blocks for jump set
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Bouncing Ball
A solution to the bouncing ball system from x(0, 0) = [1, 0] and
with T = 10, J = 20, rule = 1, is depicted in Figure 13 (height)
and Figure 14 (velocity). Both the projection onto t and j are
shown. Figure 15 depicts the corresponding hybrid arc.
These simulations reflect the expected behavior of the bouncing
ball model. Note the only difference between this example and the
example of a bouncing ball without a constant input is that, in this
example, the ball bounces on a platform at a height of the chosen
input value 0.2 rather than the ground at a value of 0.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Bouncing Ball
0 0.5 1 1.5 2 2.5 3 3.5 4
0.2
0.4
0.6
0.8
1
flows [t]
x
1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0.2
0.4
0.6
0.8
1
jumps [j]
x
1
Figure 13 : Solution of Bouncing
Ball Example: height
0 0.5 1 1.5 2 2.5 3 3.5 4
−4
−2
0
2
4
flows [t]
x2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
−4
−2
0
2
4
jumps [j]
x2
Figure 14 : Solution of Bouncing
Ball Example: velocity
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Bouncing Ball
0
5
10
15
20
0 0.5 1 1.5 2 2.5 3 3.5
0
0.5
1
x1
t
j
Figure 15 : Hybrid arc corresponding to a solution of Bouncing Ball
Example: height
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Outline
(1) Installation of the simulator (step by step)
(2) C compiler?
(3) A couple of examples from scratch (Boost converter (from
Thomas Theunisse))
(3.1) File organization
(3.2) Variables
(3.3) Debuging
(4) The use of the plot commands
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(1)] Installation of the simulator (step by step)
HyEQ Toolbox installation files can be found at MATLAB
Central’s file exchange website by accessing
http://www.mathworks.com/matlabcentral
and searching for HyEQ Toolbox or through the “Software” tab at
the author’s website
http://www.u.arizona.edu/~sricardo/.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 1
C iL
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 1
C iL
(2) ˙iL = − 1
LVc + 1E
L
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 1
C iL
(2) ˙iL = − 1
LVc + 1E
L
(3) ˙E = 0
(4) ˙q = 0
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = ON, iD = 0, q = 2) (MODE 2)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = ON, iD = 0, q = 2) (MODE 2)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 0
C iL
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = ON, iD = 0, q = 2) (MODE 2)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 0
C iL
(2) ˙iL = − 0
LVc + 1E
L
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = ON, iD = 0, q = 2) (MODE 2)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 0
C iL
(2) ˙iL = − 0
LVc + 1E
L
(3) ˙E = 0
(4) ˙q = 0
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter, (S = OFF, iD = 0, q = 1) (MODE 3)
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + 0
C iL
(2) ˙iL = − 0
LVc + 0E
L
(3) ˙E = 0
(4) ˙q = 0
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
[(3)] Examples
Example: Boost converter
Boost converter,
E
S
L
C
R
+ -
VL
VC
iL
+ -
VD
D
+
−
iDiS
Let’s write down the equations of the system...
(1) ˙Vc = − 1
RC Vc + ρ(q)
C iL
(2) ˙iL = −ρ(q)
L Vc + λ(q)E
L
(3) ˙E = 0
(4) ˙q = 0
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Boost converter
Flow Map
F(Vc, iL, E, q) =





− 1
RC Vc + ρ(q)
C iL
−ρ(q)
L Vc + λ(q)E
L
0
0





where
ρ(q) =
0 if q ∈ {2, 3}
1 if q = 1
λ(q) =
0 if q = 3
1 if q =∈ {1, 2}
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Boost converter
Flow Set
C :={x ∈ 4
| q = 1, u = 0}
∪ {x ∈ 4
| q = 2, u = 1}
∪ {x ∈ 4
| q = 3, u = 0, iL = 0}
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
Example: Boost converter
Jump Set and Jump Map
mode  mode 
mode 
S=
S=
S=0,
iL
=0,
vc
>E
vc
<E
iL
=0,
(S=0)
(S=0)
(S=)
S=0,
iL
=0
iL
>0
Figure 16 : Switching behavior of the Boost circuit.
Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013

More Related Content

Similar to HybridSimulatorPresentation

Secrets of supercomputing
Secrets of supercomputingSecrets of supercomputing
Secrets of supercomputing
fikrul islamy
 
Secrets of supercomputing
Secrets of supercomputingSecrets of supercomputing
Secrets of supercomputing
fikrul islamy
 
DMDW Lesson 08 - Further Data Mining Algorithms
DMDW Lesson 08 - Further Data Mining AlgorithmsDMDW Lesson 08 - Further Data Mining Algorithms
DMDW Lesson 08 - Further Data Mining Algorithms
Johannes Hoppe
 

Similar to HybridSimulatorPresentation (20)

Secrets of supercomputing
Secrets of supercomputingSecrets of supercomputing
Secrets of supercomputing
 
Secrets of supercomputing
Secrets of supercomputingSecrets of supercomputing
Secrets of supercomputing
 
DMDW Lesson 08 - Further Data Mining Algorithms
DMDW Lesson 08 - Further Data Mining AlgorithmsDMDW Lesson 08 - Further Data Mining Algorithms
DMDW Lesson 08 - Further Data Mining Algorithms
 
THE ACTIVE CONTROLLER DESIGN FOR ACHIEVING GENERALIZED PROJECTIVE SYNCHRONIZA...
THE ACTIVE CONTROLLER DESIGN FOR ACHIEVING GENERALIZED PROJECTIVE SYNCHRONIZA...THE ACTIVE CONTROLLER DESIGN FOR ACHIEVING GENERALIZED PROJECTIVE SYNCHRONIZA...
THE ACTIVE CONTROLLER DESIGN FOR ACHIEVING GENERALIZED PROJECTIVE SYNCHRONIZA...
 
Machine Learning - Simple Linear Regression
Machine Learning - Simple Linear RegressionMachine Learning - Simple Linear Regression
Machine Learning - Simple Linear Regression
 
ASL Lab Meeting Presentation 20/3/2013
ASL Lab Meeting Presentation 20/3/2013ASL Lab Meeting Presentation 20/3/2013
ASL Lab Meeting Presentation 20/3/2013
 
Large scale logistic regression and linear support vector machines using spark
Large scale logistic regression and linear support vector machines using sparkLarge scale logistic regression and linear support vector machines using spark
Large scale logistic regression and linear support vector machines using spark
 
HOP-Rec_RecSys18
HOP-Rec_RecSys18HOP-Rec_RecSys18
HOP-Rec_RecSys18
 
Hysys help only at myassignmenthelp.net
Hysys help only at myassignmenthelp.netHysys help only at myassignmenthelp.net
Hysys help only at myassignmenthelp.net
 
IEEE Fuzzy system Title and Abstract 2016
IEEE Fuzzy system Title and Abstract 2016 IEEE Fuzzy system Title and Abstract 2016
IEEE Fuzzy system Title and Abstract 2016
 
2012 05-10 kaiser
2012 05-10 kaiser2012 05-10 kaiser
2012 05-10 kaiser
 
ACTIVE CONTROLLER DESIGN FOR THE HYBRID SYNCHRONIZATION OF HYPERCHAOTIC XU AN...
ACTIVE CONTROLLER DESIGN FOR THE HYBRID SYNCHRONIZATION OF HYPERCHAOTIC XU AN...ACTIVE CONTROLLER DESIGN FOR THE HYBRID SYNCHRONIZATION OF HYPERCHAOTIC XU AN...
ACTIVE CONTROLLER DESIGN FOR THE HYBRID SYNCHRONIZATION OF HYPERCHAOTIC XU AN...
 
Thesis
ThesisThesis
Thesis
 
Is there a free lunch for cloud-based evolutionary algorithms?
Is there a free lunch for cloud-based evolutionary algorithms?Is there a free lunch for cloud-based evolutionary algorithms?
Is there a free lunch for cloud-based evolutionary algorithms?
 
HYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBMHYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBM
 
HYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBMHYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBM
 
HYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBMHYPERCHAOS SYNCHRONIZATION USING GBM
HYPERCHAOS SYNCHRONIZATION USING GBM
 
Hyperchaos Synchronization Using GBM
Hyperchaos Synchronization Using GBMHyperchaos Synchronization Using GBM
Hyperchaos Synchronization Using GBM
 
Introduction to OpenVX
Introduction to OpenVXIntroduction to OpenVX
Introduction to OpenVX
 
RFC's impact on project using Kolmogorov model and Python
RFC's impact on project using Kolmogorov model and PythonRFC's impact on project using Kolmogorov model and Python
RFC's impact on project using Kolmogorov model and Python
 

HybridSimulatorPresentation

  • 1. Hybrid Equations (HyEQ) Toolbox A Toolbox for Simulation of Hybrid Dynamical Systems in MATLAB/Simulink R Ricardo G. Sanfelice, David A. Copp, and Pablo ˜Na˜nez Hybrid Dynamics and Control Lab (HDC Lab) Department of Aerospace and Mechanical Engineering University of Arizona, USA Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 2. Hybrid Systems Hybrid systems combine behaviors that are typical of continuous-time dynamical systems with behaviors that are typical of discrete-time dynamical systems. In switched electrical circuits, voltages and currents that change continuously according to classical electrical network laws also change discontinuously due to switches opening or closing. Embedded systems and, more generally, systems involving both digital and analog components, execute software code discretely while interacting with their physical environments continuously. s1 s2 s4 s3 ell, r il c0 vc ic Hybrid VDC DC/AC io so vg Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 3. Hybrid Systems Hybrid systems combine behaviors that are typical of continuous-time dynamical systems with behaviors that are typical of discrete-time dynamical systems. Velocities in a multibody dynamical system change continuously according to Newton’s second law, but undergo instantaneous changes in velocity and momentum due to collisions. The concentrations in genetic networks grow or decay continuously according to binary variables that change between 1 and 0 when the concentrations reach certain thresholds. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 4. Hybrid Systems Hybrid systems combine behaviors that are typical of continuous-time dynamical systems with behaviors that are typical of discrete-time dynamical systems. Impulsive oscillators capture the dynamics of certain networked biological systems, such as fireflies and crickets, by means of timers with event-driven resets. Modern control algorithms often lead to both kinds of behavior, due to either digital components used in implementation or logic and decision making encoded in the control algorithm. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 5. Outline 1 Hybrid Systems Challenges to Simulation 2 A Toolbox for Simulation of Hybrid Systems Hybrid Equations (HyEQ) Toolbox Overview Modeling Framework and Contributions 3 Components and Usage of the HyEQ Toolbox Simulating Hybrid Systems Simulating Interconnections Internals Configuration, Initialization, Postprocessing Simulation Procedure 4 Illustrative Example 5 Conclusion and References Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 6. Simulation of hybrid systems Hybrid systems demand simulation algorithms capable of Numerically integrate differential equations Locate, detect, and manage events Reset state variables discretely Generate a time axis that jointly parameterizes continuous and discrete behavior Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 7. Simulation of hybrid systems Hybrid systems demand simulation algorithms capable of Numerically integrate differential equations Locate, detect, and manage events Reset state variables discretely Generate a time axis that jointly parameterizes continuous and discrete behavior Challenges to Simulation of Hybrid Systems: Simultaneous simulation of continuous and discrete dynamics Accurate event location and detection Large number of events/jumps in finite time (e.g., Zeno) Multiple events at the same time Time sharing in simulation of interconnected hybrid systems Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 8. Hybrid Equations (HyEQ) Toolbox A hybrid simulator for MATLAB/Simulink called Hybrid Equations (HyEQ) Toolbox with the following capabilities is introduced and illustrated in examples: Simulation of autonomous and non-autonomous hybrid systems given by hybrid equations Modular simulation of interconnections of hybrid systems Simulation of systems with Zeno behavior and multiple jumps at an instant Generation of hybrid time axis indexing jumps The HyEQ Toolbox is designed to simulate hybrid systems written in a hybrid system framework amenable for control theory for which a theory of robust stability has recently been developed. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 9. HyEQ Toolbox: Modeling Framework Hybrid systems are given by the hybrid equations H : x ∈ Rn , u ∈ Rm ˙x = f(x, u) (x, u) ∈ C x+ = g(x, u) (x, u) ∈ D or H = (C, f, D, g) for short. C D Rn ˙x = f(x, u) g(x, u) × Solutions are functions parameterized by hybrid time (t, j): Flows parameterized by t ∈ R≥0 := [0, +∞) Jumps parameterized by j ∈ N≥0 := {0, 1, 2, . . .} Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 10. HyEQ Toolbox: Modeling Framework A hybrid system is a dynamical system with continuous and discrete dynamics. Modeling Framework: A hybrid system H on a state space Rn and input space Rm is defined by the following objects: A set C ⊂ Rn × Rm called the flow set. A function f : Rn → Rn called the flow map. A set D ⊂ Rn × Rm called the jump set. A function g : Rn → Rn called the jump map. The flow map f defines the continuous dynamics on the flow set C. The jump map g defines the discrete dynamics on the jump set D. H can be explicitly denoted as H = (C, f, D, g). Hybrid systems may have states that evolve both continuously and jump, in which case the boundary of the flow and jump set intersect. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 11. Contributions to Hybrid Systems Theory Autonomous Hybrid Systems Notion of Solution Lyapunov Theory and Invariance Robustness to Small Perturbations Nonautonomus Hybrid Systems Notion of Solution Control Lyapunov Functions ISS and I/O Stability Interconnections Small gain Theorems Hybrid Control Design Tracking Control Passivity-based Control Minimum-norm Control Backstepping Numerical Simulation Simulation theory Simulation toolbox Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 12. HyEQ Toolbox: Examples Examples of such systems include: a bouncing ball on a moving platform, Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 13. HyEQ Toolbox: Examples a DC/AC inverter, s1 s2 s4 s3 ell, r il c0 vc ic Hybrid VDC DC/AC io so vg Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 14. HyEQ Toolbox: Examples a vehicle traveling along a track with boundaries, −2 −1 1 2 0 the synchronization of multiple fireflies flashing. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 15. Example: Impulsive biological oscillators Figure 1 shows how two fireflies can be modeled as periodic oscillators with timers. The timer in each firefly is denoted τ1 and τ2, respectively. The stars indicate when resets of the timers occur. The “timer threshold” defines when the timers are reset to zero, which corresponds to the respective firefly flashing. τ1, τ2 time synchronizationreset firefly1 firefly2threshold Figure 1 : Fireflies with hybrid dynamics synchronizing Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 16. Example: Impulsive biological oscillators A model for interacting fireflies can be described as a hybrid system. The fireflies are modeled mathematically as impulsive oscillators with timer variables exhibiting impulses due to flashes. In this way, the oscillator in a firefly exhibits continuous and discrete dynamics: The flow map f enforces that the timer state counts time during continuous evolution. The jump map g induces jumps in the timer state as follows: it resets the timer to zero when the firefly flashes. it is incremented a small amount when a neighboring firefly flashes. The flow set C determines when the timer should count time while the flow set D triggers the jumps of the timer. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 17. Components and Usage of the HyEQ Toolbox Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 18. Hybrid Equations (HyEQ) Toolbox The Hybrid Equations (HyEQ) Toolbox includes the following: HyEQsolver.m lite simulator script for systems w/o inputs. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 19. Hybrid Equations (HyEQ) Toolbox The Hybrid Equations (HyEQ) Toolbox includes the following: Simulink library for systems w/inputs and interconnections. HS with external functions HS with embedded functions HS with embedded functions and inputs Time t State x J umps jHS x t j Time t State x J umps jHS x t j u Time t Terminator State x J umps j HSu x t j x−(int) u u HSu x t j x−(int) u HSu x t j x−(int) u 1 2 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 20. HyEQ Toolbox: Modeling Framework A Simulink implementation in the HyEQ Toolbox is shown below. This model simulates a hybrid system with input x−(int) 4 j 3 t 2 x 1 u jump set D x u v D jump map g x u xplus g flow set C x u v C flow map f x u xdot f Time t Terminator State x Jumps j Integrator System f C g D x t j x− HSu x t j x−(int) u u1 1 Double Click to Initialize Double Click to Plot Solutions Figure 2 : MATLAB/Simulink implementation of a hybrid system with inputs. The blocks f and C implement the flow equation while the blocks g and D implement the jump equation. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 21. Simulating Hybrid Systems in the HyEQ Toolbox In the HyEQ Toolbox, the hybrid equations above are implemented in Simulink using Embedded MATLAB Functions. The data of the hybrid system is coded as follows: The flow set C is captured by the embedded function C The flow map f is captured by the embedded function f The jump set D is captured by the embedded function D The jump map g is captured by the embedded function g Each of the blocks in Figure 2 implement the embedded functions above. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 22. Simulating Interconnections in the HyEQ Toolbox The simulator implementation in HyEQ with inputs uses embedded MATLAB functions within the main Simulink file HyEQsimulator.mdl. This allows the user to modify the data of each hybrid system inside the model without having to edit several files. With such an implementation, multiple hybrid systems can be incorporated in a single Simulink file. Then, interconnections of N hybrid systems is possible. Each systems can be identical, as in the case of multiple fireflies synchronizing flashing, or they can be different, such as a bouncing ball impacting on a moving floor, which can be interpreted as an interconnection of two systems. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 23. Simulating Interconnections in the HyEQ Toolbox In the model shown below, the input of the second system is defined as the output of the first system, and viceversa. Other types of interconnections are also possible. This model simulates interconnected hybrid systems. time1 t2 time t1 state1 x2 state x1 jumps1 j2 jumps j1 Hybrid System 2 x t j x−(int) u Hybrid System 1 x t j x−(int) u Double Click to Initialize Double Click to Plot Solutions Figure 3 : Implementation of interconnected hybrid systems, H1 and H2. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 24. Simulating Interconnections in the HyEQ Toolbox Figure 4 : Bouncing ball on a moving floor 0 2 4 6 8 10 12 14 16 18 0.2 0.4 0.6 0.8 1 0 2 4 6 8 10 12 14 16 18 −1 −0.5 0 0.5 1 heightvelocity flows [t] flows [t] Figure 5 : Simulation trajectories: height and velocity Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 25. Hybrid Equations (HyEQ) Toolbox The Hybrid Equations (HyEQ) Toolbox includes the following: plotflows.m, plotjumps.m, plotHybridArc.m files for plotting solutions, initialization.m, postprocessing.m files for configuring the simulation and solutions, Files for several examples of individual and interconnected hybrid systems. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 26. Internal Structure of Simulink Implementation Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 27. Internals of the HyEQ Toolbox simulator Four basic blocks are used to define the dynamics of the hybrid system H: Flow map f Flow set C Jump map g Jump set D x u v D jump map g x u xplus g x u v C flow map f x u xdot f Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 28. Integrator System x− 4 j 3 t 2 x 1 Update logic g(x−,u) j− t− update law Stop logic t j C D stop Stop Simulation STOP Save In1 In2 Jump logic C D r jump 1 s xo ICx0 [0; 0; x0(:)] ICx [x0] Constant save CT dynamics f(x,u) dot D 4 g 3 C 2 f 1 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 29. CT Dynamics dot 1 Jumps 0 Flows 1 f(x,u) 1 This block defines the continuous dynamics by assembling the time derivative of the state [t j x ] . States t and j are considered states of the system because they need to be updated throughout the simulation in order to keep track of the time and number of jumps. The dynamics of these states is given by ˙t = 1, ˙j = 0, ˙x = f(x, u) . Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 30. Jump Logic rule=1: out = D rlule=2: out = D and ~C rule=3: out = (D and ~C) or (D and C and r>0.5) other : out = 0 jump 1 jump Multiport Switch 1 2 3 * AND OR NOT AND 0 rule Compare To Constant >= 0.5 r 3 D 2 C 1 The inputs are the outputs of blocks C and D indicating whether the state is in those sets or not, and a random signal with uniform distribution in [0, 1]. Output of 1 indicates a jump of H and triggers a reset of the integrator. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 31. Update Logic update law 1 1 t− 3 j− 2 g(x−,u) 1 The update logic uses the state port information of the integrator. This port reports the value of the state of the integrator, [t j x ] , at the exact instant that the reset condition becomes true. The flow time t is kept constant at jumps and j is incremented by one. More precisely: t+ = t− , j+ = j− + 1, x+ = g(x− , u) where [t− j− x− ] is the state that triggers the jump. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 32. Stop Logic stop 1 Logical Operator1 OR Logical Operator NOR Jump Horizon, J >= J Flow Horizon, T >= T D 4 C 3 j 2 t 1 This block stops the simulation under any of the following events: 1. flow time ≥ maximum flow time specified by T. 2. jump time ≥ maximum number of jumps specified by J. 3. state of the hybrid system x is neither in C nor in D. Under any of these events, the output of the logic operator connected to the Stop block becomes one, stopping the simulation. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 33. Configuration Before a simulation is started, the following parameters should be defined Determine the integrator scheme, zero-cross detection settings, precision, and other tolerances. Using the default settings does not always give the most efficient or most accurate simulations. One way to edit these settings is to open the Simulink Model, select Simulation>Configuration Parameters>Solver An easy way to adjust some settings is to include a line of code in the initialization.m file like that given below. % configuration of solver RelTol = 1e-8; MaxStep = .001; In this code, RelTol = 1e-8 and MaxStep = .001 define variables for the relative tolerance and maximum step size of the ODE solver, respectively. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 34. Initialization Double-click block labeled Double Click to Initialize to initialize variables. This calls initialization.m which defines the initial conditions by defining the initial values of the state components any necessary parameters the maximum flow time specified by T the maximum number of jumps specified by J, and tolerances used when simulating. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 35. Postprocessing and Plotting solutions Solutions are plotted by double-clicking on Double Click to Plot Solutions block which calls the script postprocessing.m. The script postprocessing.m may be changed to include the desired postprocessing and solution plots. The following functions are available to generate plots: plotflows(t,j,x): plots (in blue) the projection of the trajectory x onto the flow time axis t. The value of the trajectory for trivial flow intervals (zero length) is marked with ∗ (in blue). Dashed lines (in red) connect the value of the trajectory before and after the jump. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 36. Postprocessing and Plotting solutions plotjumps(t,j,x): plots (in red) the projection of the trajectory x onto the jump time axis j. The initial and final value of the trajectory on each flow interval is denoted by ∗ (in red). The continuous evolution of the trajectory on each flow interval is depicted with a dashed line (in blue). 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0 0.2 0.4 0.6 0.8 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0 0.2 0.4 0.6 0.8 1 x1 x1 flows [t] jumps [j] Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 37. Postprocessing and Plotting solutions plotHybridArc(t,j,x): plots (in blue) the trajectory x on hybrid time domains. The flow intervals indexed by the corresponding j are depicted in the t − j plane (in red). 0 2 4 6 8 10 12 14 16 18 200 1 2 3 4 0 0.5 1 x1 t j Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 38. Using the HyEQ Simulink Toolbox Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 39. Simulation Procedure The following procedure is used to simulate an example: Step 1) The main Simulink file HyEQsimulator.mdl is opened in MATLAB/Simulink. Step 2) The Embedded MATLAB function blocks f, C, g, D are edited. In each embedded function block, global variables must be added as input variables and defined as parameters by selecting Tools>Edit Data/Ports>Add>Data. Name the variables the same as they are called in the function block, and set the scope to Parameter. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 40. Simulation Procedure Step 3) The initialization script initialization.m is edited. The flow time and jump horizons, T and J are defined as well as the initial conditions for the state vector x0, a rule for jumps, and the tolerances for simulation. Step 4) The integrator system is double-clicked and the flow time T, jump horizon J, and initial condition x0 are defined on the window that appears. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 41. Simulation Procedure Step 5) The simulation stop time and simulation tolerances in the Simulink model are set to the values defined in initialization.m by selecting Simulation>Configuration Parameters and inputing the values T, RelTol, and MaxStep. Step 6) The postprocessing script postprocessing.m is to be edited. Flows and jumps may be plotted by calling the functions plotflows.m and plotjumps.m, respectively. The hybrid arc may be plotted by calling the function plotHybridArc.m. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 42. Simulation Procedure Step 7) The block labeled Double Click to Initialize is double-clicked to initialize the variables. Step 8) The play button is clicked in the Simulink model to run the simulation. Step 9) The block labeled Double Click to Plot Solutions is double-clicked to plot the desired solutions. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 43. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 44. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 45. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 46. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 47. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 48. Example: initialization.m %initialization for fireflies example % initial conditions tau1_0 = .5; tau2_0 = 0; %biological coefficient e = 0.3; % simulation horizon T = 15; J = 15; % rule for jumps rule = 1; % priority for jumps %solver tolerances RelTol = 1e-8; MaxStep = .005; Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 49. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 50. Example: Flow Map fi(τi, ui) := 1 function taudot = f(tau, u) % flow map taudot = 1; Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 51. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 52. Example: Flow Set Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} function v = C(tau, u) % flow set if ((tau >= 0) && (tau <= 1)) || ((u >= 0) && (u <= 1)) v = 1; % report flow else v = 0; % do not report flow end Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 53. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 54. Example: Jump Map gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 function out = g(tau, u, e) % jump map if (1+e)*tau <= 1 tauplus = (1+e)*tau; else (1+e)*tau >= 1 tauplus = 0; end out = tauplus; Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 55. Example: Back to Synchronization of Two Fireflies The synchronization of the fireflies can be modeled as an interconnection of two hybrid systems where each firefly can be modeled as a hybrid system given by fi(τi, ui) := 1 Ci := {(τi, ui) : 0 ≤ τi ≤ 1} ∩ {(τi, ui) : 0 ≤ ui ≤ 1} gi(τi, ui) := (1 + ε)τi if (1 + ε)τi ≤ 1 0 if (1 + ε)τi ≥ 1 Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} A state value of τi = 1 corresponds to a flash, and after each flash, the firefly automatically resets its timer to zero. When one of the fireflies flashes, the other tries to synchronize its flash by jumping ahead in its periodic cycle. This behavior is captured by the coefficient ε. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 56. Example: Jump Set Di := {(τi, ui) : τi ≥ 1} ∪ {(τi, ui) : ui ≥ 1} function v = D(tau, u) % jump set if (tau >= 1) || (u >= 1) % jump condition v = 1; % report jump else v = 0; % do not report jump end Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 57. 0 2 4 6 8 10 12 0 0.5 1 1.5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0.5 1 1.5 τ1 τ1 flows [t] jumps [j] Figure 6 : Solution of firefly system H1 0 2 4 6 8 10 12 0 0.5 1 1.5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0.5 1 1.5 τ2 τ2 flows [t] jumps [j] Figure 7 : Solution of firefly system H2 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 58. 0 2 4 6 8 10 12 0 0.5 1 1.5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0.5 1 1.5 τ1,τ2τ1,τ2 flows [t] jumps [j] Figure 8 : Solution of firefly systemfor interconnection of H1 and H2 A solution to the interconnection of hybrid systems H1 and H2 with T = 15, J = 15, rule = 1, ε = 0.3 is depicted in Figure 8. The fireflies initially flash out of phase with one another and then synchronize to flash with same phase. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 59. Simulation of N interconnected fireflies The same procedure can be used to simulate any number of fireflies. The main system can be copied N times, and then those systems can be interconnected where the input to every system is the maximum state value of all of the outputs. This interconnection is shown for 10 fireflies in Figure 9. This model simulates the synchronization of ten fireflies. x6 x5 x4 x3 x2 j1 j10 j9 t1 j8 j7 j6 j5 j4 j3 j2 t10 t9 t8 x1 t7 t6 t5 t4 t3 t2 x10 x9 x8 x7 Max u y fcn Hybrid System 9 x t j x−(int) u Hybrid System 8 x t j x−(int) u Hybrid System 7 x t j x−(int) u Hybrid System 6 x t j x−(int) u Hybrid System 5 x t j x−(int) u Hybrid System 4 x t j x−(int) u Hybrid System 3 x t j x−(int) u Hybrid System 2 x t j x−(int) u Hybrid System 10 x t j x−(int) u Hybrid System 1 x t j x−(int) u Double Click to Initialize Double Click to Plot Solutions Figure 9 : Model for 10 Fireflies Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 60. Simulation of 10 interconnected fireflies 0 5 10 15 0 0.5 1 1.5 0 1 2 3 4 5 6 7 8 9 101112131415161718192021222324252627282930313233343536373839404142434445 0 0.5 1 1.5 ττ flows [t] jumps [j] Figure 10 : Solution for 10 fireflies with T = 15, J = 45, rule = 1, ε = 0.1 It can be seen that all 10 fireflies start with different initial conditions and eventually all synchronize. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 61. Conclusion HyEQ Toolbox installation files can be found at MATLAB Central’s file exchange website by accessing http://www.mathworks.com/matlabcentral and searching for HyEQ Toolbox or through the “Software” tab at the author’s website http://www.u.arizona.edu/~sricardo/. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 62. Conclusion HyEQ Toolbox installation files can be found at MATLAB Central’s file exchange website by accessing http://www.mathworks.com/matlabcentral and searching for HyEQ Toolbox or through the “Software” tab at the author’s website http://www.u.arizona.edu/~sricardo/. We would like to thank Giampiero Campa for his thoughtful feedback and advice as well as Torstein Ingebrigtsen Bo for his comments and first version of the HyEQsolver script. MATLAB/Simulink are registered trademarks of The MathWorks, Inc. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 63. References [1] David A. Copp and Ricardo G. Sanfelice, Hybrid Equations (HyEQ) Toolbox v1.0 - A Toolbox for Simulating Hybrid Systems in MATLAB/Simulink. Hybrid Dynamics and Control Laboratory, University of Arizona. [2] http://control.ee.ethz.ch/~ifaatic/ex/example1.m. Institut f¨ur Automatik - Automatic Control Laboratory, ETH Zurich, 2011. [3] R. Goebel, R. G. Sanfelice, and A. R. Teel, Hybrid dynamical systems. IEEE Control Systems Magazine, 28-93, 2009. [4] R. G. Sanfelice and A. R. Teel, Dynamical Properties of Hybrid Systems Simulators. Automatica, 46, No. 2, 239–248, 2010. [5] Sanfelice, R. G., Interconnections of Hybrid Systems: Some Challenges and Recent Results Journal of Nonlinear Systems and Applications, 111–121, 2011. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 64. Extra Slides Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 65. Conclusion HyEQ Toolbox installation files can be found at MATLAB Central’s file exchange website by accessing http://www.mathworks.com/matlabcentral and searching for HyEQ Toolbox or through the “Software” tab at the author’s website http://www.u.arizona.edu/~sricardo/. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 66. Conclusion HyEQ Toolbox installation files can be found at MATLAB Central’s file exchange website by accessing http://www.mathworks.com/matlabcentral and searching for HyEQ Toolbox or through the “Software” tab at the author’s website http://www.u.arizona.edu/~sricardo/. We would like to thank NSF and AFOSR for partially funding this project, Giampiero Campa from The Mathworks for helpful suggestions, and Torstein Ingebrigtsen Bo for his comments and first version of the HyEQsolver script. MATLAB/Simulink are registered trademarks of The MathWorks, Inc. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 67. HyEQ Toolbox: Examples Sample hybrid systems simulated in the HyEQ Toolbox: s1 s2 s4 s3 ell, r il c0 vc ic Hybrid VDC DC/AC io so vg −2 −1 1 2 0 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 68. HyEQ Toolbox: Modeling Framework Examples of dynamical systems that may be simulated in Simulink without using an implementation like the HyEQ Toolbox are shown below. Systems with continuous states only, e.g., ˙x1 = x2, ˙x2 = u, which can be simulated by ScopeIntegrator1 1 s Integrator 1 s u 1 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 69. HyEQ Toolbox: Modeling Framework Systems with discrete states only, e.g., q(t + 1) = q + 1, which can be simulated by Unit Delay z 1 Scope Constant 1 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 70. HyEQ Toolbox: Modeling Framework Certain systems with combined continuous and discrete states, e.g., q(t + 1) = q + 1, ˙x = q Unit Delay z 1 Scope Constant Integrator 1 s 1 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 71. HyEQ Toolbox: Modeling Framework Certain systems with combined continuous and discrete states, e.g., q(t + 1) = q + 1, ˙x = q Unit Delay z 1 Scope Constant Integrator 1 s 1 However, if some of the system states evolve both continuously and discretely (that is they evolve continuously but might also jump, according to known hybrid state equations), then it might be easier to simulate the system using the HyEQ toolbox. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 72. HyEQ Toolbox: Several methods for simulation As previously noted, there are multiple methods available in this toolbox for simulating different hybrid systems. They include: 1. Simulink implementation with embedded functions: for simulation of individual or interconnected hybrid systems with or without inputs. 2. Simulink implementation with external functions: for simulation of individual hybrid systems with or without inputs without needing a C-compiler installed with MATLAB. 3. Lite simulator for simulation of individual hybrid systems without inputs straight from the command line. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 73. HyEQ Toolbox: No inputs An implementation for HyEQ without inputs is as follows: This model simulates a hybrid system. j 3 t 2 x 1 jump set D Interpreted MATLAB Fcn jump map g Interpreted MATLAB Fcn flow set C Interpreted MATLAB Fcn flow map f Interpreted MATLAB Fcn Time t State x Jumps j Integrator System f C g D x t j x− HS x t j Double Click to Initialize Double Click to Plot Solutions Figure 11 : MATLAB/Simulink implementation of a hybrid system Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 74. A Simulator for Hybrid Systems: No inputs The data is implemented in using .m files. The data of the hybrid system is coded as follows: The flow set C is captured by the function C.m The flow map f is captured by the function f.m The jump set D is captured by the function D.m The jump map g is captured by the function g.m Each of the blocks in Figure 11 implement the .m functions above. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 75. A Simulator for Hybrid Systems: No inputs The data is implemented in using .m files. The data of the hybrid system is coded as follows: The flow set C is captured by the function C.m The flow map f is captured by the function f.m The jump set D is captured by the function D.m The jump map g is captured by the function g.m Each of the blocks in Figure 11 implement the .m functions above. A stand alone script called HyEQsolver.m is also available. It evaluates these functions and finds a solution to the hybrid system with the given dynamics. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 76. Example: Bouncing Ball For the simulation of the bouncing ball system with a constant input and regular data given by f(x, u) := x2 −γ , C := (x, u) ∈ R2 × R : x1 ≥ u g(x, u) := u −λx2 , D := (x, u) ∈ R2 × R : x1 ≤ u , x2 ≤ 0 γ > 0 is the gravity constant, u is the input constant, and λ ∈ [0, 1) is the restitution coefficient. An input was chosen to be u(t, j) = 0.2 for all (t, j). The constants for the bouncing ball system are chosen to be γ = 9.81 and λ = 0.8. Note that for this example, the jump set may be implemented using Simulink logic blocks with Zero Cross Detection. See the figure below. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 77. Example: Bouncing Ball This model simulates a hybrid system with input x (int) 4 j 3 t 2 x 1 u jump map g x u xplus g flow set C x u v C flow map f x u xdot f Time t Terminator State x <= <= AND Jumps j Integrator System f C g D x t j x HSu x t j x (int) u u1 1 Double Click to Initialize Double Click to Plot Solutions Figure 12 : Implementation with Simulink logic blocks for jump set Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 78. Example: Bouncing Ball A solution to the bouncing ball system from x(0, 0) = [1, 0] and with T = 10, J = 20, rule = 1, is depicted in Figure 13 (height) and Figure 14 (velocity). Both the projection onto t and j are shown. Figure 15 depicts the corresponding hybrid arc. These simulations reflect the expected behavior of the bouncing ball model. Note the only difference between this example and the example of a bouncing ball without a constant input is that, in this example, the ball bounces on a platform at a height of the chosen input value 0.2 rather than the ground at a value of 0. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 79. Example: Bouncing Ball 0 0.5 1 1.5 2 2.5 3 3.5 4 0.2 0.4 0.6 0.8 1 flows [t] x 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0.2 0.4 0.6 0.8 1 jumps [j] x 1 Figure 13 : Solution of Bouncing Ball Example: height 0 0.5 1 1.5 2 2.5 3 3.5 4 −4 −2 0 2 4 flows [t] x2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 −4 −2 0 2 4 jumps [j] x2 Figure 14 : Solution of Bouncing Ball Example: velocity Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 80. Example: Bouncing Ball 0 5 10 15 20 0 0.5 1 1.5 2 2.5 3 3.5 0 0.5 1 x1 t j Figure 15 : Hybrid arc corresponding to a solution of Bouncing Ball Example: height Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 81. Outline (1) Installation of the simulator (step by step) (2) C compiler? (3) A couple of examples from scratch (Boost converter (from Thomas Theunisse)) (3.1) File organization (3.2) Variables (3.3) Debuging (4) The use of the plot commands Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 82. [(1)] Installation of the simulator (step by step) HyEQ Toolbox installation files can be found at MATLAB Central’s file exchange website by accessing http://www.mathworks.com/matlabcentral and searching for HyEQ Toolbox or through the “Software” tab at the author’s website http://www.u.arizona.edu/~sricardo/. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 83. [(3)] Examples E S L C R + - VL VC iL + - VD D + − iDiS Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 84. [(3)] Examples Example: Boost converter Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 85. [(3)] Examples Example: Boost converter Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 1 C iL Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 86. [(3)] Examples Example: Boost converter Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 1 C iL (2) ˙iL = − 1 LVc + 1E L Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 87. [(3)] Examples Example: Boost converter Boost converter, (S = OFF, iD > 0, q = 1) (MODE 1) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 1 C iL (2) ˙iL = − 1 LVc + 1E L (3) ˙E = 0 (4) ˙q = 0 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 88. [(3)] Examples Example: Boost converter Boost converter, (S = ON, iD = 0, q = 2) (MODE 2) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 89. [(3)] Examples Example: Boost converter Boost converter, (S = ON, iD = 0, q = 2) (MODE 2) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 0 C iL Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 90. [(3)] Examples Example: Boost converter Boost converter, (S = ON, iD = 0, q = 2) (MODE 2) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 0 C iL (2) ˙iL = − 0 LVc + 1E L Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 91. [(3)] Examples Example: Boost converter Boost converter, (S = ON, iD = 0, q = 2) (MODE 2) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 0 C iL (2) ˙iL = − 0 LVc + 1E L (3) ˙E = 0 (4) ˙q = 0 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 92. [(3)] Examples Example: Boost converter Boost converter, (S = OFF, iD = 0, q = 1) (MODE 3) E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + 0 C iL (2) ˙iL = − 0 LVc + 0E L (3) ˙E = 0 (4) ˙q = 0 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 93. [(3)] Examples Example: Boost converter Boost converter, E S L C R + - VL VC iL + - VD D + − iDiS Let’s write down the equations of the system... (1) ˙Vc = − 1 RC Vc + ρ(q) C iL (2) ˙iL = −ρ(q) L Vc + λ(q)E L (3) ˙E = 0 (4) ˙q = 0 Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 94. Example: Boost converter Flow Map F(Vc, iL, E, q) =      − 1 RC Vc + ρ(q) C iL −ρ(q) L Vc + λ(q)E L 0 0      where ρ(q) = 0 if q ∈ {2, 3} 1 if q = 1 λ(q) = 0 if q = 3 1 if q =∈ {1, 2} Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 95. Example: Boost converter Flow Set C :={x ∈ 4 | q = 1, u = 0} ∪ {x ∈ 4 | q = 2, u = 1} ∪ {x ∈ 4 | q = 3, u = 0, iL = 0} Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013
  • 96. Example: Boost converter Jump Set and Jump Map mode  mode  mode  S= S= S=0, iL =0, vc >E vc <E iL =0, (S=0) (S=0) (S=) S=0, iL =0 iL >0 Figure 16 : Switching behavior of the Boost circuit. Ricardo Sanfelice, David Copp, Pablo ˜Na˜nez - Hybrid Equations (HyEQ) Toolbox - April 9, 2013