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.

VEX IQ (2nd gen) — Blocks that are compatible with the VEX IQ (2nd gen) Distance Sensor.

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] 发现对象?>

Parameters

Description

distance sensor

Which Distance Sensor to use, configured in the Devices window.

Example

当开始
[Spin until the Distance Sensor detects an object.]
[右 v] 转
等到 <[Distance 1 v] 发现对象?>
驱动停止

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] 距离 [毫米 v])

Parameters

Description

distance sensor

Which Distance Sensor to use, configured in the Devices window.

unit

The unit of measurement:

  • mm — millimeters
  • inches

Example

当开始
[Don't print the message until the Distance Sensor detects an object.]
[右 v] 转
等到 <[Distance 1 v] 发现对象?>
驱动停止
在 [Brain v] 上打印 ([Distance 1 v] 距离 [毫米 v]) ◀ 并设定光标为下一行

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] 对象距离 [毫米 v])

Parameters

Description

distance sensor

Which Distance Sensor to use, configured in the Devices window.

unit

The unit of measurement:

  • mm — millimeters
  • inches

Example

当开始
[Don't print the message until the Distance Sensor detects an object.]
[右 v] 转
等到 <[Distance 1 v] 发现对象?>
驱动停止
在 [Brain v] 上打印 ([Distance 1 v] 对象距离 [毫米 v]) ◀ 并设定光标为下一行

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] 对象速度m/s)

Parameters

Description

distance sensor

Which Distance Sensor to use, configured in the Devices window.

Example

当开始
[Display the velocity of an object moving in front of the Distance Sensor.]
将打印精度设置为 [0.01 v] 到 [Brain v]
永久循环
在 [Brain v] 设定光标至 (1) 行 (1) 列
在 [Brain v] 上打印 ([Distance 1 v] 对象速度m/s) ◀ 并设定光标为下一行
等待 (0.1) 秒
清除 [Brain v] 第 (1) 行

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.

<[Distance 1 v] 对象尺寸 [小 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:

  • small
  • medium
  • large

Example

当开始
[Drive toward a small object until it appears large.]
如果 <[Distance 1 v] 对象尺寸 [小 v]?> 那么
驱动 [向前 v]
等到 <[Distance 1 v] 对象尺寸 [大 v]?>
驱动停止
结束

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] 发现对象?>

Parameters

Description

distance sensor

Which Distance Sensor to use, configured in the Devices window.

Example

当开始
[Print the distance detected when an object is in front of the Distance Sensor.]
[右 v] 转
等到 <[Distance 1 v] 发现对象?>
在 [Brain v] 上打印 ([Distance 1 v] 对象距离 [毫米 v]) ◀ 并设定光标为下一行
驱动停止