{"id":138,"date":"2013-03-03T20:50:58","date_gmt":"2013-03-03T20:50:58","guid":{"rendered":"http:\/\/bech.in\/?p=138"},"modified":"2021-10-22T16:02:49","modified_gmt":"2021-10-22T16:02:49","slug":"lesson-4","status":"publish","type":"post","link":"https:\/\/bech.in\/?p=138","title":{"rendered":"Lesson 4"},"content":{"rendered":"<p><strong>Date:<\/strong> 28th of Februar 2013<br \/>\n<strong>Participating group members:<\/strong> Thomas Winding and Morten D. Bech, and Kenneth joined us one hours into the exercises Thursday, and everyone was there Saturday.<br \/>\n<strong>Activity duration<\/strong><br \/>\nThursday 3,5 hours<br \/>\nSaturday 5,0 hours<\/p>\n<p><strong>Overall goal<\/strong><br \/>\nThe overall goal for this lesson is to make a black line following robot using a light sensor and a PID control algorithm. The robot should be able to detect the color green and stop if it does.<\/p>\n<p><strong>Overall plan<\/strong><br \/>\nTo complete our goal we will follow the instruction in the lesson plan which is available <a href=\"http:\/\/legolab.cs.au.dk\/DigitalControl.dir\/NXT\/Lesson4.dir\/Lesson.html\">here<\/a>.<\/p>\n<p><strong>Black\/White Detection<\/strong><br \/>\nWe would like to know what kind of values our light sensor detects for different light and dark areas, and what values different colors are measured as. As a small extra exercise we would like to see how our measurements compare to the ones we did in our <a href=\"http:\/\/bech.in\/?p=11\">first lab session<\/a>. <\/p>\n<p><em>Plan<\/em><br \/>\nWe already the light sensor mounted on the robot from the previous weeks, which means that we simply have to do the measurements. As Ole recommended using raw values from the sensor instead of the percentage values normally measured by using the readValue() method on the sensor, we will be changing the program to do that. We will, however, do a measurement of the percentage for the comparison mentioned above.<\/p>\n<p><em>Result<\/em><br \/>\nThe measurements we obtained from the sensor was:<\/p>\n<table>\n<thead>\n<th>Color<\/th>\n<th>Percentages<\/th>\n<th>Raw value<\/th>\n<\/thead>\n<tbody>\n<tr>\n<td>White<\/td>\n<td>57<\/td>\n<td>431<\/td>\n<\/tr>\n<tr>\n<td>Black<\/td>\n<td>38<\/td>\n<td>625<\/td>\n<\/tr>\n<tr>\n<td>Green<\/td>\n<td>44<\/td>\n<td>573<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>Conclusion<\/em><br \/>\nThe values we got this time differ slightly from the values we obtained at the first lesson, but we assume that is because that the cause of that is that we placed the light sensor at a somewhat large distance in the first lesson.<\/p>\n<p><strong>Line Follower with Calibration<\/strong><br \/>\nThe goal here is to get familiar with the program LineFollowerCal and determine how the it works.<\/p>\n<p><em>Plan<\/em><br \/>\nTo accomplish our goal we will at first have a look at the supplied program and try to determine what it is supposed to do. Afterwards we will upload it to our robot, run it and observe what happens.<\/p>\n<p><em>Result<\/em><br \/>\nAfter reading the code we had a rough idea that the robot would most likely behave like a bang-bang robot. We uploaded the program to the NXT and ran it. We captured the performance of the robot in a small video which is available <a href=\"http:\/\/www.youtube.com\/watch?feature=player_detailpage&#038;v=bjFWvzxpr30\">here<\/a> or you can watch it below.<\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/bjFWvzxpr30?feature=player_detailpage\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><em>Conclusion<\/em><br \/>\nAs we expected the robot did have the behaviour of a bang-bang robot, that is, the values for white and black are stored first, a threshold is calculated and the robot then moves forward while turning right\/left depending on whether it measures a black or white value.<\/p>\n<p><strong>ColorSensor with Calibration &#038; Line follower  that stops  in a Goal Zone<\/strong><br \/>\nWe want to extend the functionality of the Line Following Robot to include detecting the color green. When detecting the green color robot should stop.<\/p>\n<p><em>Plan<\/em><br \/>\nTo add the new need functionality we have created a class called ColorSensor as suggested in the lesson plan . We took a lot of the functionality from the BlackWhiteSensor class into the new class and added a new variable green for calibrating the value of green. Furthermore we need to add a boolean method akin to the black() and white() for checking if the sensor sees green.<\/p>\n<p><em>Result<\/em><br \/>\nWe made the needed changes to the program and found that we had to change the decision algorithm of black and white a bit. The change needed was that if the sensor sees green it can&#8217;t see white or black which is illustrated below.<br \/>\n<a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/bw-green1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/bw-green1.png\" alt=\"bw-green\" width=\"202\" height=\"141\" class=\"aligncenter size-full wp-image-148\" \/><\/a><br \/>\nA video documenting the robot in action was recorded and is available <a href=\"http:\/\/youtu.be\/lpCAghSWtXA\">here<\/a> or can be watched below.<\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/lpCAghSWtXA?feature=player_detailpage\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><em>Conclusion<\/em><br \/>\nWith some small modifications to the code of when we detect black and white, and letting the detection of green be an interval of 40, it worked smoothly. For the interested reader the code of the ColorSensor-class is available <a href=\".\/code\/digital_control\/lab4\/ColorSensor.java\">here<\/a>. The change to the LineFollowerCal-class was to include a new else if clause in the while-loop to ask if sees green and then stop the motors.<\/p>\n<p><strong>PID Line Follower<\/strong><br \/>\nExpanding on the line follower using the light sensor, we are going to use the light sensor to write a line following program for the robot again, this time with PID regulation.<\/p>\n<p><em>Plan<\/em><br \/>\nWe are going to implement the parts of the PID regulation one by one, starting with the proportional control, then the integral and finally the derivative. After implementing each part, we will also run the program on the robot to make sure that it is functional.<\/p>\n<p><em>Results<\/em><br \/>\nWe implemented our PID Line Follower base on [1] is note upon the subject. We started with the P-term and got that to work fairly quick. However when we tried to implement the I-term the robot quiet quickly began to spin around the line, but then after implementing the D-term it stopped to spin around and instead began to follow the line. Finally we tried to tweak the constant values so that the robot would follow the line more smoothly, however after about an hour the results weren&#8217;t improving and we stop. When tweaking the constants we sometimes experienced that robot had a very hard time following the line in very sharp corners.<\/p>\n<p>We made a small video clip of the robot which is available <a href=\"http:\/\/youtu.be\/sb7aF8P9Yjg\" title=\"Digital Control: PID Line Follower\" target=\"_blank\" rel=\"noopener\">here<\/a> or can be seen below.<\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/sb7aF8P9Yjg?feature=player_detailpage\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><em>Conclusion<\/em><br \/>\nAs can be seen in the video clip the robot oscillates quiet a bit, and as mentioned earlier we had quiet some trouble with tweaking the constants to improve the performance of the robot.<\/p>\n<p>The class code is available <a href=\"http:\/\/bech.in\/code\/digital_control\/lab4\/PIDLineFollower.java\" title=\"PIDLineFollower.java\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p><strong>Color sensor<\/strong><br \/>\nThe final task at hand is to construction\/implement a program which using a color sensor follows a black line and stops when it sees green.<\/p>\n<p><em>Plan<\/em><br \/>\nOur plan is to use a simple bang-bang algorithm with the output color from the sensor to decide the direction and speed of the robot. We are going to try smooth the curves by having five intervals or colors that we work with that is black, dark gray, gray, light gray and white. Finally if the color is green we stop the robot.<\/p>\n<p><em>Results<\/em><br \/>\nThe implementation was quickly in place, however we had a lot of trouble with how to use the color sensor correctly in the implementation. Fortunately we found <a href=\"http:\/\/lejos.svn.sourceforge.net\/viewvc\/lejos\/branches\/lejos_nxj_0.9.1-x\/samples\/src\/org\/lejos\/sample\/colorsensortest\/ColorSensorTest.java?revision=6528&#038;view=markup\" title=\"ColorSensorTest.java\" target=\"_blank\" rel=\"noopener\">this example<\/a> which was a lot of help.<\/p>\n<p>After a minor change to the code it worked very well as can be seen from the video clip below or <a href=\"http:\/\/www.youtube.com\/watch?feature=player_embedded&#038;v=TyYlK8-xDnQ\" title=\"Digital Control: Line Follower with Stop using ColorSensor \" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/TyYlK8-xDnQ?feature=player_embedded\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><em>Conclusion<\/em><br \/>\nAs can be seen in the video clip the robot work nicely but we haven&#8217;t implemented using a PID control as we get a RGB vector or a color ID back from the sensor and the easiest way for us to implement it was the color id.<\/p>\n<p>The class code is available <a href=\"http:\/\/bech.in\/code\/digital_control\/lab4\/RColLineFol.java\" title=\"RColLineFol.java\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p><strong>Status<\/strong><br \/>\nWe had some trouble with tweaking the PID controller correctly and therefore we need figure out how to get that done correctly. This is very important for the next weeks Segway robot which is an inverted pendulum.<\/p>\n<p><strong>References<\/strong><br \/>\n[1] <a href=\"http:\/\/www.inpharmix.com\/jps\/PID_Controller_For_Lego_Mindstorms_Robots.html\" title=\"A PID Controller For Lego Mindstorms Robots\" target=\"_blank\" rel=\"noopener\">A PID Controller For Lego Mindstorms Robots<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date: 28th of Februar 2013 Participating group members: Thomas Winding and Morten D. Bech, and Kenneth joined us one hours into the exercises Thursday, and everyone was there Saturday. Activity duration Thursday 3,5 hours Saturday 5,0 hours Overall goal The &hellip; <a href=\"https:\/\/bech.in\/?p=138\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-digicon"],"_links":{"self":[{"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":20,"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/789"}],"wp:attachment":[{"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}