Duration of activity: 4 Hrs
Group members participating: Alexander Rasmussen Søren Ditlev
BumperCar
Goal:
To investigate the behavior based architecture[1] implemented in the subsumption API of Lejos.
Plan:
In order to investigate the behavior based architecture we will build the Bumper car[2] and implement the Bumper car software[1]. This allows us to experiment with the behaviors “drive forward” and “detect wall”. We plan to do the following experiments to get in depth understanding of how the behavior architectures works.
- Press the touch sensor and keep it pressed. What happends ? Explain.
- 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 both when DriveForward is active and when DetectWall is active. Is the Exit behavior activated immediately ?
- Both DriveForward and DetectWall have a method takeControl that are called in the Arbitrator. Investigate the source code for the Arbitrator and figure out if takeControl of DriveForward is called when the triggering condition of DetectWall is true.
- The takeControl method of DetectWall contains a call to the ultrasonic sensor method getDistance that includes a delay. This means that the call of takeControl for the other behaviors is delayed and the reaction to an event is not immidiate. In it is recommende that takeControl "should return quickly, not perform a long calculation." To avoid the pause in the takeControl method of DetectWall a local thread in DetectWall could be implemented that sample the ultrasonic sensor e.g. every 20 msec and stores the result in a variable distance accessible to takeControl. Try that.
- For some behaviors the triggering condition depends on sensors sampled with a constant sample interval. E.g. a behavior that remembers sensor readings or sum a running average. Therefore, it might be a good idea to have a local thread to do the continous sampling.
- Try to implement the behavior DetectWall so the actions taken also involve to move backwards for 1 sec before turning.
- Try to implement the behavior DetectWall so it can be interrupted and started again e.g. if the touch sensor is pressed again while turning.
Results:
- The System drives backwards and turns a little then waits to see if sensor is still touched, if not drives forward, if it is still touched repeats behavior.
- To implement the exit behavior we copied what we could see from the detectWall class and modified what was needed. In order for the system to exit we had to add a suppress implementation to the detectWall since it no longer was top priority.
Code snippet of Exit implementation:
class Exit implements Behavior
{
private boolean _suppressed = false;
@Override
public boolean takeControl() {
return Button.ESCAPE.isDown();
}
@Override
public void action() {
System.exit(0);
}
@Override
public void suppress() {
_suppressed = true;
}
}
When the system is in “Drive forward” behaviour it exits immediately. However when the system runs the “Detect wall” behaviour the system does not exit, unless the escape button is pressed at the exact moment after the detec wall session has ended and before new one have started.
When the system is in “Drive forward” behaviour it exits immediately. However when the system runs the “Detect wall” behaviour the system does not exit, unless the escape button is pressed at the exact moment after the detec wall session has ended and before new one have started.
- The way the arbitrator works is by cycling through the behavior list with the highest priority first, for each behavior it calls the method takeControll() which returns a boolean. If the behavior returns true it will run the action if false, the lower prioritized behavior will be called.
- To implement a faster sonar response, we used the method proposed in the assignment. We implemented a new thread that read the sonar response and then updated a variable which the action method then could access if needed.
Code snippet:
Thread thread = new Thread() {
public void run(){
while(true){
sonarValue = sonar.getDistance();
}
}
};
thread.start();
- The referred problem was addressed during the implementation in regards to question 4, since we already here made the local thread in which variables are stored.
- To implement a 1 sec backward drive before before doing a turn was done by making a while loop that would run for a sec and yield the thread, as long as the behavior isn’t suppressed.
Code snippet:
BumperCar.leftMotor.backward();
BumperCar.rightMotor.backward();
while(System.currentTimeMillis() - timeVal < 1000 && !_suppressed){
Thread.yield();
}
- We have tried to implement a quick interruption of the detectWall behavior but for all the different implementation that we tried, a slight delay would still occur.
Video of system with all implementations[3]
Motivation Functions
To implement the motivation functions we used the arbitrator and behavior classes given by Ole Caprani, and then modified the takeControl functions to return an integer instead of a boolean so that it would fit the arbitrators needs. The return values of the different classes were, ordered so that the behaviors with the least priority would output the smallest value.
Conclusion:
We are able to make the system function as desired though all seven exercises. Since the we did not have time to perform do these exercises on Thursday the 01/05 we were not able to partake in the sumo wrestling contest, and therefore made no further alterations to out system that would have possible to compete in the contest.
References
[1] http://www.lejos.org/nxt/nxj/tutorial/Behaviors/BehaviorProgramming.htm
[3] https://www.youtube.com/watch?v=LOR8xUICLY4
[3]
Ingen kommentarer:
Send en kommentar