zteel created page: Week11 sumo wrestling robots authored by Sune Brinch Sletgård's avatar Sune Brinch Sletgård
...@@ -50,12 +50,12 @@ We want a behavior that if the ESCAPE button is pressed, System.Exit(0) is calle ...@@ -50,12 +50,12 @@ We want a behavior that if the ESCAPE button is pressed, System.Exit(0) is calle
When the escape button is pressed, the robot takes the following action: When the escape button is pressed, the robot takes the following action:
```java ```java
public void action() { public void action() {
LCD.drawString("Now exiting...", 0, 0); LCD.drawString("Now exiting...", 0, 0);
BumperCar.leftMotor.stop(); BumperCar.leftMotor.stop();
BumperCar.rightMotor.stop(); BumperCar.rightMotor.stop();
System.exit(0); System.exit(0);
} }
``` ```
Which simply stops the motors and exits the system if the ESCAPE button is pressed. Which simply stops the motors and exits the system if the ESCAPE button is pressed.
...@@ -75,14 +75,14 @@ Getting the distance takes a little time, which goes against the contract of a b ...@@ -75,14 +75,14 @@ Getting the distance takes a little time, which goes against the contract of a b
```java ```java
_ping = new Thread(new Runnable(){ _ping = new Thread(new Runnable(){
public void run() { public void run() {
while (true) { while (true) {
sonar.ping(); sonar.ping();
_distance = sonar.getDistance(); _distance = sonar.getDistance();
Delay.msDelay(20); Delay.msDelay(20);
} }
}}); }});
_ping.start(); _ping.start();
``` ```
...@@ -93,44 +93,44 @@ To get the robot to move backwards for one second before turning, the following ...@@ -93,44 +93,44 @@ To get the robot to move backwards for one second before turning, the following
```java ```java
BumperCar.leftMotor.backward(); BumperCar.leftMotor.backward();
BumperCar.rightMotor.backwart(); BumperCar.rightMotor.backwart();
Delay.msDelay(1000); Delay.msDelay(1000);
``` ```
#### Making call interruptible #### Making call interruptible
A problem with the implementation of Detect Wall is that both delay and the last rotate is blocking calls, meaning that we cannot do anything new. This have been solved by making small methods that do the same, but we have use some busy waiting instead, where we do checks if it should start from the beginning or if it has been suppressed. A problem with the implementation of Detect Wall is that both delay and the last rotate is blocking calls, meaning that we cannot do anything new. This have been solved by making small methods that do the same, but we have use some busy waiting instead, where we do checks if it should start from the beginning or if it has been suppressed.
```java ```java
// The backwards method returns if it has been interrupted // The backwards method returns if it has been interrupted
public boolean bwd() { public boolean bwd() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
BumperCar.leftMotor.backward(); BumperCar.leftMotor.backward();
BumperCar.rightMotor.backward(); BumperCar.rightMotor.backward();
while (System.currentTimeMillis() < time + 1000) { while (System.currentTimeMillis() < time + 1000) {
if (_suppressed) {_suppressed = false; return true;} if (_suppressed) {_suppressed = false; return true;}
if (takeControl()){ return true; } if (takeControl()){ return true; }
} }
BumperCar.leftMotor.stop(); BumperCar.leftMotor.stop();
BumperCar.rightMotor.stop(); BumperCar.rightMotor.stop();
return false; return false;
} }
private void turn() { private void turn() {
BumperCar.rightMotor.resetTachoCount(); BumperCar.rightMotor.resetTachoCount();
BumperCar.rightMotor.backward(); BumperCar.rightMotor.backward();
BumperCar.leftMotor.backward(); BumperCar.leftMotor.backward();
while (BumperCar.rightMotor.getTachoCount() > -180) { while (BumperCar.rightMotor.getTachoCount() > -180) {
if (_suppressed) {_suppressed = false; return;} if (_suppressed) {_suppressed = false; return;}
if(takeControl()){ action(); return; } if(takeControl()){ action(); return; }
} }
BumperCar.leftMotor.stop(); BumperCar.leftMotor.stop();
BumperCar.rightMotor.backward(); BumperCar.rightMotor.backward();
while (BumperCar.rightMotor.getTachoCount() > -360) { while (BumperCar.rightMotor.getTachoCount() > -360) {
if (_suppressed) {_suppressed = false; return;} if (_suppressed) {_suppressed = false; return;}
if(takeControl()){ action(); return; } if(takeControl()){ action(); return; }
} }
} }
``` ```
...@@ -196,7 +196,7 @@ By discarding the motor and the ultrasonic sensor, we suddenly had a bit more we ...@@ -196,7 +196,7 @@ By discarding the motor and the ultrasonic sensor, we suddenly had a bit more we
Image 4: The robot after removing the ultrasonic sensor and adding touch sensors in the back. Image 4: The robot after removing the ultrasonic sensor and adding touch sensors in the back.
With this design we however have another problem. We only know if have something in front of us, which is what we want, or if we have been touched on one of the three sides we do not want. Then we got the idea that we might be able to distinguish the walls from each other by small differences in the raw value from the touch sensors. This will be possible if the sensors are inaccurate i.e. the sensors do not all produce the same value, but precise i.e. the sensors keeps reproducing the same value. With this design we however have another problem. We only know if have something in front of us, which is what we want, or if we have been touched on one of the three sides we do not want. Then we got the idea that we might be able to distinguish the walls from each other by small differences in the raw value from the touch sensors. This will be possible if the sensors are inaccurate i.e. the sensors do not all produce the same value, but precise i.e. the sensors keeps reproducing the same value. If they did, we could make an analog to digital converter [11] on our NXT, thus freeing up ports while we get all the information we wanted.
We tested all the unused touch sensors in LegoLab, and found the the raw value returned by SensorPort.readRawValue() ranged in 181-185 with readings from the individual sensor being fairly consistent. We were able to pair touch sensors to get raw values of 98, 99 and 100. It was possible to get readings of +/- 3, but most readings of the paired sensors were the same. Although detecting which bumper is pressed using the raw values, may sometimes be imprecise, it is still better than random guessing. We tested all the unused touch sensors in LegoLab, and found the the raw value returned by SensorPort.readRawValue() ranged in 181-185 with readings from the individual sensor being fairly consistent. We were able to pair touch sensors to get raw values of 98, 99 and 100. It was possible to get readings of +/- 3, but most readings of the paired sensors were the same. Although detecting which bumper is pressed using the raw values, may sometimes be imprecise, it is still better than random guessing.
...@@ -262,4 +262,5 @@ https://gitlab.au.dk/lego-group-3/lego/blob/master/Week9/EnemyDetector.java ...@@ -262,4 +262,5 @@ https://gitlab.au.dk/lego-group-3/lego/blob/master/Week9/EnemyDetector.java
[10], Video of sumo battle [10], Video of sumo battle
https://youtu.be/u-2nAI61KK4 https://youtu.be/u-2nAI61KK4
[11] Analog to digital conversion - https://learn.sparkfun.com/tutorials/analog-to-digital-conversion