nhaulrik created page: Lab7 authored by Nikolaj Cilleborg Haulrik's avatar Nikolaj Cilleborg Haulrik
...@@ -80,6 +80,7 @@ Change the program so that the car drives backwards a little when all the three ...@@ -80,6 +80,7 @@ Change the program so that the car drives backwards a little when all the three
We wish to implement a behavior that handles a situation where the robot is close to a surface in the directions front, left and right and makes a u-turn and drives in the opposite direction. To do this we use the following code (Fig.4): We wish to implement a behavior that handles a situation where the robot is close to a surface in the directions front, left and right and makes a u-turn and drives in the opposite direction. To do this we use the following code (Fig.4):
``` ```
// Back up and turn 180 degrees
if ( leftDistance < stopThreshold && rightDistance < stopThreshold && frontDistance < stopThreshold ){ if ( leftDistance < stopThreshold && rightDistance < stopThreshold && frontDistance < stopThreshold ){
// back up // back up
...@@ -87,6 +88,7 @@ if ( leftDistance < stopThreshold && rightDistance < stopThreshold && frontDista ...@@ -87,6 +88,7 @@ if ( leftDistance < stopThreshold && rightDistance < stopThreshold && frontDista
Delay.msDelay(ms); Delay.msDelay(ms);
// Turn 180 degrees // Turn 180 degrees
```
car.forward(power, 0); car.forward(power, 0);
Delay.msDelay(2000); Delay.msDelay(2000);
car.backward(0, power); car.backward(0, power);
... ...
......