Using the Eye Sensor in VEXcode VR with Python

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


Eye Sensors on the VR Robot

Screenshot of VEXcode VR interface showing a block-based coding environment for programming a virtual robot, designed to support STEM education through coding tutorials and problem-solving activities.

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

Screenshot of VEXcode VR interface showcasing the block-based coding environment, designed for teaching coding concepts through virtual robotics, as part of the Tutorials section.

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

Screenshot of VEXcode VR interface showing a block-based coding environment for programming a virtual robot, designed for educational purposes in STEM learning.

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


Commands Used with the Eye Sensors

Eye sensor near object command

Screenshot of VEXcode VR tutorial interface, showcasing block-based coding options for programming a virtual robot, aimed at teaching coding concepts and robotics principles to students and educators in a STEM education context.

 

The Eye sensor near object command reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none). The Front Eye Sensor and the Down Eye Sensor have respective near object commands.

Screenshot of the VEXcode VR interface showcasing a block-based coding environment, designed for teaching coding concepts through a virtual robot, featured in the Tutorials section.

The Eye sensor near object command returns 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.

Eye sensor color command

Screenshot of VEXcode VR interface showcasing the block-based coding environment, designed for teaching coding concepts through virtual robotics, featuring tools for creating, testing, and debugging code in a simulated setting.

The Eye sensor color command reports if the Eye Sensor detects a specific color.

Screenshot of VEXcode VR interface showcasing the block-based coding environment, designed for teaching coding concepts through virtual robotics, as part of the Tutorials section.

The color that the Eye Sensor is looking for is set as the command's parameter. Both Eye Sensors can detect red, green, blue, or none.

Screenshot of VEXcode VR interface showcasing a block-based coding environment, designed for teaching coding concepts through virtual robot programming, with options for both beginners and advanced users.

The Eye sensor color command returns a Boolean that reports True when the Eye Sensor detects the selected color, and reports False when it does not detect the color set as the parameter.


Common Uses of the Eye Sensor

Screenshot of VEXcode VR tutorial interface, showcasing the block-based coding environment designed for teaching coding concepts through a virtual robot, aimed at enhancing problem-solving and computational thinking skills in STEM education.

The Eye Sensors on the VR Robot can be used in many ways. 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.

The Eye Sensors can detect the color of an object near the sensor, such as the colored disks in the Disk Mover Playground or the red border around the Castle Crasher Playground. This is useful if you want the VR Robot to sort differently colored objects, drive up to a specifically colored object, or detect the color of objects as they pass by the sensor.

def main():
while not down_eye.detect(BLUE):
drivetrain.drive(FORWARD)
wait(5, MSEC)
drivetrain.stop()
magnet.energize(BOOST)

To use the example above, copy this code into VEXcode VR and run the project on the Disk Mover Playground.

Screenshot of VEXcode VR tutorial interface, showcasing block-based coding options and a virtual robot, designed to help users learn coding concepts and robotics principles in an educational setting.

The VR Robot can use the Eye Sensors to initiate a sequence of behaviors when it is in the correct place to do so. For example, the VR Robot can drive forward until it detects that it is near an object, such as a wall, then turn 90 degrees, or drive in reverse to not crash into an object, such as a castle, disk, or wall.

def main():
while not front_eye.near_object():
drivetrain.drive(FORWARD)
wait(5, MSEC)
drivetrain.stop()

To use the example above, copy this code into VEXcode VR and run the project on the Wall Maze Playground.

Screenshot of VEXcode VR interface showing a block-based coding environment for programming a virtual robot, designed for educational purposes in STEM, highlighting tutorials for coding concepts and robotics principles.

The VR Robot can use the Eye Sensors to drive toward an object or surface until it is within a specific distance, without touching it. This can be used to make sure that the VR Robot does not fall off of a Playground or crash into walls.

def main():
drivetrain.drive_for(FORWARD, 300, MM)
drivetrain.turn_for(LEFT, 90, DEGREES)
while not down_eye.detect(RED):
drivetrain.drive(FORWARD)
wait(5, MSEC)
drivetrain.stop()

To use the example above, copy this code into VEXcode VR and run the project on the Castle Crasher Playground.


Eye Sensor Example Project

Screenshot of VEXcode VR interface showcasing block-based coding options and a virtual robot, illustrating the platform's educational tools for coding, problem-solving, and robotics principles in a tutorial context.

In the following example, 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.

def main():
drivetrain.drive(FORWARD)
while True:
if front_eye.detect(GREEN):
drivetrain.stop()
wait(2, SECONDS)
drivetrain.drive_for(REVERSE, 200, MM)
wait(5, MSEC)

To use the example above, copy this code into VEXcode VR and run the project on the Disk Maze Playground.

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

Last Updated: