Skip to main content

Lesson 2: Drive to Number ‘1’

  • Now the VR Robot will drive back to the number ‘1.’

    A top-down view of the Number Grid Map playground, with two axis indicators marking the fifth spaces' location. The VR Robot is on the fifth space at -100 X and -900 Y.
  • To navigate the VR Robot back to the number ‘1,’ remove the [Stop driving] block and replace it with the following blocks.

    An overview of the blocks that need to be added to drive the robot from space 1, to space 5, and back to space 1. This is done by adding turn, drive, and wait blocks before the Stop Driving block. The full project now reads When Started, Turn Right for 90 degrees and then Drive Forward. Wait Until X Position of Robot in millimeters is Greater Than -100 and then Turn Right for 180 degrees and then Drive Forward. Lastly Wait Until X Position of Robot in millimeters is Less Than -900 and then Stop Driving.
  • Note that the second [Wait until] block contains a <Less than> Boolean block instead of a <Greater than> block. This is because the VR Robot is now driving down the X axis and the numbers are becoming more negative. The VR Robot will stop once the X-values are LESS than -900.

    The VEXcode VR blocks project to drive the robot from the first space, to the fifth space, and back to the first space. The full project reads When Started, Turn Right for 90 degrees and then Drive Forward. Wait Until X Position of Robot in millimeters is Greater Than -100 and then Turn Right for 180 degrees and then Drive Forward. Lastly Wait Until X Position of Robot in millimeters is Less Than -900 and then 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 ‘1’ on the Number Grid Map Playground.
  • In this project, the VR Robot drives to the number ‘1’ on the Number Grid Map Playground. Since the X-values are decreasing as the VR Robot drives to the number ‘1,’ the project uses a <Less than> block.
  • The VR Robot will stop once its X-value is less than the X-value of the coordinate that the indicated number is on. Since the X-value of the number ‘1’ is -900, the VR Robot will stop driving once the X-value is less than -900.
A diagram visualizing the flow of logic in the VEXcode VR Blocks project. The project starts by turning right for 90 degrees then driving forwards, and holds that command until the Position of Robot sensor's X Position in millimeters is greater than -100. Next turn right for 180 degrees and drive forwards, holding that command until the Position of Robot sensor's X Position in millimeters is less than -900, after which a Stop Driving block ends the Drive Forward command.

For Your Information

A [Wait] block will pause the project's flow for a specific period of time in seconds before moving on to the next block in the stack. A [Wait] block can be used to help observe individual behaviors in your project that may run quickly together, such as moving between two different locations on a Playground.

Wait block that reads 'wait 1 second'.

Using Switch Blocks 

The image below displays the Switch [Wait] block. Note that the numerical value is written before the unit of measurement, separated by a comma. 

Wait switch block with Python code that reads 'wait(1, SECONDS)'

You can change the parameter from seconds to milliseconds by typing MSEC to replace the SECONDS parameter. Be sure to use all capital letters while entering the parameter.

Wait switch block to demonstrate the auto-complete feature. The block reads 'wait(1, MSEC)', and the user is typing in the millisecond parameter using auto-complete.

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