{"id":155,"date":"2011-12-16T06:41:12","date_gmt":"2011-12-16T06:41:12","guid":{"rendered":"https:\/\/peterklemperer.com\/blog\/?p=155"},"modified":"2011-12-16T06:41:13","modified_gmt":"2011-12-16T06:41:13","slug":"lego-line-follower","status":"publish","type":"post","link":"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/","title":{"rendered":"Lego Line Follower"},"content":{"rendered":"<p>Playing with Legos again tonight! I made a little simple Lego Mindstorm line follower using the light sensor and two motors providing differential drive.<\/p>\n<p><a href=\"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/p1030360\/\" rel=\"attachment wp-att-157\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"157\" data-permalink=\"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/p1030360\/\" data-orig-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360.jpg\" data-orig-size=\"600,450\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"P1030360\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360-300x225.jpg\" data-large-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360.jpg\" class=\"aligncenter size-full wp-image-157\" title=\"P1030360\" src=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360.jpg\" alt=\"\" width=\"600\" height=\"450\" srcset=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360.jpg 600w, https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360-300x225.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Simple project tonight because I haven&#8217;t posted in forever and this was fun. More code and video after the break.<\/p>\n<p><!--more--><\/p>\n<p>My Lego Mindstorms are super fun and are great for prototyping out new robot projects. For the line follower, I made a simple robot platform using the instructions from legoengineering.com for the design <a href=\"http:\/\/legoengineering.com\/library\/doc_details\/137-9797-basic-car-instructions.html\">9797 Simple Car<\/a>. The little swivel castor shown below is a nice improvement and I mounted the light sensor at the front of the robot instead of behind to prevent it from interfering with the castor.<\/p>\n<p><a href=\"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/p1030361\/\" rel=\"attachment wp-att-158\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"158\" data-permalink=\"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/p1030361\/\" data-orig-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361.jpg\" data-orig-size=\"600,450\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"P1030361\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361-300x225.jpg\" data-large-file=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361.jpg\" class=\"aligncenter size-full wp-image-158\" title=\"P1030361\" src=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361.jpg\" alt=\"\" width=\"600\" height=\"450\" srcset=\"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361.jpg 600w, https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030361-300x225.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>This version shown here tonight uses the default line following code bundled with the fantastic RobotC programming environment from robotc.org. I have reproduced pseudo-code below to illustrate their approach:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ntask main() {\r\n  while (true) {\r\n    \/\/ if you don't see the line turn left\r\n    \/\/ otherwise turn right\r\n    if (sensorValue(lightSensor) &lt; 55 ) {\r\n      motor(A) = 20;\r\n      motor(B) =  5;\r\n    } else {\r\n      motor(A) =  5;\r\n      motor(B) = 20;\r\n    }\r\n  } \/\/ end while\r\n} \/\/ end main\r\n<\/pre>\n<p>One thing I realized while testing out this code is that the difference between motor A and motor B determines the minimum line radius that can be followed. \u00a0This 4x difference works well for my small test pattern in my apartment. I could probably reduce this for a larger course.<\/p>\n<p><iframe loading=\"lazy\" title=\"Lego Line Follower\" src=\"https:\/\/player.vimeo.com\/video\/33766110?dnt=1&amp;app_id=122963\" width=\"640\" height=\"360\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write\"><\/iframe><\/p>\n<p>I made my test matt using some grey plastic from the Art Supply store and the white line from hockey stick tape I had laying around.<\/p>\n<p>Next steps:<\/p>\n<ul>\n<li>Automatic sensor calibration (wave the sensor over the line and set threshold as average of the min\/max)<\/li>\n<li>Increase speed until the robot flies off the table<\/li>\n<li>Adapt my Pololu 4-sensor line following sensor to the Mindstorms<\/li>\n<li>Adapt my Pololu 6-axis gyroscope\/accelerometer to the Mindstorms to do hill detection<\/li>\n<li>Add a decision point with a branching path or maybe a figure-8<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Playing with Legos again tonight! I made a little simple Lego Mindstorm line follower using the light sensor and two motors providing differential drive. Simple project tonight because I haven&#8217;t posted in forever and this was fun. More code and &hellip; <a href=\"https:\/\/peterklemperer.com\/blog\/2011\/12\/16\/lego-line-follower\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[38,6],"tags":[],"class_list":["post-155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-line-following","category-projects"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/peterklemperer.com\/blog\/wp-content\/uploads\/2011\/12\/P1030360.jpg","jetpack_shortlink":"https:\/\/wp.me\/p1VqWo-2v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/posts\/155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":0,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/media\/157"}],"wp:attachment":[{"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterklemperer.com\/blog\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}