Mode charts provide an intuitive way to model components characterized by a discrete set
of distinct operating modes. A car clutch is a good example of such a component. It has
several operating modes, with each mode being defined by a different set of equations. It
also has a transition logic, with a set of predicate conditions defining when the clutch
transitions from one mode to another. It is possible to model this component using primitive
constructs, such as event variables and
edge operators, but this way of
modeling lacks readability. For more complex components, the file becomes cumbersome and
unwieldy. Every time you model a component with multiple operating modes and transitions,
this component is a good candidate for a mode chart implementation.
These constructs in Simscape™ language let you perform mode chart modeling:
modecharts — A top-level section in a component file. It
can contain one or more
modechart — A named construct that contains a textual
representation of the mode chart: modes, transitions, and an optional initial mode
modes — A section in a mode chart that describes all the
operating modes. It can contain one or more
mode — A named construct that corresponds to a distinct
operating mode of the component, defined by a set of equations.
transitions — A section in a mode chart that describes
transitions between the operating modes, based on predicate conditions.
initial — An optional section in a mode chart that
specifies the initial operating mode, based on a predicate condition. If the predicate
is not true, or if the
initial section is missing, then the first
mode listed in the
modes section is active at the start of
In its simplest form, the hierarchical structure of a
section can look like this:
modecharts mc1 = modechart modes mode m1 equations ... end end mode m2 equations ... end end end transitions m1->m2 : p1; end initial m2 : p2; end end end
It contains one mode chart,
mc1, with two modes,
The system transitions from mode
m1 to mode
when the predicate condition
p1 is true.
If the predicate condition
p2 is true, the simulation starts in mode
m2, otherwise in mode
In this example, the
transitions section does not define a transition
m2 to mode
m1. Therefore, according to this
mode chart, once the system reaches mode
m2, it never goes back to mode
Use this simple example to understand how the mode charts work. For a more detailed example, see Switch with Hysteresis.
component ExampleChart inputs u1 = 0; end outputs y = 0; end parameters p = 1; end modecharts(ExternalAccess = observe) mc1 = modechart modes mode m1 equations y==1; end end mode m2 equations y==2; end end mode m3 equations y==3; end end end transitions m1->m2 : u1<0; m2->m3 : u1>0; end initial m2 : p<0; end end end end
The component implements a simple chart with three operating modes:
In the first mode, the output signal equals 1.
In the second mode, the output signal equals 2.
In the third mode, the output signal equals 3.
The component transitions from the first to the second mode when the input signal is negative, and from the second to the third mode when the input signal is positive.
The initial mode depends on the block parameter value: if parameter
is negative, simulation starts with the block in the second mode, otherwise — in the