{"id":26,"date":"2013-02-18T16:05:58","date_gmt":"2013-02-18T16:05:58","guid":{"rendered":"http:\/\/bech.in\/?p=26"},"modified":"2021-10-22T16:02:50","modified_gmt":"2021-10-22T16:02:50","slug":"lesson-2-sensing-and-sensors-analogdigital-conversion","status":"publish","type":"post","link":"https:\/\/bech.in\/?p=26","title":{"rendered":"Lesson 2"},"content":{"rendered":"<p><strong>Exercise 1:<\/strong><br \/>\n<em>Goal<\/em><br \/>\nThe goal of the exercise is to measure the distances that the ultrasonic sensor records with different distances and object\/materiales.<\/p>\n<p><em>Plan<\/em><br \/>\nWe are going to use hard and soft materiales at different distances and measure the actual distance with a\u00a0folding ruler.<br \/>\n<a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/IMAG0111.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-31\" alt=\"IMAG0111\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/IMAG0111-1024x682.jpg\" width=\"584\" height=\"388\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/IMAG0111-1024x682.jpg 1024w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/IMAG0111-300x200.jpg 300w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/IMAG0111-450x300.jpg 450w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p><em>Results<\/em><\/p>\n<table>\n<tbody>\n<tr>\n<td>Surface<\/td>\n<td>Sensor value<\/td>\n<td>Actual value<\/td>\n<\/tr>\n<tr>\n<td>Soft<\/td>\n<td>42<\/td>\n<td>42<\/td>\n<\/tr>\n<tr>\n<td>Soft<\/td>\n<td>79<\/td>\n<td>78<\/td>\n<\/tr>\n<tr>\n<td>Medium<\/td>\n<td>80<\/td>\n<td>78<\/td>\n<\/tr>\n<tr>\n<td>Medium<\/td>\n<td>42<\/td>\n<td>41<\/td>\n<\/tr>\n<tr>\n<td>Hard<\/td>\n<td>43<\/td>\n<td>42<\/td>\n<\/tr>\n<tr>\n<td>Hard<\/td>\n<td>78<\/td>\n<td>78<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>Conclusion<\/em><br \/>\nThe results contradict our expectations that the softer materiales would resolve in a larger difference between the measured and actual values. We expected that the softer materials would absorb the soundwaves and thus cause readings that would not be as accurate.<\/p>\n<p><strong>Exercise 2<\/strong><br \/>\n<em>Goal<\/em><br \/>\nTo see if different sample intervals will affect the distance measured by the ultrasonic sensor.<\/p>\n<p><em>Plan<\/em><br \/>\nThe way we are doing to test this by keeping the distance to the object constant and conduct measurements with different sample intervals.<\/p>\n<p><em>Result<\/em><br \/>\nWhile measuring we kept a constant distance of 17 cm.<\/p>\n<table>\n<tbody>\n<tr>\n<td>Sample interval<\/td>\n<td>Measured Distance<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>200<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>300<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>400<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>500<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>2000<\/td>\n<td>20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>Conclusion<\/em><br \/>\nAs can be seen from the results it made no difference using different sample intervals. This means that the old minimum interval is no longer necessary, it might&#8217;ve been present in the older versions of lejOS due to the possibility of the sensor receiving an ultrasonic ping which it sent previously and thus getting a wrong reading.<\/p>\n<p><strong>Exercise 3<\/strong><br \/>\n<em>Goal<\/em><br \/>\nOur goal in this exercise is to examine if it&#8217;s possible to measure 254 cm and to see whether a lower sample interval will affect the measurement.<\/p>\n<p><em>Plan<\/em><br \/>\nOur plan is to place the sensor towards a wall and move it away from the wall until we get a measurement of 254 cm, once we have that distance we will change the sample interval to be less than the time it takes to receive a echo. The time it takes sound to move 254 cm to wall and back again is 14.928 msec, which is calculated this way:<\/p>\n<p>(2*distance to travel)\/speed of sound -&gt;<br \/>\n(2 * 2.54m)\/340.29m\/sec = 0.014928sec = 14.928msec.<\/p>\n<p>Therefore we will set the sample interval to 5msec.<\/p>\n<p><em>Result<\/em><br \/>\nOur observation was that there was no difference when using the short sample interval. This let to a discussion with Ole Caprani in which he pointed out to us that the code might hold the answer &#8211; that no ping can be made until the echo has been received.<\/p>\n<p>After having a look at the code below from the LeJOS UltrasonicSensor-class we can see that the system waits for atleast 30msec before making another ping, which is more than the minimum wait time calculated above. This means that the sample interval does not actually have an impact on measurements.<\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/getDistance.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-43\" alt=\"getDistance\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/getDistance.png\" width=\"437\" height=\"386\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/getDistance.png 437w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/getDistance-300x264.png 300w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/getDistance-339x300.png 339w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><\/a> <a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/waitUntil.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-44\" alt=\"waitUntil\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/waitUntil.png\" width=\"366\" height=\"78\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/waitUntil.png 366w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/waitUntil-300x63.png 300w\" sizes=\"auto, (max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n<p><em>Conclusion<\/em><br \/>\nThe sample interval doesn&#8217;t affect the practical usage of the sensor, it simply delays measurements (the default of the sample interval is 300msec, which makes the time between pings atleast 330msec, so about three times a second.)<\/p>\n<p><strong>Exercise 4<\/strong><br \/>\n<em>Goal<\/em><br \/>\nFor this exercise the goal is to change the values of the constants in the code and observe what the changes does to the behaviour of the robot, and finally determine what kind of controller this is.<\/p>\n<p><em>Plan<\/em><br \/>\nThe way we go about this is by adjusting the value of one variable and leaving the other variables unchanged. By only working with one variable at a time we hope it will be easier to see what the variable controls and ultimately compare the results of changing the different constants to see which kind of controller it is.<\/p>\n<p><em>Result<\/em><br \/>\nBy changing the desiredDistance-variable in the program the only change in the behaviour we observed was that the distance to the object it found changed, the robot didn&#8217;t oscillate more or less around the point of the desiredDistance. On the other hand, changing the minPower-variable made the robot oscillate with larger amplitude around the specified desiredDistance.<\/p>\n<p><em>Conclusion<\/em><br \/>\nFrom what we have observed we conclude that the controller in question is a PID controller, because the oscillation is larger when we increase the motor power.<\/p>\n<p><strong>Exercise 5<\/strong><br \/>\n<em>Goal<\/em><br \/>\nIn the previous exercise we made the robot oscillate by just calculating the error between the current and desired point. Now we have to introduce the derivative term as described in [1].<\/p>\n<p><em>Plan<\/em><br \/>\nOur plan is to follow the instruction in [1] and introduce the necessary new code in the class.<\/p>\n<p><em>Result<\/em><br \/>\nWith the derivative term introduced in the code, the robot still oscillates a little, but less compared to the original implementation.<\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/exercise5_code.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-50\" alt=\"exercise5_code\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/exercise5_code.png\" width=\"661\" height=\"350\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/exercise5_code.png 661w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/exercise5_code-300x158.png 300w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/exercise5_code-500x264.png 500w\" sizes=\"auto, (max-width: 661px) 100vw, 661px\" \/><\/a><\/p>\n<p><em>Conclusion<\/em><br \/>\nBy introducing the derivative term in the program for the robot we have achieved less oscillation in the robot around the point of the desired distance.<\/p>\n<p><strong>Exercise 6<\/strong><br \/>\n<em>Goal<\/em><br \/>\nTo make a wall follower, using Philippe Hurbain&#8217;s concept for the RCX[2].<\/p>\n<p><em>Plan<\/em><br \/>\nFirst off we have to remount the ultrasonic sensor to place it at a 45 degree angle to the forward facing direction of the robot, which will cause the measurements of distance for the robot to be small if it&#8217;s turning towards the wall, while becoming increasingly larger when turning away from the wall. Next we will have to program the robot to utilize the ultrasonic sensor to follow the wall &#8211; we are going to do that based on Philippe Hurbain&#8217;s program, although we&#8217;ll have to chance the constants proposed in his code since they are based on the raw 0-1023 interval while we only have a 0-255 interval (the raw value parsed to centimeters). We will try to get the appropriate values for the constants by doing empirical research of turning the robot towards and away from the wall, while measuring.<\/p>\n<p><em>Result<\/em><br \/>\n<a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12-1024x624.jpg\" alt=\"Photo 18-02-13 16.44.12\" width=\"584\" height=\"355\" class=\"alignnone size-large wp-image-63\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12-1024x624.jpg 1024w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12-300x182.jpg 300w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12-492x300.jpg 492w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.12.jpg 1365w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.21.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.21.jpg\" alt=\"Photo 18-02-13 16.44.21\" width=\"584\" height=\"447\" class=\"alignnone size-large wp-image-64\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.21.jpg 945w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.21-300x229.jpg 300w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.21-391x300.jpg 391w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.35.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.35-1008x1024.jpg\" alt=\"Photo 18-02-13 16.44.35\" width=\"584\" height=\"593\" class=\"alignnone size-large wp-image-65\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.35-1008x1024.jpg 1008w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.35-295x300.jpg 295w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/Photo-18-02-13-16.44.35.jpg 1536w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/wall1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/02\/wall1-659x1024.jpg\" alt=\"wall1\" width=\"584\" height=\"907\" class=\"alignnone size-large wp-image-66\" srcset=\"https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/wall1-659x1024.jpg 659w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/wall1-193x300.jpg 193w, https:\/\/bech.in\/wp-content\/uploads\/2013\/02\/wall1.jpg 987w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><br \/>\nWe found it problematic to get the appropriate values for the constants and had to change the positioning of the sensor because it would get very large increases in distances measured when turning away from the wall. We suspect this was because, by chance, the receiving part of the sensor was the part that was the furthest away from the wall and thus a slight turn meant a larger increase in the angle to the wall.<\/p>\n<p><em>Conclusion<\/em><br \/>\nWe didn&#8217;t get the robot to work very well, but the concept did work. Compare to Fred G. Martin&#8217;s algorithm[1] the major differences are that we have five different states and Martin&#8217;s only three, the smoothing of Martin&#8217;s algorithm &#8211; 50% on one wheel and 100% on the other &#8211; can be compared to the two extra states in our program in which we let the wheel float. We still stop one of the wheels if we either get too close or too far from the wall to increase the turning angle.<\/p>\n<p><strong>References<\/strong><br \/>\n[1] Martin, Fred G. Robotic Explorations \u2013 A Hands-On Introduction to Engineering<br \/>\n[2] Philippe Hurbain, http:\/\/www.philohome.com\/wallfollower\/wallfollower.htm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Exercise 1: Goal The goal of the exercise is to measure the distances that the ultrasonic sensor records with different distances and object\/materiales. Plan We are going to use hard and soft materiales at different distances and measure the actual &hellip; <a href=\"https:\/\/bech.in\/?p=26\">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-26","post","type-post","status-publish","format-standard","hentry","category-digicon"],"_links":{"self":[{"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/26","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=26"}],"version-history":[{"count":24,"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions\/791"}],"wp:attachment":[{"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}