A transition is a line with an arrowhead that links one graphical
object to another. In most cases, a transition represents the passage of the system from one
mode (state) to another. A transition typically connects a source and a destination object.
The source object is where the transition begins and the
destination object is where the transition ends. The following chart
shows a transition from a source state, B
, to a destination state,
A
.
Junctions divide a transition into transition segments. In this case, a full transition consists of the segments taken from the origin to the destination state. Each segment is evaluated in the process of determining the validity of a full transition.
The following example has two segmented transitions: one from state On
to state Off
, and the other from state On
to
itself:
A default transition is a special type of transition that has no source object. See Default Transitions for details.
Transitions cannot contain other objects the way that states can. However, transitions are contained by states. The hierarchy for a transition is described in terms of its parent, source, and destination states. The parent is the lowest level that contains the source and destination of the transition. Consider the parents for the transitions in the following example:
The following table resolves the parentage of each transition in the preceding example.
The /
character represents the chart. Each level in the hierarchy of
states is separated by the period (.
) character.
Transition Label | Transition Parent | Transition Source | Transition Destination |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
A transition label can consist of an event or message, a
condition, a condition action, and a transition action. Each part of the label is optional.
The ?
character is the default transition label. Transition labels have
this overall format:
event_or_message[condition]{condition_action}/transition_action
This example illustrates the parts of a transition label.
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 Transitions,
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 Transitions,
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. For more information, see
Check State Activity by Using the in Operator.
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.
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 Transitions,
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.
In transition label syntax, transition actions are preceded with a forward slash
(/
) and are enclosed in curly braces ({}
). In the
example in Transitions, 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.
Usually, a transition is valid when the source state of the transition is active and the transition label is valid. Default transitions are different because there is no source state. Validity of a default transition to a substate is evaluated when there is a transition to its superstate, assuming the superstate is active. This labeling criterion applies to both default transitions and general case transitions. The following table lists possible combinations of valid transition labels.
Transition Label | Is Valid If... |
---|---|
Event only | That event occurs |
Event and condition | That event occurs and the condition is true |
Message only | That message occurs |
Message and condition | That message occurs and the condition is true |
Condition only | Any event occurs and the condition is true |
Action only | Any event occurs |
Not specified | Any event occurs |
This example shows simple transitions to and from exclusive (OR) states.
The following transition... | Is valid when... |
---|---|
B to A | State B is active and the event E1
occurs. |
A1 to A2 | State A1 is active and event E2
occurs. |
See Transition Between Exclusive States for more information on the semantics of this notation.
The following chart shows transitions to and from connective junctions.
The chart uses temporal logic to determine when the input u
equals
1.
If the input equals 1... | A transition occurs from... |
---|---|
Before t = 2 | Start to Fast |
Between t = 2 and t = 5 | Start to Good |
After t = 5 | Start to Slow |
For more information about temporal logic, see Control Chart Execution by Using Temporal Logic. For more information on the semantics of this notation, see Transition from a Common Source to Multiple Destinations.
This example shows transitions to and from an exclusive (OR) superstate and the use of a default transition.
The chart has two states at the highest level in the hierarchy,
Power_off
and Power_on
. By default,
Power_off
is active. The event Switch
toggles the
system between the Power_off
and Power_on
states.
Power_on
has three substates: First
,
Second
, and Third
. By default, when
Power_on
becomes active, First
also becomes
active. When Shift
equals 1, the system transitions from
First
to Second
, Second
to
Third
, Third
to First
, for each
occurrence of the event Switch
, and then the pattern repeats.
For more information on the semantics of this notation, see Control Chart Execution by Using Default Transitions.
The following example shows transitions to and from exclusive (OR) substates.
For details on how this chart works, see Debounce Signals with Fault Detection. For information on the semantics of this notation, see Transition from a Substate to a Substate with Events.