... | ... | @@ -40,6 +40,7 @@ After activating the touch sensor the robot starts reversing. It stays in revers |
|
|
|
|
|
##### Fig. 2: The robot drives along a table. Once the touch sensors are activated the robot goes in reverse.
|
|
|
|
|
|
|
|
|
If the touch sensor is pressed, the takeControl() method returns a value of 100 (see fig 3) which initiates the prioritised action() behavior. Once initiated, the boolean value ‘active’ is set to true and the priority value is set to 50. This means that if the touch sensor is pressed while the action() is still running the method will start over due to the higher priority.
|
|
|
|
|
|
```
|
... | ... | @@ -53,4 +54,33 @@ If the touch sensor is pressed, the takeControl() method returns a value of 100 |
|
|
}
|
|
|
|
|
|
```
|
|
|
##### Fig. 3: takeControl() method. Shows how different values are returned according to sensor values and if the methods is ‘active’. |
|
|
\ No newline at end of file |
|
|
##### Fig. 3: takeControl() method. Shows how different values are returned according to sensor values and if the methods is ‘active’.
|
|
|
|
|
|
|
|
|
```
|
|
|
// Find behavior with highest priority
|
|
|
maxPriority = -1; highest = -1;
|
|
|
for (int i = 0; i < behavior.length; i++)
|
|
|
{
|
|
|
int priority = behavior[i].takeControl();
|
|
|
if (priority > maxPriority )
|
|
|
{
|
|
|
highest = i;
|
|
|
maxPriority = priority;
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
##### Fig. 4: Shows the Arbitrator class and how it determines which behavior should be prioritised.
|
|
|
|
|
|
|
|
|
2. 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 in the class DriveForward, has no triggering conditions which means that a value of 10 will always be returned (see fig. 5 below).
|
|
|
|
|
|
```
|
|
|
public int takeControl()
|
|
|
{
|
|
|
return 10; // this behavior always wants control.
|
|
|
}
|
|
|
```
|
|
|
##### Fig. 5: takeControl() method from DriveForward class always returns value 10. |