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 all 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.
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.
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.
<[Distance 1 v] Encontraste un objeto?>
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
cuando empezó
[Spin until the Distance Sensor detects an object.]
turno [derecha v]
esperar hasta <[Distance 1 v] Encontraste un objeto?>
deja de conducir
object distance#
The object distance block returns the distance of the nearest object from the Distance Sensor in a range from 24mm to 1000mm or 1 inch to 40 inches.
([Distance 1 v] distancia en [mm v])
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
unit |
The unit of measurement:
|
Example
cuando empezó
[Don't print the message until the Distance Sensor detects an object.]
turno [derecha v]
esperar hasta <[Distance 1 v] Encontraste un objeto?>
deja de conducir
imprimir ([Distance 1 v] distancia en [mm v]) en [Brain v] ◀ y coloque el cursor en la siguiente fila
VEX IQ (2nd gen)#
object distance#
The object distance block 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.
([Distance 1 v] distancia del objeto en [mm v])
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
unit |
The unit of measurement:
|
Example
cuando empezó
[Don't print the message until the Distance Sensor detects an object.]
turno [derecha v]
esperar hasta <[Distance 1 v] Encontraste un objeto?>
deja de conducir
imprimir ([Distance 1 v] distancia del objeto en [mm v]) en [Brain v] ◀ y coloque el cursor en la siguiente fila
object velocity#
The object velocity block returns the current velocity of a detected object as a decimal number in m/s (meters per second).
([Distance 1 v] velocidad del objeto en m/s)
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
cuando empezó
[Display the velocity of an object moving in front of the Distance Sensor.]
Establezca la precisión de impresión en [0.01 v] sobre [Brain v]
para siempre
Coloque el cursor en la fila (1) columna (1) de [Brain v]
imprimir ([Distance 1 v] velocidad del objeto en m/s) en [Brain v] ◀ y coloque el cursor en la siguiente fila
esperar (0.1) segundos
Limpiar la fila (1) en [Brain v]
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.
<¿El tamaño del objeto [Distance 1 v] es [pequeño 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
cuando empezó
[Drive toward a small object until it appears large.]
si <¿El tamaño del objeto [Distance 1 v] es [pequeño v]?> entonces
unidad [adelante v]
esperar hasta <¿El tamaño del objeto [Distance 1 v] es [grande v]?>
deja de conducir
fin
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.
<[Distance 1 v] Encontraste un objeto?>
Parameters |
Description |
|---|---|
distance sensor |
Which Distance Sensor to use, configured in the Devices window. |
Example
cuando empezó
[Print the distance detected when an object is in front of the Distance Sensor.]
turno [derecha v]
esperar hasta <[Distance 1 v] Encontraste un objeto?>
imprimir ([Distance 1 v] distancia del objeto en [mm v]) en [Brain v] ◀ y coloque el cursor en la siguiente fila
deja de conducir