Ojo#
Introducción#
The VEX GO Eye Sensor can detect objects and colors. It can also report how much light reflects back to the sensor and the hue value of the detected color.
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.
The Eye Sensor can be placed in different positions depending on the build. For example, the Code Base 2.0 - Eye Forward build has the Eye Sensor facing forward. The Code Base 2.0 - Eye Down build, Code Base 2.0 ‑ Eye + Electromagnet, and Super Code Base 2.0 has the Eye Sensor facing down.
For the examples below, the configured Eye Sensor is named eye. This name is used in the examples to call Eye class methods.
There are many ways to code the Eye Sensor. Below is a list of all Eye methods:
Mutators — Adjust Eye Sensor settings.
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.
Getters — Return what the Eye Sensor detects.
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 |
|---|---|
|
The state of the Eye Sensor’s light: |
# 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 |
|---|---|
|
The Eye Sensor’s object detection range. |
# 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.
A higher percentage makes the light brighter. A lower percentage makes the light dimmer.
If the Eye Sensor’s light is off, setting the light power above 0% will turn the light on.
If the Eye Sensor’s light is on, setting the light power at 0% will turn the light off.
Uso:
eye.set_light_power(value)
Parámetros |
Descripción |
|---|---|
|
The brightness to set the Eye Sensor’s light to, from 0% to 100%. Use whole numbers. |
# 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.
This method can return:
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.
Hue is a way to describe color using numbers around a color wheel.

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%.
A higher percentage means more light is reflected back to the Eye Sensor. A lower percentage means less light is reflected back.
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.
The Eye Sensor works best when the object is close enough to detect and the lighting is clear.
Uso:
eye.is_color_detected(color)
Parámetros |
Descripción |
|---|---|
|
The color for the Eye Sensor to check:
|
# 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)