Distancia#
Introducción#
The Distance Sensor can detect whether an object is in front of the sensor and return how far away that object is.
A continuación se muestra una lista de todos los métodos disponibles:
Getters — Return whether an object is detected and how far away it is.
found_object— Returns whether the Distance Sensor currently detects an object.get_distance— Returns the distance between the Distance Sensor and the nearest detected object.
Captadores#
found_object#
found_object returns whether the Distance Sensor currently detects an object.
True— The Distance Sensor detects an object.False— The Distance Sensor does not detect an object.
Usage:
distance.found_object()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
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 between the Distance Sensor and the nearest detected object.
Usage:
distance.get_distance(units)
Parámetros |
Descripción |
|---|---|
|
The distance unit: |
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)