Distance Sensor#
Introduction#
The Distance Sensor category can include blocks depending on whether you’re working with the VEX IQ (1st gen) or VEX IQ (2nd gen) Distance Sensor. These blocks allow your robot to detect the presence of an object, measure its distance, determine the object’s size classification, and report its relative velocity.
Below is a list of available blocks:
VEX IQ (1st gen) – Blocks that are compatible with the VEX IQ (1st gen) Distance Sensor.
Distance found object? – Returns whether any object is currently detected.
object distance – Returns the distance of the nearest object from the Distance Sensor from 24mm to 1000mm.
VEX IQ (2nd gen) – Blocks that are compatible with the VEX IQ (2nd gen) Distance Sensor.
object distance – Returns the distance of the nearest object from the Distance Sensor from 20mm to 2000mm.
object velocity – Returns the relative speed of the detected object.
object size is? – Returns whether the object is a certain size.
Distance found object? – Returns whether any object is currently detected.
VEX IQ (1st gen)#
Distance found object?#
The Distance found object? block returns a Boolean indicating whether the Distance Sensor has detected an object.
True – The Distance Sensor has detected an object.
False – The Distance Sensor has not detected an object.
<[Distance1 v] found an object?>
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
when started :: hat events
[Don't print the message until the Distance Sensor detects an object.]
wait until <[Distance9 v] found an object?>
print ([Distance9 v] distance in [mm v]) on [Brain v] ◀ and set cursor to next row
object distance#
The object distance returns the distance of the nearest object from the Distance Sensor in a range from 24mm to 1000mm or 1 inch to 40 inches.
([Distance9 v] distance in [mm v])
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
unit |
The unit of measurement, which can be one of the following:
|
Example
when started :: hat events
[Don't print the message until the Distance Sensor detects an object.]
wait until <[Distance9 v] found an object?>
print ([Distance9 v] distance in [mm v]) on [Brain v] ◀ and set cursor to next row
VEX IQ (2nd gen)#
object distance#
The object distance returns the distance of the nearest object from the Distance Sensor in a range from 20mm to 2000mm or 0.78 inches to 78 inches.
([Distance1 v] object distance in [mm v])
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
unit |
The unit of measurement, which can be one of the following:
|
Example
when started :: hat events
[Don't print the message until the Distance Sensor detects an object.]
wait until <[Distance10 v] found an object?>
print ([Distance10 v] object distance in [mm v]) on [Brain v] ◀ and set cursor to next row
object velocity#
The object velocity block returns the current velocity of a detected object in m/s (meters per second).
([Distance11 v] object velocity in m/s)
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
when started :: hat events
print ([Distance10 v] object velocity in m/s) on [Brain v] ◀ and set cursor to next row
object size is?#
The object size is? block returns a Boolean indicating if an object detected by the Distance Sensor is a specific size. The Distance Sensor determines the size of the object detected (none, small, medium, large) based on the amount of light reflected and returned to the sensor.
True – The Distance Sensor has detected an object of the specified size.
False – The Distance Sensor has not detected an object of the specified size.
<[Distance1 v] object size is [small v]?>
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
object size |
The size of the object to check for:
|
Example
when started :: hat events
[Check if the Distance Sensor sees a small object.]
if <[Distance10 v] object size is [small v]?> then
[If a small object is detected, drive forward]
drive [forward v]
[Wait until the small detected object is large]
wait until <[Distance10 v] object size is [large v]?>
[When the object size is large, stop driving.]
stop driving
end
Distance found object?#
The Distance Sensor found object? block returns a Boolean indicating whether the Distance Sensor has detected an object.
True – The Distance Sensor has detected an object.
False – The Distance Sensor has not detected an object.
<[Distance1 v] found an object?>
Parameters |
Description |
---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
when started :: hat events
[Don't print the message until the Distance Sensor detects an object.]
wait until <[Distance10 v] found an object?>
print ([Distance10 v] object distance in [mm v]) on [Brain v] ◀ and set cursor to next row