眼睛#

介绍#

VEX GO 眼部传感器可以检测物体和颜色。它还可以报告反射回传感器的光量以及检测到的颜色色调值。

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.

根据不同的构建版本,眼部传感器可以放置在不同的位置。例如,Code Base 2.0 - Eye Forward 构建版本中的眼部传感器朝前。Code Base 2.0 - Eye Down 构建版本、Code Base 2.0 - Eye + Electromagnet 构建版本以及 Super Code Base 2.0 构建版本中的眼部传感器则朝下。

For the examples below, the configured Eye Sensor is named eye. This name is used in the examples to call Eye class methods.

眼动追踪传感器的编码方式有很多种。以下列出了所有眼动追踪方法:

变异器 — 调整眼部传感器设置。

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

获取器 — 返回眼部传感器检测到的内容。

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

修改器#

set_light#

set_light 打开或关闭眼睛传感器的灯。

用法:
eye.set_light(state)

参数

描述

state

The state of the Eye Sensor’s light: ON or OFF.

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

用法:
eye.set_range(distance)

参数

描述

distance

The Eye Sensor’s object detection range. NEAR detects objects up to 18 millimeters away, while FAR detects objects up to 40 millimeters away.

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

百分比越高,灯光越亮;百分比越低,灯光越暗。

如果眼部传感器的灯是关闭的,将灯光功率设置为 0% 以上即可打开灯。

如果眼部传感器的指示灯亮着,将灯光功率设置为 0% 将关闭指示灯。

用法:
eye.set_light_power(value)

参数

描述

value

设置眼部传感器灯光的亮度,范围从 0% 到 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)

吸气剂#

get_color#

get_color 返回眼睛传感器检测到的颜色。

此方法可以返回:

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

用法:
eye.get_color()

参数

描述

该方法没有参数。

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

色相是用色轮上的数字来描述颜色的一种方法。

一个圆形色轮,显示完整的色调光谱,边缘标有度数,从顶部的 0° 到 360°,以 30° 为增量递增。

用法:
eye.get_hue()

参数

描述

该方法没有参数。

# 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%.

百分比越高,意味着反射回眼部传感器的光线越多;百分比越低,意味着反射回的光线越少。

用法:
eye.get_brightness()

参数

描述

该方法没有参数。

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

用法:
eye.is_object_detected()

参数

描述

该方法没有参数。

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

当物体距离足够近且光线充足时,眼部传感器的工作效果最佳。

用法:
eye.is_color_detected(color)

参数

描述

color

The color for the Eye Sensor to check:

  • BLUE – Hue value between 160° and 254°.
  • GREEN – Hue value between 75° and 154°.
  • NONE
  • RED – Hue value between 340° and 20°.

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