Active state data can simplify the design of some Stateflow® charts because you do not have to maintain data that is highly correlated to the chart hierarchy. When you enable active state data, Stateflow reports state activity through an output port to Simulink® or as local data in your chart. Using active state data, you can:
Avoid manual data updates reflecting chart activity.
View chart activity by using a scope, the Simulation Data Inspector, or the Logic Analyzer.
Log chart activity for diagnostics.
Drive other Simulink subsystems.
When you enable active state data, Stateflow creates a Boolean or enumerated data object to match the activity type.
Activity Type | Active State Data Type | Description |
---|---|---|
Self activity | Boolean | Is the state active? |
Child activity | Enumeration | Which child is active? |
Leaf state activity | Enumeration | Which leaf state is active? |
For self-activity of a chart or state, the data value is
true
when active and false
when inactive.
For child and leaf state activity, the data is an enumerated type. Stateflow can define the enumeration class or you can create the definition
manually. For more information, see Define State Activity Enumeration Type.
You can enable active state data for a Stateflow chart, state, state transition table, or atomic subchart. This table lists the activity types supported by each kind of Stateflow object.
Stateflow Object | Self-Activity | Child Activity | Leaf State Activity |
---|---|---|---|
Charts | Not supported | Supported | Supported |
States with exclusive (OR) decomposition | Supported | Supported | Supported |
States with parallel (AND) decomposition | Supported | Not supported | Not supported |
Atomic subcharts | Supported at the container level | Supported inside the subchart | Supported inside the subchart |
State transition tables | Not supported | Supported | Supported |
You can enable active state data in either the Property Inspector or the Model Explorer.
Property Inspector
To open the Property Inspector, in the Modeling tab, click Property Inspector.
In the Stateflow Editor canvas, select the Stateflow object to monitor.
In the Monitoring section of the Property Inspector, select the Create output for monitoring check box and edit the active state data properties.
Model Explorer
To open the Model Explorer, in the Modeling tab, click Model Explorer.
In the Model Hierarchy pane, double-click the Stateflow object to monitor.
In the Stateflow object pane, select the Create output for monitoring check box and edit the active state data properties.
Type of state activity to monitor. Choose from these options:
Self activity
Child activity
Leaf state activity
Name of the active state data object. For more information, see Rules for Naming Stateflow Objects.
Name of the enumerated data type for the active state data object. This property applies only to child and leaf state activity.
Specifies whether you define the enumerated data type manually. This property applies only to child and leaf state activity. For more information, see Define State Activity Enumeration Type.
By default, active state data has a scope of Output
.
Stateflow creates an output port on the chart block in the Simulink model.
To access active state data inside a Stateflow chart, change the scope to Local
in the Symbols
pane or in the Model Explorer. For more information, see Set Data Properties.
You can specify information for code generation by binding the local active state
data to a Simulink.Signal
object. Modify the
properties of the object through the CoderInfo
property. For more
information, see Simulink.CoderInfo
.
By default, Stateflow defines the enumeration data type for child and leaf activity. If you select the Define enumerated type manually check box and no enumeration data type definition exists, then Stateflow provides a link to create a definition. Clicking the Create enum definition from template link generates a customizable definition.
The enumeration data type definition contains one literal for each state name plus an extra
literal to indicate that no substate is active. For example, in the model
sf_car
,
the state gear_state
contains four child states that correspond
to the gears in a car: first
, second
,
third
, fourth
. The model specifies the
child activity data type with this enumeration class
definition:
classdef gearType < Simulink.IntEnumType enumeration None(0), first(1), second(2), third(3), fourth(4) end ... end
The base storage type for automatically created enumerations defaults to
Native Integer
. For a smaller memory footprint, in the Optimization pane of the Configuration Parameters dialog box, change the value of
the Base storage type for automatically created enumerations
field. For more information, see Base storage type for automatically created enumerations (Simulink Coder).
In states with parallel (AND) decomposition, child activity and leaf state activity are not available because the parallel substates are active simultaneously.
When you enable leaf state activity in a chart or state, a substate with parallel
(AND) decomposition is treated as a leaf state. For example, suppose that you enable
leaf state activity for this chart. Because state B
has parallel
decomposition, its substates B1
and B2
are
active simultaneously so B
is treated as a leaf state of the chart.
During simulation, a scope connected to the active state output
data shows the enumerated values for the leaf states A1
,
A2
, and B
.
Enabling child activity output for states that have no children results in an error at compilation and run time.
You cannot enable child or leaf state activity in charts or states with
parallel decomposition. To check state activity in substates of parallel
states, use the in
operator. For more information, see
Check State Activity by Using the in Operator.
Active state data is not supported in charts that use classic or Mealy semantics when the chart property Initialize outputs every time chart wakes up is enabled. For more information, see Initialize outputs every time chart wakes up.
Simulink.CoderInfo
| Simulink.Signal