Monitor State Activity Through Active State Data
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.
Types of Active State Data
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|
|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|
Enable Active State Data
You can enable active state data in either the Property Inspector or the Model Explorer.
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.
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.
Active State Data Properties
Type of state activity to monitor. Choose from these options:
Leaf state activity
Name of the active state data object. For more information, see Guidelines 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.
Define Enumerated Type Manually
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.
Set Scope for Active State Data
By default, active state data has a scope of
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 (Simulink) object. Modify the
properties of the object through the
CoderInfo property. For more
Define State Activity Enumeration Type
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 enumerated value for each state
name. The definition also contains an enumerated value that serves as the default
value for the enumeration data type and indicates that no substate is active. For
example, in the model
gear_state contains four child states that correspond
to the gears in a car:
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
You can customize this definition by reordering the enumerated values or renaming
the default value. Do not rename the enumerated values that correspond to states or
getDefaultValue method to specify a different default
value. For more information, see Define Enumerated Data Types.
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).
State Activity and Parallel States
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
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
Limitations for Active State Data
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
inoperator. 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.
- Simplify Stateflow Charts by Incorporating Active State Output
- View State Activity by Using the Simulation Data Inspector
- Check State Activity by Using the in Operator
- Guidelines for Naming Stateflow Objects
- Define State Activity Enumeration Type
- Base storage type for automatically created enumerations (Simulink Coder)