{"id":4986,"date":"2016-01-07T14:24:34","date_gmt":"2016-01-07T19:24:34","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=4986"},"modified":"2016-01-14T12:36:32","modified_gmt":"2016-01-14T17:36:32","slug":"stateflow-semantics-shortcut-to-default","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/01\/07\/stateflow-semantics-shortcut-to-default\/","title":{"rendered":"Stateflow Semantics: Shortcut to Default"},"content":{"rendered":"<p>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.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/zoomedIn.png\" alt=\"Transition that ends on an inner boundary\" \/><\/p>\r\n\r\n<p>This is <i>not<\/i> an <a href=\"https:\/\/www.mathworks.com\/help\/stateflow\/ug\/transition-connections.html#f18-69337\" target=\"_blank\">inner transition<\/a>; those start on an inner boundary, not end on one. Rather, these transitions serve as shortcuts back to the default transition path.<\/p>\r\n\r\n<p><strong>Get Back<\/strong><\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><ul><li>When the chart is first entered, the top-level default transition directs Stateflow to enter state P. The entry action for that state sets <tt>y1 = 1<\/tt>.<\/li>\r\n<li>Stateflow then looks for children of P; finding none already active, it follows the default transition inside P to child A.<\/li>\r\n<li>Now A's entry action sets <tt>y2 = 1<\/tt> as well.<\/li>\r\n<li>At time = 1 second, the transition to B is valid. During that same timestep, Stateflow sets both <tt>y2 = 0<\/tt> and <tt>y3 = 1<\/tt>.<\/li>\r\n<li>At time = 2 seconds, the transition going out from B is now valid. Stateflow sets <tt>y1 = 2<\/tt>, then <tt>y3 = 0<\/tt> as B is exiting.<\/li>\r\n<li>From there, Stateflow jumps back up to the default transition that leads to A, and does the entry action for A again, setting <tt>y2 = 1<\/tt>, all in the same timestep.<\/li><\/ul><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/capture-22.gif\" alt=\"Shortcut to default example\" \/><\/p>\r\n\r\n<p>And we can look at the outputs on a Scope:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/stateflowScope.png\" alt=\"Output signals\" \/><\/p>\r\n\r\n<p>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; <tt>y1 = 2<\/tt> until P is exited for Q at time = 5 seconds.<\/p>\r\n\r\n<p>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.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/equivalentModel.png\" alt=\"Alternative, though not a perfect match because that initial default transition segment is not traversed\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n<p>Do you have a really interesting application for this Stateflow semantic? Share it in the comments below!<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/simulink\/files\/feature_image\/theStateflowModel1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>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.\r\n\r\n\r\n\r\nThis is not an inner transition; those start on an... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/01\/07\/stateflow-semantics-shortcut-to-default\/\">read more >><\/a><\/p>","protected":false},"author":88,"featured_media":5013,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[56],"tags":[455,465],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4986"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=4986"}],"version-history":[{"count":13,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4986\/revisions"}],"predecessor-version":[{"id":5010,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4986\/revisions\/5010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media\/5013"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=4986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=4986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=4986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}