{"id":25,"date":"2008-08-05T17:15:52","date_gmt":"2008-08-05T22:15:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2008\/08\/05\/advanced-masking-concepts\/"},"modified":"2008-08-05T17:28:10","modified_gmt":"2008-08-05T22:28:10","slug":"advanced-masking-concepts","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2008\/08\/05\/advanced-masking-concepts\/","title":{"rendered":"Advanced Masking Concepts"},"content":{"rendered":"<p>Masking does more than just put a professional interface on\r\nyour algorithm. \u00a0Simulink blocksets provide elaborate graphical user interfaces\r\n(GUIs) to control the behavior of blocks.\u00a0 The block dialog can dynamically\r\nenable and disable its GUI elements.\u00a0 Blocks can sprout additional ports in\r\norder to accept parameters as input signals.\u00a0 The algorithm can rewire itself\r\nbased on the setting in the dialog.\u00a0 Did you ever ask yourself, \u201chow can I do\r\nthat?\u201d<\/p>\r\n\r\n<p>This is the first in a series of posts that will introduce these\r\nadvanced masking concepts.\u00a0 I have created an example that has:<\/p>\r\n\r\n<p><ul>\r\n<li>A block dialog that enables and disables parameters based on user settings<\/li>\r\n<li>The option to add and delete ports to match dialog settings<\/li>\r\n<\/ul><\/p>\r\n\r\n<p>This example builds on top of the basic concepts introduced\r\nin <a\r\nhref=\"https:\/\/blogs.mathworks.com\/seth\/2008\/07\/27\/how-to-make-your-own-simulink-block\/\">my\r\nrecent post on masking<\/a>. \u00a0That post covered how to make a mask icon, and\r\nprovide a mask dialog to control the parameters used in an algorithm.<\/p>\r\n\r\n<p><strong>Two saturation blocks<\/strong><\/p>\r\n\r\n<p>The example I have created combines the dynamic saturation\r\nblock from a <a\r\nhref=\"https:\/\/blogs.mathworks.com\/seth\/2008\/07\/18\/libraries-in-simulink\/\">recent\r\npost on libraries<\/a> and the fixed saturation block in <a\r\nhref=\"https:\/\/blogs.mathworks.com\/seth\/2008\/07\/27\/how-to-make-your-own-simulink-block\/\">my\r\nrecent post on masking<\/a>.\u00a0 The algorithms for these two blocks differ\r\nslightly.\u00a0 The dynamic saturation block uses inports to provide the limits, and\r\nthe fixed saturation uses constant blocks to provide the same signals.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/startingBlocks.png\" alt=\"Dynamic limits and fixed limits saturation systems\"><\/p>\r\n\r\n<p>The Fixed Saturation block has a mask that sets the values\r\nof the uplim and lowlim variables in the mask workspace.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/fixedSaturationDialog.png\" alt=\"Fixed saturation limit mask dialog\"><\/p>\r\n\r\n<p><strong>A combined saturation block interface<\/strong><\/p>\r\n\r\n<p>To combine these blocks, I present the user with a simple\r\ninterface that allows them to control the source of their upper and lower\r\nsaturation limits.\u00a0 The value can be internal or external.\u00a0 <\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/saturationDialog.png\" alt=\"Mask dialog for the saturation block, internal source for limits\"><\/p>\r\n\r\n<p>When internal limits are used, the value comes from the\r\nUpper Limit and Lower Limit fields.\u00a0 When using external limits, those fields\r\nare disabled, and inports provide the limit signals.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/saturationDialogExternalSrc.png\" alt=\"Mask dialog for the saturation block, external source for limits\"><\/p>\r\n\r\n<p><strong>How does this combined block work?<\/strong><\/p>\r\n\r\n<p>Here is a test model that exercises some of the different\r\nmodes of this saturation block.\u00a0 The three saturation blocks in this model are\r\nactually three instances of the same library block.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/saturationModelTest.png\" alt=\"Saturation block test model\"><\/p>\r\n\r\n<p>The top block uses the fixed limits.\u00a0 The middle block uses\r\nan external source for the upper limit and a fixed value for the lower limit.\u00a0\r\nThe bottom block uses external sources for both the upper and lower limit.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/saturationModelTestScope.png\" alt=\"Saturatino block test model scopes\"><\/p>\r\n\r\n<p>How does the same block behave in these three different\r\nways?\u00a0 To see how, you can look under the masks of these blocks and see the\r\nblocks involved in the algorithm.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q3\/saturationTestUnderMasks.png\" alt=\"Algorithms for three instances of the saturation block, fixed limits, dynamic upper and fixed lower, dynamic upper and lower\"><\/p>\r\n\r\n<p>All three instances of the subsystems get their upper limit\r\nfrom a block named <i>system<\/i>\/up, and their lower limit from a block named <i>system<\/i>\/lo.\u00a0\r\nIn the case where the limits are fixed, the block is a constant block.\u00a0 In the\r\ncase where the limit is dynamic (external source), the block is an inport.\u00a0 To\r\nachieve this, the block runs some M-code that replaces the Constant block with\r\nan Inport when the source is external and replaces the Inport with a Constant\r\nblock when the source is internal.<\/p>\r\n\r\n<p>In future posts we will examine:<\/p>\r\n\r\n<p><ul>\r\n    <li>Mask dialog callbacks<\/li>\r\n    <li>Mask initialization and self modifiable library blocks<\/li>\r\n    <li>Best practices for masking<\/li>\r\n<\/ul><\/p>\r\n\r\n<p><strong>Now it\u2019s your turn<\/strong><\/p>\r\n\r\n<p>Have you implemented masks using these concepts?\u00a0 Share your\r\nexperience <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=25&amp;#comment\">here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Masking does more than just put a professional interface on\r\nyour algorithm. \u00a0Simulink blocksets provide elaborate graphical user interfaces\r\n(GUIs) to control the behavior of blocks.\u00a0 The block... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2008\/08\/05\/advanced-masking-concepts\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,47],"tags":[48,441],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/25"}],"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\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}