測距儀#

介紹#

超音波測距儀利用聲波測量到最近物體的距離。它的工作原理是發出超音波脈衝,並測量聲波反射回來所需的時間。

VEX EXP測距儀。

本頁使用 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 EXP 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)