User Tools

Site Tools


marvin:lab10

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
marvin:lab10 [2008/11/27 10:19] riepermarvin:lab10 [2008/11/28 09:16] (current) deva
Line 5: Line 5:
  
 ====Project Goal==== ====Project Goal====
-In this lab session we will investigate how a behaviour-based architecture(([[http://lejos.sourceforge.net/nxt/nxj/tutorial/Behaviors/BehaviorProgramming.htm]])), has been implemented in the subsumption API of leJOS NXJ. We will investigate the interface lejos.subsumption.Behavior and the class lejos.subsumption.Arbitrator and try to make an alternative implementation of the Arbitrator.+In this lab session we will investigate how a behaviour-based architecture(([[http://lejos.sourceforge.net/nxt/nxj/tutorial/Behaviors/BehaviorProgramming.htm]])), has been implemented in the subsumption API of LeJOS NXJ. We will investigate the interface lejos.subsumption.Behavior and the class lejos.subsumption.Arbitrator and try to make an alternative implementation of the Arbitrator.\\ 
 +\\ 
 +{{marvin:lab10-1.jpg?300}}\\ 
 +//Marvin//
  
-**Marvin**\\ 
-{{marvin:lab10-1.jpg?300}} 
  
 ====Plan==== ====Plan====
-The plan for today is devided into two parts. First we will investigate and evaluate the behaviour of BumperCar((Indsæt ref. til bumpercar.java)). And second we will change the behaviour of Arbitrator for BumberCar(([[http://legolab.daimi.au.dk/DigitalControl.dir/NXT/Lesson10.dir/Lesson.html]]))+The plan for today is devided into two parts. First we will investigate and evaluate the behaviour of BumperCar((BumperCar.java can be found in the example folder of the LejOS source code - http://lejos.sourceforge.net/nxj-downloads.php))And second make suggestions on how to improve the Arbitrator in LejOS to better suite the model described in Krink. 
 ===Part One=== ===Part One===
 This will include the following: This will include the following:
-  * Behaviour of BumberCar((ref hertil 1)) +  * Behaviour of BumberCar((BumperCar.java can be found in the example folder of the LejOS source code - http://lejos.sourceforge.net/nxj-downloads.php)) 
-  * Investigate the source code for the Arbitrator ((ref hertil 2)) +  * Investigate the source code for the Arbitrator((http://lejos.sourceforge.net/nxt/nxj/api/lejos/subsumption/Arbitrator.html)) 
-  * Implement a third behaviour called Exit that will react on Escape button +  * Implement a third behaviour called ExitOnEscape that will react on Escape button 
-  * Implement a fourth behaviour called Playsound that will react on Enter button+  * Implement a fourth behaviour called PlaySound that will react on Enter button 
 ===Part Two=== ===Part Two===
-Implementation of an alternative Arbitrator that will make sure that takeControl of all behaviours are called each time through the loop. When the Arbitrator is working we will compare it to the lejos Arbitrator.  +Suggest alternative implementation of an Arbitrator that will make sure that ''takeControl'' of all behaviours are called each time through the loop.
-====Execution====+
  
-The program bumberCar.java is run in the NXT and we observe what happens when the touch sensor is kept pressed constantly. We expect the hitWall behaviour to be active making Marvin go backwards and turn over and over. This is not what happens though and the reason for this is found by inspection of the arbitrator within the Lejos system. The source code for the arbitrator is shown below.  
  
-The lejOS Arbitrator+ 
 +====Execution==== 
 +The program BumberCar.java is run in the NXT and we observe what happens when the touch sensor is kept pressed constantly. We expect the ''HitWall'' behaviour to be active making Marvin go backwards and turn over and over. This is not what happens though and the reason for this is found by inspection of the arbitrator within the LejOS system. The source code for the arbitrator is shown below.  
 + 
 +The LejOS Arbitrator
 <code java> <code java>
 public class Arbitrator { public class Arbitrator {
Line 90: Line 95:
 </code> </code>
  
-Observe the test if(i != currentBehavior). This condition ensures that the same behaviour is not detected over and over, which is in fact the reason why HitWall() is not run continuously when the touch sensor is held pressed. Both DriveForward and HitWall contains the method takeControl and again by inspection of the arbitrator we observe that takeControl of DriveForward is called when HitWall is active, but because HitWall has a higher priority, the arbitrator waits until HitWall is done.\\  +Observe the test ''if(i != currentBehavior)''. This condition ensures that the same behaviour is not detected over and over, which is in fact the reason why ''HitWall()'' is not run continuously when the touch sensor is held pressed. Both ''DriveForward'' and ''HitWall'' contains the method ''takeControl'' and again by inspection of the arbitrator we observe that ''takeControl'' of ''DriveForward'' is called when ''HitWall'' is active, but because ''HitWall'' has a higher priority, the arbitrator waits until ''HitWall'' is done.\\  
-In order to further investigate the arbitrator we now implement a new behaviour called Exit, which calls System.exit(0) when the button escape is pressed. This new behaviour has the highest priority, which means that the priorities listed in descending order is Exit, HitWall and DriveForward. We now investigate what happens when pushing the escape button while HitWall is active. If Exit was an alarm indicator we would prefer that the current behaviour, HitWall, was interrupted when Exit is called. To our surprise, the result of this test is, that when Exit is called via the escape button the arbitrator allows HitWall to finish and further more it chooses DriveForward to be activated before the Exit. After some tests we realize that the arbitrator does not notice the escape button being pressed while HitWall is active. Therefore it activates DriveForward, which is called once by the arbitrator and only then the arbitrator will notice the Exit call. The reason that the arbitrator does not react to the Exit behaviour (even though it has the highest priority) when HitWall is active is, that the program is stuck in the while loop  while\\ \\ (!actionThread.done) {Thread.yield();\\ \\ The conclusion is that the arbitrator is working improperly in terms of a desired interrupt for the Exit behaviour. There are no reasons for further testing of this arbitrator as we may as well start to modify the arbitrator. One could of course write a new arbitrator from the ground off, but we believe that the arbitrator can be properly modified towards our desired goal. If we omit the line (i != currentBehavior) it is possible to run the same behaviour over and over, which could be important for an alarm sensor, which may have reason for re-activating itself. We may add another condition to the while loop, which allows an interrupt from a higher priority behaviour, but a final decision has not been made. The remaining time of this lab session we decided to devote to Motivation functions instead of working on a new arbitrator.      +In order to further investigate the arbitrator we now implement a new behaviour called Exit, which calls ''System.exit(0)'' when the button escape is pressed. This new behaviour has the highest priority, which means that the priorities listed in descending order is ''Exit''''HitWall'' and ''DriveForward''. We now investigate what happens when pushing the escape button while ''HitWall'' is active. If ''Exit'' was an alarm indicator we would prefer that the current behaviour, ''HitWall'', was interrupted when ''Exit'' is called. To our surprise, the result of this test is, that when ''Exit'' is called via the escape button the arbitrator allows ''HitWall'' to finish and further more it chooses ''DriveForward'' to be activated before the ''Exit''. After some tests we realize that the arbitrator does not notice the escape button being pressed while ''HitWall'' is active. Therefore it activates ''DriveForward'', which is called once by the arbitrator and only then the arbitrator will notice the ''Exit'' call. The reason that the arbitrator does not react to the ''Exit'' behaviour (even though it has the highest priority) when ''HitWall'' is active is, that the program is stuck in the while loop 
 +<code java> 
 +while(!actionThread.done) {Thread.yield();} 
 +</code> 
 +The conclusion is that the arbitrator is working improperly in terms of a desired interrupt for the ''Exit'' behaviour. There are no reasons for further testing of this arbitrator as we may as well start to modify the arbitrator. One could of course write a new arbitrator from the ground off, but we believe that the arbitrator can be properly modified towards our desired goal. If we omit the line ''(i != currentBehavior)'' it is possible to run the same behaviour over and over, which could be important for an alarm sensor, which may have reason for re-activating itself. We may add another condition to the while loop, which allows an interrupt from a higher priority behaviour, but a final decision has not been made. The remaining time of this lab session we decided to devote to Motivation functions instead of working on a new arbitrator.      
  
 ====Motivation Functions==== ====Motivation Functions====
-The "normal" case is that when hitWall is active, Marvin will back out, turn a little bit an step out of that rutine. But what if the hitWall rutine is activated repeatly. What happes then? In the group, we talked about the case where Marvin would hit a bouncing wall, e.g. a wall with a spring attached to tha back of it, so that it would move towards Marvin when pushed once. In this case Marvin would react the normal way, that is, back out and turn, but the wall will then hit him again, and this will repeat itself. In this case, it would be convient to implement some sort of mechanism that would help Marvin to get out of that situation. Lets could it a motivation to do something. Thiemo Krink(([[http://www.legolab.daimi.au.dk/DigitalControl.dir/Krink.pdf]])) has some proposals on this topic. Marvin could have some sort of motivation factor to get away from the wall on change direction. As is seen in the picture below we have drawn a simpel graph to illustrate how we think Marvin should behave in the case where he hits the wall several times.  +The "normal" case is that when hitWall is active, Marvin will back out, turn a little bit an step out of that routine. But what if the hitWall routine is activated repeatedly. What happens then? In the group, we talked about the case where Marvin would hit a bouncing wall, e.g. a wall with a spring attached to the back of it, so that it would move towards Marvin when pushed once. In this case Marvin would react the normal way, that is, back out and turn, but the wall will then hit him again, and this will repeat itself. In this case, it would be convenient to implement some sort of mechanism that would help Marvin to get out of that situation. Lets could it a motivation to do something. Thiemo Krink(([[http://www.legolab.daimi.au.dk/DigitalControl.dir/Krink.pdf]])) has some proposals on this topic. Marvin could have some sort of motivation factor to get away from the wall on change direction. As is seen in the picture below we have drawn a simple graph to illustrate how we think Marvin should behave in the case where he hits the wall several times. \\ 
- +\\ 
-**Motivation over time**\\ +{{:marvin:lab10-krink.png?300}}\\ 
-{{marvin:lab10-2.jpg?300}} +//The Krink model//\\ 
- +\\ 
-The first time Marvin hits the wall his motivation to backout and turn should be major. If takeControl takes over to reactivate the rutine the motivation should thereafter me minor because of e.g. the spring wall mentioned earlier. There after the motivation should again rise over some time (the time period is case not important as we only talk principles, but is ofcourse important in the implementation) to improve the motivation to get away from the wall. It should be noted that the first time Marvin hits the wall, it would be the normal case and after some time the motivation should be greater than normal state. This may not be that well illustrated on the graph.+{{:marvin:lab10-2.jpg?300}}\\ 
 +//Motivation over time//\\ 
 +\\ 
 +The first time Marvin hits the wall his motivation to back out and turn should be major. If ''takeControl'' takes over to reactivate the routine the motivation should thereafter me minor because of e.g. the spring wall mentioned earlier. There after the motivation should again rise over some time (the time period is case not important as we only talk principles, but is of course important in the implementation) to improve the motivation to get away from the wall. It should be noted that the first time Marvin hits the wall, it would be the normal case and after some time the motivation should be greater than normal state. This may not be that well illustrated on the graph.
  
 The implementation of this could be e.g. 10-20 seconds time interval from first hit to full motivation and could be an integer or percentage (floating point number) that will increase the speed Marvin backs up with and second the degree of turn that he makes. The implementation of this could be e.g. 10-20 seconds time interval from first hit to full motivation and could be an integer or percentage (floating point number) that will increase the speed Marvin backs up with and second the degree of turn that he makes.
  
-====Discussion==== 
-{{:marvin:lab10-krink.png}} 
 ====Conclusion==== ====Conclusion====
 +The LejOS implementation of the Arbitrator seems very random, and in many cases it disqualifies as an arbitrator.\\
 +A new implementation of the arbitrator could be made using the Krink model.
 +
marvin/lab10.1227777583.txt.gz · Last modified: 2008/11/27 10:19 by rieper