Documentation

Execution of aStateflowChart

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

  • At each time step according to the Simulink®solver.

  • When the Stateflow chart receives an event.

When a chart wakes up for the first time, the chart is initialized and becomes active. SeeChart Entry. Once the chart is active but with no more actions to take, the chart goes to sleep until it is triggered by a new time step or an event.

Workflow forStateflowChart Execution

这个流程图显示了th事件的进展at Stateflow takes for executing a chart or state. In this flow chart, the current state refers to the state in which a decision or a process is taking place.

During Actions

During actions for a state execute when:

  • The state is active, a new time step occurs, and no valid transition to another state is available.

  • The state is active, an event occurs, and no valid transition to another state is available.

During actions are preceded by the prefixduringordu, and then followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). If you do not specify the state action type explicitly for a statement, the chart treats that statement as anentry,duringaction.

A state performs itsduringactions (if specified) when the chart wakes up. The preceding flow chart depicts the process of state execution and shows whenduringactions occur.

If your Stateflow chart does not contain states, each time the chart is executed, Stateflow always evaluates the default transition path.

Outgoing Transition

Stateflow marks outgoing transitions for evaluation as a part of the execution of a Stateflow chart. Once an outgoing transition is marked for evaluation, follow theWorkflow for Evaluating Transitions. For more information about how Stateflow evaluates outgoing transitions, seeEvaluate Transitions.

Inner Transitions

Stateflow marks inner transitions for evaluation as a part of the execution of a Stateflow chart. Once an inner transition is marked for evaluation, follow theWorkflow for Evaluating Transitions. For more information about how Stateflow evaluates inner transitions, seeEvaluate Transitions.

Chart Execution with a Valid Transition

In this example, the Stateflow chart is initialized and theentryactions are performed forStateAandStateA1. A new time step occurs and the chart wakes up.

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

By following theWorkflow for Stateflow Chart Execution, the execution steps for chart execution are in this order:

  1. The chart has an active substate,StateA.

  2. StateAhas an outgoing transition toStateB. By following theWorkflow for Evaluating Transitions, the transition is determined to be valid.

  3. StateBis marked forentryandStateAis marked forexit.

To complete the time step, follow theWorkflow for Exiting a StateforStateAand theWorkflow for Entering a Chart or StateforStateB.

Chart Execution Without a Valid Transition

In this example, the Stateflow chart is initialized and theentryactions are performed forStateAandStateA1. A new time step occurs and the chart wakes up.

At this time step,x = 3,y = 0, andz = 0.

By following theWorkflow for Stateflow Chart Executionuntil the chart goes to sleep, the execution steps for chart execution are in this order:

  1. The chart has an active substate,StateA.

  2. StateAhas an outgoing transition toStateB. By following theWorkflow for Evaluating Transitions, the transition is determined to be invalid.

  3. Perform theduringactions forStateA. Nowy = 1.

  4. StateAdoes not have any inner transitions.

  5. The active substate ofStateAisStateA1.

  6. StateA1has an outgoing transition toStateA2. By following theWorkflow for Evaluating Transitions, the transition is determined to be invalid.

  7. Perform theduringactions forStateA1. Nowx = 4.

  8. StateA1does not have any active substates.

  9. The chart goes to sleep.

Steps 1 through 9 take place in the second time step.

Related Topics

Was this topic helpful?