Stateflow default path to substate
46 views (last 30 days)
Show older comments
Jason Muller on 27 Mar 2018
Answered: Arunkumar M on 9 Nov 2018
Often while programming in Stateflow, I split a superstate's default transition using a junction. Downstream of the junction, I guard each possible path with different transition conditions, so that when the superstate is entered, the activated substate changes according to other factors (such as external inputs to the state machine). I find this is a very useful construct.
However, not leaving at least one "unconditional" pathway trips a diagnostic warning when the model is built. ("Warning - No unconditional default path to a substate"). This warning occurs even when there is no possible way that indeterminate logic exists within the transition tree. For example, consider the case where default transition splits into two paths at a junction; one transition is guarded by the condition [my_boolean] and the other is guarded by [~my_boolean]. One or the other path has to be taken, so there is a valid default transition to some substate in all cases. But the warning is still triggered.
One option is of course to disable the diagnostic. And I realize that there are other ways to program such logic to prevent the diagnostic from appearing -- for instance in my example above, one of the two possible transitions out of the junction can be left unguarded & that transition can be set lower in the execution order. However in general I prefer to explicitly guard transitions with conditions where possible, rather then rely implicitly on execution ordering. I feel that this makes for more clearly understandable state machines & offers less chance for inadvertently affecting the behavior of the program when future changes are made.
Therefore I was wondering if there is a way for the stateflow diagnostic to be made smarter? So that when such a split default transition is detected, the parser first checks whether indeterminate behavior is possible before flagging the construct as faulty?
(I am currently using Matlab 2014b, apologies if this has already been addressed in newer versions)
Arunkumar M on 9 Nov 2018
"For example, consider the case where default transition splits into two paths at a junction; one transition is guarded by the condition [my_boolean] and the other is guarded by [~my_boolean]"
Looking at your above statement, the condition [~my_boolean] in your 2nd transition is redundant. If you make your 1st transition with condition [my_boolean] (1st priority), then the second condition (2nd priority) doesnt need any condition in this case, as you are just checking opposite condition. This is because, stateflow executes transitions based on priorities defined. If your 2nd transition is executed, it means that, the 1st transition was checked and not found to be true - which indirectly means [~my_boolean] => hence your 2nd transition can be left without any condition. Then you will not get any diagnostic warnings. This kind of redundant conditions need to be avoided also for getting better coverage of your model.
Find more on Configure and View Diagnostics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!