{"id":523,"date":"2012-03-05T20:00:58","date_gmt":"2012-03-06T01:00:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=523"},"modified":"2020-09-03T14:35:52","modified_gmt":"2020-09-03T18:35:52","slug":"running-simulink-models-on-lego-mindstorms-nxt","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/03\/05\/running-simulink-models-on-lego-mindstorms-nxt\/","title":{"rendered":"Running Simulink models on LEGO MINDSTORMS NXT"},"content":{"rendered":"<p>As you probably already know, MATLAB R2012a is now available for download!<\/p>\r\n\r\n<p>One of my favorite feature in this release is the built-in support for running models on low-cost target hardware, including LEGO\u00ae MINDSTORMS\u00ae NXT and <a href=\"http:\/\/beagleboard.org\/\">BeagleBoard<\/a>.\r\n\r\nTo give you an idea of this feature, here is a discussion I had with my friend <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/1297554-ashish-uthama\">Ashish Uthama<\/a>.<\/p>\r\n\r\n<p><strong>Background<\/strong><\/p>\r\n\r\n<p>Ashish and I started as <a href=\"\">Application Support Engineers<\/a> at MathWorks on the same day. While I was focusing on Simulink, he quickly transferred into the Image Processing Toolbox team. Consequently, he never really had opportunities to use Simulink.<\/p>\r\n\r\n<p>As part of my job, I am currently developing what we call <em>Model-Based Design Labs<\/em>. In these internal training labs, we use LEGO\u00ae MINDSTORMS\u00ae NXT to give participants a Model-Based Design experience. Ashish just signed up for the next set of labs I will teach next month.<\/p>\r\n\r\n<p><strong>Part 1 - Setup<\/strong><\/p>\r\n\r\n<p><strong>Ashish:<\/strong> Hey Guy, I am really excited about the Model-Based Design Lab!. I just bought a LEGO\u00ae MINDSTORMS\u00ae NXT kit. Here is a <a href=\"http:\/\/youtu.be\/-qNeEWFmvuw\">YouTube video<\/a> of what I did last weekend.<\/p>\r\n\r\n<p><strong>Guy:<\/strong> WHAT!!! You did not use Simulink to program the NXT???<\/p>\r\n\r\n<p><strong>Ashish:<\/strong> I was planning to, eventually. Isn\u2019t there a whole lot of setup steps? Like downloading drivers, compilers, blocks and the associated configuration? I\u2019ll get to it when I have more time to spare.<\/p>\r\n\r\n<p><strong>Guy:<\/strong> It used to be that way. But we have made the process a whole lot simpler with R2012a. Now it's literally a couple of clicks to install it. Once you have MATLAB and Simulink installed, go to the <strong>Tools<\/strong> menu and you should see an option to <em>Install\/Update Support Package<\/em>.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"Installing the NXT support package\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/install_package.png\"><\/p>\r\n\r\n<p>In R2012a, we offer support packages for two targets: <a href=\"http:\/\/beagleboard.org\/\">Beagle Board<\/a> and LEGO\u00ae MINDSTORMS\u00ae NXT. Select the one you need and Simulink will install everything needed.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"Selecting a target\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/install_select_target.png\"><\/p>\r\n\r\n<p><strong>Ashish:<\/strong> That's it? And I only need MATLAB and Simulink installed? No Simulink Coder?<\/p>\r\n\r\n<p><strong>Guy:<\/strong> Absolutely, and in fact, it also works with the <a href=\"https:\/\/www.mathworks.com\/academia\/student_version\">Student Version of MATLAB and Simulink<\/a>.<\/p>\r\n\r\n<p><em>A few hours later...<\/em><\/p>\r\n\r\n<p><strong>Part 2 - Results<\/strong><\/p>\r\n\r\n<p><strong>Ashish:<\/strong> With just a basic introduction to Simulink I received 4 years back when I started with tech support at MathWorks, it only took me a couple of minutes to install the required software and an hour or so to get my first bot programmed! Here is a video of what it does:<\/p>\r\n\r\n<P><iframe loading=\"lazy\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/1CPx3G7yk78?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\r\n\r\n<p><strong>Guy:<\/strong> Nice... and what does your model look like?<\/p>\r\n\r\n<p><strong>Ashish:<\/strong> As you can see below, I used the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/legomindstormsnxtcolorsensor.html\">Color Sensor<\/a> and configured it as a light sensor. I analyzed the data realized I could program it to follow the edge of the line.  The algorithm is simple, white means turn left and black means turn right.<\/p>\r\n\r\n<p><img decoding=\"async\" alt=\"Line Tarcking Model\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/lineTrackingModel.png\"><\/p>\r\n\r\n<p><strong>Guy:<\/strong> Not bad for a first try. I\u2019ll show you how to improve that in the Model-Based Design Lab.<\/p>\r\n\r\n<p><strong>Ashish:<\/strong> Considering it's actually running a compiled program on the hardware, this is really impressive. I am excited about the power of Simulink!<\/p>\r\n\r\n<p><strong>Guy:<\/strong> I really think this built-in support for running models on low-cost target hardware is a great tool to learn many engineering concepts.<\/p> \r\n\r\n<p><strong>Now it's your turn!<\/strong><\/p>\r\n\r\n<p>Do you think it could be useful for you to learn or teach engineering concepts and Model-Based Design?<\/p>\r\n\r\n<p>For more information, consult the documentation for more details on <a href=\" https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/ug\/bsejk4o-1roth.html\">how to run models on target hardware<\/a>.<\/p>\r\n\r\n<p>Leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=523&amp;#comment\">comment here<\/a>.<\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>As you probably already know, MATLAB R2012a is now available for download!\r\n\r\nOne of my favorite feature in this release is the built-in support for running models on low-cost target hardware,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/03\/05\/running-simulink-models-on-lego-mindstorms-nxt\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[71,65,16],"tags":[445],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/523"}],"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=523"}],"version-history":[{"count":57,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":9711,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/523\/revisions\/9711"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}