{"id":362,"date":"2013-05-09T08:52:16","date_gmt":"2013-05-09T08:52:16","guid":{"rendered":"http:\/\/bech.in\/?p=362"},"modified":"2021-10-22T16:02:34","modified_gmt":"2021-10-22T16:02:34","slug":"lesson-10","status":"publish","type":"post","link":"http:\/\/bech.in\/?p=362","title":{"rendered":"Lesson 10"},"content":{"rendered":"<p><strong>Date:<\/strong> 2nd of May 2013<br \/>\n<strong>Participating group members:<\/strong> Kenneth Baag\u00f8e, Morten D. Bech and Thomas Winding<br \/>\n<strong>Activity duration:<\/strong> 5 hours<\/p>\n<p><strong>Goal<\/strong><br \/>\nThe goal of this lesson is to test the BumperCar example provided by lejOS according to the <a href=\"http:\/\/legolab.cs.au.dk\/DigitalControl.dir\/NXT\/Lesson10.dir\/Lesson.html\" title=\"Lesson plan\" target=\"_blank\" rel=\"noopener\">lesson plan<\/a>. Furthermore the goal is also to expand upon the BumperCar example, also described in the lesson plan.<\/p>\n<p><strong>Plan<\/strong><br \/>\nWe will use the basic robot from the previous lesson and add an ultrasonic sensor and a touch sensor to it. We will then run the BumperCar example and observe how it functions and describe that. Afterwards we will modify the program according to modifications described in the lesson plan and observe how they work.<\/p>\n<p><strong>Progress<\/strong><br \/>\nWe added the ultrasonic sensor and the touch sensor to the robot and also added a bumper to increase the detection range of the touch sensor (pictured below).<\/p>\n<p><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11.jpg\" alt=\"BumperCar\" width=\"2048\" height=\"1536\" class=\"alignnone size-full wp-image-382\" srcset=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11.jpg 2048w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11-300x225.jpg 300w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11-1024x768.jpg 1024w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/Photo-07-05-13-13.42.11-400x300.jpg 400w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/p>\n<p>Running the basic BumperCar example we saw that the robot would back off and turn a bit if the ultrasonic sensor was close to an obstacle and the same thing happened if the touch sensor was pressed. We also tried holding down the touch sensor and this resulted in the robot repeatedly backing off and turning slightly. The same behaviour was observed if we held an object close to the ultrasonic sensor. We did, however, have a slight problem with the ultrasonic sensor detecting even a very low obstacle, so to actually test the functionality of the touch sensor we had to temporarily remove the obstacle detection using the ultrasonic sensor.<\/p>\n<p><em>Adding the Exit behavior<\/em><br \/>\nTo add the Exit behavior, described in the lesson plan, we added an additional class in the BumperCar class, aptly named Exit, which, like the other classes, implemented the Behavior interface.<\/p>\n<p>The implementation of the class looked like the following:<br \/>\n<div id=\"attachment_372\" style=\"width: 298px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/exitClass.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-372\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/exitClass.png\" alt=\"Implementation of the Exit behavior\" width=\"288\" height=\"246\" class=\"size-full wp-image-372\" \/><\/a><p id=\"caption-attachment-372\" class=\"wp-caption-text\">Implementation of the Exit behavior<\/p><\/div><\/p>\n<p>We also had to modify the DetectWall behavior as the suppress method was not implemented properly, it simply did nothing. We went about the basic idea of the suppression the same way that it was done in the DriveForward behavior: We added a _suppressed boolean and implemented the suppress() method to set this boolean to true. Furthermore the action() method of the DetectWall behavior did not properly check for suppression either. Thus we also modified the action() method to immediately return from both of the rotate() methods and added a loop that would yield its timeslices until either the rotation was completed or the behavior was suppressed.<\/p>\n<div id=\"attachment_373\" style=\"width: 695px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallAction.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-373\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallAction.png\" alt=\"Our modification of the detectWall action\" width=\"685\" height=\"154\" class=\"size-full wp-image-373\" srcset=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallAction.png 685w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallAction-300x67.png 300w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallAction-500x112.png 500w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/a><p id=\"caption-attachment-373\" class=\"wp-caption-text\">Our modification of the detectWall action<\/p><\/div>\n<p>Pressing the escape button seems to exit the program immediately, however from a previous lesson we are aware that the ultrasonic has a short delay of about 30ms when pinging, this will, of course, block the entire program and it is most likely because of the delay being relatively short that we are not able to observe it affecting the program.<\/p>\n<p><em>Functionality of the Arbitrator class<\/em><br \/>\nWhen the triggering condition of the DetectWall behavior is true, the Arbitrator class does not call the takeControl method of the DriveForward behavior. This can be seen in the code snippet below from the Arbitrator class: It starts from the top priority, checking if the takeControl() method returns true, if it does not, it moves on to the second highest priority and so on. If the triggering condition, however, returns true, the method breaks out of the loop as there is no need to check for the lower priorities.<\/p>\n<div id=\"attachment_377\" style=\"width: 290px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/arbitrator.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-377\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/arbitrator.png\" alt=\"The loop that determines the highest priority that wants control of the robot\" width=\"280\" height=\"129\" class=\"size-full wp-image-377\" \/><\/a><p id=\"caption-attachment-377\" class=\"wp-caption-text\">The loop that determines the highest priority that wants control of the robot<\/p><\/div>\n<p><em>Sampling the ultrasonic sensor in an isolated thread<\/em><br \/>\nTo alleviate the problem of the ultrasonic sensor delaying the program every time it is sampled, we added the sampling to a thread that would update a variable which the takeControl() method would then evaluate upon.<\/p>\n<div id=\"attachment_378\" style=\"width: 369px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/ultrasonic.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-378\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/ultrasonic.png\" alt=\"Implementation of a thread to remove the delay from the sonic sensor\" width=\"359\" height=\"278\" class=\"size-full wp-image-378\" srcset=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/ultrasonic.png 359w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/ultrasonic-300x232.png 300w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><\/a><p id=\"caption-attachment-378\" class=\"wp-caption-text\">Implementation of a thread to remove the delay from the sonic sensor<\/p><\/div>\n<p><em>Further modifying the DetectWall behavior<\/em><br \/>\nTo make the robot move backwards for one second before turning we employed the same basic principles as when we modified the DetectWall behavior to be able to be suppressed, as described above. We made the robot move backwards until either a second had passed or the behavior was suppressed by way of another loop, see the code below.<\/p>\n<div id=\"attachment_379\" style=\"width: 695px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallActionModified.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-379\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallActionModified.png\" alt=\"The DetectWall action that moves backwards for one second before turning\" width=\"685\" height=\"287\" class=\"size-full wp-image-379\" srcset=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallActionModified.png 685w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallActionModified-300x125.png 300w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallActionModified-500x209.png 500w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/a><p id=\"caption-attachment-379\" class=\"wp-caption-text\">The DetectWall action that moves backwards for one second before turning<\/p><\/div>\n<p>We were also asked to try to modify the code to make it possible to interrupt the DetectWall action if the touch sensor was pressed or the ultrasonic sensor detected an object. This interruption should then start the action of the behavior again. We were not able to make this part work, we tried adding a boolean to tell if the action was already running and if it was running, the program would stop the motors and start the action over. Unfortunately we couldn&#8217;t come up with a solution for this, however when we implemented motivation, which is described in the next section, the interruption worked without any problems. Again we were not exactly sure why.<\/p>\n<p><em>Motivation<\/em><br \/>\nTo make the robot motivation based we used the Behavior and Arbitrator implementations provided by Ole Caprani[1][2]. We then changed our modified BumperCar to return integers on the different takeControl() methods instead of booleans. DriveForward was given a low value as it is still a low priority behavior while Exit was given a high value as it should still take precedence over other behaviors. To make DetectWall return a somewhat lower value when it was already active, we added a boolean that was set to true when the action method was run and set to false when the method finished. Thus the takeControl method was able to differentiate between the two states.<\/p>\n<div id=\"attachment_380\" style=\"width: 424px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallTakeControlMotivation.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-380\" src=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallTakeControlMotivation.png\" alt=\"takeControl() for the motivation-based DetectWall behavior\" width=\"414\" height=\"77\" class=\"size-full wp-image-380\" srcset=\"http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallTakeControlMotivation.png 414w, http:\/\/bech.in\/wp-content\/uploads\/2013\/05\/detectWallTakeControlMotivation-300x55.png 300w\" sizes=\"auto, (max-width: 414px) 100vw, 414px\" \/><\/a><p id=\"caption-attachment-380\" class=\"wp-caption-text\">takeControl() for the motivation-based DetectWall behavior<\/p><\/div>\n<p><strong>Conclusion<\/strong><br \/>\nWe have followed the lesson plan almost to its full extend, the only catch was that we had trouble implementing the DetectWall behaviour so that it could be interrupted while turning if e.g. the touch sensor was activated. However the change to motivation based decision making fixed this problem as we were able to dynamically return higher values if some other action was in progress.<\/p>\n<p><strong>Class-files<\/strong><br \/>\n<a href=\"http:\/\/bech.in\/code\/digital_control\/lab10\/BumperCar.java\" title=\"BumperCar.java\" target=\"_blank\" rel=\"noopener\">BumperCar<\/a> &#8211; Arbitrator<br \/>\n<a href=\"http:\/\/bech.in\/code\/digital_control\/lab10\/motivation\/BumperCar.java\" title=\"BumperCar.java\" target=\"_blank\" rel=\"noopener\">BumperCar<\/a> &#8211; Motivation based<br \/>\n<a href=\"http:\/\/bech.in\/code\/digital_control\/lab10\/motivation\/Behavior.java\" title=\"Behavior.java\" target=\"_blank\" rel=\"noopener\">Behavior<\/a> &#8211; Motivation based<br \/>\n<a href=\"http:\/\/bech.in\/code\/digital_control\/lab10\/motivation\/Arbitrator.java\" title=\"Arbitrator\" target=\"_blank\" rel=\"noopener\">Arbitrator<\/a> &#8211; Motivation based<\/p>\n<p><strong>Reference<\/strong><br \/>\n[1] http:\/\/legolab.cs.au.dk\/DigitalControl.dir\/NXT\/Lesson10.dir\/Behavior.java<br \/>\n[2] http:\/\/legolab.cs.au.dk\/DigitalControl.dir\/NXT\/Lesson10.dir\/Arbitrator.java<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date: 2nd of May 2013 Participating group members: Kenneth Baag\u00f8e, Morten D. Bech and Thomas Winding Activity duration: 5 hours Goal The goal of this lesson is to test the BumperCar example provided by lejOS according to the lesson plan. &hellip; <a href=\"http:\/\/bech.in\/?p=362\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-digicon"],"_links":{"self":[{"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":19,"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":779,"href":"http:\/\/bech.in\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions\/779"}],"wp:attachment":[{"href":"http:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bech.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}