Simplify Stateflow Charts by Incorporating Active State Output

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 old_sf_car, the Stateflow chart shift_logic tracks child state activity in gear_state by updating the value of the output data gear.

By incorporating active state data, the model sf_car avoids manual data updates reflecting chart activity. Instead, the chart outputs child state activity automatically through the active state output gear.

Modify the Model

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 gear_state.

Eliminate Manual Tracking of State Activity

  1. Open the model old_sf_car.

  2. Open the Symbols pane. In the Modeling tab, click Symbols Pane.

  3. In each substate of gear_state, delete the entry action assigning a value to the output data variable gear.

  4. In the Symbols pane, right-click the output variable gear and select Delete.

Enable Active State Output

  1. Open the Property Inspector. In the Modeling tab, click Property Inspector.

  2. In the Stateflow Editor canvas, select the state gear_state.

  3. In the Property Inspector, select the Create output for monitoring check box and choose Child activity.

  4. In the Data name field, enter the name gear of the active state data.

  5. In the Enum name filed, enter the name gearType of the enumeration data type for the active state data.

  6. In the Simulink model, reconnect the output signal gear from the shift_logic chart to the Transmission and Threshold Calculation subsystems.

View Simulation Results

The output of gear is an enumerated type managed by Stateflow. You can view the active state output signal gear 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.

Related Topics