turning a corner

The next part of the program uses the Touch Sensor to detect when the robot reaches a corner, at which point it turns the TriBot so that it can follow the new wall. This is similar to the BumperBot program, which has the TriBot back up and turn when it runs into something.

Example 7-4 shows the pseudocode for this section of the program.

Example 7-4. Turning a corner

if the Touch Sensor is pressed then
  stop the motors
  backup far enough to turn the robot
  spin a quarter turn
end if

After the TriBot backs up and turns, it needs to be positioned the correct distance from the wall, or it might run into the wall or wander away from it. To make this section of code work, you have to determine the correct Duration settings for the two Move ...

Get The Art of LEGO MINDSTORMS NXT-G Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.