Óptico#
Para que los comandos ópticos aparezcan en VEXcode V5, se debe configurar un sensor óptico en la ventana Dispositivos.
Para obtener más información, consulte estos artículos:
Inicializando la clase óptica#
Un sensor óptico se crea utilizando el siguiente constructor:
Optical(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
|---|---|
|
A valid |
# Construct an Optical Sensor "optical" with the
# Optical class.
optical = Optical(Ports.Port1)
This optical object will be used in all subsequent examples throughout this API documentation when referring to Optical class methods.
Métodos de clase#
hue()#
The hue() method returns the value of the hue detected by the Optical Sensor.
Devuelve: El valor del tono detectado por el sensor óptico como un flotante en el rango 0 - 359,99.
# Set a variable hue, to the value of the hue detected by
# the Optical Sensor.
hue = optical.hue()
brightness()#
The brightness(readraw) method returns the brightness detected by the Optical Sensor.
Parámetros |
Descripción |
|---|---|
|
Opcional. Un valor booleano para leer datos de brillo sin procesar en lugar de porcentaje. |
Devuelve: El brillo detectado por el sensor óptico como un flotante en el rango 0 - 100%.
# Set a variable brightness, to the value of the brightness
# detected by the Optical Sensor.
brightness = optical.brightness()
# Print the brightness detected by the Optical Sensor to
# the Brain's screen.
brain.screen.print(brightness)
color()#
The color() method returns the color detected by the Optical Sensor.
Devuelve: El color detectado por el sensor óptico como una instancia de la clase de color.
# Set a variable, color, to the color detected by the
# Optical Sensor.
color = optical.color()
# Print the color detected by the Optical Sensor to the
# Brain's screen.
brain.screen.print(color)
is_near_object()#
The is_near_object() method checks if the Optical Sensor detects a nearby object.
Returns: True if a nearby object is detected. False if one is not.
# If an object is detected yb the Optical Sensor, print "near object".
if optical.is_near_object():
brain.screen.print("near object")
set_light()#
The set_light(value) method sets Optical Sensor’s LED to on or off.
Parámetros |
Descripción |
|---|---|
|
El estado para configurar la luz o el porcentaje de energía en el rango 0 - 100. |
Devoluciones: Ninguna.
# Turn on led with previous intensity.
optical.set_light(LedStateType.ON)
# Turn on led with new intensity.
optical.set_light(65)
set_light_power()#
The set_light_power(value) method sets the light power of the Optical Sensor’s LED.
Parámetros |
Descripción |
|---|---|
|
El nivel de potencia para configurar la luz de 0 a 100 como porcentaje. |
Devoluciones: Ninguna.
# Set the light power to 50 percent.
optical.set_light_power(50)
integration_time()#
The integration_time(value) method sets the Optical Sensor’s LED to the requested power.
Parámetros |
Descripción |
|---|---|
|
Opcional. El tiempo de integración en milisegundos de 5 a 700. |
Devoluciones: Ninguna.
# Set the integration time to 50 milliseconds.
optical.integration_time(50)
rgb()#
The rgb(raw) method returns the Optical Sensor’s RGB value.
Parámetros |
Descripción |
|---|---|
|
Opcional. Un valor booleano para determinar si devuelve valores sin procesar o procesados. |
Devuelve: Una tupla con valores de rojo, verde, azul y brillo.
# Get the RGB value of the Optical Sensor.
rgb = optical.rgb()
object_detect_threshold()#
The object_detect_threshold(value) method sets the object detection threshold.
Parámetros |
Descripción |
|---|---|
|
Un número en el rango 0 - 255. Un valor de 0 solo devolverá el valor actual. |
Devuelve: El valor actual del umbral de detección de objetos.
# Set the object detection threshold to 100.
optical.value = object_detect_threshold(100)
object_detected()#
The object_detected(callback, arg) method registers a callback function for when an object is detected.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se detecte un objeto. |
|
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devuelve: Una instancia de la clase Event.
# Define a function detected().
def detected():
# The Brain will print that an object was detected on
# the Brain's screen.
brain.screen.print("object detected")
# Run detected when the Optical Sensor detects an object.
optical.object_detected(detected)
object_lost()#
The object_lost(callback, arg) method registers a callback function for when an object is lost.
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se pierda un objeto. |
|
Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada. |
Devuelve: Una instancia de la clase Event.
# Define a function lost().
def lost():
# The Brain will print that an object was lost on the
# Brain's screen.
brain.screen.print("object lost")
# Run lost when the Optical Sensor loses an object.
optical.object_lost(lost)
installed()#
The installed() method checks if the Optical Sensor is connected.
Returns: True if the Optical Sensor is connected. False if it is not.
timestamp()#
The timestamp() method returns the timestamp of the last received status packet from the Optical Sensor.
Devuelve: La marca de tiempo del último paquete de estado recibido del sensor óptico en milisegundos.