Modeling Guidelines for Stateflow Charts
Use these guidelines to efficiently model charts with events, states, and transitions.
Use signals of the same data type for input events
When you use multiple input events to trigger a chart, verify that all input signals use the same data type. Otherwise, simulation stops and an error message appears. For more information, see Data Types Allowed for Input Events.
Use a default transition to mark the first state to become active among exclusive (OR) states
This guideline prevents state inconsistency errors during chart execution.
Use condition actions instead of transition actions whenever possible
Condition actions execute as soon as the condition evaluates to true. Transition actions do not execute until after the transition path is complete, to a terminating junction or a state.
Unless an execution delay is necessary, use condition actions instead of transition actions.
Use explicit ordering to control the testing order of a group of outgoing transitions
You can specify explicit or implicit ordering of transitions. By default, a chart uses explicit ordering. If you switch to implicit ordering, the transition testing order can change when graphical objects move.
Verify intended backtracking behavior in flow charts
If your chart contains unintended backtracking behavior, a warning message appears with instructions on how to avoid that problem. For more information, see Best Practices for Creating Flow Charts.
Use a superstate to enclose substates that share the same state actions
When you have multiple exclusive (OR) states that perform the same state actions, group these states in a superstate and define state actions at that level.
This guideline enables reuse of state actions that apply to multiple substates. You write the state actions only once, instead of writing them separately in each substate.
You cannot use boxes for this purpose because boxes do not support state actions.
Use MATLAB functions for performing numerical computations in a chart
MATLAB® functions are better at handling numerical computations than graphical functions, truth tables, or Simulink® functions.
Use descriptive names in function signatures
Descriptive function names enhance readability of chart objects.
Use history junctions to record state history
If reentry to a state with exclusive (OR) decomposition depends on the previously active substate, use a history junction. This type of junction records the active substate when the chart exits the state. If you do not record the previously active substate, the default transition occurs and the wrong substate can become active upon state reentry.
Do not use history junctions in states with parallel (AND) decomposition
This guideline prevents compile-time errors. Since all parallel states at a level of hierarchy are active at the same time, history junctions have no meaning.
Use explicit ordering to control the execution order of parallel (AND) states
You can specify explicit or implicit ordering of parallel states. By default, a chart uses explicit ordering. If you switch to implicit ordering, the execution order can change when parallel states move.