{"id":10017,"date":"2018-08-17T09:00:14","date_gmt":"2018-08-17T13:00:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=10017"},"modified":"2018-08-17T12:37:56","modified_gmt":"2018-08-17T16:37:56","slug":"sphero","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/08\/17\/sphero\/","title":{"rendered":"Sphero"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n   <introduction><\/p>\n<p><i>Richard is a Consulting Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the aerospace industry.<\/i><\/p>\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1016860-richard-ruff\">Richard&#8217;s<\/a> pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481-sphero-connectivity-package\">Sphero Connectivity Package<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/4383814-danvir-sethi\">Danvir Sethi<\/a>.\n      <\/p>\n<p>   <\/introduction><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">Pick<\/a><\/li>\n<li><a href=\"#2\">What you get<\/a><\/li>\n<li><a href=\"#3\">Examples<\/a><\/li>\n<li><a href=\"#6\">Comments<\/a><\/li>\n<\/ul><\/div>\n<h3>Pick<a name=\"1\"><\/a><\/h3>\n<p>My pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481-sphero-connectivity-package\">Sphero Connectivity Package<\/a>.\n   <\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/main_Sphero\/Sphero.png\"> <\/p>\n<p>If you like MATLAB, then you probably enjoy playing with technical toys.  If so, then this post is for you. <a href=\"\">Sphero<\/a> is an inexpensive differential-drive robotic ball that can be controlled from a Bluetooth enabled device. It features a number of sensors (accelerometers, gyros, back-emf encoders) which allows it to measure its position and velocity with a fair degree of accuracy. The Sphero&#8217;s RGB LEDs allow it to glow in any color of choice, while the blue back LED indicates its current orientation. Two wheels allow the Sphero to roll on the ground and to rotate along its vertical axis.\n   <\/p>\n<p>While playing with the Sphero via your phone or tablet can be fun, being able to use your engineering skills and MATLAB and Simulink to interface with and control the Sphero is a blast.\n   <\/p>\n<h3>What you get<a name=\"2\"><\/a><\/h3>\n<p>The Sphero Connectivity package allows us to communicate with a Sphero from within MATLAB (and Simulink), on a computer running either Windows or 64-bit version of Mac OS 10.7 or earlier. The package is mainly based upon a &#8220;sphero&#8221; class, which in turn relies on the MATLAB Bluetooth class. The class methods and properties allow you to perform (within MATLAB) many operations available with the underlying Sphero API, such as connecting, disconnecting, sleeping, changing LED colors, reading (and\/or streaming back) the Sphero&#8217;s position and velocity, and commanding each of the 2 motors independently. A higher-level roll command can also be used to move the Sphero with a certain speed and direction. The Simulink library contained in the package also features Simulink blocks for setup, timing, and basic sensing and actuation.\n   <\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/main_Sphero\/SimulinkLibrary.png\"> <\/p>\n<p>The readme.txt file explains how to pair up the Sphero to your computer, install the package, and create Sphero objects in MATLAB, while several examples are also included to illustrate the use of the available commands and Simulink blocks.\n   <\/p>\n<h3>Examples<a name=\"3\"><\/a><\/h3>\n<p>Along with the Sphero class and corresponding Simulink library, the package includes a number of MATLAB examples and Simulink models the user can start from to develop their own custom controls.  Below are position plots for a couple of the supplied examples.\n   <\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/main_Sphero\/PositionPlot.png\"> <\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/main_Sphero\/PositionPlot2.png\"> <\/p>\n<p>What patterns can you get Sphero to trace?<\/p>\n<h3>Comments<a name=\"6\"><\/a><\/h3>\n<p>Danvir&#8217;s Sphero Connectivity Package provides a great example of how you can interface MATLAB and Simulink with hardware.  If you have a Sphero (or just need an excuse to buy one) give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=10017#respond\">here<\/a> or leave a <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481#comments\">comment<\/a> for Danvir.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_05761e2c964d43cbb0f833acedd46492() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='05761e2c964d43cbb0f833acedd46492 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 05761e2c964d43cbb0f833acedd46492';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Richard Ruff';\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_05761e2c964d43cbb0f833acedd46492()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n            the MATLAB code<br \/>\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2018a<\/p>\n<\/div>\n<p><!--\n05761e2c964d43cbb0f833acedd46492 ##### SOURCE BEGIN #####\n%% Sphero Connectivity Package\n%\n% Posted by *Richard Ruff* , August 17, 2018\n%\n% _Richard is a Consulting Engineer at MathWorks focused on the Embedded\n% Coder product for code generation, primarily in the Aerospace industry._\n% \n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1016860-richard-ruff\n% Richard's> pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481-sphero-connectivity-package\n% Sphero Connectivity Package> by\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/4383814-danvir-sethi\n% Danvir Sethi>.\n% \n%% Pick\n% My pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481-sphero-connectivity-package\n% Sphero Connectivity Package>.  \n% \n% <<C:\\MATLAB\\PCTransferMATLAB\\PickOfWeek\\Sphero\\Sphero.png>>\n% \n% If you like MATLAB, then you probably\n% enjoy playing with technical toys.  If so, then this post is for you.\n% < Sphero> is an inexpensive\n% differential-drive robotic ball that can be controlled from a Bluetooth\n% enabled device. It features a number of sensors (accelerometers, gyros,\n% back-emf encoders) which allows it to measure its position and velocity\n% with a fair degree of accuracy. The Sphero's RGB LEDs allow it to glow in\n% any color of choice, while the blue back LED indicates its current\n% orientation. Two wheels allow the Sphero to roll on the ground and to\n% rotate along its vertical axis.\n%\n% While playing with the Sphero via your phone or tablet can be fun, being\n% able to use your engineering skills and MATLAB and Simulink to interface\n% with and control the Sphero is a blast.  \n\n%% What you get\n% The Sphero Connectivity package allows us to communicate with a Sphero\n% from within MATLAB (and Simulink), on a computer running either Windows\n% or 64-bit version of Mac OS 10.7 or earlier. The package is mainly based\n% upon a \"sphero\" class, which in turn relies on the MATLAB Bluetooth\n% class. The class methods and properties allow you to perform (within\n% MATLAB) many operations available with the underlying Sphero API, such as\n% connecting, disconnecting, sleeping, changing LED colors, reading (and\/or\n% streaming back) the Sphero's position and velocity, and commanding each\n% of the 2 motors independently. A higher-level roll command can also be\n% used to move the Sphero with a certain speed and direction. The Simulink\n% library contained in the package also features Simulink blocks for setup,\n% timing, and basic sensing and actuation.\n%\n% <<C:\\MATLAB\\PCTransferMATLAB\\PickOfWeek\\Sphero\\SimulinkLibrary.png>>\n% \n% The readme.txt file explains how to pair up the Sphero to your computer,\n% install the package, and create Sphero objects in MATLAB, while several\n% examples are also included to illustrate the use of the available\n% commands and Simulink blocks. \n\n%% Examples\n% Along with the Sphero class and corresponding Simulink library, the\n% package includes a number of MATLAB examples and Simulink models the user\n% can start from to develop their own custom controls.  Below are position\n% plots for a couple of the supplied examples.\n%%\n% \n% <<C:\\MATLAB\\PCTransferMATLAB\\PickOfWeek\\Sphero\\PositionPlot.png>>\n% \n%%\n% \n% <<C:\\MATLAB\\PCTransferMATLAB\\PickOfWeek\\Sphero\\PositionPlot2.png>>\n% \n% What patterns can you get Sphero to trace?\n\n%% Comments\n% \n% Danvir's Sphero Connectivity Package provides a great example of how you\n% can interface MATLAB and Simulink with hardware.  If you have a Sphero\n% (or just need an excuse to buy one) give it a try and let us know what\n% you think <http:\/\/blogs.mathworks.com\/pick\/?p=10017#respond here> or leave\n% a <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/52481#comments\n% comment> for Danvir.\n%\n \n\n##### SOURCE END ##### 05761e2c964d43cbb0f833acedd46492\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/images\/pick\/Sean\/main_Sphero\/Sphero.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Richard is a Consulting Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the aerospace industry.<br \/>\nRichard&#8217;s pick this week is Sphero&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/08\/17\/sphero\/\">read more >><\/a><\/p>\n","protected":false},"author":131,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10017"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/131"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=10017"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10017\/revisions"}],"predecessor-version":[{"id":10033,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10017\/revisions\/10033"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=10017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=10017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=10017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}