In the below two state charts , the first one has an action to perform when it moves from StateA to StateD , ie. /{z=5}; and the second one has to perform the action {z=5}; I understand that this is a Transition Action , but i am unable to understand what is the different between the two transition
Transition Action and Condition Action in Stateflow
6.1k views Asked by beastboy AtThere are 3 answers
The "transition action" /z=5;
is equal to an "entry action" of a destination state entry: z=5;
. It might look like an "elegant" solution if you have multiple destination states but want to set a value based on the previous state and lots of additional logics (not in your example).
In the model reviews our people spent too much time figuring out what exctly happened in the charts using "transition actions". The generated code was also difficult to read. In our company-wide modeling guidelines we evntually prohibited using the "transition actions" because they make the models difficult to review.
The "condition actions" {z=5;}
in combination with the "state actions" entry: z=5;
are sufficient for any logics we needed to implement.
It would be a good move for MathWorks to discontinue the transition action semantics in the future releases.
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. 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.
See the link given by @am304 for specific information, but in brief,
in your first image you have a
Transition Action
, which executes when the transition occurs (and after any state exit actions - if you had any forState A
),in your second image you have a
Condition Action
, which executes when any condition associated with the transition is determined to be true. You do not have any explicit conditions (i.e. nothing likee1[cond1]{z = 5}
) so the condition is considered to be true when any event occurs. This will execute even if the transition is not made (i.e. it is only dependent on the condition.) This means that it would occur before any state exit action (if you had any forState A
.)Given the above, in your specific case (i.e. no exit actions for
State A
and no conditions on the transition), the two will give the same result.