Skip to main content

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). A top down view of the Wall Maze Playground with the robot in its ending location, with a black line showing its path from the start. The distance from the front of the robot to the wall obstacle opposite is labeled as approximately 300mm. 

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.

A top down view of the Wall Maze Playground with the VR Robot stuck at the obstacle wall below the letter B. The Stop button in the bottom left corner of the Playground Window is highlighted with a red box.

Stopping the project when the VR Robot reaches a specific point, enables you to pause the project to see what value the Distance Sensor is reporting in real time. In the case of the Wall Maze, this value can be used in the greater than (>) operator to make the VR Robot stop at a further distance from the wall.
A top down view of the Wall Maze Playground with the VR Robot stopped at approximately the location it needs to turn in order to drive around the wall and onto the path to the letter B. The Dashboard is open in the Playground Window and the Distance value, reported to the far right, reads 272mm.

  • 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'. VEXcode VR with the project shown to the left in the Workspace, and the final position of the VR Robot on the Playground. The robot is now facing downward, within the open path that will lead to the letter B, and is not blocked by a wall.
  • 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.

    A top down view of the Wall Maze Playground with the VR Robot stopped on the Letter B.
  • 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'.
    The Playground Window with the VR Robot at the turning point to navigate towards the open path to the letter B. The Distance value reported in the Dashboard reads 300mm.

Select the Next button to continue with the rest of this Lesson.