{"id":557,"date":"2014-08-02T17:29:02","date_gmt":"2014-08-02T17:29:02","guid":{"rendered":"http:\/\/www.dyalog.com\/blog\/?p=557"},"modified":"2014-08-04T10:06:26","modified_gmt":"2014-08-04T10:06:26","slug":"dancing-with-the-bots","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2014\/08\/dancing-with-the-bots\/","title":{"rendered":"Dancing with the Bots"},"content":{"rendered":"<p>Last week the &#8216;bots were busy preparing for the <a title=\"J Conference 2014\" href=\"http:\/\/www.jsoftware.com\/jwiki\/Community\/Conference2014\" target=\"_blank\">J Language Conference<\/a> in Toronto, where they made their first public appearance together. Upon returning to Bramley they continued training and we are proud to present the first recording of their new dance:<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\"  id=\"_ytid_13519\"  width=\"584\" height=\"329\"  data-origwidth=\"584\" data-origheight=\"329\"  src=\"https:\/\/www.youtube.com\/embed\/oO50UqFBsCw?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"autoplay; encrypted-media\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/p>\n<p>The &#8216;bots are both running the same <a title=\"DyaBot code on GitHub\" href=\"https:\/\/github.com\/APLPi\/APLBot\">DyaBot class<\/a> as <a title=\"Driving my Pi\" href=\"http:\/\/www.dyalog.com\/blog\/2013\/05\/driving-my-pi\/\">last year<\/a>. This class exposes a property called Speed, which is a 2-element vector representing the speed of the right and left wheels respectively. Valid values range from +100 (full speed ahead) to -100 (full reverse). The annotations displayed at the top left show the settings used for each step of the dance.<\/p>\n<h2>Controlling Two Robots at Once using Isolates<\/h2>\n<p>Isolates are a new feature included with Dyalog version 14.0, designed to make it easy to perform distributed processing. In addition to making it easy to used all the cores on your own laptop or workstation, isolates make it possible to harness the power of other machines. This requires the launching of an &#8220;isolate server&#8221; on each machine that wants to offer its services:<\/p>\n<div id=\"attachment_564\" style=\"width: 612px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2014\/08\/Isolate-Server-on-DyaBot001.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-564\" class=\"size-full wp-image-564\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2014\/08\/Isolate-Server-on-DyaBot001.png\" alt=\"Starting an isolate server using PuTTY to run Dyalog on the robot.\" width=\"602\" height=\"378\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2014\/08\/Isolate-Server-on-DyaBot001.png 602w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2014\/08\/Isolate-Server-on-DyaBot001-300x188.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2014\/08\/Isolate-Server-on-DyaBot001-477x300.png 477w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/a><p id=\"caption-attachment-564\" class=\"wp-caption-text\">Starting an isolate server on DyaBot00 using PuTTY.<\/p><\/div>\n<p>Once we have an isolate server running on each robot we can take control of them from a remote session as follows:<\/p>\n<pre><code class=\"language-apl\">\u00a0\u00a0\u00a0\u00a0\u00a0 )load isolate\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #.isolate.AddServer 'dyabot00' (7052)\u00a0\u00a0\u00a0\u00a0\u00a0 \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #.isolate.AddServer 'dyabot04' (7052)\r\n      bots\u2190isolate.New\u00a8Bot Bot\r\n      bots.Init<\/code>\r\n dyabot00  dyabot04<\/pre>\n<p>Above, we create two instances of the Bot namespace. The expression Bots.Init invokes the Init function, which returns the hostname, in each isolate:<\/p>\n<pre><code class=\"language-apl\">:Namespace Bot\r\n\r\n\u00a0\u00a0\u00a0 \u2207 r\u2190Init;pwd\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 pwd\u2190\u220a\u2395SH'pwd' \u235d Find out where to copy from\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #.\u2395CY botws\u2190pwd,'\/DyaBot\/DyaBot.dws' \u235d copy ws\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 i\u2190\u2395NEW #.DyaBot \u236c \u235d Make DyaBot instance \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 r\u2190\u2395SH'hostname' \u235d Return hostname\r\n\u00a0\u00a0\u00a0\u00a0\u2207\r\n\r\n:EndNamespace<\/code><\/pre>\n<p>Next, we define a function &#8220;run&#8221; that will take a vector of dance steps as input. Each step is a character vector (because that makes editing slightly easier!) containing five numbers: The first two set the speed of one robot, the next two the speed of the other and the fifth defines the duration of the step. After each step we pause for a second, to give humans time to appreciate the spectacle:<\/p>\n<pre><code class=\"language-apl\">\r\n    \u2207 run cmds;data;i;cmd;z\r\n[1]\u00a0\u00a0\u00a0 \u2395DL 5\r\n[2]\u00a0\u00a0\u00a0 :For i :In \u2373\u2262cmds\r\n[3]\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 :If ' '\u2228.\u2260cmd\u2190i\u2283cmds\r\n[4]\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data\u21901 0 1 0 1\u22822\u2283\u2395VFI cmd \u235d Cut into 3 numeric pieces\r\n[5]\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 z\u2190bots.{i.Speed\u2190\u2375}2\u2191data \u22c4 \u2395DL\u2283\u00af1\u2191data \u22c4 z\u2190bots.(i.Speed\u21900)\r\n[6]\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u2395DL 1\r\n[7]\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 :EndIf\r\n[8]\u00a0\u00a0\u00a0 :EndFor\r\n    \u2207\r\n<\/code><\/pre>\n<p>Now we are ready to roll: Call the run function with a suitable array and watch the robots dance (see the video at the top)!<\/p>\n<pre><code class=\"language-apl\">\u00a0\u00a0\u00a0\u00a0\u00a0 \u2191choreography<\/code>\r\n50\u00a0 50\u00a0 0\u00a0\u00a0 0 1.5\r\n\u00a00\u00a0\u00a0 0 50\u00a0 60 1.2\r\n50 \u00af50 50 \u00af50 0.3\r\n20\u00a0 80 10\u00a0 70 5 \u00a0\r\n50 \u00af50 50 \u00af50 0.3\r\n50\u00a0 50\u00a0 0\u00a0\u00a0 0 1.5\r\n\u00a00\u00a0\u00a0 0 50\u00a0 60 1.2\r\n\r\n<code class=\"language-apl\">\u00a0\u00a0\u00a0\u00a0\u00a0 dance choreography<\/code><\/pre>\n<p>Join us again next week to hear what happened when Romilly came to Bramley to help wire up the accelerometer and gyro!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week the &#8216;bots were busy preparing for the J Language Conference in Toronto, where they made their first public appearance together. Upon returning to Bramley they continued training and we are proud to present the first recording of their &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2014\/08\/dancing-with-the-bots\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,8,12,9,5],"tags":[],"class_list":["post-557","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-apl-language","category-cto","category-raspberry-pi","category-robots"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=557"}],"version-history":[{"count":19,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/557\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}