... | ... | @@ -45,7 +45,7 @@ class Exit implements Behavior |
|
|
}
|
|
|
```
|
|
|
|
|
|
The takeControl method waits for the ESCAPE button to be pressed and then returns true. This allows the Exit behavior to control the car with the action method. In this case the action is to Exit the program. The "Exit" behavior is activated immediately if the car is controlled by the "DriveForward" behavior due the implementation of the suppress method. In the "DetectWall" behavior this method is not implemented as therefore the "Exit" behavior is not allowed to overrule the current behavior.
|
|
|
The takeControl method waits for the ESCAPE button to be pressed and then returns true. This allows the Exit behavior to control the car with the action method. In this case the action is to Exit the program. The "Exit" behavior is activated immediately if the car is controlled by the "DriveForward" behavior due to the implementation of the suppress method. In the "DetectWall" behavior this method is not implemented, therefore the "Exit" behavior is not allowed to overrule the current behavior.
|
|
|
|
|
|
In order to effectuate the "DetectWall" behavior a continuous reading of the ultra sonic sensor has been implemented using threading. The "DetectWall" class extends the "Thread" class as shown in the following code snippet.
|
|
|
|
... | ... | @@ -89,7 +89,7 @@ The suppressed functionality has also been implemented so that the behavior can |
|
|
|
|
|
### Physical setup
|
|
|
|
|
|
In order to win a sumo battle an offense and a defense strategy needs to be determined. The initial idea for the offense strategy is to place a shovel in front of the LEGO car which goal is to lift the opposing LEGO car and thereby remove its control abilities. By combining the shovel with a sonar sensor the car should be able localize the opponent and drive towards it. The defense strategy involves keeping the LEGO car inside the ring. For this a light sensor is used that can distinguish between the black battle area and the white border. Whenever the border is detected the car will back up and make a turn.
|
|
|
In order to win a sumo battle an offense and a defense strategy needs to be determined. The initial idea for the offense strategy is to place a shovel in front of the LEGO car which goal is to lift the opposing LEGO car and thereby remove its control abilities. By combining the shovel with a sonar sensor the car should be able to localize the opponent and drive towards it. The defense strategy involves keeping the LEGO car inside the ring. For this a light sensor is used that can distinguish between the black battle area and the white border. Whenever the border is detected the car will back up and make a turn.
|
|
|
|
|
|
### Software setup
|
|
|
|
... | ... | @@ -193,7 +193,7 @@ We quickly realized that the shovel in front of the car was too poorly attached |
|
|
|
|
|
### Added randomness
|
|
|
|
|
|
Before adding randomness to the search for the opponent(s), the robot sumo wrestler would drive straight forward until the edge was detected, then backup, turn in a deterministic manner, and then drive forward again. In order to increase the chance of finding the opponent(s), randomness was added to this search. The algorith used for the random search is as follows:
|
|
|
Before adding randomness to the search for the opponent(s), the robot sumo wrestler would drive straight forward until the edge was detected, then backup, turn in a deterministic manner, and then drive forward again. In order to increase the chance of finding the opponent(s), randomness was added to this search. The algorithm used for the random search can was as follows:
|
|
|
|
|
|
```java
|
|
|
@Override
|
... | ... | @@ -230,11 +230,11 @@ public void action() { |
|
|
}
|
|
|
```
|
|
|
|
|
|
We first determine whether to rotate, or drive forward. I case of the rotation, a direction(left or right) and an angle is determined. On the other hand, when driving forward a duration to drive for is determined.
|
|
|
We first determine whether to rotate, or drive forward. In case of the rotation, a direction(left or right) and an angle is determined. On the other hand, when driving forward a duration to drive for is determined.
|
|
|
|
|
|
#### About the LejOS implementation of `util.Random`
|
|
|
|
|
|
The algorithm for used generating pseudorandom numbers in the LejOS implementation of `util.Random` generates only odd numbers. This is not a problem for our usage of the function `Random.nextInt()`. But it *is* a problem when using `Random.nextBoolean()` because the default implementation relies on an 50/50 chance of even and odd numbers:
|
|
|
The algorithm used for generating pseudorandom numbers in the LejOS implementation of `util.Random` generates only odd numbers. This is not a problem for our usage of the function `Random.nextInt()`. But it *is* a problem when using `Random.nextBoolean()` because the default implementation relies on an 50/50 chance of even and odd numbers:
|
|
|
|
|
|
```java
|
|
|
return this.next(1) != 0;
|
... | ... | @@ -254,7 +254,7 @@ public boolean nextBoolean() |
|
|
|
|
|
### Added weight
|
|
|
|
|
|
The weight limit is determined in the rules to be 1 kg. It is estimated that it will be beneficial to reach this limit in order to make it harder for the opponent to push our LEGO car off the battle area. A simple weight block is build using relatively heavy lead bricks as shown in the following image. The weight of the LEGO car is verified using a standard kitchen weight.
|
|
|
The weight limit is determined in the rules to be 1 kg. It is estimated that it will be beneficial to reach this limit in order to make it harder for the opponent to push our LEGO car off the battle area. A simple weight block is build using relatively heavy lead bricks as shown in the following image. The weight of the LEGO car is verified using a standard kitchen weight.
|
|
|
|
|
|
![Weight is added to make the car harder to push of the battle area](https://gitlab.au.dk/rene2014/lego/raw/master/Lesson9/Images/ExtraWeight.jpg)
|
|
|
|
... | ... | @@ -266,7 +266,7 @@ Since there are free sensor inputs available on the NXT, an easy fix is just to |
|
|
|
|
|
![An extra light is added to cope with problems about approaching the border of the battle area.](https://gitlab.au.dk/rene2014/lego/raw/master/Lesson9/Images/ExtraLightSensor.jpg)
|
|
|
|
|
|
With the additional light sensor the LEGO is able to stop, back up and turn no matter which side the border is approached from.
|
|
|
With the additional light sensor the LEGO car is able to stop, back up and turn no matter which side the border is approached from.
|
|
|
|
|
|
## Conclusion
|
|
|
|
... | ... | |