CS Level 1 - VEXcode VR Blocks

Unit 5 - Detecting Walls from a Distance

# Lesson 1: Distance Sensor

In this Lesson, you will learn what the Distance Sensor is, and why you would use the Distance Sensor with a VR Robot. You will learn how the Distance Sensor works, and how to use the Distance Sensor in a VEXcode VR project.

## Learning Outcomes

• Identify that the Distance Sensor reports the distance between it and the nearest object.
• Identify that the Distance Sensor determines distance by using the time it takes for ultrasonic waves to bounce off of an object and return to the sensor.
• Identify that the <Distance found object> block is a Boolean reporter block that reports if the Distance Sensor has found an object.
• Identify that the (Distance from) block reports the distance of the nearest object in millimeters or inches.
• Describe why the Distance Sensor would be used in a VEXcode VR project.

### Distance Sensor

The Distance Sensor reports the distance between the front of the Distance Sensor on the VR Robot and the nearest object. The Distance Sensor is located in the Front Eye on the VR Robot.

The Distance Sensor calculates distance by using the time it takes for ultrasonic waves to bounce off of an object and return to the sensor.

Read the article Distance Sensor - Robot Features - VEX VR for detailed information on how the Distance Sensor works, and how to use the Distance Sensor in a VEXcode VR project.

### <Distance found object> block

The Distance Sensor detects if there is an object in front of it when the <Distance found object> block is used in a project. The <Distance found object> block is a Boolean reporter block that reports a TRUE or FALSE value.  This block is used inside blocks with hexagonal (six-sided) spaces.

• <Distance found object> reports TRUE when the Distance Sensor detects an object or surface within its field of view, and within 3000 mm of the sensor.
• <Distance found object> reports FALSE when the Distance Sensor does not detect an object or surface within 3000 mm.

### (Distance from) block

The (Distance from) block is a numeric reporter block that reports the distance of the nearest object from the front of a VR Robot. The (Distance from) numeric reporter block is an oval block that is used inside blocks with oval input spaces. The following Knowledge Base article discusses the five different shapes of VEXcode VR blocks and what each shape of the blocks tells you about its role in VEXcode VR projects.

Choose whether the (Distance from) is reported in millimeters (mm) or inches (in).

The (Distance from) block can be used with other blocks in a project to instruct a VR Robot to drive a certain distance away from (or toward) an object, or to complete an action when a specific distance is reported.

In the following example, you can see how the (Distance from) block is used inside of a Boolean reporter block in a VEXcode VR project. In this project the VR Robot will drive forward until the distance reported is less than 50 millimeters (mm) from an object. Then, the VR Robot will stop.

Note: This project uses a <Less than> block. You will learn more about the <Greater than> and <Less than> Boolean reporter blocks in this Unit.

### Apply

The Distance Sensor can detect if there is an object in front of a VR Robot. This can be used to avoid or find a wall or object. The Distance Sensor can measure the distance between the front of the Distance Sensor and the front of the wall or object.

Using the Distance Sensor will allow a VR Robot to drive up to an object without touching it. This can be helpful in navigating a maze without continuously bumping into the walls, to avoid an object, or to drive to an object or wall in the VEXcode VR Playgrounds.

This video is an example of a VR Robot navigating the Wall Maze Playground using the Distance Sensor. Notice that the VR Robot does not touch any walls.