... | ... | @@ -10,14 +10,81 @@ |
|
|
|
|
|
## Goal
|
|
|
|
|
|
The goal for this lab session is to make a sumo wrestling lego car.
|
|
|
The goal for this lab session is to make a sumo wrestling LEGO car.
|
|
|
|
|
|
## Plan
|
|
|
|
|
|
The plan is to follow the plan described in [1], and to build a sumo wrestling lego car and decide on a control strategy to win the tournament.
|
|
|
The plan is to follow the plan described in [1], and to build a sumo wrestling LEGO car and decide on a control strategy to win the tournament.
|
|
|
|
|
|
## Bumper car
|
|
|
|
|
|
When the touch sensor is pressed the "DetectWall" behavior is triggered which makes the car drive backwards and turn to the right. This will continue as long as the touch sensor is triggered.
|
|
|
|
|
|
An Exit behavior is added to the BumperCar in the following way.
|
|
|
|
|
|
```java
|
|
|
class Exit implements Behavior
|
|
|
{
|
|
|
|
|
|
public boolean takeControl()
|
|
|
{
|
|
|
if ( Button.ESCAPE.isDown() )
|
|
|
return true;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public void suppress()
|
|
|
{
|
|
|
//_suppressed = true;// standard practice for suppress methods
|
|
|
}
|
|
|
|
|
|
public void action()
|
|
|
{
|
|
|
System.exit(0);
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
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.
|
|
|
|
|
|
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.
|
|
|
|
|
|
```java
|
|
|
class DetectWall extends Thread implements Behavior
|
|
|
```
|
|
|
|
|
|
The thread is started in the constructor of the "DetectWall behavior" and the reading performed using the runnable interface in the method `run()` as shown in the following code snippet.
|
|
|
|
|
|
```java
|
|
|
public void run()
|
|
|
{
|
|
|
while(true) {
|
|
|
sonar.ping();
|
|
|
distance = sonar.getDistance();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The action method of the "DetectWall" behavior is now extended so that the car drives backwards for one second whenever the touch sensor is pressed or the sonar sensor detects an object in front. The implementation of the action method is shown in the following code snippet.
|
|
|
|
|
|
```java
|
|
|
public void action()
|
|
|
{
|
|
|
_suppressed = false;
|
|
|
Motor.A.backward();
|
|
|
Motor.C.backward();
|
|
|
int now = (int)System.currentTimeMillis();
|
|
|
while (!_suppressed && ((int)System.currentTimeMillis()< now + 1000))
|
|
|
{
|
|
|
Thread.yield();
|
|
|
}
|
|
|
BumperCar.leftMotor.rotate(-180, true);// start Motor.A rotating backward
|
|
|
BumperCar.rightMotor.rotate(-360); // rotate C farther to make the turn
|
|
|
}
|
|
|
```
|
|
|
The suppressed functionality has also been implemented so that the behavior can escape from an higher order behavior.
|
|
|
|
|
|
|
|
|
|
|
|
## Motivation functions
|
|
|
|
... | ... | @@ -25,11 +92,22 @@ The plan is to follow the plan described in [1], and to build a sumo wrestling l |
|
|
## Sumo Wrestler Lego Car
|
|
|
|
|
|
|
|
|
### Setup
|
|
|
### Physical setup
|
|
|
|
|
|
Offense: Sonar and light, shovel
|
|
|
Defense: From the side: pressure sensors
|
|
|
|
|
|
ITERATIONER
|
|
|
|
|
|
-> Original som vi først havde tænkt
|
|
|
|
|
|
-> Fæstnet skovl, da den faldt af
|
|
|
|
|
|
-> Tilfjøet randomness, for at variere search
|
|
|
|
|
|
|
|
|
### Software setup
|
|
|
|
|
|
### Results
|
|
|
|
|
|
|
... | ... | |