Using the IQ Distance (2nd gen) Sensor

The IQ Distance (2nd gen) Sensor is one of the powerful IQ sensors which are designed for complete integration with the IQ 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.

IQ_Gen_2_Distance_Sensor.png

The following article will cover:


Description of the Sensor

The IQ Distance (2nd gen) 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 IQ.
  • 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.

IQ_Gen_2_Distance_Sensor_Mounting.png

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

IQ_Gen_2_Distance_Sensor-WindowCallout.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.

IQ_Gen_2_Brain_Connected_to_Distance_Sensor_Gen_2.png

In order for the Distance (2nd gen) Sensor to be functional with the IQ Brain, the sensor’s Smart Port and an IQ 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 IQ Brain.

When connecting an IQ 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 (2nd gen) Sensor Works

The IQ Distance (2nd gen) 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 (2nd gen) Sensor needs to be paired with VEXcode IQ to create a user program for the IQ Brain to utilize the sensor’s readings to control the robot’s behavior.

The IQ Brain in concert with a user project can be used to convert the Distance (2nd gen) 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 (2nd gen) Sensor

Placement

IQ_Gen_2_Simple_Clawbot_with_Distance_Sensor-Callout.png

The placement of the Distance (2nd gen) 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 (2nd gen) Sensor Values

IQ_Gen_2_Brain-On-DistanceMenu.png

It is helpful to use the Devices screen on the IQ Brain to see the information the Distance (2nd gen) Sensor is reporting.

From the Sensor Dashboard, the Distance (2nd gen) 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 (2nd gen) Sensor as a Device in VEXcode IQ

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

Distance.png

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

To add the Distance (2nd gen) Sensor to the configuration, follow the steps in this article. 

Distance_2.png

Once the Distance (2nd gen) 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 (2nd gen) Sensor, view the Help information (Blocks project or C++ project).


Common Uses of the Distance (2nd gen) Sensor

The Distance (2nd gen) 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 (2nd gen) Sensor. The Distance (2nd gen) 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 (2nd gen) 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 (2nd gen) 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 IQ (2nd generation) Brain. See this article for more information about using the Sensor Dashboard.

Report object velocity

velocity_example.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 (2nd gen) 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

size_of_object.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.


Uses of the Distance (2nd gen) Sensor on a Competition Robot

The Distance (2nd gen) Sensor will provide a superior competitive advantage for competition robots. The ability to detect distance to the perimeter wall and be able to measure a robot's velocity will provide a great deal of information when designing autonomous routines. Object detection and determining the object’s relative size will provide helpful information with the detection of game pieces and or goals.

IQ_Gen_2_Fling_-_Distance_Callout.png

For example, in the 2021 - 2022 VEX IQ Challenge, Pitching In, a Distance (2nd gen) sensor could be mounted on the back of your robot to detect walls when driving in reverse.

This can help automate movements, especially when retrieving a ball into the intake, driving in reverse, and then turning to launch the ball into the goal.

No matter what the application the VEX IQ Distance (2nd gen) Sensor is used for, there is no doubt it will be a welcomed addition for teams.

The function of the sensor’s values are open for the imagination of the user.