{"id":235,"date":"2011-12-27T09:00:39","date_gmt":"2011-12-27T14:00:39","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=235"},"modified":"2011-12-28T10:36:58","modified_gmt":"2011-12-28T15:36:58","slug":"model-based-design-dilemma","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2011\/12\/27\/model-based-design-dilemma\/","title":{"rendered":"Model-Based Design Dilemma"},"content":{"rendered":"<p>I am currently working on a model and I have a dilemma. There are two ways I could model my system. I need you to tell me which approach is best and why.<\/p>\r\n<h2>I need your help!<\/h2>\r\n\r\n<p><strong>The Goal<\/strong><\/p>\r\n\r\n<p>I am building a model to drive a small robot made of Lego blocks. The system is similar to the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/19-delta-sigma-toolbox-nxtway-gs-self-balancing-two-wheeled-robot-controller-design\">NXTWay-GS<\/a> submission on the MATLAB Central.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q4\/theRobot.png\" alt=\"NXTWay-GS\"><\/p>\r\n\r\n<p>Following a <a href=\"https:\/\/www.mathworks.com\/solutions\/model-based-design.html\">Model-Based Design<\/a> approach, I want to setup my files so that I can easily develop my controller in simulation and generate code to test my algorithm on the real hardware. This means that in simulation I need to send my actuator commands to an LTI system approximating the system dynamics; and for code generation I need to send and receive signals from hardware drivers.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q4\/hardwareVSsim.png\" alt=\"Hardware drivers and simulation model\"><\/p>\r\n\r\n<p>My question now is: <em>What is the best way to include these 2 sets of blocks in my model architecture?<\/em><\/p>\r\n\r\n<p><strong>Option 1: Two Top Models<\/strong><\/p>\r\n\r\n<p>My first option is to create 2 top models that will both refer to the same controller using <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/ug\/f4-141721.html\">model referencing<\/a>.<\/p>\r\n\r\n<p>I would have one top model for simulation:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q4\/SimulationModel.png\" alt=\"Model for simulation\"><\/p>\r\n\r\n<p>and one top model for code generation:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q4\/HardwareModel.png\" alt=\"model for code generation\"><\/p>\r\n\r\n<p><strong>Option 2: Subsystem Variants<\/strong><\/p>\r\n\r\n<p>My second option is to create one top model. In this top model, use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/simulink\/slref\/variantsubsystem.html\">Subsystem Variants<\/a> to switch between the simulation and the hardware drivers:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2011Q4\/oneTop.png\" alt=\"One top model with 2 variant\"><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>What architecture do you prefer? For which reasons? Do you see other options? I am very interested to hear your comments and ideas. Please leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=235&amp;#comment\">comment here<\/a>.<\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>I am currently working on a model and I have a dilemma. There are two ways I could model my system. I need you to tell me which approach is best and why.\r\nI need your help!\r\n\r\nThe Goal\r\n\r\nI am... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2011\/12\/27\/model-based-design-dilemma\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[50,21,66,24,30,181,10],"tags":[445,241],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/235"}],"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=235"}],"version-history":[{"count":30,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/235\/revisions\/300"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}