An event is a nongraphical object that can wake up and trigger actions in Stateflow® chart. For more information, see Synchronize Model Components by Broadcasting Events.
Stateflow charts respond to events in a cyclical manner.
An event wakes up an inactive chart.
The chart responds to the event by executing transitions and state actions from the top down through the chart hierarchy. Starting at the chart level:
The chart checks for valid transitions between states.
The chart executes during
and
on
actions for the active state.
The chart proceeds to the next level down the hierarchy.
The chart becomes inactive until it receives the next event.
For more information, see Execution of a Stateflow Chart.
In Simulink® models, Stateflow charts receive input events from other blocks in the model.
While processing an event, a state or transition action can generate explicit or implicit events that trigger additional steps. For example:
In each case, the chart interrupts its current activity to process the new event. When the activity caused by the new event finishes executing, the chart returns to the activity that was taking place before the interruption.
Note
In a Simulink model, the execution of output edge-trigger events is equivalent to toggling the value of an output data value between 0 and 1. This type of event does not interrupt the current activity of a chart. Instead, the receiving block processes the event the next time that the model executes the block. For more information, see Activate a Simulink Block by Sending Output Events.
The results of processing a local event can conflict with the action that was taking place before the event was generated. Depending on the type of action, charts resolve these conflicts by using early return logic.
Action Type | Early Return Logic |
---|---|
State entry action | If the state is no longer active after the local event is processed,
the chart stops the process of entering the state. The chart does not
perform the remaining statements in the entry
action. |
State during action | If the state is no longer active after the local event is processed,
the chart stops executing the state. The chart does not perform the
remaining statements in the during action. |
State exit action | If the state is no longer active after the local event is processed,
the chart stops the process of exiting the state. The chart does not
perform the remaining statements in the exit action
nor any transition actions and state entry actions
that result from exiting the state. |
Condition action | If the source state of the inner or outer transition path, or the
parent state of the default transition path, is no longer active after
the local event is processed, the chart stops the transition process. The
chart does not perform the remaining actions on the transition path or
any state exit and entry actions
that result from taking the transition. |
Transition action | If the parent of the transition path is not active, or if the parent
has an active substate, the chart stops the transition process. The chart
does not perform the remaining actions on the transition path or any
state entry actions that result from taking the
transition. |
For example, in this chart, the input event E
and the local
event F
trigger the transitions between states.
Suppose that state A
is active when the chart receives event
E
. The chart responds to the event with these steps:
The chart determines that the transition from the
active state A
to state B
is valid as a
result of event E
.
The chart executes the condition action of the valid
transition and broadcasts event F
.
The chart interrupts the transition from state A
to state
B
and begins to process event
F
.
The chart determines that the transition from the
active state A
to state C
is valid as a
result of event F
.
State A
executes its
exit
action.
State A
becomes inactive.
State C
becomes active.
State C
executes its
entry
action.
After the chart processes event F
, state C
is the active state of the chart. Because state A
is no longer
active, the chart uses early return logic and stops the transition from state
A
to state B
.
Tip
Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. For more information, see Broadcast Local Events to Synchronize Parallel States.
You can set the diagnostic level for detecting undirected local event broadcasts. In the
Configuration Parameters dialog box, open the Diagnostics > Stateflow pane and set the Undirected event broadcasts parameter to
none
, warning
, or
error
. The default setting is
warning
.
Standalone Stateflow charts receive an input event when you call the step
function or an input event function in MATLAB®.
Standalone charts also receive implicit events from MATLAB
timer
objects associated with the
absolute-time temporal logic operators after
, at
, and every
. These operators define temporal logic in terms of
wall-clock time. If the state associated with the temporal logic operator becomes
inactive before the chart processes the implicit event, the event does not wake up the
chart.
If a chart is processing another operation when it receives an event, the chart
queues the event for execution when the current step is completed. You can specify
the size of the event queue by setting the configuration option
-eventQueueSize
when you create the chart object. For more
information, see Chart Object Configuration Options.
For example, in this chart, the input events E
and
F
trigger the transitions between states. Assume that
SendF
is a function in the MATLAB path that calls the input event function F
.
Suppose that state A
is active when the chart receives event
E
. The chart responds to the event with these steps:
The chart determines that the transition from the active state
A
to state B
is valid as a result of
event E
.
The chart executes the condition action of the valid transition and calls
the function SendF
.
SendF
calls the input event function
F
. Because the chart is busy processing a condition action,
it queues event F
.
The chart completes executing the condition action.
State A
executes its exit
action.
State A
becomes inactive.
State B
becomes active.
State B
executes its entry
action.
The chart begins to process the queued event F
.
The chart determines that the transition from the active state
B
to state D
is valid as a result of
event F
.
State B
executes its exit
action.
State B
becomes inactive.
State D
becomes active.
State D
executes its entry
action.
After the chart processes event F
, state D
is the active state of the chart.
after | at | change | enter | every | exit | send | timer