Main Content

Execution of a Stateflow Chart

When a Stateflow® chart wakes up, the chart follows a workflow and executes actions. A Stateflow chart wakes up:

  • At each time step

  • When the Stateflow chart receives an event

When a chart wakes up for the first time, the chart is initialized and becomes active, as described in Workflow for Entering a Chart or State. When there are no more actions to take, the chart goes to sleep until a new time step or event wakes up the chart.

Workflow for Stateflow Chart Execution

This flow chart shows the progression of events that Stateflow takes when executing a chart or state. In this flow chart, the current state refers to the state in which a decision or a process takes place.

Flow chart that shows the steps for executing a chart or state.

Default Transitions

A default transition is a transition that has no source. In a Stateflow chart that does not contain any states, a default transition marks the start of a flow chart. For more information, see Create Flow Charts in Stateflow.

If a Stateflow chart does not contain any states, the chart evaluates the default transition paths each time the chart wakes up. After marking a default transition for evaluation, the chart follows the steps shown in Workflow for Evaluating Transitions.

Note

Charts evaluate default transition paths inside a state only during state entry, and not each time the chart wakes up.

Outer Transition

An outer transition is a transition that exits the source state. A Stateflow chart marks outer transitions for evaluation as the first step in executing a state. After marking an outer transition for evaluation, the chart follows the steps shown in Workflow for Evaluating Transitions.

During Actions

A during action is an action defined in a state label actions by using the prefix during or du. For more information, see Define Actions in a State.

A state performs during actions when the chart wakes up, the state is active, and there are no valid outer transitions.

Inner Transitions

An inner transition is a transition that does not exit the source state. For more information, see Control Chart Execution by Using Inner Transitions.

A Stateflow chart marks inner transitions for evaluation after a state performs during actions. After marking an inner transition for evaluation, the chart follows the steps shown in Workflow for Evaluating Transitions.

Chart Execution with a Valid Transition

In this example, the Stateflow chart has been initialized and the entry actions have been performed for StateA and StateA1. A new time step occurs and the chart wakes up.

At this time step, x = 5, y = 2, and z = 0.

Stateflow chart with top-level states called StateA and StateB. StateA has substates StateA1 and StateA2. StateB has substates StateB1 and StateB2.

The chart executes these steps:

  1. The chart has an active substate, StateA.

  2. StateA has an outer transition to StateB. The chart determines that the transition is valid.

  3. The chart marks StateB for entry and StateA is marked for exit.

  4. To exit StateA, the chart follows the steps shown in Workflow for Exiting a State.

  5. To enter StateB, the chart follows the steps shown in Workflow for Entering a Chart or State

Chart Execution Without a Valid Transition

In this example, the Stateflow chart has been initialized and the entry actions have been performed for StateA and StateA1. A new time step occurs and the chart wakes up.

At this time step, x = 3, y = 0, and z = 0.

Stateflow chart with top-level states called StateA and StateB. StateA has substates StateA1 and StateA2. StateB has substates StateB1 and StateB2.

The chart executes these steps:

  1. The chart has an active substate, StateA.

  2. StateA has an outer transition to StateB. The chart determines that the transition is invalid.

  3. The chart performs the during actions for StateA. Now y = 1.

  4. StateA does not have any inner transitions.

  5. The active substate of StateA is StateA1.

  6. StateA1 has an outer transition to StateA2. The chart determines that the transition is invalid.

  7. The chart performs the during actions for StateA1. Now x = 4.

  8. StateA1 does not have any active substates.

  9. The chart goes to sleep.

Related Topics