机器人专用模块#
介绍#
V5RC 25-26 推式游乐场 配备了专为该游乐场设计的专属积木,包括两种电机选项、AI 视觉传感器、光学传感器和游戏定位系统 (GPS) 传感器。
所有标准 VEXcode VR 积木都可用于 V5RC 25-26 推背式游乐场。
以下是所有可用的游乐场专用积木列表:
运动控制——移动并跟踪机器人的电机。
操作
旋转电机 – 无限期地旋转选定的电机或电机组。
spin motor for – 使电机或电机组旋转指定的角度或圈数。
旋转电机到位置 – 将电机或电机组旋转到设定的位置。
停止电机 – 停止特定电机或电机组的旋转。
设置
位置
价值观
人工智能视觉——使用人工智能视觉传感器捕捉和分析物体。
感知——利用机器人的各种传感器。
光学的
光学检测到物体? – 返回是否检测到物体。
光学检测颜色? – 返回是否检测到特定颜色。
光学亮度 – 返回亮度值(百分比)。
光学色调 – 返回检测到的颜色的色调。
当光学传感器检测到或丢失物体时 – 当光学传感器检测到或丢失物体时执行附加的块。
全球定位系统
本页示例使用 Playground 的默认起始位置。
运动#
行动#
旋转马达#
旋转电机 模块使用 当前电机速度 沿指定方向旋转选定的电机或电机组。
spin [ConveyorMotor v] [up v]
参数 |
描述 |
|---|---|
发动机 |
待旋转的电机组:
|
方向 |
旋转方向:
|
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [350] [mm v] ▶
用于旋转马达#
spin motor for 模块使用 当前电机速度 使选定的电机或电机组旋转特定的圈数,以度或圈数衡量。
spin [ConveyorMotor v] [up v] for (90) [degrees v] ▶
参数 |
描述 |
|---|---|
发动机 |
待旋转的电机组:
|
方向 |
旋转方向:
|
距离 |
旋转次数,以整数或小数表示。 |
单元 |
表示距离的计量单位:
|
展开箭头 |
默认情况下,这是一个等待块,因此电机将在运行下一个块之前完成运转。要使电机立即开始运转并立即运行下一个块,请展开该块,添加“不要等待”字样。 |
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [350] [mm v] ▶
旋转电机定位#
旋转电机到位置 模块使用当前的 电机速度 和 电机位置 将电机或电机组旋转到特定的绝对位置。
spin [ConveyorMotor v] to position (90) [degrees v] ▶
参数 |
描述 |
|---|---|
发动机 |
待旋转的电机组:
|
位置 |
电机组旋转到的目标位置。 |
单元 |
计量单位:
|
展开箭头 |
默认情况下,这是一个等待块,因此电机将在运行下一个块之前完成运转。要使电机立即开始运转并立即运行下一个块,请展开该块,添加“不要等待”字样。 |
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] to position [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [350] [mm v] ▶
停止电机#
停止电机 模块会立即停止选定的电机或电机组。
stop [ConveyorMotor v]
参数 |
描述 |
|---|---|
发动机 |
要停止的电机组:
|
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [350] [mm v] ▶
stop [IntakeMotor v]
设置#
设定电机速度#
设置电机速度 模块将电机或电机组的默认旋转速度设置为百分比,该百分比将应用于项目中所有后续的电机模块。
set [ConveyorMotor v] velocity to [50] [% v]
参数 |
描述 |
|---|---|
发动机 |
设置以下电机组速度:
|
速度 |
设置默认移动速度,范围从 0 到 100,以百分比表示。 |
单元 |
表示速度的单位:
|
例子
当开始
[Pick up a second Block.]
set [ConveyorMotor v] velocity to [100] [% v]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [400] [mm v] ▶
设置电机超时#
设置电机超时模块用于设置电机模块等待到达目标位置的时间限制。如果机器人无法在设定的时间内完成移动,它将自动停止并继续执行下一个模块。
**注意:**电机的时间限制用于防止未到达目标位置的电机模块停止堆栈中其他模块的执行。
set [ConveyorMotor v] timeout to [1] seconds
参数 |
描述 |
|---|---|
发动机 |
要设置超时时间的电机组:
|
时间 |
电机模块在停止并移动到下一个模块之前将运行的最大秒数。 |
例子
当开始
[Pick up a second Block.]
set [ConveyorMotor v] timeout to [0.5] seconds
spin [ConveyorMotor v] to position [1000] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [400] [mm v] ▶
位置#
电机位置#
电机位置模块返回所选电机或电机组旋转的总距离。
([ConveyorMotor v] position in [degrees v])
参数 |
描述 |
|---|---|
发动机 |
电机组返回以下位置:
|
单元 |
计量单位:
|
例子
当开始
[Pick up a second Block.]
while <([ConveyorMotor v] position in [degrees v]) [math_less_than v] [200]>
spin [ConveyorMotor v] [up v]
结束
stop [ConveyorMotor v]
spin [IntakeMotor v] [intake v]
drive [forward v] for [400] [mm v] ▶
设置电机位置#
设置电机位置 模块为电机或电机组设置特定的位置值,从而更新编码器读数。
set [ConveyorMotor v] position to (0) [degrees v]
参数 |
描述 |
|---|---|
发动机 |
设置以下电机组位置:
|
位置 |
要设置的编码器位置值。 |
单元 |
计量单位:
|
例子
当开始
[Pick up a second Block.]
set [ConveyorMotor v] position to [-200] [degrees v]
spin [ConveyorMotor v] to position [0] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [400] [mm v] ▶
价值观#
电机已完成#
电机是否停止? 模块返回一个布尔值,指示电机或电机组是否停止旋转。
没错——电机没有转动。
错误——电机正在旋转。
<[ConveyorMotor v] is done?>
参数 |
描述 |
|---|---|
发动机 |
要检查的电机组是否停止旋转:
|
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
驱动 [向前 v]
spin [IntakeMotor v] [intake v]
wait until <[ConveyorMotor v] is done?>
驱动停止
stop [IntakeMotor v]
电机在转动吗?#
电机是否正在旋转? 模块返回一个布尔值,指示电机是否正在旋转。
没错——电机正在转动。
错误——电机没有转动。
<[ConveyorMotor v] is spinning?>
参数 |
描述 |
|---|---|
发动机 |
要检查的电机组是否旋转:
|
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
等待 [0.1] 秒
while <[ConveyorMotor v] is spinning?>
驱动 [向前 v] [200] [毫米 v] ▶
spin [IntakeMotor v] [intake v]
电机速度#
电机速度模块返回电机或电机组的当前转速,范围从-100%到100%。
([ConveyorMotor v] velocity in [% v] :: custom-motion)
参数 |
描述 |
|---|---|
发动机 |
返回速度的电机组:
|
单元 |
表示速度的单位:
|
例子
当开始
[Pick up a second Block.]
set [ConveyorMotor v] velocity to [100] [% v]
spin [ConveyorMotor v] to position [300] [degrees v] ◀ and don't wait
等待 [0.2] 秒
print ([ConveyorMotor v] velocity in [% v] :: custom-motion) ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [400] [mm v] ▶
人工智能视觉#
行动#
获取对象数据#
“获取对象数据”模块用于过滤来自 AI 视觉传感器帧的数据。AI 视觉传感器可以检测场地上的比赛元素。
数据集按宽度从大到小排序存储对象,索引从 0 开始。可以使用 AI Vision 对象属性 代码块访问每个对象的属性。如果没有检测到匹配的对象,则返回空数据集。
get [AI Classifications v] data from AI Vision
范围 |
描述 |
|---|---|
签名 |
筛选数据集仅包含具有给定签名的数据。唯一可用的签名是:
|
例子
当开始
[If an object is detected, pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
wait until <[Bumper v] pressed?>
驱动停止
退出循环
设置#
设置对象项#
设置对象项 块设置要使用数据集中的哪个项。
set [AIVision v] object item to [1]
参数 |
描述 |
|---|---|
物品 |
要使用的数据集中的项目编号。 |
例子
当开始
[Display what object is farthest away.]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
set [AIVision v] object item to ([AIVision v] object count)
清除所有行
if <[AIVision v] object is [BlueBlock v]?> then
print [Blue Block farthest away.] ▶
否则
print [Red Block farthest away.] ▶
价值观#
对象是否存在?#
对象存在? 代码块返回一个布尔值,指示是否在数据集中检测到任何对象。
正确——数据集中包含检测到的对象。
错误——该数据集不包含任何检测到的对象。
<[AIVision v] object exists?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[If an an object is detected, pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
wait until <[Bumper v] pressed?>
驱动停止
退出循环
人工智能分类是#
AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
正确——数据集中的项就是特定的对象。
错误——数据集中的项不是特定对象。
<[AIVision v] object is [BlueBlock v]?>
范围 |
描述 |
|---|---|
目的 |
要将该物品与哪个对象进行比较:
|
例子
当开始
[Display what object is farthest away.]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
set [AIVision v] object item to ([AIVision v] object count)
清除所有行
if <[AIVision v] object is [BlueBlock v]?> then
print [Blue Block farthest away.] ▶
否则
print [Red Block farthest away.] ▶
对象计数#
对象计数 模块返回数据集中检测到的对象数量,以整数形式表示。
([AIVision] object count)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Display what object is farthest away.]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
set [AIVision v] object item to ([AIVision v] object count)
清除所有行
if <[AIVision v] object is [BlueBlock v]?> then
print [Blue Block farthest away.] ▶
否则
print [Red Block farthest away.] ▶
对象属性#
使用 获取对象数据 块 后,每个对象都包含六个属性(如下所示)。
([AIVision v] object [width v])
某些属性值基于使用“获取对象数据”模块时,检测到的对象在 AI 视觉传感器视野中的位置。AI 视觉传感器的分辨率为 320 x 240 像素。
范围 |
描述 |
|---|---|
财产 |
要使用检测到的对象的哪个属性: |
宽度#
width 函数返回检测到的对象的宽度(以像素为单位),数值为 1 到 320 之间的整数。
([AIVision v] object [width v])
例子
当开始
[If an an object is detected, approach and pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [width v]) [math_greater_than v] [65]> then
驱动停止
退出循环
否则
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
高度#
height 返回检测到的对象的高度(以像素为单位),数值为 1 到 240 之间的整数。
([AIVision v] object [height v])
例子
当开始
[If an an object is detected, approach and pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [height v]) [math_greater_than v] [55]> then
驱动停止
退出循环
否则
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
centerX#
centerX 返回检测到的对象中心的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。
([AIVision v] object [centerX v])
例子
当开始
[Pick up a Block from the top left group.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
turn [left v] for [80] degrees ▶
驱动 [向前 v] [100] [毫米 v] ▶
set turn velocity to [20] [% v]
[左 v] 转
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <<[140] [math_less_than v] ([AIVision v] object [centerX v])> and <([AIVision v] object [centerX v]) [math_less_than v] [180]>> then
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
wait until <[Bumper v] pressed?>
驱动停止
中心Y#
centerY 返回检测到的对象中心的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。
([AIVision v] object [centerY v])
例子
当开始
[If an an object is detected, approach and pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerY v]) [math_greater_than v] [140]> then
驱动停止
退出循环
否则
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
originX#
originX 返回检测到的对象边界框左上角的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。
([AIVision v] object [originX v])
例子
当开始
[Pick up a Block from the top left group.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
turn [left v] for [80] degrees ▶
驱动 [向前 v] [100] [毫米 v] ▶
set turn velocity to [20] [% v]
[左 v] 转
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <<[100] [math_less_than v] ([AIVision v] object [originX v])> and <([AIVision v] object [originX v]) [math_less_than v] [140]>> then
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
wait until <[Bumper v] pressed?>
驱动停止
originY#
originY 返回检测到的对象边界框左上角的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。
([AIVision v] object [originY v])
例子
当开始
[If an an object is detected, approach and pick it up.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <[120] [math_less_than v] ([AIVision v] object [originY v])> then
驱动停止
退出循环
否则
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
结束
结束
传感#
光学的#
光学仪器发现物体了吗?#
光学传感器检测到物体? 模块返回一个布尔值,指示光学传感器是否检测到物体。
正确——光学传感器已检测到物体。
错误——光学传感器未检测到物体。
<[Optical v] found an object?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Move the preloaded Block to the top of the Conveyor.]
spin [ConveyorMotor v] [up v]
wait until <[Optical v] found an object?>
stop [ConveyorMotor v]
光学器件能检测颜色吗?#
光学传感器检测到颜色? 模块返回一个布尔值,指示光学传感器是否检测到特定颜色。
正确——光学传感器已检测到指定颜色。
错误——光学传感器未检测到指定颜色。
<[Optical v] detects [red v]?>
参数 |
描述 |
|---|---|
颜色 |
要检查的颜色:
|
例子
当开始
[Pick up and move a Blue Block to the top of the Conveyor.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [360] [mm v] ▶
spin [ConveyorMotor v] [up v]
wait until <[Optical v] detects [blue v]?>
stop [ConveyorMotor v]
光学亮度#
光学亮度模块返回光学传感器检测到的光量,范围从 0% 到 100%。
([Optical v] brightness in %)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Move the preloaded Block to the top of the Conveyor.]
spin [ConveyorMotor v] [up v]
wait until <[0] [math_less_than v] ([Optical v] brightness in %)>
stop [ConveyorMotor v]
光学色调#
光学色调模块返回光学传感器检测到的颜色的色调值。
色调值范围从 0 到 359 度,对应于下图所示色轮上的位置。

([Optical v] hue in degrees)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Pick up and move a Blue Block to the top of the Conveyor.]
spin [ConveyorMotor v] [up v] for [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
drive [forward v] for [360] [mm v] ▶
spin [ConveyorMotor v] [up v]
wait until <[240] [math_equal v] ([Optical v] hue in degrees)>
stop [ConveyorMotor v]
光学#
当光学传感器检测到或丢失物体时,when Optical 模块会运行其堆栈。您可以放置多个 when Optical 模块,以便同时运行多个模块堆栈。
when [Optical v] [detects v] an object
参数 |
描述 |
|---|---|
行动 |
触发帽子格挡的操作:
|
全球定位系统#
GPS定位#
GPS 位置 模块使用 GPS(游戏定位系统™)传感器返回机器人转弯参考点相对于场地中心的偏移位置。
([GPS v] position [X v] in [mm v])
参数 |
描述 |
|---|---|
轴 |
要报告哪个坐标轴:
|
单位 |
表示位置的单位:
|
例子
当开始
[Pick up a second Block.]
spin [ConveyorMotor v] to position [200] [degrees v] ▶
spin [IntakeMotor v] [intake v]
驱动 [向前 v]
wait until <[-450] [math_greater_than v] ([GPS v] position [Y v] in [mm v])>
驱动停止
GPS航向#
GPS航向模块根据GPS(游戏定位系统™)传感器从VEX GPS场码读取的0.00到359.99度的读数,返回机器人当前面向的航向。
([GPS v] heading in degrees)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Score the preloaded Block into a Center Goal.]
[左 v] 转
wait until <[40] [math_greater_than v] ([GPS v] heading in degrees)>
drive [forward v] for [1000] [mm v] ▶
[右 v] 转
wait until <([GPS v] heading in degrees) [math_greater_than v] [310]>
驱动 [反 v] [200] [毫米 v] ▶
spin [ConveyorMotor v] [up v]