光学传感器#

介绍#

光学传感类别包含用于控制 VEX IQ 光学传感器并从中检索数据的模块。该传感器可以检测物体、识别颜色以及测量亮度和色调。

以下是所有模块的列表:

设置光学灯#

The set Optical light stack block turns the light on the Optical Sensor on or off. The light lets the Optical Sensor see objects better if it is looking at an object in a dark area.

设定 [Optical 1 v] 灯 [on v]

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

状态

The state of the Optical Sensor’s light to set:

  • on — Turns the light on.
  • off — Turns the light off.

例子

当开始
[Repeatedly flash the Optical Sensor's lights.]
永久循环
设定 [Optical 1 v] 灯 [on v]
等待 (1) 秒
设定 [Optical 1 v] 灯 [灭 v]
等待 (1) 秒

设置光学光功率#

The set Optical light power stack block sets how bright the Optical Sensor’s light is. The light can help the Optical Sensor detect objects and colors more clearly.

A higher percentage makes the light brighter. A lower percentage makes the light dimmer.

If the Optical Sensor’s light is off, setting the light power above 0% will turn the light on.

If the Optical Sensor’s light is on, setting the light power at 0% will turn the light off.

set [Optical1 v] light power to (50)%

**注意:**如果光学传感器的灯关闭,此块将打开灯。

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

亮度

光学传感器的光亮度从 0 到 100 的百分比。

例子

当开始
[Repeatedly change the brightness of the Optical Sensor's lights.]
永久循环
set [Optical1 v] light power to (10)%
等待 (2) 秒
set [Optical1 v] light power to (50)%
等待 (2) 秒
set [Optical1 v] light power to (100)%
等待 (2) 秒

光学仪器发现物体了吗?#

The Optical found an object? Boolean block reports whether the Optical Sensor detects an object within range.

  • True — The Optical Sensor has detected an object.

  • False — The Optical Sensor has not detected an object.

<[Optical 1 v] 发现对象?>

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

例子

当开始
[Turn until the Optical Sensor detects an object.]
设定转向速度为 (10) [% v]
set [Optical1 v] light power to [75]%
[右 v] 转
等到 <[Optical 1 v] 发现对象?>
在屏幕上打印 [Object detected]◀ 并设定光标为下一行
驱动停止

光学检测颜色?#

The Optical detects color? Boolean block reports whether the Optical Sensor detects a specific color.

  • True — The Optical Sensor has detected the specified color.

  • False — The Optical Sensor has not detected the specified color.

<[Optical 1 v] 测得 [红色 v]?>

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

颜色

Which color to check for:

  • red – Hue value between 341° and 20°.
  • green - Hue value between 81° and 140°.
  • blue - Hue value between 200° and 240°.
  • yellow - Hue value between 41° and 60°.
  • orange
  • purple - Hue value between 281° and 320°.
  • cyan - Hue value between 141° and 200°.

例子

当开始
[Turn until the Optical Sensor detects a red object.]
设定转向速度为 (10) [% v]
set [Optical1 v] light power to [75]%
[右 v] 转
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 [Red detected]◀ 并设定光标为下一行
驱动停止

光学颜色名称#

The Optical color name reporter block reports the name of the color detected by the Optical Sensor.

可能的颜色有:

  • red

  • green

  • blue

  • yellow

  • orange

  • purple

  • cyan

**注意:**此模块可以插入到 设置触摸 LED 颜色 模块 中,使触摸 LED 与检测到的颜色相匹配。

([Optical 1 v] 颜色)

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

例子

当开始
[Display a message when the Optical Sensor detects red.]
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 ([Optical 1 v] 颜色)◀ 并设定光标为下一行

光学亮度#

The Optical brightness reporter block reports how bright the detected light is, as a percentage from 0% to 100%.

A higher percentage means the Optical Sensor detects more light. A lower percentage means the Optical Sensor detects less light.

([Optical 1 v] 亮度百分比)

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

例子

当开始
[Display the brightness when the Optical Sensor detects red.]
等到 <[Optical 1 v] 测得 [红色 v]?>
在屏幕上打印 ([Optical 1 v] 亮度百分比)◀ 并设定光标为下一行

光学色调#

The Optical hue reporter block reports the hue detected by the Optical Sensor as a number from 0 to 359 degrees.

Hue is a way to describe color using numbers around a color wheel, as shown below:

圆形色轮,显示全光谱色调,周边标有度数值,从顶部的 0° 到 360°,以 30 度为增量增加。

([Optical 1 v] 色调度数)

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

例子

当开始
[Print when the Optical Sensor detects pink.]
永久循环
清屏
在屏幕上设定光标至 (1) 行 (1) 列
如果 <<([Optical 1 v] 色调度数) [math_greater_than v] [290]> 与 <([Optical 1 v] 色调度数) [math_less_than v] [350]>> 那么
在屏幕上打印 [Pink!]▶
等待 (0.1) 秒
否则
在屏幕上打印 [Not pink.]▶
等待 (0.1) 秒

当光学#

The When Optical hat block runs the attached stack of blocks when the selected Optical Sensor detects or loses an object.

当 [Optical 1 v] [detects v] 一个对象

参数

描述

光学传感器

使用哪种光学传感器,在设备窗口中配置。

状态

When the attached stack of blocks will run:

  • detects – An undetected object is now detected
  • loses – A detected object is now no longer detected

例子

当 [Optical 1 v] [detects v] 一个对象
[Find an object when it is lost.]
[右 v] 转
等到 <[Optical 1 v] 发现对象?>
驱动停止