距離#
介紹#
距離感測器可以偵測物體是否在感測器前方,並返回該物體與感測器的距離。
以下是所有可用方法的清單:
獲取器 — 返回是否偵測到物體以及物體距離。
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)