Ojo#
Introducción#
El sensor ocular VR puede detectar objetos e identificar su color, brillo y tono. También permite ajustar el rango de detección y la configuración de iluminación para obtener lecturas más precisas.
A continuación se muestra una lista de todos los métodos disponibles:
Obtenedores: leen la presencia de objetos, color, brillo, tono, RGB y estado del sensor.
near_object– Returns whether or not a detected object is near the Eye Sensor.detect– Returns a Boolean indicating if the Eye Sensor detects the selected color.brightness– Returns the brightness of a detected object.
Devolución de llamada: ejecuta el código cuando se detecta o se pierde un objeto.
object_detected– Calls a function when an object is detected.object_lost– Calls a function when an object is lost.
Captadores#
near_object#
near_object returns a Boolean indicating whether or not the Eye Sensor is nearby an object.
True– The sensor is near an object.False– The sensor is not near an object.
Usage:
eye.near_object()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
def main():
# Stop driving when Eye Sensor is
# near an object
drivetrain.drive(FORWARD)
while True:
if front_eye.near_object():
drivetrain.stop()
wait(5, MSEC)
# VR threads — Do not delete
vr_thread(main)
detect#
detect returns a Boolean indicating whether or not the selected color is detected by the Eye Sensor.
True– The sensor detects the color.False– The sensor does not detect the color.
Usage:
eye.detect(color)
Parámetros |
Descripción |
|---|---|
|
The color for the Eye Sensor to check for:
|
def main():
# Stop the robot if the Eye Sensor
# detects red
drivetrain.turn(RIGHT)
while True:
if front_eye.detect(RED):
drivetrain.stop()
wait(5, MSEC)
# VR threads — Do not delete
vr_thread(main)
brightness#
brightness returns the brightness detected by the Eye Sensor as a percent from 0 to 100.
Usage:
eye.brightness(units)
Parámetros |
Descripción |
|---|---|
|
The unit that represents the brightness:
|
Llamar de vuelta#
object_detected#
object_detected registers a callback function for when an object is detected.
Usage:
eye.object_detected(callback)
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando cambia el valor del eje. |
def detected():
# Display a message
drivetrain.stop()
brain.print("object detected")
wait(0.5,SECONDS)
brain.clear()
def main():
# Drive until an object is detected
drivetrain.drive(FORWARD)
front_eye.object_detected(detected)
# VR threads — Do not delete
vr_thread(main)
object_lost#
object_lost registers a callback function for when an object is lost.
Usage:
eye.object_lost(callback)
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando cambia el valor del eje. |
def lost():
# Display a message
drivetrain.stop()
brain.print("object lost")
wait(0.5,SECONDS)
brain.clear()
def main():
# Back away from an object
drivetrain.drive(REVERSE)
front_eye.object_lost(lost)
# VR threads — Do not delete
vr_thread(main)