The Distance Sensor on the VR Robot reports the distance between the VR Robot and the nearest object. The sensor calculates distance by using the time it takes for laser light to bounce off of an object and return to the sensor.


Distance Sensor on the VR Robot

front eye down

The Distance Sensor is a sensor that reports the distance between the VR Robot and the nearest solid object.

VR top down

The Distance Sensor uses the same principles as sonar devices to measure sound. It sends out a tiny pulse of laser light with its emitter at one side of the sensor, and then times how long it takes for the light to reflect back to the receiver at the other side of the sensor. The sensor calculates the distance based on how long the pulse took to make the round trip. Then, the Distance Sensor reports to the VR Robot how far the nearest object is.

Screen_Shot_2021-12-10_at_2.45.39_PM.png

The width of the Distance Sensors range of vision changes as it looks further away from the front of the VR Robot:

  • The sensor can detect objects within a 10 degree field of view when looking for objects less than 1000 millimeters (~ 39 inches) away.
  • The sensor can detect objects within a 5 degree field of view when looking for objects between 1000 millimeters (~ 39 inches) and 2000 millimeters (~ 78 inches) away.
  • The sensor can detect objects within a 2 degree field of view when looking for objects greater than 2000 millimeters (~ 78 inches) away.

Common Uses of the Distance Sensor

VR topdown

The Distance Sensor can detect if there is an object in front of the VR Robot. This can be used to avoid an obstacle.

Wall Maze Playground

VEXcode VR Blocks

VEXcode VR Python

wall_maze_playground.jpg

distance_between_it_and_an_object.png

Screen_Shot_2021-12-10_at_2.25.52_PM.png

The Distance Sensor can measure the distance between the front of the Distance Sensor and the front of the object. This can be helpful to complete a maze without continuously bumping into the walls or to avoid an object.

Dynamic Castle Crasher Playground

VEXcode VR Blocks

VEXcode VR Python

Dynamic_Castle_Crasher_copy.jpg

Screen_Shot_2021-12-10_at_3.02.31_PM.png

Screen_Shot_2021-12-10_at_2.59.15_PM.png

In this example, the VR Robot will drive forward if the Distance Sensor finds an object. If it does not detect an object, the VR Robot will turn right and keep checking for an object.

Note: This example will find the first building, but needs improvements to avoid falling off the table.


Using the Distance Sensor with VEXcode VR Blocks

view

The blocks used with the Distance Sensor can be found in the Sensing category.

<Distance found object> Block

VR Block

The Distance Sensor detects if there is an object in front of it using the <Distance found object> block. The Distance Sensor can detect an object or surface within 3000 mm (~118 inches) of the sensor.

VR Blocks

The <Distance found object> block is a Boolean block that returns a condition as either true or false and fits inside any blocks with hexagonal (six-sided) spaces for other blocks. For more information on boolean blocks visit, Block Shapes and Meaning - Tutorials - VEXcode VR article.

(Distance from) Block

VR Blocks

Using the (Distance from) block, the Distance Sensor can report the distance of the nearest object in millimeters (mm) or inches.

VR Blocks

The (Distance from)  block reports number values and fits inside any blocks with oval spaces. For more information on reporter blocks visit, Block Shapes and Meaning - Tutorials - VEXcode VR article.

The value of the (Distance from)  block can be displayed on the Monitor Console in VEXcode VR. To learn more about the Monitor Console, view the Variable and Sensing Values Monitoring - Tutorials - VEXcode VR article.

VR Blocks

The value of the Distance from block can be reported in millimeters (mm) or inches.

Distance in mm

Distance in inches

The units of millimeters (mm) or inches will appear in the Monitor Console. To learn more about the Monitor Console, view the Variable and Sensing Values Monitoring - Tutorials - VEXcode VR article.

VR Blocks

The value of the <Distance found object> block is a Boolean block that reports true when the Distance Sensor is close to an object, and reports false when it is not close enough to an object.

Distance found an object

True or false will be reported and appear in the Monitor Console.


Using the Distance Sensor in VEXcode VR Python

Screen_Shot_2021-11-11_at_9.49.14_AM.png

To begin programming the Distance Sensor with Python, you will need to first open a text project VEXcode VR. For more information, see this article.

Screen_Shot_2021-12-10_at_2.26.12_PM.png

Next, locate the Sensing category in the Toolbox and find found_object and get_distance commands. These are functions that report a Boolean value or numerical value about the sensor.

Screen_Shot_2021-12-10_at_2.38.31_PM.png

To add the command to your project, you can drag the command in from the Toolbox, or type out the command in the workspace using the Autocomplete function. To learn more about Autocomplete in VEXcode VR with Python, see this article.

Screen_Shot_2021-12-10_at_2.25.52_PM.png

A while loop can be used with sensors on your robot when you want your robot to do something like drive until the Distance Sensor is 50mm or less from a wall, then stop or turn.

In this project, the robot will drive forward while the Distance Sensor reports a value greater than 50mm, and will stop driving when the Distance Sensor is less than 50mm away from a wall.

Screen_Shot_2021-12-10_at_2.34.04_PM.pngScreen_Shot_2021-12-10_at_2.34.17_PM.png

The value of the get_distance and found_object commands can be displayed on the Monitor Console in VEXcode VR. To learn more about using the Monitor Console in VEXcode VR Python, see this article.

For more information, help, and tips, check out the many resources at VEX Professional Development Plus