Skip to main content

Lesson 1: Eye Sensor

In this Lesson, you will learn about the Front and Down Eye Sensors on the VR Robot. You will learn how to use the Eye Sensors and identify why the Eye Sensors are used in a project.

Learning Outcomes

  • Identify that a VR Robot contains two Eye Sensors, one facing forward and the other facing down.
  • Identify that the Eye Sensors can detect if there is an object present and the color of that object (red, green, blue, none).
  • Identify that the front_eye.near_object and down_eye.near_object commands return a Boolean value that reports True when the Front or Down Eye Sensor is close to an object, and False when it is not.
  • Identify that the front_eye.detect and down_eye.detect commands return a Boolean value that reports True when the Front or Down Eye Sensor detects a selected color, and False when it detects a different color than the one selected.
  • Describe why a project would use the Front or Down Eye Sensor.

Eye Sensors

The Eye Sensors can detect if there is an object present, and if so, detect the color of the object (red, green, blue, none). This can be used to detect an object, like a colored disk, on the Playground.

A VR Robot has two Eye Sensors – a Front Eye Sensor and a Down Eye Sensor. The Front Eye Sensor is mounted in front of the VR Robot and faces forward. This can be useful when detecting raised objects on the Playground, so that the VR Robot can crash castles or navigate via colored disks on a Playground. The Down Eye Sensor is mounted below the VR Robot and faces downward. This can be useful when detecting disks to pick up from the floor of a Playground, or to detect lines or markings on the Playground.

eye sensor call out

To learn more about the Eye Sensors, and common uses for the Eye Sensors in VEXcode VR Python projects, view this article.

In this Unit, you will use the Front Eye Sensor to detect objects in front of the VR Robot, and their colors. Like the other sensors you have learned about in previous Units, data from the Eye Sensor can be used in a project to make the VR Robot make decisions. 

Eye Sensor Near Object Command

The Eye Sensors can be used to detect if there is an object (like a disk) in front of it. This data can then be used in a project so the VR Robot can make a decision when the Eye Sensor is near an object.

The near_object command reports if the Eye Sensor is close enough to an object to detect a color (red, green, blue, none). Each Eye Sensor on the VR Robot has its own near_object command that will return Boolean values of True or False, depending on whether an object is detected by the sensor.

image of the front and down eye near object commands in the workspace

  • The front_eye.near_object and down_eye.near_object commands report True when the Front Eye Sensor or Down Eye Sensor is close enough to an object to detect its color.
  • The front_eye.near_object and down_eye.near_object commands reports False if the Front Eye Sensor or Down Eye Sensor is not close enough to an object to detect its color.

The near_object command is typically used with a Control structure, like an if statement, so that the VR Robot can use the data from an Eye Sensor to make a decision. You will learn more about if statements in this Unit.

Eye Sensor Detect Command

The Eye Sensors can also report the color of an object that is detected, and use that value to make a decision. Each Eye Sensor on the VR Robot has its own detect command that reports if the sensor detects a specific color. The Eye Sensors can detect red, blue, or green.

Set the parameter as the color to be detected. The detect command can accept 'red', 'blue', 'green' or 'none' as detectable colors. The 'none' parameter is used to report any color that is not red, blue, or green.

image of the front eye detect command in the workspace with all color parameters image of the down eye detect command with all four color parameters

  • The front_eye.detect and down_eye.detect commands report True when the Front or Down Eye Sensor detects the specific color in the parameter.
  • The front_eye.detect and down_eye.detect commands report False ;when the Front or Down ;Eye Sensor does not detect the specific color in the parameter.

The detect command can be used with other commands, like if statements, in a project to instruct a VR Robot to make a decision based on the specific color that is detected, like turning right when green is detected, or stopping when red is detected.

Select the Next button to continue with the rest of this Lesson.