距离传感器#

介绍#

距离传感器类别包含的模块取决于您使用的是 VEX IQ(第一代)还是 VEX IQ(第二代)距离传感器。这些模块允许您的机器人检测物体的存在、测量其距离、确定物体的尺寸分类并报告其相对速度。

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(第一代)#

距离发现物体?#

**距离找到物体?**块返回一个布尔值,指示距离传感器是否检测到物体。

  • True — The Distance Sensor has detected an object.

  • False — The Distance Sensor has not detected an object.

<[Distance 1 v] 发现对象?>

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

例子

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

物体距离#

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])

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

单元

The unit of measurement:

  • mm — millimeters
  • inches

例子

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

VEX IQ(第二代)#

物体距离#

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])

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

单元

The unit of measurement:

  • mm — millimeters
  • inches

例子

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

物体速度#

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)

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

例子

当开始
[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) 行

物体尺寸是多少?#

物体尺寸是? 模块返回一个布尔值,指示距离传感器检测到的物体是否为特定尺寸。距离传感器根据反射回传感器的光量来确定检测到的物体的尺寸(无、小、中、大)。

  • 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]?>

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

物体尺寸

要检查的对象的大小:

例子

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

距离发现物体?#

**距离传感器找到物体?**块返回一个布尔值,指示距离传感器是否检测到物体。

  • True — The Distance Sensor has detected an object.

  • False — The Distance Sensor has not detected an object.

<[Distance 1 v] 发现对象?>

参数

描述

距离传感器

使用哪个距离传感器,在设备窗口中配置。

例子

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