Using the Eye Sensor in VEXcode VR

The VEX VR Robot has a multitude of sensors, including two Eye Sensors.


Eye Sensors on the VR Robot

front down eye

The VR Robot has two Eye Sensors, one that faces forward, and another that faces down. The sensors can detect if there is an object present as well as detect color (red, green, blue, none).

Eye_sensor_dashboard.png

The Eye Sensor values can be displayed on the Dashboard in VEXcode VR. To learn more about the Dashboard, view the Dashboard - Playground Features - VEXcode VR article.

Screen_Shot_2022-04-19_at_1.33.25_PM.png

The Eye Sensor values can be displayed on the Monitor Console in VEXcode VR. To learn more about the Monitor Console, see this article.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.


VEXcode VR Blocks Used with the Eye Sensors

<Color near object> block

Color_near_object_block.png

The <Color near object> block reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none).

Color_near_object_drop_down_menu.png

The Front or Down Eye Sensor can be selected from the drop-down menu on the block.

Monitor true zoom

The <Color near object> block is a Boolean block that reports true when the Eye Sensor is close to an object that has detectable colors, and reports false when it is not close enough to an object with detectable colors.

<Color sensing> block

Color sensing block

The Color sensing block reports if the Eye Sensor detects a specific color.

Color sensing block

The Front or Down Eye Sensor can be selected from the drop-down menu on the block.

Color sensing dropdown

The color that the Eye Sensor is looking for can be selected from the drop-down menu on the block.

Monitor detect green

The <Color sensing> block is a Boolean block that reports true when the Eye Sensor detects the selected color, and reports false when it does not detect the selected color.


VEXcode VR Python Commands Used With the Eye Sensor

near_object Command

Screenshot 2023-07-25 at 4.35.26 PM.png

The near_object command reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none). The front or down Eye Sensor can be selected when dragging in a command from the Toolbox or when typing in the command.

Monitor true zoom

The near_object command is a Boolean that reports true when the Eye Sensor is close to an object that has detectable colors, and reports false when it is not close enough to an object with detectable colors.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.

detect Command

Screenshot 2023-07-25 at 4.37.11 PM.png

The detect command reports if the Eye Sensor detects a specific color. The front or down Eye Sensor can be selected when dragging in a command from the Toolbox or when typing in the command.

Screen_Shot_2021-11-11_at_1.32.48_PM.png

The color that the Eye Sensor is looking for can be selected through the autocomplete feature when adding the command. For more information on using the autocomplete feature in VEXcode VR with Python, see this article.

Monitor detect green

The detects command is a Boolean that reports true when the Eye Sensor detects the selected color, and reports false when it does not detect the selected color.

To monitor sensor values in VEXcode VR Python, the monitor_sensors command needs to be added to the project. For more information about monitoring sensors in VEXcode VR with Python, see this article.


Using the Front Eye Sensor in a VEXcode VR Project

The VR Robot can use the Front Eye Sensor to initiate a sequence of behaviors when an object or color is detected. This can include driving until an object (like a wall, disk, or castle) is detected then stop driving to avoid a crash or driving and sensing a specific color and executing an action depending on the color detected. 

VEXcode VR Blocks Wall Maze Playground
eye sensor code 0.png eye sensor playground 0.png
VEXcode VR Python
def main():
drivetrain.drive(FORWARD)
while not front_eye.near_object():
wait(20, MSEC)
drivetrain.stop()

In this example, using the Wall Maze Playground, the VR Robot will drive forward until it detects that it is near an object, in this case the wall, then stop driving.

Disk Color Maze Playground
eye sensor playground 1.png
VEXcode IQ Blocks
eye sensor code 1.png
VEXcode IQ Python
def main():
drivetrain.drive(FORWARD)
while True:
if front_eye.detect(GREEN):
drivetrain(stop)
wait(2, seconds)
drivetrain.drive_for(REVERSE, 200, MM)
wait(20, MSEC)

In this example on the Disk Maze Playground, the VR Robot will drive forward until the Front Eye Sensor detects a green object, then it will stop and wait, before driving in reverse. Notice that in the Dashboard, the Front Eye Sensor values are reporting true that an object was detected, and the color of that object (disk) is green.


Using the Down Eye Sensor in a VEXcode VR Project

The Down Eye Sensor can be used on the Playgrounds to help detect the color of disks in the Disk Mover Playground, find the edge of the Castle Crasher Playground, and more. One thing to note about the Down Eye Sensor, is that it is tuned to not detect the floor of a Playground as an object. Other items, such as disks, will register as an object.

VEXcode VR Blocks Disk Mover Playground
eye sensor code 2.png eye sensor playground 2.png
VEXcode VR Python
def main():
drivetrain.drive(FORWARD)
while not down_eye.detect(BLUE):
wait(20, MSEC)
drivetrain.stop()
magnet.energize(BOOST)

This project can be used with the Disk Mover Playground. In this project, the VR Robot will drive forward until the Down Eye Sensor detects blue, then stop driving and set the Electromagnet to 'boost' to pick up the disk.

VEXcode VR Blocks Castle Crasher Playground
eye sensor code 3.png eye sensor playground 3.jpeg
VEXcode VR Python
def main():
drivetrain.drive_for(FORWARD, 300, MM)
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive(FORWARD)
while not down_eye.detect(RED):
wait(20, MSEC)
drivetrain.stop()

In this example on the Castle Crasher Playground, the VR Robot will drive until the red border is detected by the Down Eye Sensor.

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: