测距仪#

介绍#

超声波测距仪利用声波测量到最近物体的距离。它的工作原理是发出超声波脉冲,并测量声波反射回来所需的时间。

VEX V5测距仪。

本页面使用 range_finder 作为示例测距仪名称。您可以根据需要将其替换为您自己配置的名称。

以下是可用方法列表:

  • found_object – 返回测距仪是否检测到对象。

  • distance – 返回测距仪与最近检测到的对象之间的距离。

构造函数 – 手动初始化测距仪。

  • Sonar – 创建测距仪。

找到的对象#

found_object 返回 Boolean ,指示测距仪是否在其视野范围内检测到物体。

  • True – 测距仪正在检测物体。

  • False ​​– 测距仪未检测到物体。

Usage:
range_finder.found_object()

参数

描述

此方法没有参数。

距离#

distance 返回传感器检测到的最近对象的测量距离,以十进制数表示 float。

Usage:
range_finder.distance(units)

范围

描述

units

表示距离的单位: MM,或 INCHES。

构造函数#

构造函数用于手动创建 Sonar 对象,这些对象对于在 VEXcode 之外配置测距仪是必要的。

Sonar#

Sonar 创建测距仪。

Usage:
Sonar(port)

范围

描述

port

The 3-Wire Port that the Range Finder is connected to:

  • On the V5 Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a Range Finder in Port A
range_finder = Sonar(brain.three_wire_port.a)