测距仪#

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

VEX V5测距仪。

This page uses range_finder as the example Range Finder name. Replace it with your own configured name as needed.

以下是可用方法列表:

  • found_object – Returns whether the Range Finder detects an object.

  • distance – Returns the distance between the Range Finder and the nearest detected object.

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

  • Sonar – Create a Range Finder.

找到的对象#

found_object returns a Boolean indicating whether the Range Finder detects an object within its field of view.

  • True – The Range Finder is detecting an object.

  • False – The Range Finder is not detecting an object.

Usage:
range_finder.found_object()

参数

描述

此方法没有参数。

距离#

distance returns the measured distance to the nearest object detected by the sensor.

Usage:
range_finder.distance(units)

范围

描述

单位

The unit that will represent the distance:

  • MM – millimeters
  • INCHES

构造函数#

Constructors are used to manually create Sonar objects, which are necessary for configuring Range Finders outside of VEXcode.

Sonar#

Sonar creates a Range Finder.

Usage:
Sonar(port)

范围

描述

port

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

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.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)