{"id":3878,"date":"2014-07-03T13:43:39","date_gmt":"2014-07-03T18:43:39","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3878"},"modified":"2017-01-20T17:24:16","modified_gmt":"2017-01-20T22:24:16","slug":"what-about-a-resettable-subsystem","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/07\/03\/what-about-a-resettable-subsystem\/","title":{"rendered":"What about a Resettable Subsystem?"},"content":{"rendered":"<p><em><strong>UPDATE: Since R2015a, a resettable block is now shipping with Simulink... yeah!<\/strong><\/em><\/p>\r\n\r\n<p><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/reset-block-states-in-a-subsystem.html\">https:\/\/www.mathworks.com\/help\/simulink\/ug\/reset-block-states-in-a-subsystem.html<\/a><\/p>\r\n\r\n<p>------------------- original post --------------------<\/p>\r\n\r\n<p>I often write about new features in Simulink. Today I take a different route and write about a feature that I would like to see in Simulink.<\/p>\r\n\r\n<p>Please leave a comment below if you have similar needs and use cases.<\/p>\r\n\r\n<p><strong>My Need<\/strong><\/p>\r\n\r\n<!--introduction-->\r\n<p>In various applications I work on, I often end up needing to reset the states of multiple blocks at the same time. Some blocks like <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/integrator.html\">Integrator<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/delay.html\">Delay<\/a> have reset ports which I can use for this purpose. However other blocks like <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/statespace.html\">State-Space<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/transferfcn.html\">Transfer Function<\/a> or <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/unitdelay.html\">Unit Delay<\/a> do not.<\/p>\r\n<!--\/introduction-->\r\n<p><strong>Blocks with Reset Ports<\/strong><\/p>\r\n\r\n<p>If blocks have reset ports, I can arrange my diagram to reset all those blocks at the same time:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/withPorts.png\" alt=\"Resetting Blocks\" \/><\/p>\r\n\r\n<p>This gives me the behavior I need, but if I have many blocks that need to be reset, this is a lot of routing. Also, there are multiple blocks that have states, but do not have an optional reset port.<\/p>\r\n\r\n<p><strong>Enabled Subsystem<\/strong><\/p>\r\n\r\n<p>What I am really dreaming of is a subsystem with a control port like the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/enabledsubsystem.html\">Enabled Subsystem<\/a>, without the need to disable for one step to reset the states. With an Enabled Subsystem the control signal resets the states when it is re-enabled.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/enabledSS.png\" alt=\"Enabled Subsystem\" \/><\/p>\r\n\r\n<p>When simulating the model, we can see that this is not ideal because the system is disabled during one step:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/disabledResults.png\" alt=\"Enabled Subsystem Results\" \/><\/p>\r\n\r\n<p><strong>Function-Call subsystem and Stateflow<\/strong><\/p>\r\n\r\n<p>Using Stateflow it is possible to reset the states in a subsystem without disabling it for one step.<\/p>\r\n\r\n<p>To make that happen, we need to place the blocks inside a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsubsystem.html\">Function-Call Subsystem<\/a>. We can then drive the subsystem with a <a href=\"https:\/\/www.mathworks.com\/help\/stateflow\/ref\/chart.html\">Stateflow Chart<\/a>. In the chart, <a href=\"https:\/\/www.mathworks.com\/help\/stateflow\/ug\/using-bind-actions-to-control-function-call-subsystems.html\">bind an output event to a state<\/a> and exit this state to trigger the reset of the states in the Function-Call Subsystem:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/FcnCallSS.png\" alt=\"Function-Call Subsystem and Stateflow\" \/><\/p>\r\n\r\n<p>Note, this solution will not work for blocks with continuous states like Transfer Function, State-Space, etc.<\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Do you see the need in your applications for a subsystem where the states of all the blocks inside would reset from a rising edge on a control port? Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=3878&#comment\">comment here<\/a>.<\/p>\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q3\/FcnCallSS.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->\r\n<p>In various applications I work on, I often end up needing to reset the states of multiple blocks at the same time. Some blocks like <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/integrator.html\">Integrator<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/delay.html\">Delay<\/a> have reset ports which I can use for this purpose. However other blocks like <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/statespace.html\">State-Space<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/transferfcn.html\">Transfer Function<\/a> or <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/unitdelay.html\">Unit Delay<\/a> do not.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/07\/03\/what-about-a-resettable-subsystem\/\">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],"tags":[390,391],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3878"}],"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=3878"}],"version-history":[{"count":18,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3878\/revisions"}],"predecessor-version":[{"id":6320,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3878\/revisions\/6320"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}