Stateflow Semantics: Shortcut to Default
Today I want to share with you one of the lesser known semantics of Stateflow: the transition that ends on an inner boundary of a state.
This is not an inner transition; those start on an inner boundary, not end on one. Rather, these transitions serve as shortcuts back to the default transition path.
Get Back
Here we have a small example, with a state P that has two children, A and B, and four outputs to help us understand what's going on.
- When the chart is first entered, the top-level default transition directs Stateflow to enter state P. The entry action for that state sets y1 = 1.
- Stateflow then looks for children of P; finding none already active, it follows the default transition inside P to child A.
- Now A's entry action sets y2 = 1 as well.
- At time = 1 second, the transition to B is valid. During that same timestep, Stateflow sets both y2 = 0 and y3 = 1.
- At time = 2 seconds, the transition going out from B is now valid. Stateflow sets y1 = 2, then y3 = 0 as B is exiting.
- From there, Stateflow jumps back up to the default transition that leads to A, and does the entry action for A again, setting y2 = 1, all in the same timestep.
And we can look at the outputs on a Scope:
In effect, this transition has served as a shortcut to the default transition path of the parent, P. Notice from the screenshot of the Scope above that parent P is not exited and re-entered at time = 2 seconds; y1 = 2 until P is exited for Q at time = 5 seconds.
We could obtain the same result by using a junction on the default path (below), but that can get messy visually, especially if you have a large parent state with many children.
Now it's your turn
Do you have a really interesting application for this Stateflow semantic? Share it in the comments below!
- 범주:
- Stateflow
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.