{"id":1022,"date":"2012-07-18T17:44:33","date_gmt":"2012-07-18T22:44:33","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1022"},"modified":"2012-07-18T17:46:40","modified_gmt":"2012-07-18T22:46:40","slug":"breaking-up-a-stateflow-chart-for-collaborative-development","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/07\/18\/breaking-up-a-stateflow-chart-for-collaborative-development\/","title":{"rendered":"Breaking up a Stateflow Chart for Collaborative Development"},"content":{"rendered":"<p>This week I have been experimenting with a feature released in R2010b that I have not used before: <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/stateflow\/ug\/bsbm40z-1.html\">Stateflow Atomic Subcharts<\/a><\/p>\r\n\r\n<p><strong>The Problem<\/strong><\/p>\r\n\r\n<p>I am currently working on a model architecture where different functionalities will be developed by different people simultaneously.<\/p>\r\n\r\n<p>Typically, when I need to componentize a Simulink model, I use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f4-141721.html\">Model Referencing<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/f13-85323.html\">Block Libraries<\/a>. However, for my application, the algorithms to be developed are very procedural and better suited for Stateflow.<\/p>\r\n\r\n<p>While going through the Stateflow documentation, I ran into a page titled <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/stateflow\/ug\/bscvp8b.html\">When to Use Atomic Subcharts<\/a> and saw the following scenario:<\/p>\r\n\r\n<p><em>You want to break a chart into standalone parts because multiple people are working on different parts of the chart.<\/em><\/p>\r\n\r\n<p>That sounds exactly like what I am looking for... so let's give that a try!<\/p>\r\n\r\n<p><strong>Initial Design<\/strong><\/p>\r\n\r\n<p>Let's start with a simple example chart:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/simpleChart1.png\" alt=\"Simple chart\" \/><\/p>\r\n\r\n<p>In this chart, I have 3 sub-states for 3 different tasks. At a high level, I know that <tt>TaskA<\/tt> will be followed by <tt>TaskB<\/tt>, who is followed by <tt>TaskC<\/tt>. Each of these tasks are pretty complex and will developed by different engineers.<\/p>\r\n\r\n<p>So let's see how we can store states <tt>TaskA<\/tt>, <tt>TaskB<\/tt> and <tt>TaskC<\/tt> in different files.<\/p>\r\n\r\n<p><strong>Atomic Subcharts<\/strong><\/p>\r\n\r\n<p>If I right-click on the states, I can select <strong>Make Content -> Atomic Subcharted<\/strong>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/makeSubchart.png\" alt=\"Simple chart\" \/><\/p>\r\n\r\n<p>and the content of the state becomes atomic<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/simpleChartAtomic.png\" alt=\"Simple Atomic Subchart\" \/><\/p>.\r\n\r\n<p><strong>One File Per Atomic Subchart<\/strong><\/p>\r\n\r\n<p>The next step is to store the state in a library. To do this, I copy the Atomic Subchart to a Simulink Library and recopy it back to the chart. Notice that the annotation on the state changes from Atomic to Link:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/atomic_convert.gif\" alt=\"Storing an Atomic chart in a library\" \/><\/p>.\r\n\r\n<p>and that's it... I now have a Stateflow chart with different states stored in different files.<\/p>\r\n\r\n<p><strong>Data Mapping<\/strong><\/p>\r\n\r\n<p>Now we have one more step to go. To use an Atomic Subchart, you need to map the data internal to the subchart to the main chart data. To accomplish this task, right-click on the chart and select <strong>Edit Subchart mappings...<\/strong><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/editMapping.png\" alt=\"Opening Subchart Mapping\" \/><\/p>.\r\n\r\n<p>This will launch a dialog containing tables to map inputs, outputs, data store memory, parameters and input events.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/chartMapping.png\" alt=\"subchart mapping\" \/><\/p>.\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Do you componentize Stateflow using Atomic Subcharts? Leave us a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1022&#comment\">comment here<\/a>.<\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>This week I have been experimenting with a feature released in R2010b that I have not used before: Stateflow Atomic Subcharts\r\n\r\nThe Problem\r\n\r\nI am currently working on a model architecture where... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/07\/18\/breaking-up-a-stateflow-chart-for-collaborative-development\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,56],"tags":[280,455,279],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1022"}],"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\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=1022"}],"version-history":[{"count":32,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1022\/revisions"}],"predecessor-version":[{"id":1174,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1022\/revisions\/1174"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}