Ojo#

Introducción#

El sensor ocular VEX GO puede detectar objetos y colores. También puede informar sobre la cantidad de luz que se refleja hacia el sensor y el valor de tono del color detectado.

The Eye Sensor has a light that can be turned on or off to help it see objects and colors more clearly. The Eye Sensor can also use a NEAR or FAR range to detect objects at different distances.

El sensor ocular se puede colocar en diferentes posiciones según la configuración. Por ejemplo, en la configuración Code Base 2.0 - Eye Forward, el sensor ocular apunta hacia adelante. En las configuraciones Code Base 2.0 - Eye Down, Code Base 2.0 - Eye + Electromagnet y Super Code Base 2.0, el sensor ocular apunta hacia abajo.

For the examples below, the configured Eye Sensor is named eye. This name is used in the examples to call Eye class methods.

Existen muchas maneras de programar el sensor ocular. A continuación se muestra una lista de todos los métodos para programar el sensor ocular:

Motadores: Ajusta la configuración del sensor ocular.

  • set_light — Turns the Eye Sensor’s light on or off.

  • set_range — Sets how far the Eye Sensor can detect an object.

  • set_light_power — Sets the Eye Sensor’s light power level.

Obtenedores: Devuelven lo que detecta el sensor ocular.

  • get_color — Returns the color detected by the Eye Sensor.

  • get_hue — Returns the hue detected by the Eye Sensor.

  • get_brightness — Returns the brightness detected by the Eye Sensor.

  • is_object_detected — Returns whether the Eye Sensor detects an object within range.

  • is_color_detected — Returns whether the Eye Sensor detects a specific color.

Mutadores#

set_light#

set_light enciende o apaga la luz del sensor ocular.

Uso:
eye.set_light(state)

Parámetros

Descripción

state

The state of the Eye Sensor’s light: ON or OFF.

# Build Used: Super Code Base 2.0
def main():
    # Turn the light on and off
    while True:
        eye.set_light(ON)
        wait(2, SECONDS)
        eye.set_light(OFF)
        wait(2, SECONDS)

# Start threads — Do not delete
start_thread(main)

set_range#

set_range sets how far an object can be from the Eye Sensor before it can be detected.

Every project begins with the Eye Sensor set to FAR range by default.

Uso:
eye.set_range(distance)

Parámetros

Descripción

distance

The Eye Sensor’s object detection range. NEAR detects objects up to 18 millimeters away, while FAR detects objects up to 40 millimeters away.

# Build Used: Code Base 2.0 - Eye Forward
def main():
    # Drive to an object with different ranges
    eye.set_range(FAR)
    drivetrain.drive(FORWARD)
    wait(0.2, SECONDS)
    while not eye.is_object_detected():
        wait(0.2, SECONDS)
    drivetrain.drive_for(REVERSE, 100, MM)
    # Closer detection range
    eye.set_range(NEAR)
    drivetrain.drive(FORWARD)
    wait(0.2, SECONDS)
    while not eye.is_object_detected():
        wait(0.2, SECONDS)
    drivetrain.stop()


# Start threads — Do not delete
start_thread(main)

set_light_power#

set_light_power sets how bright the Eye Sensor’s light is. The light can help the Eye Sensor detect objects and colors more clearly.

Un porcentaje mayor hace que la luz sea más brillante. Un porcentaje menor hace que la luz sea más tenue.

Si la luz del sensor ocular está apagada, al configurar la potencia de la luz por encima del 0% se encenderá la luz.

Si la luz del sensor ocular está encendida, al ajustar la potencia de la luz al 0%, esta se apagará.

Uso:
eye.set_light_power(value)

Parámetros

Descripción

value

El nivel de brillo al que se ajustará la luz del sensor ocular, de 0% a 100%. Utilice números enteros.

# Build Used: Super Code Base 2.0
def main():
    # Turn on the light at different brightnesses
    eye.set_light_power(25)
    wait(2, SECONDS)
    eye.set_light_power(50)
    wait(2, SECONDS)
    eye.set_light_power(100)

# Start threads — Do not delete
start_thread(main)

Captadores#

get_color#

get_color devuelve el color detectado por el sensor ocular.

Este método puede devolver:

  • RED — A hue value between 340° - 20°

  • GREEN — A hue value between 75° - 154°

  • BLUE — A hue value between 160° - 254°

  • NONE — None of the available colors are detected.

Uso:
eye.get_color()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Stop when red is detected
    drivetrain.drive(FORWARD)
    while True:
        if eye.get_color() == RED:
            break
        wait(0.2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

get_hue#

get_hue returns the color detected by the Eye Sensor as a whole number from 0 to 359.00 degrees.

El matiz es una forma de describir el color utilizando números alrededor de una rueda de colores.

Una rueda de colores circular que muestra un espectro completo de tonalidades etiquetadas con valores de grados alrededor del perímetro, aumentando en incrementos de 30 grados desde 0° en la parte superior hasta 360°.

Uso:
eye.get_hue()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Code Base 2.0 - Eye Forward
def main():
    # Display the hue of a pink GO piece
    while True:
        console.clear()
        if 10 < eye.get_hue() < 40:
            console.print("Pink!")
            wait(0.1,SECONDS)
        else:
            console.print("Not pink.")
            wait(0.1,SECONDS)

# Start threads — Do not delete
start_thread(main)

get_brightness#

get_brightness returns how bright the detected light is, as a whole number from 0% to 100%.

Un porcentaje más alto significa que se refleja más luz hacia el sensor ocular. Un porcentaje más bajo significa que se refleja menos luz.

Uso:
eye.get_brightness()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Monitor the brightness until red is detected
    monitor_sensor("eye.get_brightness")
    drivetrain.drive(FORWARD)
    while not eye.get_color() == RED:
        wait(0.2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

is_object_detected#

is_object_detected returns a Boolean that reports whether or not the Eye Sensor detects an object within range.

  • True — The Eye Sensor detects an object.

  • False — The Eye Sensor does not detect an object.

The detection range can be changed using set_range.

Uso:
eye.is_object_detected()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Code Base 2.0 - Eye Forward
def main():
    # Drive forward until an object is detected
    drivetrain.drive(FORWARD)
    wait(0.2, SECONDS)
    while not eye.is_object_detected():
        wait(0.5, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

is_color_detected#

is_color_detected returns a Boolean that reports whether the Eye Sensor detects a specified color, based on the detected hue value.

  • True — The Eye Sensor detects the selected color.

  • False — The Eye Sensor does not detect the selected color.

El sensor ocular funciona mejor cuando el objeto está lo suficientemente cerca como para detectarlo y la iluminación es buena.

Uso:
eye.is_color_detected(color)

Parámetros

Descripción

color

The color for the Eye Sensor to check:

  • BLUE – Hue value between 160° and 254°.
  • GREEN – Hue value between 75° and 154°.
  • NONE
  • RED – Hue value between 340° and 20°.

# Build Used: Super Code Base 2.0
def main():
    # Drive forward until a green object is detected
    drivetrain.drive(FORWARD)
    wait(0.2, SECONDS)
    while not eye.is_color_detected(GREEN):
        wait(0.5, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)