距离#
介绍#
距离传感器可以检测物体是否在传感器前方,并返回该物体与传感器的距离。
以下是所有可用方法的列表:
获取器 — 返回是否检测到物体以及物体距离。
found_object— 返回距离传感器当前是否检测到对象。get_distance— 返回距离传感器与最近检测到的对象之间的距离。
获取器#
found_object#
found_object 返回距离传感器当前是否检测到物体。
True— 距离传感器检测到物体。False— 距离传感器未检测到物体。
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 返回距离传感器与最近检测到的物体之间的距离。
Usage:
distance.get_distance(units)
参数 |
描述 |
|---|---|
|
距离单位: |
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)