{"id":47,"date":"2012-05-29T02:11:53","date_gmt":"2012-05-29T02:11:53","guid":{"rendered":"http:\/\/arkorobotics.com\/blog\/?p=47"},"modified":"2012-06-01T00:06:25","modified_gmt":"2012-06-01T00:06:25","slug":"layerone-2012-autonomous-car-stanley-jr-badge-hack","status":"publish","type":"post","link":"http:\/\/arkorobotics.com\/blog\/?p=47","title":{"rendered":"Layerone 2012 Autonomous Car &#8220;Stanley Jr&#8221; Badge Hack"},"content":{"rendered":"<p>Woo! Haven&#8217;t been blogging much since most of my recent projects have required me to keep quiet until they are done.. it sucks not to be able to share a lot of what&#8217;s going on \ud83d\ude41<\/p>\n<p>Anyway, with more to come I thought I&#8217;d share a recent project that was completed within a few hours of tinkering and hacking.<\/p>\n<p>But first a quick back story, I had the great pleasure to be running the Hardware Hacking Village this year at <a href=\"http:\/\/www.layerone.org\/\" target=\"_blank\">Layerone 2012<\/a>\u00a0along side with Krs, Charliex, and Mmca of Nullspace Labs. Layerone is a security conference that covers everything from computer security to lockpicking and hardware hacking. Each year since last year, Layerone has had <a href=\"http:\/\/charliex2.wordpress.com\/2012\/05\/24\/preparing-for-layerone-2012\/\" target=\"_blank\">electronics badges<\/a> and has provided a working space for attendees to build and hack their badges. What happens is we pretty much pack up most of our\u00a0equipment\u00a0at the <a href=\"http:\/\/032.la\/\" target=\"_blank\">Nullspace Labs Hackerspace in Downtown LA<\/a>\u00a0and bring it down to the conference. This year we had 12 metcal solder stations and 10 microscopes along with many tools such as heat guns and tweezers to help you build and hack your badge. <a href=\"http:\/\/charliex2.wordpress.com\/\">Charliex<\/a>, Krs, and Mmca spent the last 2 week designing, revising, ordering, testing, and building them (along with some help of a few NSL members,\u00a0fiances, \u00a0and myself). With only 4 hours and 45 minutes left to spare, we all arrived at the Layerone hotel at 4:15am.. good times.<\/p>\n<p>This years badge was a bullet proof pcb that was half an Arduino and half an RC car controller (with traces running between them allowing you to control it with the Arduino). When you bought the kit to populate the boards you also received an RC car which you could interface with your badge. I felt that human control was fun, but thought it would be awesome if my badge could just follow me and avoid\u00a0obstacles so I wouldn&#8217;t have to carry it around my neck \ud83d\ude1b<\/p>\n<p>I, \u00a0knowing ahead of time what the badge would be, decided to order a few parts a week in advance so when I had some time I could build and hack my own badge. I should note that there was a badge hacking competition held at the conference, and very fairly, I was disqualified due to prior knowledge \ud83d\ude09 no problem though, I have an awesome car that drives itself! I should note that you should check out <a href=\"http:\/\/charliex2.wordpress.com\/\">Charliex&#8217;s blog<\/a> which has a much more\u00a0in depth\u00a0write up\u00a0about the badge hacking\u00a0competition. Mad props to Jason who made a <a href=\"http:\/\/w6iee.blogspot.com\/2012\/05\/i-won-layerone-badge-hacking-contest.html\">morse code keyer<\/a> and Funsized who made <a href=\"http:\/\/zachpahle.wordpress.com\/2012\/05\/29\/layerone-badge-hack\/\">an EL-wire\/IMU based badge<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>Back to the car, I purchased the following:<\/p>\n<p>&nbsp;<\/p>\n<p>Sparkfun Prototyping Shield: ($14)\u00a0<a href=\"http:\/\/www.sparkfun.com\/products\/7914\">http:\/\/www.sparkfun.com\/products\/7914<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Parallax Ultrasonic Range Sensor PING))): ($30) <a href=\"http:\/\/www.parallax.com\/StoreSearchResults\/tabid\/768\/txtSearch\/ping\/List\/0\/SortField\/4\/ProductID\/92\/Default.aspx\">http:\/\/www.parallax.com\/&#8230;.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Servo Motor Hitec HS-81: ($16) \u00a0<a href=\"http:\/\/www.xheli.com\/hrc31081s.html?gclid=CLvBwq6hpLACFY4FRQods2JqXg\">http:\/\/www.xheli.com\/hrc31081s.html?gclid=CLvBwq6hpLACFY4FRQods2JqXg<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>and \u00a0few wires..<\/p>\n<p>&nbsp;<\/p>\n<p>What I decided to make was an autonomous car that would use the badge as a base\/brain, the car as the controls, and the ultrasonic sensor on top of a servo for finding and avoiding obstacles.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290363510_c3fdd402b5_c.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-48\" title=\"stanley jr\" src=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290363510_c3fdd402b5_c.jpg\" alt=\"\" width=\"600\" height=\"800\" srcset=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290363510_c3fdd402b5_c.jpg 600w, http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290363510_c3fdd402b5_c-225x300.jpg 225w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>I ended up naming it &#8220;Stanley Jr&#8221; after the notorious &#8220;<a href=\"http:\/\/cs.stanford.edu\/group\/roadrunner\/stanley.html\" target=\"_blank\">Stanley<\/a>&#8221; DARPA Grand Challenge car built by Stanford&#8217;s team. I will take this moment to note that if you are a GoogleX Labs employer (or know of one) and are looking for someone madly obsessed with self-driving cars to work on your team, I will gladly send you my resume \ud83d\ude00 I build robots too!<\/p>\n<p>So between helping others build their badges for the con, I was able to piece together the hardware in under an hour. After some troubleshooting I had a non-continuous hour of coding. The results aren&#8217;t great by a long shot when it comes to autonomous vehicles, but I do plan to improve the code and make Stanley Jr smarter. As of right now, the ultrasonic pans in three positions, left 45deg, center 90deg, and right 135deg. Since the steering is practically\u00a0trianary (left, center, right) I figured it&#8217;d be best to sweep the three directions it had available, move a small step, and then repeat. After solving a few bugs and fixing \u00a0other peoples badges I had some working code. The goal the vehicle is given is to drive in the direction in which it sees the furthest distance. If the\u00a0distances\u00a0on all three options is too small, it will not make any moves to avoid accidents. Improved code that is currently in the works has a mode where it backs up in the direction it came in and then picks the alternative direction from that previous move.<\/p>\n<p>The proper way to go about this control system would be to have a smooth sweeping of the ultrasonic sensors to obtain a more accurate model of the world. The car would then be given the goal of &#8220;drive forward and don&#8217;t hit anything&#8221;. \u00a0Then rather than &#8220;sweep, stop, think, act, repeat&#8221;, it would be constantly moving at a regulated speed based on how far it can see. Once objects to its center get close it will pick the furthest distance out and go in that direction with the intention to return to wheels center. So lots to come \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<p>Stanley Jr is pretty stupid at this point, but not bad for about 2 hours of work. I plan to drastically improve the code and eventually move to a wheelchair base system that can drive around a beer keg\u00a0delivering beer to bystanders while using a Microsoft Kinect to both\u00a0recognize\u00a0people and avoid objects.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Here&#8217;s a video and few pictures of the car:<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/V4vyJ-SEwXo\" frameborder=\"0\" width=\"560\" height=\"315\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290365398_42ec05b93a_c.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-51\" title=\"stanley jr 2\" src=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290365398_42ec05b93a_c.jpg\" alt=\"\" width=\"600\" height=\"800\" srcset=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290365398_42ec05b93a_c.jpg 600w, http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290365398_42ec05b93a_c-225x300.jpg 225w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290367392_fc4a17cd2b_c.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-52\" title=\"stanley jr 3\" src=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290367392_fc4a17cd2b_c.jpg\" alt=\"\" width=\"800\" height=\"600\" srcset=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290367392_fc4a17cd2b_c.jpg 800w, http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290367392_fc4a17cd2b_c-300x225.jpg 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290370940_108346d2e4_c.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-53\" title=\"stanley jr 4\" src=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290370940_108346d2e4_c.jpg\" alt=\"\" width=\"800\" height=\"600\" srcset=\"http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290370940_108346d2e4_c.jpg 800w, http:\/\/arkorobotics.com\/blog\/wp-content\/uploads\/2012\/05\/7290370940_108346d2e4_c-300x225.jpg 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Be warned, I wrote this code in a rush, it&#8217;s no where near complete or smart. Here&#8217;s the code:<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ Layerone 2012 Autonomous Car Code<br \/>\n\/\/ By: Arko<\/p>\n<p>#include &lt;Servo.h&gt;<\/p>\n<p>Servo myservo;<\/p>\n<p>int pos = 0;<\/p>\n<p>const int pingPin = 2;<\/p>\n<p>long world[4];<br \/>\nint world_count = 0;<\/p>\n<p>void setup()<br \/>\n{<br \/>\nSerial.begin(9600);<br \/>\nmyservo.attach(3);<\/p>\n<p>pinMode(13,OUTPUT);<\/p>\n<p>pinMode(9, OUTPUT); \/\/ BACK<br \/>\npinMode(8, OUTPUT); \/\/ FWD<\/p>\n<p>pinMode(7, OUTPUT); \/\/ RIGHT<br \/>\npinMode(6, OUTPUT); \/\/ LEFT<\/p>\n<p>}<\/p>\n<p>void loop()<br \/>\n{<\/p>\n<p>digitalWrite(6,HIGH);<br \/>\ndigitalWrite(7,HIGH);<br \/>\ndigitalWrite(8,HIGH);<br \/>\ndigitalWrite(9,HIGH);<\/p>\n<p>digitalWrite(13,HIGH);<br \/>\n\/\/ Obtain Environmental Model<\/p>\n<p>world_count = 0;<br \/>\ndelay(500);<\/p>\n<p>for(pos = 45; pos &lt; 180; pos += 45)<br \/>\n{<br \/>\nmyservo.write(pos);<br \/>\nlong duration, inches, cm;<br \/>\ndelay(500);<br \/>\npinMode(pingPin, OUTPUT);<br \/>\ndigitalWrite(pingPin, LOW);<br \/>\ndelayMicroseconds(2);<br \/>\ndigitalWrite(pingPin, HIGH);<br \/>\ndelayMicroseconds(5);<br \/>\ndigitalWrite(pingPin, LOW);<\/p>\n<p>pinMode(pingPin, INPUT);<br \/>\nduration = pulseIn(pingPin, HIGH);<\/p>\n<p>\/\/ convert the time into a distance<br \/>\ninches = microsecondsToInches(duration);<br \/>\ncm = microsecondsToCentimeters(duration);<\/p>\n<p>world[world_count] = cm;<br \/>\nworld_count++;<\/p>\n<p>Serial.print(inches);<br \/>\nSerial.print(&#8220;in, &#8220;);<br \/>\nSerial.print(cm);<br \/>\nSerial.print(&#8220;cm&#8221;);<br \/>\nSerial.println();<\/p>\n<p>delay(1000);<br \/>\n}<\/p>\n<p>Serial.print(&#8220;World: &#8220;);<br \/>\nfor(int c=0; c&lt;3; c++)<br \/>\n{<br \/>\nSerial.print(world[c]);<br \/>\nSerial.print(&#8220;,&#8221;);<br \/>\n}<\/p>\n<p>digitalWrite(13,LOW);<\/p>\n<p>delay(100);<\/p>\n<p>\/\/ Control<\/p>\n<p>\/\/ Direction 0 &#8211; LEFT<br \/>\n\/\/ 1 &#8211; CENTER<br \/>\n\/\/ 2 &#8211; RIGHT<\/p>\n<p>if((world[0] &gt; world[1]) &amp;&amp; (world[0] &gt; world[2]) &amp;&amp; (world[0] &gt; 30)) \/\/ Go Left<br \/>\n{<br \/>\ndigitalWrite(6, LOW);<br \/>\ndigitalWrite(7, HIGH);<br \/>\ndigitalWrite(8, LOW);<br \/>\nSerial.println(&#8220;LEFT&#8221;);<br \/>\n}<br \/>\nelse if((world[0] &lt; world[2]) &amp;&amp; (world[2] &gt; world[1]) &amp;&amp; (world[2] &gt; 30)) \/\/ Go Right<br \/>\n{<br \/>\ndigitalWrite(6, HIGH);<br \/>\ndigitalWrite(7, LOW);<br \/>\ndigitalWrite(8, LOW);<br \/>\nSerial.println(&#8220;RIGHT&#8221;);<br \/>\n}<br \/>\nelse if(world[1] &gt; 30) \/\/ Go Center<br \/>\n{<br \/>\ndigitalWrite(6, HIGH);<br \/>\ndigitalWrite(7, HIGH);<br \/>\ndigitalWrite(8, LOW);<br \/>\nSerial.println(&#8220;CENTER&#8221;);<br \/>\n}<br \/>\ndelay(500);<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>long microsecondsToInches(long microseconds)<br \/>\n{<br \/>\nreturn microseconds \/ 74 \/ 2;<br \/>\n}<\/p>\n<p>long microsecondsToCentimeters(long microseconds)<br \/>\n{<br \/>\nreturn microseconds \/ 29 \/ 2;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Woo! Haven&#8217;t been blogging much since most of my recent projects have required me to keep quiet until they are done.. it sucks not to be able to share a lot of what&#8217;s going on \ud83d\ude41 Anyway, with more to come I thought I&#8217;d share a recent project that was completed within a few hours [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47"}],"collection":[{"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":18,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":58,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions\/58"}],"wp:attachment":[{"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/arkorobotics.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}