{"id":117,"date":"2021-04-19T18:51:32","date_gmt":"2021-04-19T18:51:32","guid":{"rendered":"https:\/\/mileggedrobots.eecs.umich.edu\/?page_id=117"},"modified":"2022-07-31T15:04:25","modified_gmt":"2022-07-31T15:04:25","slug":"control","status":"publish","type":"page","link":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/create-your-website-with-blocks\/control\/","title":{"rendered":"CONTROL"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Assuming that your Micro Maestro 6-Channel USB Servo Controller and servos are still wired as they were when you finished the <a href=\"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/create-your-website-with-blocks\/hardware\/\"><strong>Hardware<\/strong><\/a> build, we&#8217;ll start by double checking that the Controller is properly configured, then confirm your install of <strong>PyCKBot<\/strong> is able to communicate with your hardware. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, we&#8217;ll briefly demonstrate  <strong>scripted control<\/strong> (programming your robot to move in a prescribed manner) and <strong>dynamic control<\/strong> (piloting your robot in real time).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Controller USB Setup<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Launch the <strong>Pololu Maestro Control Center&nbsp;<\/strong>(i.e.,&nbsp;<strong>MCC<\/strong>) by:&nbsp;<ol><li>opening the&nbsp;<strong>Terminal Emulator<\/strong><\/li><li>Navigating to the Maestro folder (probably by running&nbsp;<kbd>cd ~\/Desktop\/maestro-linux<\/kbd>),&nbsp;typing<kbd> .\/MaestroControlCenter<\/kbd>, and hitting&nbsp;<kbd><strong>Enter<\/strong><\/kbd><\/li><\/ol><\/li><li>Go to the \u201cSerial Settings\u201d tab and make sure that you are using either of the USB settings. <ol><li>If you&#8217;ve changed anything here, you&#8217;ll need to click the &#8220;Apply Settings&#8221; button in the lower right in order to update the Controller firmware. The button will grey-out and become unclickable once the changes are saved.<\/li><\/ol><\/li><li>Close the MCC.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Testing-Testing-1-2-3<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Open the <strong>Terminal Emulator<\/strong>,&nbsp;navigate to your&nbsp;<strong>pyckbot\/tests<\/strong>&nbsp;folder (probably by typing&nbsp;<kbd>cd ~\/pyckbot\/tests<\/kbd>&nbsp;and hitting&nbsp;<kbd><strong>Enter<\/strong><\/kbd>)<\/li><li>Type <kbd>python3 test_pololu.py<\/kbd> and hit&nbsp;<kbd><strong>Enter<\/strong><\/kbd> to run the Controller-specific test script.<\/li><li>Servo0 should <em>tic-tok<\/em> once (for the &#8220;serial port&#8221; test), then <em>tic-tok<\/em> again (for the &#8220;CKBot layer&#8221; test). The following output will scroll in the Terminal window:<\/li><\/ol>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-code\"><code><code>Direct from serial port test\nhigh\nlow\noff\nCKBot layer\non\noff\nJoyApp layer<\/code><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After a brief pause a fresh blank &#8220;<strong>pygame<\/strong>&#8221; window will pop open. Tons<em> <\/em>of stuff will start scrolling madly across the open Terminal windows, <em>Matrix<\/em>-style, and Serv0 will start <em>tic-toking<\/em> back and forth, and keep it up basically indefinitely.  That&#8217;s fine. Click on the <strong>pygame<\/strong> window and hit <kbd>Q<\/kbd> (or select the Terminal window and hit <strong><kbd>Ctrl-c<\/kbd><\/strong>) to kill the script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>NOTE<\/strong>:  If the servo doesn&#8217;t move at all, it may be because it just happened to already be &#8220;zeroed&#8221; (unlikely, but possible). Just to be sure, unplug the servo from the Controller board, and then plug it back in. (It will juke a little during both unplugging and re-plugging). Now run <strong><em>test_pololu.py<\/em><\/strong> again. If the servo doesn&#8217;t move this time, there&#8217;s a problem (probably a dead servo or dead batteries).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scripted Control<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>First, launch the <strong>Interactive Python Shell<\/strong> (iPython) by typing  <kbd>ipython3<\/kbd> into any open Terminal window<\/li><li>Now enter the following each on its own line:<ol><li><kbd>import ckbot.logical as L<\/kbd><\/li><li><kbd>c = L.Cluster(required=[0x80,0x81,0x82],names={0x80:\"headfoot\", 0x81:\"mid\", 0x82:\"tailfoot\"})<\/kbd><\/li><\/ol><\/li><li>The terminal will reply<ol><li><code>Adding ServoModule headfoot<\/code><\/li><li><code>Adding ServoModule mid<\/code><\/li><li><code>Adding ServoModule tailfoot<\/code><\/li><\/ol><\/li><li>Enter <kbd>c.at.headfoot.set_pos(3000)<\/kbd><ol><li>Servo0&#8211;the &#8220;headfoot&#8221;&#8211;will move to position 3000<\/li><\/ol><\/li><li>Repeat step #4 several times, replacing <code><kbd>headfoot<\/kbd><\/code> with <kbd>mid<\/kbd> or <kbd>tailfoot<\/kbd>, and replacing <kbd>100<\/kbd> with various values between <kbd>-9000<\/kbd> and <kbd>9000<\/kbd>.  Watch your servos juke and jive!<\/li><li>When you are done, type <kbd>exit<\/kbd> and hit <kbd><strong>Enter<\/strong><\/kbd> to close iPython and return to the Terminal command line.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;re clearly just scratching the surface of scripted control. To learn much more about how PyCKBot works, please go work through our intro this library: <a href=\"https:\/\/birds.eecs.umich.edu\/pyckbot-doc\/\">Make Your Life Easier with PyCKBot<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dynamic-control\">Dynamic Control<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Using your text editor of choice (such as <strong>Mousepad<\/strong>\u2014included with Xubuntu\u2014or the command line utility <strong>pico<\/strong>) create the script shown below and save it on the Desktop as &#8220;<strong><em>dynamic.py<\/em><\/strong>&#8221; (You can just copy the text from the box below and paste it into your text editor.)<\/li><li>Next, using the Terminal, navigate to the Desktop and run your script by entering &#8220;<kbd>python3 dynamic.py<\/kbd>&#8221;  (The Terminal may reply with a string of <strong>WARNING<\/strong>s you can ignore.) A fresh blank &#8220;<strong>pygame<\/strong>&#8221; window will pop open. (Tons<em> <\/em>of stuff will start scrolling madly across the open Terminal windows, <em>Matrix<\/em>-style. That&#8217;s fine.)<\/li><li>Click on the <strong>pygame<\/strong> window, so that it&#8217;s in the foreground.<\/li><li>Hit the <kbd><strong>a<\/strong><\/kbd> and <kbd><strong>z<\/strong><\/kbd> keys. The following will happen: The headfoot servo will now move back and forth at your command.<\/li><li>Click on the <strong>pygame<\/strong> window and hit <kbd>Q<\/kbd> (or select the Terminal window and hit <strong><kbd>Ctrl-c<\/kbd><\/strong>) to kill the script.<\/li><li>Open <strong>dynamic.py<\/strong> in your text editor.  Can you:<ol><li>Add all three of your servos, controlling each with a different set of keys?  <\/li><li>Give each servo a real name (like &#8220;headfoot&#8221;) instead of calling it by its default (e.g., &#8220;Nx10&#8221;)?  <\/li><li>Change the increments your servo rotates with each keystrike?<\/li><\/ol><\/li><\/ol>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h3 class=\"wp-block-heading\">dynamic.py<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom joy.decl import *\n\nROBOT=dict(required=&#91;0x80])\n\ndef on_K_a(evt):\n\tapp.robot.at.Nx80.set_pos(9000)\n\ndef on_K_z(evt):\n\tapp.robot.at.Nx80.set_pos(-9000)\n\n### You need this at the end. It starts the robot and runs your code\n\nfrom joy import runFlatScript\nrunFlatScript(locals())\n<\/pre><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Universal-PyCKBot-Troubleshooting\">Universal PyCKBot Troubleshooting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If there is something wrong and you&#8217;re sure it isn&#8217;t hardware related (did you check the batteries?), then it may be the PyCKBot software, which is still being actively developed. The following procedure is always a safe move, and will ensure that you have the latest version of PyCKBot and its vital libraries:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Download this &#8220;<strong><a href=\"https:\/\/www.birds.eecs.umich.edu\/pyckbot.git\/public-net-installer.sh\">public-net-installer<\/a><\/strong>&#8221; shell script, if you don&#8217;t still have it sitting on your Desktop. (Your browser may open it instead of downloading, because the script is a text file. If that happens, you can just save the page to your Desktop as &#8220;<em>public-net-installer.sh<\/em>&#8220;)<\/li><li>Open the <strong>Terminal Emulator<\/strong> and navigate to your Desktop (probably by typing <kbd>cd Desktop<\/kbd> and hitting <strong><kbd>Enter<\/kbd><\/strong>)<\/li><li>Run the script by typing <kbd style=\"background-color: rgb(255, 255, 255); color: initial; font-size: 18px;\">bash public-net-installer.sh<\/kbd><strong style=\"color: initial; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, sans-serif;\"><em> <\/em><\/strong><span style=\"color: initial; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, sans-serif;\">into the Terminal window and hitting <\/span><strong style=\"color: initial; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, sans-serif;\"><kbd>Enter<\/kbd><\/strong>. (Get an error? No big deal; the script is gathering many packages from all over the place. An error usually means something was temporarily offline. Just try running the script again.)<\/li><li>If this doesn&#8217;t fix your problem, then zap the <em>pyckbot<\/em> directory: from the <strong>Terminal<\/strong> type <kbd>rm -rf ~\/pyckbot<\/kbd> and hit <kbd><strong>Enter<\/strong><\/kbd>). That&#8217;ll kill any lingering gremlins. Now run <em>public-net-installer.sh<\/em> once more (as per Step #3 in this process) and you&#8217;ll have a clean install. <\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Next Steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You have hardware and software.  You can make them work together. Let&#8217;s put it all together and <strong><a href=\"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/create-your-website-with-blocks\/build\/\">Build<\/a><\/strong> a robot that can actually do something.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Assuming that your Micro Maestro 6-Channel USB Servo Controller and servos are still wired as they were when you finished the Hardware build, we&#8217;ll start by double checking that the Controller is properly configured, then confirm your install of PyCKBot is able to communicate with your hardware. After that, we&#8217;ll briefly demonstrate scripted control (programming your robot to move in a prescribed manner) and dynamic control (piloting your robot in real time). Controller USB Setup Launch the Pololu Maestro Control&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/create-your-website-with-blocks\/control\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":7,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-117","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/pages\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":24,"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/pages\/117\/revisions"}],"predecessor-version":[{"id":408,"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/pages\/117\/revisions\/408"}],"up":[{"embeddable":true,"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/pages\/7"}],"wp:attachment":[{"href":"https:\/\/mileggedrobots.eecs.umich.edu\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}