Using the Distance Sensor in VEXcode VR with Python

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 Class 1 lasers similar to lasers modern cell phones use for head detection. It sends out a tiny pulse of safe laser light, then uses the time it takes for the pulse to reflect to calculate the distance of nearby objects. The sensor calculates the distance based on how long the laser pulse took to make the round trip.


VEXcode VR Commands used with the Distance Sensor

distance_commands.png

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

get_distance Command

Screen_Shot_2021-10-07_at_4.17.49_PM.png

Using the get_distance command, the Distance Sensor can report the distance of the nearest object in millimeters (mm) or inches. The get_distance command reports numeric values in either millimeters (mm) or inches.

Screen_Shot_2021-10-07_at_4.52.59_PM.png

The distance will be displayed in millimeters (mm) and inches in the Monitor Console.

found object Command

Screen_Shot_2021-10-07_at_4.24.37_PM.png

The Distance Sensor detects if there is an object in front of it using the Distance found object command. The Distance Sensor can detect an object or surface within 3000 mm (~118 inches) of the sensor. The Distance found object command returns a Boolean value as either True or False.

Screen_Shot_2021-10-07_at_5.12.14_PM.png

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

The laser allows the sensor to have a very narrow field of view, so detection is always directly in front of the sensor. 


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.

Screen_Shot_2021-10-07_at_4.39.16_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.


Distance Sensor Example Project

Screen_Shot_2021-10-07_at_4.48.44_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.

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

Last Updated: