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!

A top-down view of the Number Grid Map playground, with the number 31 highlighted by a red box. The VR robot starts on number 1, and the number 31 square is three spaces above it.

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

A top-down view of the Number Grid Map playground, with the number 31 space highlighted by a black box. A line indicates measurements across the Y axis, with the first space being -900 millimeters on the Y axis, and the next being -700 continuing to count by 200 each time. The number 31 space is at a Y location of -300 millimeters.

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).

A top-down view of the Number Grid Map playground, with two axis indicators marking the location of the number 31 space. The VR Robot starts at -900 X and -900 Y, while the number 31 space is at -900 X and -300 Y.
  • Drag the [Drive] non-waiting block into the workspace.

    A new VEXcode VR blocks project that begins with a When Started block followed by a Drive Forward block.
  • Attach a [Wait until] block beneath the [Drive] block.

    A continuation of the VEXcode VR blocks project, now with a Wait Until block added after the Drive Forward block. The whole project now reads When Started, Drive Forward and Wait Until. The Wait Until block has an empty boolean parameter.
  • Drag the <Greater than> Boolean reporter block into the [Wait until] block.

    A continuation of the VEXcode VR blocks project, now with a Greater Than block inserted into the Wait Until block. The whole project now reads When Started, Drive Forward followed by a Wait Until block with a Greater Than block in it that reads 'blank is Greater Than 50'.
  • Note that the <Greater than> block is used instead of the <Less than> block 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.

    The same top-down view of the Number Grid Map playground with two axis indicators marking the location of the number 31 space from earlier. The VR Robot starts at -900 X and -900 Y, while the number 31 space is at -900 X and -300 Y.
  • Drag the (Position of Robot) block into the <Greater than> block.

    A continuation of the VEXcode VR blocks project, now with a Position of Robot block inserted into the Greater Than block. The whole project now reads When Started, Drive Forward and Wait Until X Position of Robot in millimeters is Greater Than 50.
  • Set the parameter of the (Position of Robot) block to “Y” and the parameter of the <Greater than> block to -300.

    A continuation of the VEXcode VR blocks project, now with the Position of Robot block's axis changed from X to Y and the Greater Than block's second parameter changed from 50 to -300. The whole project now reads When Started, Drive Forward and Wait Until Y Position of Robot in millimeters is Greater Than -300.
  • Drag in a [Stop driving] block and add it to the project.

    A continuation of the VEXcode VR blocks project, now with a Stop Driving block added below the Wait Until block. The whole project now reads When Started, Drive Forward and Wait Until Y Position of Robot in millimeters is Greater Than -300. Lastly, Stop Driving.
  • Launch the Number Grid Map Playground if it is not already open and run the project.
  • Watch the VR Robot drive to number ‘31’ on the Number Grid Map Playground.

    A top-down view of the Number Grid Map playground with the VR robot resting on the number 31 space.
  • 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 <Greater than> block.
  • The VR Robot will stop once its Y-value is greater than the Y-value of the coordinate that the indicated number is on. Since the Y-value of the number ‘31’ is -300, the VR Robot will stop driving once the Y-value is greater than -300.
A diagram visualizing the flow of logic in the VEXcode VR Blocks project. The project begins with a When Started block and then starts driving forwards, and holds that command until the Position of Robot sensor's Y Position in millimeters is greater than -300, after which a Stop Driving block ends the Drive Forward command.

Using Switch Blocks 

In this Lesson, you learned how to use the VEXcode [Wait until] block with a Boolean condition to command the robot to wait until the robot reaches a position of greater than -300 on the Y-axis before moving to the next behavior.

The image below shows the VEXcode block beside the Switch block containing the Python command for the same behaviors. 

A comparison of a VEXcode VR Wait Until block and its corresponding switch block. The VR block reads 'Wait Until Y Position of Robot in millimeters is greater than -300'. The switch block's Python code reads 'while not location.position(Y, MM) > -300: wait(5, MSEC)'. The wait command is indented beneath the while not.Within the Switch block, while not location.position(Y, MM) > -300: is the first Python command that checks whether the position of the robot along the X-axis is greater than -300.

The second indented command, wait (5, MSEC), pauses the execution of the conditional loop for 5 milliseconds.

In VEXcode VR, a wait command is always added with the conditional loop. The purpose of the wait command is to ensure that VEXcode VR can properly run the project as intended, due to the web-based nature of the VEXcode VR platform. The wait command should never be deleted when using a conditional loop, or your project may not run as intended. 

In this example, the project checks whether or not the robot's position is greater than a Y value of -300 every 5 MSEC. This line of code is indented underneath the first line of code because this command is the behavior that will repeat until the condition (a Y coordinate value of greater than -300) is met. 

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