Stateflow® uses transitions in charts to move from one exclusive (OR) state to another
exclusive (OR) state. For the entry
and execution
workflows of chart execution, Stateflow evaluates transitions to determine if they are valid. A valid transition is a
transition whose condition labels are true and whose path ends at a state. If a transition
is valid, Stateflow exits from the source state and enters the destination state. To learn about
when evaluation occurs during the execution
and entry
workflows, see Execution of a Stateflow Chart and Enter a Chart or State.
When multiple transitions originate from a single source, such as a state or junction, Stateflow uses evaluation order to determine when to test each transition. Depending on which action language your chart uses, you can create the order of your transitions explicitly or implicitly. Whether explicitly or implicitly ordered, transitions show a number near the source of the transition that designates the transition order.
Note
Use explicit ordering to avoid your transitions from changing order while you are editing a chart.
When you open a new Stateflow chart, all outgoing transitions from a source are automatically
numbered in the order in which you create them. The order starts with
1
and continues to the next available number for the
source.
To change the execution order of a transition, right-click the transition, place
your cursor over Execution Order
, and select the order in
which you want your transition to execute. When you change a transition number, the
Stateflow chart automatically renumbers the other outgoing transitions for the
source by preserving their relative order.
For C charts in implicit ordering mode, a Stateflow chart evaluates a group of outgoing transitions from a single source based on:
Hierarchy.
A chart evaluates a group of outgoing transitions in an order based on the hierarchical level of the parent of each transition.
Label.
A chart evaluates a group of outgoing transitions with equal hierarchical priority based on the labels, in the following order of precedence:
Labels with events and conditions
Labels with events
Labels with conditions
No label
Angular surface position of transition source.
A chart evaluates a group of outgoing transitions with equal hierarchical and label priority based on angular position on the surface of the source object. The transition with the smallest clock position has the highest priority. For example, a transition with a 2 o'clock source position has a higher priority than a transition with a 4 o'clock source position. A transition with a 12 o'clock source position has the lowest priority.
In this example, the Stateflow chart is initialized and the entry
actions are
performed for StateA
. A new time step occurs and the chart wakes up.
By following the Workflow for Stateflow Chart Execution, Stateflow finds multiple outgoing transitions from StateA
. At
this time step x = 1
, y = 1
, and z =
1
.
By following the Workflow for Evaluating Transitions, the steps for evaluating the transitions of this chart are in this order:
Transition 1 from StateA
is marked for evaluation.
Transition 1 from StateA
has a condition.
The condition is true.
The destination of transition 1 from StateA
is not a
state.
The junction does have outgoing transitions.
Transition 1 from the junction is marked for evaluation.
Transition 1 from the junction has a condition.
The condition is false.
Transition 2 from the junction is marked for evaluation.
Transition 2 from the junction does not have a condition.
The destination of transition 2 from the junction is a state
(StateD
).
StateD
is marked for entry
, and
StateA
is marked for exit
.
To complete the time step, follow the Workflow for Exiting a State for
StateA
and the Workflow for Entering a Chart or State for
StateE
.
When all outgoing transitions from a source are invalid or do not end with a terminating junction, but there are previously unevaluated transitions, Stateflow returns to the previous state or junction to evaluate all possible paths.
In this example, the Stateflow chart is initialized and the entry
actions are
performed for StateA
. A new time step occurs, and the chart wakes up.
By following the Workflow for Stateflow Chart Execution, Stateflow finds multiple outgoing transitions from StateA
. At
this time step x = 1
, y = 1
, and z =
1
.
By following the Workflow for Evaluating Transitions, the steps for evaluating the transitions of this chart are in this order:
Transition 1 from StateA
is marked for evaluation.
Transition 1 from StateA
has a condition.
The condition is true.
The destination of transition 1 from StateA
is not a
state.
The junction does have outgoing transitions.
Transition 1 from the junction is marked for evaluation.
Transition 1 from the junction has a condition.
The condition is false.
Transition 2 from the junction is marked for evaluation.
Transition 2 from the junction has a condition.
The condition is false.
Transition 2 from StateA
is marked for evaluation.
Transition 2 from StateA
does not have a
condition.
The destination of transition 2 from StateA
is a state
(StateE
).
StateE
is marked for entry
, and
StateA
is marked for exit
.
To complete the time step, follow the Workflow for Exiting a State for
StateA
and the Workflow for Entering a Chart or State for
StateE
.
In this example, a terminating junction prevents backtracking. The Stateflow chart is initialized and the entry
actions are
performed for StateA
. A new time step occurs and the chart wakes
up. By following the Workflow for Stateflow Chart Execution, Stateflow finds multiple outgoing transitions from StateA
. At
this time step x = 1
, y = 1
, and z =
1
.
By following the Workflow for Evaluating Transitions, the steps for evaluating the transitions of this chart are in this order:
Transition 1 from StateA
is marked for evaluation.
Transition 1 from StateA
has a condition.
The condition is true.
The destination of transition 1 from StateA
is not a
state.
The junction does have outgoing transitions.
Transition 1 from the junction is marked for evaluation.
Transition 1 from the junction has a condition.
The condition is false.
Transition 2 from the junction is marked for evaluation.
Transition 2 from the junction has a condition.
The condition is false.
Transition 3 from the junction is marked for evaluation.
Transition 3 from the junction does not have a condition.
The destination is not a state and does not have any outgoing transitions.
Return to Workflow for Stateflow Chart Execution.
To complete the time step, follow the Workflow for Stateflow Chart Execution for
StateA
, starting where you left off.
In transition label syntax, condition actions follow the transition condition and
are enclosed in curly braces ({}
). Condition actions are executed
when the condition is evaluated as true but before the transition path has been
determined to be valid.
In transition label syntax, transition actions are preceded with a forward slash
(/
) and are enclosed in curly braces ({}
).
Transition actions execute only after the transition path is determined to be
valid.
In this example, both condition actions and transition actions exist. The
Stateflow chart is initialized and the entry
actions are
performed for StateA
. A new time step occurs and the chart wakes
up. There are multiple outgoing transitions from StateA
. At this
time step x = 1
, y = 1
, and z =
1
.
By following the Workflow for Evaluating Transitions, the steps for evaluating the transitions of this chart are in this order:
Transition 1 from StateA
is marked for evaluation.
Transition 1 from StateA
has a condition ([y >=
1]
).
The condition is true.
There are no condition actions.
The destination of transition 1 from StateA
is not a
state.
The junction does have outgoing transitions.
Transition 1 from the junction is marked for evaluation.
Transition 1 from the junction has a condition ([x >
2]
).
The condition is false.
Transition 2 from the junction is marked for evaluation.
Transition 2 from the junction has a condition ([x >=
1]
).
The condition is true.
There is a condition action ({y = 0;}
). Now y =
0
.
The junction does have outgoing transitions.
The transition from the junction is marked for evaluation.
Transition 1 from the junction has a condition ([z >=
5]
).
The condition is false.
Transition 2 from StateA
is marked for evaluation.
Transition 2 from StateA
does not have a
condition.
The destination of transition 2 from StateA
is a state
(StateD
).
StateD
is marked for entry
, and
StateA
is marked for exit
. Execute the
transition action for this valid path (/{z = 5}
). Now
z = 5
.
To complete the time step, follow the Workflow for Exiting a State for
StateA
and the Workflow for Entering a Chart or State for
StateE
.