Skip to main content

Lesson 3: Drive to Number '31'

In this Lesson, the VR Robot will drive to the number ‘31’ and then back to number ‘1’ on the Number Grid Map Playground!

Top down of the number grid playground. The VR Robot can be seen in the bottom left corner on the number 1. A callout box is on the number 31 in the leftmost column of the Playground.

Notice that the VR Robot will be traveling along the Y axis to move to the number ‘31’ on the Number Grid Map Playground.

Number grid map playground with the y axis overlaid across the vertical center of the Playground. The center of each square is marked with the Y axis value, starting with -900 on the bottom side and increasing by 200 each square to 900 on the top. A VR robot can be seen on the number 1 in the bottom left corner with an arrow pointing to the number 31.

The VR Robot will drive to the location of the number ‘31’ on the Number Grid Map Playground. However, before the VR Robot can navigate to that number, the VR Robot has to be told where that number’s location is. The coordinates of number ‘31’ are (-900, -300).

Bottom left corner of the number grid map playground from before with the x and y axis overlaid. An arrow is shown from negative 900 on the x axis to the number 31 and negative 300 on the y axis to the number 31. The VR Robot is still on the number 1 with the coordinates negative 900, negative 900 below the robot.
  • Drag in or type a while loop.
# Add project code in "main"
def main():
    while condition:
        wait(5, MSEC)
  • Set the condition for the while loop to the position command in the Y-axis less than -300 in millimeters (mm). Your project should look like this:
# Add project code in "main"
def main():
    while location.position(Y, MM) < -300:
        wait(5, MSEC)
  • Drag or type the non-waiting drive command inside the while loop. Your project should look like this:
# Add project code in "main"
def main():
    while location.position(Y, MM) < -300:
        drivetrain.drive(FORWARD)
        wait(5, MSEC)
  • Note that the less than operator is used instead of the greater than operator because the VR Robot is driving up from the bottom of the Playground. The VR Robot is starting at a Y-value of -900 millimeters (mm). As the VR Robot drives forward, the Y-values increase.

    Bottom left corner of the number grid map playground from before with the x and y axis overlaid. An arrow is shown from negative 900 on the x axis to the number 31 and negative 300 on the y axis to the number 31. The VR Robot is still on the number 1 with the coordinates negative 900, negative 900 below the robot.
  • Drag in or type the stop command outside the while loop. Your project should look like this:
# Add project code in "main"
def main():
    while location.position(Y, MM) < -300:
        drivetrain.drive(FORWARD)
        wait(5, MSEC)
    drivetrain.stop()
  • Open the Playground Window if it is not already open. Be sure the Number Grid Map Playground opens, and run the project.
  • Watch the VR Robot drive to number ‘31’ on the Number Grid Map Playground.

    Top down view of the Number Grid Map playground with the VR Robot on the number 31.
  • In this project, the VR Robot drives to the number ‘31’ on the Number Grid Map Playground. Since the Y-values are increasing as the VR Robot drives to the number ‘31,’ the project uses a less than operator.
  • The VR Robot will drive forward while the Y-value is less than the coordinate that the indicated number is on and stop once its Y-value is greater than the Y-value of the coordinate. Since the Y-value of the number ‘31’ is -300, the VR Robot will stop driving once the Y-value is greater than -300.

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