Ojo#

Introducción#

El sensor GO Eye permite al robot detectar objetos y devolver información relacionada con su apariencia, como colores y brillo.

For the examples below, the configured Eye Sensor will be named eye. This name is used in all subsequent examples throughout this API documentation when referring to Eye class methods.

A continuación se muestra una lista de todos los métodos:

Mutators — Change the settings of the Eye Sensor.

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

  • set_range — Set the Eye Sensor’s detection range.

  • set_light_power — Set the Eye’s light power level.

Getters — Return data from detected objects.

  • 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 or not an object is detected.

  • is_color_detected — Returns whether or not a certain color is detected.

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 light to set:

  • OFF
  • ON

# 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 the range at which the Eye Sensor can detect objects. By default, the range is set to FAR.

Uso:
eye.set_range(distance)

Parámetros

Descripción

distance

The detection range of the sensor:

  • FAR — Up to 40 millimeters
  • NEAR — Up to 18 millimeters

# 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 establece el brillo de la luz del sensor ocular. Si la luz no está encendida al usar este método, se encenderá con el brillo especificado.

Uso:
eye.set_light_power(value)

Parámetros

Descripción

value

El brillo de la luz como porcentaje de 0% a 100%.

# 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.

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 devuelve el tono de un color detectado por el sensor ocular en grados de 0 a 359,99.

A circular color wheel displaying a full spectrum of hues labeled with degree values around the perimeter, increasing in 30-degree increments from 0° at the top to 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 devuelve el brillo detectado por el sensor ocular como un porcentaje del 0% al 100%.

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 devuelve un valor booleano que indica si el sensor ocular detecta o no un objeto.

  • True — The Eye Sensor detects an object.

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

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 devuelve un valor booleano que indica si el sensor ocular detecta o no un color específico.

  • True — The Eye Sensor detects the color.

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

Uso:
eye.is_color_detected(color)

Parámetros

Descripción

color

The color the Eye Sensor will check:

  • BLUE
  • GREEN
  • NONE
  • RED

# 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)