************************************************
ESEA - LESSON 9
Date: 13. november 2008
Teacher: Ole Caprani
Made by: Henrik Hagen, Klaus Neumann and
Martin Kristensen
************************************************
Todays lesson:
We have to investigate how a behavior-based architecture works. This behavior is implemented in the leJOS subsumption interface. For more info look at the class page.
BumperCar
For this exercise we use the car as instructed in the LEGO Mindstorm Education Base set 9797. And the code found at the class page.
1. Press the touch sensor and keep it pressed. What happends ? Explain.
The car drives backwards, turn a little and then stop. HitWall has the highest priority and when the bumper is kept in, it will never let takeControl go. !!! RETTES !!!
2. Both DriveForward and HitWall have a method takeControl that are called in the Arbitrator. Investigate the source code for theArbitrator and figure out if takeControl of DriveForward is called when HitWall is active.
It is, but HitWall has the highest priority so it will run if takeControl is true. DriveForward will wait until HitWall is done and then continue.
3. Implement a third behavior,Exit . This behavior should react to the ESCAPE button and call System.Exit(0) if ESCAPE is pressed. Exit should be the highest priority behavior. Try to press ESCAPE when HitWall is active (hint: set the back up time to 10 sec to be sure HitWall is active when ESCAPE is pressed). The Exit behavior is not activated immediately. Why (hint: look in the Arbitrator ) ? Can it happend that HitWall continues controlling the motors even after the suppress method has been called from the Arbitrator (hint: the answer is yes, explain) ?
For this we made our own class ExitCar
---------------------------------------------------------------------------------------------
import lejos.nxt.*;
import lejos.subsumption.*;
public class ExitCar implements Behavior {
public boolean takeControl() {
return Button.ESCAPE.isPressed();
}
public void suppress() {
}
public void action() {
System.exit(0);
}
}
---------------------------------------------------------------------------------------------
With this class we expect it to exit the program, but not immediately.
The program exited, but first when the HitWall was finished. We pressed the button when it was driving forward and the program exited at the moment it was pressed.
When it was in HitWall mode we had to hold the button pressed until the end of HitWall.
The reason why it does that, is that the whole behavior class is one thread, and HitWall calls thread.sleep('') which makes the whole behavior class sleep.
Yes it because it use non blocking functions.
4. Implement a fourth behavior PlaySound that react to the ENTER button and play a sound when the ENTER button is pressed. Insert an instance of this behavior in the Behavior array between the instances of Drive Forward and HitWall. Now Drive Forward has the lowest priority, PlaySound is next, then comes HitWall and Exit has the highest priority. Activate HitWall by a touch sensor press. While HitWall is active press ENTER and then ESCAPE. What happens ? Explain.
For this we again made our own class
---------------------------------------------------------------------------------------------
import lejos.subsumption.*;
import lejos.nxt.*;
public class PlaySound implements Behavior {
public boolean takeControl() {
return Button.ENTER.isPressed();
}
public void suppress() {
}
public void action() {
Sound.playTone(3500, 5000);
}
}
---------------------------------------------------------------------------------------------
We expect it to play a sound when enter is pressed and it has the highest priority.
When the HitWall mode is active it won't play the sound when enter is pressed, and the reason is the same as explained before.
Below is a little video witch show what happen when the buttons is pressed at different times.
Todays lesson:
We have to investigate how a behavior-based architecture works. This behavior is implemented in the leJOS subsumption interface. For more info look at the class page.
BumperCar
For this exercise we use the car as instructed in the LEGO Mindstorm Education Base set 9797. And the code found at the class page.
1. Press the touch sensor and keep it pressed. What happends ? Explain.
The car drives backwards, turn a little and then stop. HitWall has the highest priority and when the bumper is kept in, it will never let takeControl go. !!! RETTES !!!
2. Both DriveForward and HitWall have a method takeControl that are called in the Arbitrator. Investigate the source code for the
It is, but HitWall has the highest priority so it will run if takeControl is true. DriveForward will wait until HitWall is done and then continue.
3. Implement a third behavior,
For this we made our own class ExitCar
---------------------------------------------------------------------------------------------
import lejos.nxt.*;
import lejos.subsumption.*;
public class ExitCar implements Behavior {
public boolean takeControl() {
return Button.ESCAPE.isPressed();
}
public void suppress() {
}
public void action() {
System.exit(0);
}
}
---------------------------------------------------------------------------------------------
With this class we expect it to exit the program, but not immediately.
The program exited, but first when the HitWall was finished. We pressed the button when it was driving forward and the program exited at the moment it was pressed.
When it was in HitWall mode we had to hold the button pressed until the end of HitWall.
The reason why it does that, is that the whole behavior class is one thread, and HitWall calls thread.sleep('') which makes the whole behavior class sleep.
Yes it because it use non blocking functions.
4. Implement a fourth behavior PlaySound that react to the ENTER button and play a sound when the ENTER button is pressed. Insert an instance of this behavior in the Behavior array between the instances of Drive Forward and HitWall. Now Drive Forward has the lowest priority, PlaySound is next, then comes HitWall and Exit has the highest priority. Activate HitWall by a touch sensor press. While HitWall is active press ENTER and then ESCAPE. What happens ? Explain.
For this we again made our own class
---------------------------------------------------------------------------------------------
import lejos.subsumption.*;
import lejos.nxt.*;
public class PlaySound implements Behavior {
public boolean takeControl() {
return Button.ENTER.isPressed();
}
public void suppress() {
}
public void action() {
Sound.playTone(3500, 5000);
}
}
---------------------------------------------------------------------------------------------
We expect it to play a sound when enter is pressed and it has the highest priority.
When the HitWall mode is active it won't play the sound when enter is pressed, and the reason is the same as explained before.
Below is a little video witch show what happen when the buttons is pressed at different times.
An Alternative Arbitrator
To be continued....
No comments:
Post a Comment