{"id":123,"date":"2013-05-22T14:51:01","date_gmt":"2013-05-22T14:51:01","guid":{"rendered":"http:\/\/cto.dyalog.com\/?p=123"},"modified":"2014-07-10T14:14:54","modified_gmt":"2014-07-10T14:14:54","slug":"c3pi-opens-eyes","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2013\/05\/c3pi-opens-eyes\/","title":{"rendered":"C3Pi Opens Eyes at the APL Moot"},"content":{"rendered":"<div id=\"attachment_129\" style=\"width: 452px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/mice-at-moot.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-129\" class=\" wp-image-129 \" alt=\"The &quot;Three Blind Mice&quot; at the APL Moot at the YHA in the Lee Valley\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/mice-at-moot.jpg\" width=\"442\" height=\"266\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/mice-at-moot.jpg 552w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/mice-at-moot-300x180.jpg 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/mice-at-moot-497x300.jpg 497w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><p id=\"caption-attachment-129\" class=\"wp-caption-text\">Sam Gutsell, Shaquil Sidiki and James Greeley (aka &#8220;Three Blind Mice&#8221;) at the APL Moot at the YHA in the Lee Valley<\/p><\/div>\n<p>This weekend, the Dyalog C3Pi reached the final stop on the European spring tour, attending the\u00a0British APL Association&#8217;s\u00a0<a title=\"moot.aplwiki.com\" href=\"http:\/\/moot.aplwiki.com\/\" target=\"_blank\">Annual General Meeting and &#8220;Moot&#8221;<\/a>\u00a0just north of London, where the robot met the famous <a title=\"Three Blind Mice\" href=\"http:\/\/threeblindmiceapl.wordpress.com\/\" target=\"_blank\">mice from Optima<\/a>. The day before, the C3Pi also travelled to an\u00a0<a title=\"OSHUG Event 26\" href=\"http:\/\/oshug.org\/event\/26\" target=\"_blank\">OSHUG meeting in London on Thursday<\/a>,\u00a0where\u00a0<a title=\"quick2wire.com\" href=\"http:\/\/quick2wire.com\/\" target=\"_blank\">Romilly Cocking<\/a>\u00a0was talking about\u00a0<a title=\"Quick2link (GitHub)\" href=\"https:\/\/github.com\/quick2wire\/quick2link\" target=\"_blank\">quick2link<\/a>. Alas, poor C3Pi was confined to\u00a0a cardboard box due to problems with wiring up its new \u201ceyes\u201d:<\/p>\n<div id=\"attachment_127\" style=\"width: 407px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/red-eyes.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-127\" class=\" wp-image-127\" title=\"Resistance is Futile!\" alt=\"Sharp &quot;GP2Y0A21YK0F&quot; IR sensors attached to the Dyalog C3Pi\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/red-eyes.jpg\" width=\"397\" height=\"195\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/red-eyes.jpg 496w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/red-eyes-300x147.jpg 300w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><p id=\"caption-attachment-127\" class=\"wp-caption-text\">Resistance is Futile!<\/p><\/div>\n<p><a title=\"Laws of Robotics - Wikipedia\" href=\"http:\/\/en.wikipedia.org\/wiki\/Three_Laws_of_Robotics\" target=\"_blank\">Asimov&#8217;s third law of robotics<\/a> states that\u00a0<i>a robot must protect its own existence<\/i>.\u00a0Thanks to the addition of a <a title=\"SHARP IR Distance Sensor\" href=\"http:\/\/sharp-world.com\/products\/device\/lineup\/data\/pdf\/datasheet\/gp2y0a21yk_e.pdf\" target=\"_blank\">SHARP infrared distance measuring sensor<\/a>, our robot is now capable of at least not running head first into walls or other obstructions (and if the obstruction is a spectator, we&#8217;re also providing some support for the first law)!<\/p>\n<div id=\"attachment_128\" style=\"width: 390px\" class=\"wp-caption aligncenter\"><a style=\"font-style: normal; line-height: 24px; text-decoration: underline;\" href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/first-third-laws.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-128\" class=\"size-full wp-image-128\" style=\"border-color: #bbbbbb; margin-top: 0.4em; background-color: #eeeeee;\" title=\"First and Third Laws of Robotics in Action\" alt=\"first-third-laws\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/first-third-laws.jpg\" width=\"380\" height=\"275\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/first-third-laws.jpg 380w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/first-third-laws-300x217.jpg 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/a><p id=\"caption-attachment-128\" class=\"wp-caption-text\">C3Pi obeying the First and Third Laws of Robotics<\/p><\/div>\n<h2>Connecting the Sensor to the Raspberry Pi<\/h2>\n<p>The sensor is attached to an analog input pin on the Arduino (we picked pin #0). Our Arduino command interpreter, which allows APL on the Rasperry Pi to use the Arduino as a &#8220;controller&#8221; for analog and digital I\/O, was extended with an \u201cAnalog Read\u201d command consisting of the letter \u201ca\u201d followed by a byte giving the pin number and a dummy pad byte in order to ensure that the command length is 3 bytes (the fixed length simplifies the interpreter). Thus, if APL transmits (97 0 0) to address 4 on the I2C bus, and then issues an I2C read command, it will receive a string containing the current voltage (up to 5v, in 1024ths) measured \u2013 for example \u201c<strong>a0:480;<\/strong>\u201d if the input is 2v. We elected to include a confirmation of the pin number in the result, and separators which will allow us to send several sensor input values in a single string, as we add more sensors to the robot.<\/p>\n<p>In the <a title=\"APLBot repository\" href=\"https:\/\/github.com\/APLPi\/APLBot\" target=\"_blank\">APLBot GitHub Repository<\/a>, The DyaBot class has been extended to run a background thread which updates the value of a new property called \u201cIRange\u201d, every 100ms (a public method UpdateIRange can be called at any time to refresh the value). The input voltage is converted to a distance in centimetres, using the tables from the sensor datasheet. The next blog post will illustrate some of the data that we are now able to collect from the sensor.<\/p>\n<p>The DrivePi game code also runs a background thread which monitors the value of IRange, and stops the wheels if the measured distance drops below 20cm &#8211; but this code still needs some testing and tweaking.<\/p>\n<p><span style=\"color: #000000; font-weight: bold;\">Accelerometer and Gyro on the Way<\/span><\/p>\n<p>My experience to date is that controlling the robot is a little bit tricky, because the output of the wheels seems quite variable (changes from day to day, and from hour to hour). Determining the position of the robot using &#8220;dead reckoning&#8221; based on the voltage applied to the wheels seems unlikely to succeed. We either need to find some more reliable wheels &#8211; or find some sensors that can help us understand what is going on.<\/p>\n<p>I have been able to lay my hands on an <a title=\"MPU6050\" href=\"http:\/\/www.invensense.com\/mems\/gyro\/mpu6050.html\" target=\"_blank\">MPU-6050 motion tracking device from InvenSense<\/a>. We&#8217;ll be trying to wire this up over the next couple of weeks and see whether it allows us to accurately track the motion of the robot. We will also soon take delivery of an ultra-sonic sonar mounted on a servo, so we can start measuring longer distances accurately (the IR sensor is really only suitable for collision avoidance). Once these are wired up, all we have to do is write &#8220;a little&#8221; APL code to do the localization and mapping!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This weekend, the Dyalog C3Pi reached the final stop on the European spring tour, attending the\u00a0British APL Association&#8217;s\u00a0Annual General Meeting and &#8220;Moot&#8221;\u00a0just north of London, where the robot met the famous mice from Optima. The day before, the C3Pi also &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2013\/05\/c3pi-opens-eyes\/\">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":[12,4,9,5],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-cto","category-events","category-raspberry-pi","category-robots"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/123","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=123"}],"version-history":[{"count":21,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":468,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions\/468"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}