Using Distance Sensor with VEX EXP

The Distance Sensor is one of the powerful sensors which are designed for complete integration with the EXP robotics platform. This sensor uses a pulse of classroom-safe laser light to measure the distance from the front of the sensor to an object.

EXP_distance.png


Description of the Sensor

The Distance Sensor has the following capabilities:

  • Measuring distance: The sensor uses a pulse of classroom-safe laser light to measure the distance from the front of the sensor to an object. The distance is reported in inches or centimeters on the Brain's Sensor Dashboard, and in inches or millimeters in VEXcode EXP.
  • Detect object: The sensor can also be used to detect when it is near an object.
  • Determine object relative size: The sensor can also be used to determine the relative size of an object that has been detected. The approximate size of an object is reported as small, medium, or large.
  • Report object velocity: The sensor can be used to calculate and report the velocity in meters per second for an object approaching the sensor, or the sensor approaching an object.

Screen_Shot_2022-01-27_at_1.10.30_PM.png

The back of the sensor's housing has five holes to provide flexibility when mounting the sensor to a robot.

EXP_distance_highlighted.png

On the face of the sensor there is a small window where the laser beam is sent out and then received in order to measure distance.

EXP_brain_and_distance.png

In order for the Distance Sensor to be functional with the EXP Brain, the sensor’s Smart Port and an EXP Brain’s Smart Port need to be connected with a Smart Cable.

The sensor will work with any of the 12 Smart Ports on the EXP Brain.

When connecting an EXP Smart Cable to the ports, be sure the cable’s connector is fully inserted into the port and the connector’s locking tab is fully engaged.


How the Distance Sensor Works

The Distance Sensor sends out a pulse of classroom-safe laser light and measures the amount of time it takes for the pulse to be reflected. This allows for a calculation of distance.

The sensor’s Class 1 Laser is similar to the lasers used on modern cell phones for head detection. The laser allows the sensor to have a very narrow field of view, so detection is always directly in front of the sensor.

The sensor’s measurement range is 20 millimeters (mm) to 2,000 millimeters (mm) (0.79 inch to 78.74 inches). Below 200 millimeters (mm) the accuracy is approximately +/‐15 millimeters (mm); above 200 millimeters (mm) the accuracy is approximately 5%.

The Distance Sensor needs to be paired with VEXcode EXP to create a user program for the EXP Brain to utilize the sensor’s readings to control the robot’s behavior.

The EXP Brain in concert with a user project can be used to convert the Distance Sensor readings into:

  • Distance to an object measured in centimeters, millimeters, or inches.
  • Object velocity in meters per second.
  • Object size is small, medium, or large.
  • Object found.

Setup of the Distance Sensor

Placement

EXP_CC_Lesson_3_Tile_distance.png

The placement of the Distance Sensor is very important to obtaining accurate readings.

Be sure no structure on the robot is in front of the small sensor's window on the face of the sensor.

There needs to be a clear path in front of the sensor between any object being measured and the sensor.

Reading Distance Sensor Values

exp-brain-screen-distance.png

It is helpful to use the Devices screen on the EXP Brain to see the information the Distance Sensor is reporting.

From the Sensor Dashboard, the Distance Sensor dashboard reports the distance of the nearest object in either inches or centimeters.

The units can be changed by selecting the Check button on the Brain to toggle between inches and centimeters.

To use the Sensor Dashboard, follow the steps in this article. 


Adding the Distance Sensor as a Device in VEXcode EXP

Whenever a sensor is used with a programming language, it needs to be configured within that language. 

Add_a_Distance_Sensor.png

With VEXcode EXP, this is accomplished by using the ‘Add a device’ feature from the Devices window.

To add the Distance Sensor to the configuration, follow the steps in this article. 

Distance_Sensor_Blocks.png

Once the Distance Sensor has been added to your project, a new set of sensor blocks will become available.

For more information on the blocks from the ‘Sensing’ category pertaining to the Distance Sensor, view the Help information (Blocks project).


Common Uses of the Distance Sensor

The Distance Sensor can produce several measurements which can be used to change the behavior of the robot. These features include:

Detect an object

found_object_block.png

This feature allows your robot to detect an object when it becomes within the range of the Distance Sensor. The Distance Sensor will report a found object when it is approximately less than 1000mm away.

The example project shown on the left is used to code a robot with a Distance Sensor mounted on the front to turn until it detects an object, such as a cube, and then drive forward once the object is detected by the sensor.

Distance to an object

object_distance_in_mm.png

This provides a measurement between the front of the sensor and an object or a barrier/wall.

The example project shown on the left is used to code a robot with a Distance Sensor mounted on the front and a claw attached. The robot will drive until it detects an object is less than 75mm away from the sensor, then close the Claw around the object. This example would be helpful if it is known that there is an object in front of the robot and you want the robot to drive forward to collect that object. 

To determine how far away an object is from the sensor and use that parameter in the project, use the Sensor Dashboard on the EXP Brain. See this article for more information about using the Sensor Dashboard.

Report object velocity

Report_Object_Velocity.png

This feature provides a measurement of the velocity in meters per second for an object approaching the sensor, or the sensor approaching an object.

In order to observe the velocity changing with an approaching object, the example to the left can be used. In this project, information will be printed to the Brain's screen. The Brain will print when an object is detected by the Distance Sensor and the velocity of that object in meters/second. To more accurately see those changing numbers, the print precision is set to 0.1. 

Test this project by moving a cube closer and further away from the sensor. When the object and/or sensor are moving away from one another, the velocity values will be negative.

Determine object relative size

Report_Object_Size.png

This feature allows your robot to identify an object as being small, medium, or large depending on the sensor’s reading.

This example to the left uses [If then else] and [Print] blocks to print the relative size of an object on the Brain. Place various objects in front of the sensor and look at the readings on the Brain's screen to see the size identification in real time.

To determine the relative size of an object, the sensor uses information about the amount of light being reflected back at the sensor. Objects should be placed between 100mm and 300mm (about 4-12 inches) away from the sensor to get the most accurate representation of the size.

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