距离#

介绍#

距离传感器使机器人能够检测到物体的存在并测量其距离。

以下是所有可用方法的列表:

获取器 – 返回是否检测到物体及其距离。

  • found_object – Return a Boolean indicating if an object is detected.

  • get_distance – Return the distance of the closest object to the Distance Sensor.

获取器#

found_object#

found_object returns a Boolean indicating whether or not an object is detected by the Distance Sensor.

  • True – An object is detected.

  • False – An object is not detected.

Usage:
distance.found_object()

参数

描述

此方法没有参数。

def main():
    # Stop turning when an object is detected
    drivetrain.turn(RIGHT)
    while True:
        wait(5, MSEC)
        if front_distance.found_object():
            drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

get_distance#

get_distance returns the distance of the object closest to the Distance Sensor.

Usage:
distance.get_distance(units)

参数

描述

units

The unit that represents the distance:

  • INCHES
  • MM – millimeters
def main():
    # Drive forward until an object is 200 mm away
    while front_distance.get_distance(MM) > 200:
        wait(5, MSEC)
        drivetrain.drive(FORWARD)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)