Skip to main content

Lesson 2: Using Comparison Blocks and Driving Until Near

In this Lesson, you will create a project that navigates the VR Robot to the letter ‘A’ using the Distance Sensor with the <Less than> Boolean reporter block. In the mini-challenge, you will apply these skills to navigate from the beginning of the Wall Maze to the number '1.'

Move to A

Learning Outcomes

  • Identify that the <Greater than> block is a Boolean block that reports if the first value is larger than the second value.
  • Identify that the <Less than> block is a Boolean block that reports if the first value is less than the second value.
  • Identify that the <Greater than> or <Less than> blocks report a TRUE or FALSE value in a [Wait until] block.
  • Describe how to create a project that has a VR Robot drive forward until the value of the Distance Sensor is less than a threshold value of 50 millimeters (mm).

Name and Save the Project

  • Start a new project in VEXcode VR and name the project Unit5Lesson2.
Name and save the project.

Use the Distance Sensor to Avoid Walls

  • Drag the [Drive] block into the workspace.
    [Drive] block
  • Attach a [Wait until] block beneath the [Drive] block.
    [Wait until] block

This project will use the Distance Sensor to navigate through the Wall Maze Playground without bumping into walls. You will use the (Distance from) block inside of the <Less than> Boolean block in this project.

The <Less than>, <Greater than>, and <Equal to> are comparison blocks - they compare values. They are also Boolean reporter blocks that report a TRUE value when the comparison condition is met, and FALSE when the condition is NOT met.

  • <Less than> reports TRUE when the first value is smaller than the second value and FALSE when the first value is greater than or equal to the second value.
    <Less than> block
  • <Greater than> reports TRUE when the first value is larger than the second value, and FALSE when the first value is smaller than or equal to the second value.
    <Greater than> block
  • <Equal to> reports TRUE when the two values are exactly the same, and FALSE when they are not.
    <Equal to> block

Comparison blocks can accept decimals, integers, or numeric blocks. They also accept round reporter blocks, such as the (Distance from) block. The (Distance from) block can be with a comparison block when using the Distance Sensor in a project.

In this example, the block will report TRUE when the distance from an object and the Distance Sensor on a VR Robot is less than 50 millimeters (mm).

Distance in mm block

  • Drag the <Less than> Boolean block into the [Wait until] block.
  • Place the round (Distance from) block inside the Boolean reporter block.
    (Distance from) block
  • The [Wait until] block will keep the VR Robot driving forward until the condition is met, and the distance reported is less than 50 millimeters (mm). Then, the project will move on to the next block in the stack, which will be the [Stop driving] block.
    Project flow
  • A [Stop driving] block is needed after the [Wait until] block because the VR Robot will continue to drive until it is instructed to stop. Add a [Stop driving] block to the project.
    Add stop
  • 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 and stop when the Distance Sensor reports that it is less than 50 millimeters (mm) from the wall.
    Distance less than 50
  • Using the <Less than> block with the (Distance from) block inside of the [Wait until] block, instructs the VR Robot to wait until it is less than 50 millimeters (mm) from the wall before stopping.
  • Reset the Playground to move the VR Robot back to the starting position.

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