nhaulrik created page: Lab7 authored by Nikolaj Cilleborg Haulrik's avatar Nikolaj Cilleborg Haulrik
...@@ -31,7 +31,7 @@ The program was executed without changes in the code. ...@@ -31,7 +31,7 @@ The program was executed without changes in the code.
##### Fig.2 - Observed results for surface avoidance ##### Fig.2 - Observed results for surface avoidance
As seen in Fig.2 the video the car drives and turns in order to avoid surface contact. When it encounters a surface that is less than the stopThreshold (Fig.3) the car stops and turns to measure distances to it’s left and right. It then compares these readings and drives in the direction with most space available. As seen in Fig.2 the car drives and turns in order to avoid surface contact. When it encounters a surface that is less than the stopThreshold (Fig.3) the car stops and turns to measure distances to it’s left and right. It then compares these readings and drives in the direction with most space available.
``` ```
while ( true ) while ( true )
...@@ -77,11 +77,10 @@ Change the program so that the car drives backwards a little when all the three ...@@ -77,11 +77,10 @@ Change the program so that the car drives backwards a little when all the three
#### Plan #### Plan
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 used 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 when all three distances are less than threshold
// and turn 180 degrees.
if(leftDistance < stopThreshold && rightDistance < stopThreshold && frontDistance < stopThreshold ){ if(leftDistance < stopThreshold && rightDistance < stopThreshold && frontDistance < stopThreshold ){
// back up // back up
... ...
......