nhaulrik created page: Lab7 authored by Nikolaj Cilleborg Haulrik's avatar Nikolaj Cilleborg Haulrik
# Group-22: Lab Notebook 7 - Behavior Controlled Vehicle
#### Date: 17/4/2015
#### Group members participating:
* Christian Bonde Andersen
* Nikolaj Cilleborg Haulrik
* Rasmus Meldgaard Petersen
* Jesper Kurtzmann Svith
#### Activity duration: 5 + ...
## Exercise 1: LEGO vehicle that exhibits a single behavior
Task: The program AvoidFigure9_3.java implements the avoid behavior with a single ultrasonic sensor. Download the program and observe the car. Describe how the car behaves.
Plan: The program was executed without changes.
Result:
The car drives and turns in order to avoid surface contact. When it encounters a surface that is less than the stopThreshold the car stops and turns to measure distances to it’s left and right. It then compare these readings and drives in the direction with most space.
```
while ( true )
{
// Go forward
car.forward(power, power);
// Monitor the distance in front of the car and stop
// when an object gets to close
frontDistance = sonar.getDistance();
while ( frontDistance > stopThreshold )
{
frontDistance = sonar.getDistance();
}
car.stop();
// Get the distance to the left
car.forward(0, power);
Delay.msDelay(ms);
leftDistance = sonar.getDistance();
// Get the distance to the right
car.backward(0, power);
Delay.msDelay(ms);
car.forward(power, 0);
Delay.msDelay(ms);
rightDistance = sonar.getDistance();
// Turn in the direction with most space in front of the car
if ( leftDistance > rightDistance ){
car.backward(power, 0);
Delay.msDelay(ms);
car.forward(0, power);
Delay.msDelay(ms);
}
}
```