How the Navigating by Touch Code Works
How the project roaming_with_whiskers works
The first part of roaming_with_whiskers defines the four navigation functions: forward, left, right, and backwards. Notice how the left, right, and backwards functions all have a pause block. Every time each of these functions are called, the cyber:bot moves in that direction for a predetermined amount of time. 750 milliseconds is enough time to back up away from an obstacle, and 500 milliseconds makes about a 90 degree turn to the right or the left. The forward function does not have a pause block inside of it.
After the four navigation functions have been defined, the project enters into the forever loop. Inside of this loop, we have a four-part if statement. The first thing it checks is if both whiskers are touching, that is, if both whisker_left and whisker_right are equal to 0. If this is true, then the program runs through the backwards and right functions making the cyber:bot backup and then turn right, presumably away from the obstacle.
If whisker_right and whisker_left are not touching, then the program goes to the next part of the if statement which says else if (else if) the left whisker is not touching (whisker_left = 1) and the right whisker is touching (whisker_right = 0), then the program executes the backwards and left functions.
If the if statement has still not found a true condition, then it checks to see if the left whisker is touching (whisker_left = 0) and the right whisker is not touching (whisker_right = 1). If this is true, the program executes the functions backwards and right.
Finally, if all three of the above conditions are not met, the program executes the forward function and drives a little bit before once again checking to see if an obstacle is detected.