Eye#

Introduction#

The GO Eye Sensor enables the robot to detect objects and return information relating to its appearance, such as colors and brightness.

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

Below is a list of all methods:

Mutators – Change the settings of the Eye Sensor.

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

  • set_range – Set the Eye’s Sensor 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.

Mutators#

set_light#

set_light turns the Eye Sensor’s light on or off.

Usage:
eye.set_light(state)

Parameters

Description

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.

Usage:
eye.set_range(distance)

Parameters

Description

distance

The detection range of the sensor:

  • FAR
  • NEAR
# 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.stop()
    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 the brightness of the Eye Sensor’s light. If the light is not on when using this method, it will be turned on at the specified brightness.

Usage:
eye.set_light_power(value)

Parameters

Description

value

The brightness of the light as a percent from 0% to 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)

Getters#

get_color#

get_color returns the color detected by the Eye Sensor.

Usage:
eye.get_color()

Parameters

Description

This method has no parameters.

# 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 hue of a color detected by the Eye Sensor in degrees from 0 to 359.99.

Usage:
eye.get_hue()

Parameters

Description

This method has no parameters.

# Build Used: Code Base 2.0 - Eye Forward
def main():
    # Check the hue of a pink GO piece
    while True:
        console.clear()
        if 290 < eye.get_hue() < 350:
            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 the brightness detected by the Eye Sensor as a percent from 0% to 100%.

Usage:
eye.get_brightness()

Parameters

Description

This method has no parameters.

# Build Used: Super Code Base 2.0
def main():
    # Continuously monitor the detected brightness
    # until detecting red
    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 indicating whether or not an object is detected by the Eye Sensor.

  • True – The Eye Sensor detects an object.

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

Usage:
eye.is_object_detected()

Parameters

Description

This method has no parameters.

# 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 indicating whether or not a specific color is detected by the Eye Sensor.

  • True – The Eye Sensor detects the color.

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

Usage:
eye.is_color_detected(color)

Parameters

Description

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)