Skip to main content

Lesson 3: Adjusting Distances

In the previous Lesson, you used the Distance Sensor and comparison operators for the VR Robot to drive from start to the number ‘1’ on the Wall Maze Playground. In this Lesson, you will learn how to monitor the values from sensors in the Dashboard, and have the VR Robot drive from start to the letter ‘B’ on the Wall Maze Playground.

A top down view of the Wall Maze Playground, with the VR Robot in the starting location in the center bottom, and the letter B highlighted with a red box in the center of the left side wall, separated by a series of walls.

Learning Outcomes

  • Identify that the Dashboard can be used to monitor data from the Distance Sensor.
  • Identify how to change parameters in a project to use the Distance Sensor data to navigate the VR Robot through the Wall Maze Playground.

Driving to the Letter 'B' 

There are several ways to navigate to the letter 'B' in the Wall Maze. To begin, let's look at what the most direct path to letter 'B' would be. A top down view of the Wall Maze Playground, with the VR Robot on the letter B location in the center of the left wall, and black lines showing the path from the start to letter B. The first line extends upward toward the first wall opposite, then a line extends left to the next wall. The next 3 line segments point upward, to the left, and downward, to track the path around the wall into the open path to the bottom of the maze. The last two lines run left to the far wall and upward to the letter B.

 

Start a New Project

  • Start a new text project and select the Wall Maze Playground when prompted. Wall Maze Playground selection tile.
  • Name the project Unit5Lesson3.
    VEXcode VR Toolbar and the project name box in the center reads Unit 5 Lesson 3.

Drive to the Letter ‘B’

  • To begin, the first few movements of our VR Robot are similar to what we have done in the previous Lesson. Build the following project to get started on the path:

    def main():
        while front_distance.get_distance(MM) > 50:
            drivetrain.drive(FORWARD)
            wait(5, MSEC)
    
        drivetrain.turn_for(LEFT, 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.turn_for(LEFT, 90, DEGREES)
    
  • Open the Playground Window if it is not already open. Be sure the Wall Maze Playground opens, and run the project.
  • Notice where the VR Robot stops at this point in the project. It is facing left, the correct direction to continue driving to the letter 'B'. VEXcode VR with the above project shown in the Workspace to the left and the ending location of the VR Robot highlighted with a yellow circle on the Playground. The robot is facing left, beside the wall opposite the letter A.

Figuring out the Desired Turning Location

The VR Robot is now facing the correct direction to continue to the next part of the path. However, if we used the same distance value from the Distance Sensor to continue on, as we did in the previous Lesson, the VR Robot would follow this path. A top down view of the Wall Maze Playground, with the VR Robot in the ending position from the previous project. A solid black line traces its path from the start, and a dotted black line extends in front of the robot to the wall opposite, showing the potential path of the robot with the current parameters. This would get the robot stuck and unable to reach the letter B. 

We could reverse and use Drivetrain commands, like we did in the previous Unit with the Bumper Sensor, to reach the desired turning point. That could look like this:A top down view of the Wall Maze Playground, with the VR Robot in the ending position from the previous project. A solid black line traces its path from the start, and a dotted black line extends in front of the robot to the wall opposite, and returning, showing the potential path of the robot if the Bumper Sensor was used. This would get the robot stuck and unable to reach the letter B.

However, the Distance Sensor can be used to allow the VR Robot to make turns at any distance away from a wall. At this turn, the VR Robot is further away from the wall than other turns. We can adjust the distance value in the comparison operator, to enable the VR Robot to turn at a further distance from the wall, to make our project, and the VR Robot's path, more efficient. 

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