机器人专用模块#
介绍#
VIQRC 25-26 Mix & Match 游乐场配备了该游乐场独有的积木,包括两种电机选项、IQ AI 视觉传感器、光学传感器和触摸 LED。
所有标准 VEXcode VR 积木都可用于 VIQRC 25-26 Mix & Match 游乐场。
以下是所有可用的游乐场专用积木列表:
运动控制 - 控制机器人电机的移动和跟踪。
操作
旋转电机 - 使选定的电机无限期旋转。
spin motor for - 使电机旋转指定的角度或圈数。
旋转电机到位置 - 将电机旋转到设定的位置。
停止电机 - 停止特定电机的旋转。
设置
位置
价值观
AI视觉——使用IQ AI视觉传感器捕捉和分析物体。
感知——利用机器人的各种传感器。
光学的
光学检测到物体? - 返回是否检测到物体。
光学检测颜色? - 返回是否检测到特定颜色。
光学亮度 - 返回传感器检测到的亮度百分比。
光学色调 - 返回检测到的颜色的色调值。
当光学传感器检测到或丢失物体时 - 当光学传感器检测到或丢失物体时,执行附加的堆栈代码块。
触摸式LED灯
设置触摸LED颜色 - 将触摸LED设置为选定的颜色。
本页示例使用 Playground 的默认起始位置。
运动#
行动#
旋转马达#
旋转电机模块使用当前电机速度使选定的电机沿指定方向旋转。
spin [ClawMotor v] [open v]
参数 |
描述 |
|---|---|
发动机 |
旋转电机:
|
方向 |
旋转方向:
|
例子
当开始
[Place a pin atop another pin.]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
用于旋转马达#
spin motor for 模块使用 当前电机速度 使选定的电机旋转特定的圈数,以度或圈数衡量。
spin [ClawMotor v] [open v] for (90) [degrees v] ▶
参数 |
描述 |
|---|---|
发动机 |
旋转电机:
|
方向 |
旋转方向:
|
距离 |
旋转次数,以整数或小数表示。 |
单元 |
表示距离的计量单位:
|
展开箭头 |
默认情况下,这是一个等待块,因此电机将在运行下一个块之前完成运转。展开该块,添加“and don’t wait”即可将其更改为非等待块。 |
例子
当开始
[Place a pin atop another pin.]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
旋转电机定位#
旋转电机到特定位置 模块使用当前的 电机速度 和 电机位置 将电机旋转到特定的绝对位置。
spin [ClawMotor v] to position (90) [degrees v] ▶
参数 |
描述 |
|---|---|
发动机 |
旋转电机:
|
位置 |
电机旋转到的目标位置。 |
单元 |
计量单位:
|
展开箭头 |
默认情况下,这是一个等待代码块。展开代码块,添加“and don’t wait”即可将其变为非等待代码块。 |
例子
当开始
[Place a pin atop another pin.]
spin [LiftMotor v] to position [-2] [turns v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
停止电机#
停止电机 模块会立即停止选定的电机。
stop [ClawMotor v]
参数 |
描述 |
|---|---|
发动机 |
要停止的电机:
|
例子
当开始
[Raise the lift for 2 seconds, then stop.]
spin [LiftMotor v] [up v]
等待 (2) 秒
stop [LiftMotor v]
设置#
设定电机速度#
设置电机速度 模块将电机的默认旋转速度设置为百分比,该百分比将应用于项目中所有后续的电机模块。
set [ClawMotor v] velocity to (50) [% v]
参数 |
描述 |
|---|---|
发动机 |
设置以下电机速度的参数:
|
速度 |
设置默认移动速度,范围从 0 到 100,以百分比表示。 |
单元 |
表示速度的单位:
|
例子
当开始
[Raise the lift at full speed.]
set [LiftMotor v] velocity to [100] [% v]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
设置电机超时#
设置电机超时模块用于设置电机模块到达目标位置的等待时间限制。如果机器人无法在设定的时间内完成移动,它将自动停止并继续执行下一个模块。
set [ClawMotor v] timeout to (1) seconds
参数 |
描述 |
|---|---|
发动机 |
设置超时时间的电机:
|
时间 |
电机模块在停止并移动到下一个模块之前将运行的最大秒数。 |
例子
当开始
set [LiftMotor v] timeout to [2] seconds
spin [LiftMotor v] [up v] for [5] [turns v] ▶
位置#
电机位置#
电机位置模块返回所选电机旋转的总距离。
([ClawMotor v] position in [degrees v])
参数 |
描述 |
|---|---|
发动机 |
用于返回以下位置的电机:
|
单元 |
计量单位:
|
例子
当开始
[Raise the lift until it reaches 600 degrees.]
spin [LiftMotor v] [up v]
wait until <([LiftMotor v] position in [degrees v]) [math_less_than v] [-600]>
stop [LiftMotor v]
设置电机位置#
设置电机位置 模块为电机设置一个特定的位置值,从而更新编码器读数。
set [ClawMotor v] position to (0) [degrees v]
参数 |
描述 |
|---|---|
发动机 |
用于设置以下位置的电机:
|
位置 |
要设置的编码器位置值。 |
单元 |
计量单位:
|
例子
当开始
set [LiftMotor v] position to [100] [degrees v]
spin [LiftMotor v] to position [-500] [degrees v] ▶
价值观#
电机已完成#
电机是否停止运转? 模块返回一个布尔值,指示电机是否停止运转。
没错——电机没有转动。
错误 - 电机正在旋转。
<[ClawMotor v] is done?>
参数 |
描述 |
|---|---|
发动机 |
要检查的电机是否停止旋转:
|
例子
当开始
[Flash the Touch LED while the lift is moving.]
spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
等待 [0.1] 秒
repeat until <[LiftMotor v] is done?>
set [TouchLED v] color to [red v]
等待 [0.5] 秒
set [TouchLED v] color to [none v]
等待 [0.5] 秒
结束
电机在转动吗?#
电机是否正在旋转? 模块返回一个布尔值,指示电机是否正在旋转。
没错——电机正在转动。
错误——电机没有转动。
<[ClawMotor v] is spinning?>
参数 |
描述 |
|---|---|
发动机 |
要检查的电机当前是否正在旋转:
|
例子
当开始
[Flash the Touch LED while the lift is spinning.]
spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
等待 [0.1] 秒
repeat until <not <[LiftMotor v] is spinning?>>
set [TouchLED v] color to [red v]
等待 [0.5] 秒
set [TouchLED v] color to [none v]
等待 [0.5] 秒
结束
电机速度#
电机速度模块返回电机的当前转速,范围从-100%到100%。
([ClawMotor v] velocity in [% v] :: custom-motion)
参数 |
描述 |
|---|---|
发动机 |
用于恢复以下部件速度的电机:
|
单元 |
表示速度的单位:
|
例子
当开始
set [LiftMotor v] velocity to [100] [% v]
spin [LiftMotor v] [up v] for [600] [degrees v] ◀ and don't wait
等待 [0.5] 秒
print ([LiftMotor v] velocity in [% v] :: custom-motion) ▶
人工智能视觉#
行动#
获取对象数据#
“获取对象数据”模块用于过滤来自 IQ AI 视觉传感器帧的数据。IQ AI 视觉传感器可以检测场地上的比赛元素。
数据集按宽度从大到小排序存储对象,索引从 0 开始。可以使用 [**对象属性**](#object-property) 代码块访问每个对象的属性。如果没有检测到匹配的对象,则返回空数据集。
get [AI Classifications v] data from [AIVision v]
范围 |
描述 |
|---|---|
签名 |
筛选数据集,仅包含给定签名的数据。唯一可用的签名是:
|
例子
当开始
[Place the Red Pin on the top left Blue Pin.]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
turn [left v] for [38] degrees ▶
repeat until <([AIVision v] object [width v]) [math_greater_than v] [48]>
get [AI Classifications v] data from [AIVision v]
驱动 [向前 v]
结束
drive [forward v] for [160] [mm v] ▶
spin [ClawMotor v] [open v]
设置#
设置对象项#
设置对象项 块设置要使用数据集中的哪个项。
set [AIVision v] object item to [1]
参数 |
描述 |
|---|---|
物品 |
要使用的数据集中的项目编号。 |
例子
当开始
[Find the object index of the nearest Orange Pin.]
set [object_counter v] to [1]
get [AI Classifications v] data from [AIVision v]
repeat ([AIVision v] object count)
set [AIVision v] object item to (object_counter)
if <[AIVision v] object is [Orange Pin v]> then
print (join [Nearest Orange Pin is ] (object_counter)) ▶
否则
change [object_counter v] by [1]
结束
结束
价值观#
对象是否存在?#
对象存在? 代码块返回一个布尔值,指示是否在数据集中检测到任何对象。
正确 - 数据集包含检测到的对象。
错误 - 该数据集不包含任何检测到的对象。
<[AIVision v] object exists?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Raise the Lift until a Pin or Beam is detected.]
repeat until <[AIVision v] object exists?>
get [AI Classifications v] data from [AIVision v]
spin [LiftMotor v] [up v]
结束
stop [LiftMotor v]
对象计数#
对象计数 模块返回数据集中检测到的对象数量,以整数形式表示。
([AIVision v] object count)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
get [AI Classifications v] data from [AIVision v]
print ([AIVision v] object count) ▶
对象属性#
使用 获取对象数据 块 后,存储的每个对象都包含六个属性。
([AIVision v] object [width v])
某些属性值基于使用“获取对象数据”模块时,检测到的对象在 IQ AI 视觉传感器视野中的位置。IQ AI 视觉传感器的分辨率为 320 x 240 像素。
范围 |
描述 |
|---|---|
财产 |
要使用检测到的对象的哪个属性: |
宽度#
width 函数返回检测到的对象的宽度(以像素为单位),数值为 1 到 320 之间的整数。
([AIVision v] object [width v])
高度#
height 返回检测到的对象的高度(以像素为单位),数值为 1 到 240 之间的整数。
([AIVision v] object [height v])
centerX#
centerX 返回检测到的对象中心的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。
([AIVision v] object [centerX v])
中心Y#
centerY 返回检测到的对象中心的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。
([AIVision v] object [centerY v])
originX#
originX 返回检测到的对象边界框左上角的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。
([AIVision v] object [originX v])
originY#
originY 返回检测到的对象边界框左上角的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。
([AIVision v] object [originY v])
人工智能分类是#
AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
正确 - 数据集中的项是特定对象。
错误 - 数据集中的项不是特定对象。
<[AIVision v] object is [Beam v]?>
范围 |
描述 |
|---|---|
目的 |
要将该物品与哪个物体进行比较:
|
例子
当开始
[Find the object index of the nearest Orange Pin.]
set [object_counter v] to [1]
get [AI Classifications v] data from [AIVision v]
repeat ([AIVision v] object count)
set [AIVision v] object item to (object_counter)
if <[AIVision v] object is [Orange Pin v]> then
print (join [Nearest Orange Pin is ] (object_counter)) ▶
否则
change [object_counter v] by [1]
结束
结束
传感#
光学的#
光学仪器发现物体了吗?#
光学传感器检测到物体? 模块返回一个布尔值,指示光学传感器是否检测到物体。
正确 - 光学传感器已检测到物体。
错误 - 光学传感器未检测到物体。
<[Optical v] found an object?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Place a pin atop another pin.]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
wait until <not <[Optical v] found an object?>>
spin [LiftMotor v] to position [0] [degrees v] ▶
光学检测颜色#
光学传感器检测到颜色? 模块返回一个布尔值,指示光学传感器是否检测到特定颜色。
正确 - 光学传感器已检测到指定颜色。
错误 - 光学传感器未检测到指定颜色。
<[Optical v] detects [red v]?>
参数 |
描述 |
|---|---|
颜色 |
要检查的颜色:
|
例子
当开始
[Place a pin atop another pin.]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
wait until <[Optical v] detects [red v]?>
spin [LiftMotor v] to position [0] [degrees v] ▶
光学亮度#
光学亮度模块返回光学传感器检测到的光量,范围从 0% 到 100%。
([Optical v] brightness in %)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
光学色调#
光学色调模块返回光学传感器检测到的颜色的色调值。
色调值范围从 0 到 359 度,对应于下图所示色轮上的位置。

([Optical v] hue in degrees)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
光学#
当光学传感器检测到或丢失物体时,when Optical 模块会运行其堆栈。您可以放置多个 when Optical 模块,以便同时运行多个模块堆栈。
when [Optical v] [detects v] an object
参数 |
描述 |
|---|---|
行动 |
哪个动作会触发帽子阻挡:
|
例子
when [Optical v] [loses v] an object
[Lower the lift when the object is no longer in the claw.]
spin [LiftMotor v] to position [0] [degrees v] ▶
触摸 LED#
设置触摸LED颜色#
设置触摸LED颜色模块用于设置触摸LED的颜色。
set [TouchLED v] color to [none v]
参数 |
描述 |
|---|---|
颜色 |
设置 LED 灯颜色:
|
例子
当开始
[Light the Touch LED while placing a pin.]
set [TouchLED v] color to [red v]
spin [LiftMotor v] [up v] for [600] [degrees v] ▶
drive [forward v] for (140) [mm v] ▶
spin [ClawMotor v] [open v]
set [TouchLED v] color to [none v]