Skip to main content

Lesson 2: Drive to the Letter ‘A’

Drive to the Letter ‘A’

Now that you have created and tested a project that has the VR Robot stop once the Distance Sensor detects a wall, you will build a project that navigates the VR Robot to the letter ‘A’ on the Wall Maze Playground.

A top-down view of the wall maze with red arrows indicating the path from the VR robot to the letter A goal. The robot needs to drive forward, turn left, drive forward, turn left again and then drive forward one last time to reach the A goal.

  • To drive to the letter ‘A’, the VR Robot will need to detect two walls, and turn left when these walls are detected. Then, the VR Robot will stop when it detects the third wall, located behind the letter ‘A.’
    The same wall maze diagram with arrows as before. The robot needs to drive forward, turn left, drive forward, turn left again and then drive forward one last time to reach the A goal.
  • Begin by modifying the previous project or create a new project to match this base project. Note that the [Turn for] block is needed because once the Distance Sensor is within 50 millimeters (mm) of a wall, the VR Robot will turn left to continue toward the letter ‘A.’ Remember that you can use VEXcode blocks, Switch blocks, or a combination of both block types. 
    VEXcode VR blocks project that drives forwards until it reaches a wall and then turns left. The whole project reads When Started Drive Forward and Wait Until Front Distance in millimeters is less than 50, after which Turn Left for 90 degrees.
  • Add another [Drive], and [Wait until] block with the  <Less than> block set to 50 millimeters (mm), and the (Distance from) inside the <Less than> block.The same VEXcode VR blocks project from before, but with another set of the Drive Forward and Wait Until commands added on to the bottom of the stack. The whole project now reads When Started Drive Forward and Wait Until Front Distance in millimeters is less than 50, after which Turn Left for 90 degrees. Drive Forward and then Wait Until Front Distance in millimeters is less than 50.

    For Your Information

    Use the Duplicate tool for sections of code that repeat in a project. This allows you to save time. For more information on how to duplicate blocks, view the Context Menu - VR Blocks article.

  • Finally, add the following blocks to instruct the VR Robot to detect the final wall behind the letter ‘A’ then stop driving.
    The same VEXcode VR blocks project from before, but with another set of the Turn Left, Drive Forward, Wait Until, and finally a Stop Driving block added on to the bottom of the stack. The whole project now reads When Started, Drive Forward and Wait Until Front Distance in millimeters is less than 50, after which Turn Left for 90 degrees. Repeat those three blocks again, then Drive Forward one last time, Wait Until Front Distance in millimeters in less than 50, and Stop Driving.
  • Launch the Wall Maze Playground if it is not already open and run the project.
  • Watch the VR Robot drive from the start of the Wall Maze to the letter ‘A,’ and then stop.
    A top-down view of the wall maze with the letter A goal highlighted in a red box, near the VR robot's starting position.
  • Notice that the VR Robot does not bump into any walls as it drives to the letter ‘A.’ When the Distance Sensor value reports that the VR Robot is less than 50 millimeters (mm) from the wall, the VR Robot is instructed to turn or stop in the project.

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