Transitions can have different action types, which include event or message triggers, conditions, condition actions, and transition actions. The action types follow the label notation with this general format:
event_or_message trigger[condition]{condition_action}/{transition_action}
The following example shows typical transition label syntax:
Transition | Event Trigger | Condition | Condition Action | Transition Action |
---|---|---|---|---|
State A to state C | event1 | temp > 50 | func1() | None |
State A to state B | event2 | None | None | data1 = 5 |
In transition label syntax, event or message triggers appear first as the name of an
event or message. They have no distinguishing special character to separate them from other
actions in a transition label. In the example in Transition Action Types, both transitions from state A have
event triggers. The transition from state A to state B has the event trigger
event2
and the transition from state A to state C has the event trigger
event1
.
Event triggers specify an event that causes the transition to be taken, provided the
condition, if specified, is true. Specifying an event is optional. Message triggers specify
the transition to be taken if the message is present in the message queue. The absence of an
event or message indicates that the transition is taken upon the occurrence of any event.
Multiple events or messages are specified using the OR logical operator
(|
).
In transition label syntax, conditions are Boolean expressions enclosed in square
brackets ([]
). In the example in Transition Action Types, the transition from state A to state
C has the condition temp > 50
.
A condition is a Boolean expression to specify that a transition occurs given that the specified expression is true. Follow these guidelines for defining and using conditions:
The condition expression must be a Boolean expression that evaluates to true (1) or
false
(0).
The condition expression can consist of any of the following:
Boolean operators that make comparisons between data and numeric values
A function that returns a Boolean value
An in(state_name)
condition that evaluates to true
when the state specified as the argument is active (see Check State Activity by Using the in Operator)
Note
A chart cannot use the in
condition to trigger actions
based on the activity of states in other charts.
Temporal logic conditions (see Control Chart Execution by Using Temporal Logic)
The condition expression can call a graphical function, truth table function, or MATLAB® function that returns a numeric value.
For example, [test_function(x, y) < 0]
is a valid condition
expression.
Note
If the condition expression calls a function with multiple return values, only the first value applies. The other return values are not used.
The condition expression should not call a function that causes the chart to change state or modify any variables.
Boolean expressions can be grouped using & for expressions with AND
relationships and |
for expressions with OR relationships.
Assignment statements are not valid condition expressions.
Unary increment and decrement actions are not valid condition expressions.
In transition label syntax, condition actions follow the transition condition and are
enclosed in curly braces ({}
). In the example in Transition Action Types, the transition from state A to state
C has the condition action func1()
, a function call.
Condition actions are executed as soon as the condition is evaluated as true, but before the transition destination has been determined to be valid. If no condition is specified, an implied condition evaluates to true and the condition action is executed.
Note
If a condition is guarded by an event, it is checked only if the event trigger is active. If a condition is guarded by a message, it is checked only if the message is present.
In transition label syntax, transition actions are preceded with a forward slash
(/
) and are enclosed in curly braces ({}
). In the
example in Transition Action Types, the transition from state A to state
B has the transition action data1 = 5
. In C charts, transition actions
are not required to be enclosed in curly braces. In charts that use MATLAB as the action
language, the syntax is auto corrected if the curly braces are missing from the transition
action. See Auto Correction When Using MATLAB as the Action Language.
Transition actions execute only after the complete transition path is taken. They execute after the transition destination has been determined to be valid, and the condition, if specified, is true. If the transition consists of multiple segments, the transition action executes only after the entire transition path to the final destination is determined to be valid.
Transition actions are supported only in Stateflow® charts in Simulink® models.