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. This example shows how to simplify the design of a Stateflow chart by adding active state output data. For more information, see Monitor State Activity Through Active State Data.
In the legacy model
Stateflow chart shift_logic tracks child state activity in
gear_state by updating the value of the output data
By incorporating active state data, the model
avoids manual data updates reflecting chart activity. Instead, the chart outputs child
state activity automatically through the active state output
To simplify the design of the
old_sf_car model, eliminate data that is
highly correlated to the chart hierarchy and enable automatic monitoring of child
state activity in
Open the model
Open the Symbols window by selecting View > Symbols.
In each substate of
gear_state, delete the
entry action assigning a value to the output data
In the Symbols window, right-click the output variable
gear and select
Open the Property Inspector by selecting View > Property Inspector.
In the Stateflow Editor canvas, select the state
In the Property Inspector, select the Create output for
monitoring check box and choose
In the Data name field, enter the name
gear of the active state data.
In the Enum name filed, enter the name
gearType of the enumeration data type for the
active state data.
In the Simulink model, reconnect the output signal
shift_logic chart to the
Transmission and Threshold Calculation
The output of
gear is an enumerated type managed by Stateflow. You can view the active state output signal
during simulation by connecting the chart to a Scope block. The names
of the enumerated values match the names of the states in
gear_state. The additional enumerated value of
None indicates when no child is active.