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 prefixduring
ordu
, 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
,during
action.
A state performs itsduring
actions (if specified) when the chart wakes up. The preceding flow chart depicts the process of state execution and shows whenduring
actions 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 theentry
actions are performed forStateA
andStateA1
. 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:
The chart has an active substate,
StateA
.StateA
has an outgoing transition toStateB
. By following theWorkflow for Evaluating Transitions, the transition is determined to be valid.StateB
is marked forentry
andStateA
is marked forexit
.
To complete the time step, follow theWorkflow for Exiting a StateforStateA
and theWorkflow for Entering a Chart or StateforStateB
.
Chart Execution Without a Valid Transition
In this example, the Stateflow chart is initialized and theentry
actions are performed forStateA
andStateA1
. 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:
The chart has an active substate,
StateA
.StateA
has an outgoing transition toStateB
. By following theWorkflow for Evaluating Transitions, the transition is determined to be invalid.Perform the
during
actions forStateA
. Nowy = 1
.StateA
does not have any inner transitions.The active substate of
StateA
isStateA1
.StateA1
has an outgoing transition toStateA2
. By following theWorkflow for Evaluating Transitions, the transition is determined to be invalid.Perform the
during
actions forStateA1
. Nowx = 4
.StateA1
does not have any active substates.The chart goes to sleep.
Steps 1 through 9 take place in the second time step.