Lesson 3: Turning at a Further Distance
Navigating to the Turning Location
-
Add the following commands to your project, after the last turn_for command. Be sure the indentation of the while loops matches those in the project. You can copy and paste into or from your existing project, or type them into the Workspace.
while front_distance.get_distance(MM) > 50: drivetrain.drive(FORWARD) wait(5, MSEC) drivetrain.turn_for(LEFT, 90, DEGREES)
- We can estimate that the distance from the next wall to our desired turning location in the maze, is approximately 300 millimeters (mm).
For Your Information
You can use the Distance Sensor data as reported in the Dashboard to estimate the distance the VR Robot is from an object. Stop your project when the VR Robot reaches your desired location. Once stopped, the values in the Dashboard will display the sensor values for the VR Robot where it is currently positioned. This can be used to observe sensor values as well as visualize the distance between the VR Robot and an object at a certain point in time.
-
Adjust the value in the final while loop comparison operator to 300 millimeters (mm), as shown below. This will enable the VR Robot to drive forward while the distance to the wall is greater than 300 millimeters. When it is less than 300 millimeters, the VR Robot will turn left, at the desired turning location in the Wall Maze.
while front_distance.get_distance(MM) > 300: drivetrain.drive(FORWARD) wait(5, MSEC) drivetrain.turn_for(LEFT, 90, DEGREES)
- Launch the Wall Maze Playground if it is not already open and run the project. Notice how the VR Robot turns left at the desired turning location, so that it is ready to continue through the maze to the letter 'B'.
- Next, add the following commands to your project, after the final turn_for command, so the VR Robot continues on its path to the letter 'B'. Be sure that the while loops are indented correctly.
-
while front_distance.get_distance(MM) > 50: drivetrain.drive(FORWARD) wait(5, MSEC) drivetrain.turn_for(RIGHT, 90, DEGREES) while front_distance.get_distance(MM) > 50: drivetrain.drive(FORWARD) wait(5, MSEC) drivetrain.turn_for(RIGHT, 90, DEGREES) while front_distance.get_distance(MM) > 50: drivetrain.drive(FORWARD) wait(5, MSEC) drivetrain.stop()
-
Launch the Wall Maze Playground if it is not already open and run the project again.
- The VR Robot now drives from the start of the Wall Maze Playground and stops on the letter ‘B.’
- Notice that changing the right operand to 300 millimeters allowed the VR Robot to turn at a distance farther from the wall, which was necessary to turn at the correct location.
- The distance value reported in the Dashboard can be used to observe how far the VR Robot was from a wall when it needed to turn to get to the letter ‘B'.
Select the Next button to continue with the rest of this Lesson.