机器人专用模块#

介绍#

V5RC 24-25 高风险 游乐场配备了专为该游乐场设计的专属积木,包括两种电机选项、AI 视觉传感器、光学传感器、旋转传感器和游戏定位系统 (GPS) 传感器。

所有标准 VEXcode VR 积木都可用于 V5RC 25-26 推背式游乐场

以下是所有可用的游乐场专用积木列表:

运动控制——移动并跟踪机器人的电机。

人工智能视觉——使用人工智能视觉传感器捕捉和分析物体。

感知——利用机器人的各种传感器。

本页示例使用 Playground 的默认起始位置。

运动#

行动#

旋转马达#

旋转电机 模块使用 当前电机速度 沿指定方向旋转选定的电机或电机组。

[ArmMotor v] [向上 v] 转

参数

描述

发动机

要旋转的电机组:

  • 臂电机
  • 推杆电机

方向

旋转方向:

  • 臂电机
  • 推杆电机

例子

当开始
[Lift the Arm before moving to a Mobile Goal.]
[ArmMotor v] [向上 v] 转
等待 (1) 秒
[ArmMotor v] 停止

用于旋转马达#

spin motor for 模块使用 当前电机速度 使选定的电机或电机组旋转特定的圈数,以度或圈数衡量。

spin [ArmMotor v] [up v] for (90) [degrees v] ▶

参数

描述

发动机

要旋转的电机组:

  • 臂电机
  • 推杆电机

方向

旋转方向:

  • 臂电机
  • 推杆电机

距离

旋转次数,以整数或小数表示。

单元

计量单位:

展开箭头

默认情况下,这是一个等待块,因此电机将在运行下一个块之前完成运转。要使电机立即开始运转并立即运行下一个块,请展开该块,添加“不要等待”字样。

例子

当开始
[Lift the Arm.]
spin [ArmMotor v] [up v] for [200] [degrees v] ▶

旋转电机定位#

旋转电机到位置 模块使用当前的 电机速度电机位置 将电机或电机组旋转到特定的绝对位置。

[ArmMotor v] 转至 (90) [度 v] ▶

参数

描述

发动机

要旋转的电机组:

  • 臂电机
  • 推杆电机

位置

要旋转到的目标位置。

单元

计量单位:

展开箭头

默认情况下,这是一个等待块,因此电机将在运行下一个块之前完成运转。要使电机立即开始运转并立即运行下一个块,请展开该块,添加“不要等待”字样。

例子

当开始
[Lift the Arm.]
spin [ArmMotor v] to position [350] [degrees v] ▶

停止电机#

停止电机 模块会立即停止选定的电机或电机组。

[ArmMotor v] 停止

参数

描述

发动机

要停止的电机组:

  • 机械臂电机
  • 推杆电机

例子

当开始
[ArmMotor v] [向上 v] 转
等待 (1) 秒
[ArmMotor v] 停止

设置#

设定电机速度#

设置电机速度 模块将电机或电机组的默认旋转速度设置为百分比,该百分比将应用于项目中所有后续的电机模块。

set [ArmMotor v] velocity to [50] [% v]

参数

描述

发动机

要设置的电机组:

  • 机械臂电机
  • 推杆电机

速度

设置默认移动速度,范围从 0 到 100,以百分比表示。

单元

表示速度的单位:

  • %

例子

当开始
set [ArmMotor v] velocity to [100] [% v]
spin [ArmMotor v] [up v] for [200] [degrees v] ▶

设置电机超时#

设置电机超时模块用于设置电机模块等待到达目标位置的时间限制。如果机器人无法在设定的时间内完成移动,它将自动停止并继续执行下一个模块。

**注意:**电机的时间限制用于防止未到达目标位置的电机模块停止堆栈中其他模块的执行。

设定 [ArmMotor v] 超时为 [1] 秒

参数

描述

发动机

要设置的电机组:

  • 机械臂电机
  • 推杆电机

时间

电机模块在停止并移动到下一个模块之前将运行的最大秒数。

例子

当开始
设定 [ArmMotor v] 超时为 [1] 秒
spin [ArmMotor v] [up v] for [5] [turns v] ▶

位置#

电机位置#

电机位置模块返回所选电机或电机组旋转的总距离。

([ArmMotor v] position in [degrees v])

参数

描述

发动机

电机组返回以下位置:

  • 机械臂电机
  • 推杆电机

单元

计量单位:

设置电机位置#

设置电机位置 模块为电机或电机组设置特定的位置值,从而更新编码器读数。

设定 [ArmMotor v] 转位至 (0) [度 v]

参数

描述

发动机

用于设置以下部件位置的电机组:

  • 机械臂电机
  • 推杆电机

位置

要设置的编码器位置值。

单元

计量单位:

价值观#

电机已完成#

电机是否停止? 模块返回一个布尔值,指示电机或电机组是否停止旋转。

  • 没错——电机没有转动。

  • 错误——电机正在旋转。

<[ArmMotor v] 已结束?>

参数

描述

发动机

要检查是否停止旋转的电机组:

  • 臂电机
  • 推杆电机

电机在转动吗?#

电机是否正在旋转? 模块返回一个布尔值,指示电机是否正在旋转。

  • 没错——电机正在转动。

  • 错误——电机没有转动。

<[ArmMotor v] 正在转?>

参数

描述

发动机

要检查的电机组是否旋转:

  • 臂电机
  • 推杆电机

电机速度#

电机速度模块返回电机或电机组的当前转速,范围从-100%到100%。

([ArmMotor v] velocity in [% v] :: custom-motion)

参数

描述

发动机

返回速度的电机组:

  • 机械臂电机
  • 推杆电机

单元

表示速度的单位:

  • %

人工智能视觉#

行动#

获取对象数据#

“获取对象数据”模块用于过滤来自 AI 视觉传感器帧的数据。AI 视觉传感器可以检测场地上的比赛元素。

数据集按宽度从大到小排序存储对象,索引从 0 开始。可以使用 AI Vision 对象属性 代码块访问每个对象的属性。如果没有检测到匹配的对象,则返回空数据集。

获取对象数据堆栈块。#
get [AI Classifications v] data from [AIVision v]

范围

描述

签名

筛选数据集,仅包含给定签名的数据。唯一可用的签名是:

  • AI 分类 – 检测移动目标、红色圆环和蓝色圆环

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
[Only if an AI Classification is detected, then print data from the largest AI Classification.]
print [Largest object's width:] ▶
print ([AIVision v] object [width v]) ◀ and set cursor to next row
结束

设置#

设置对象项#

设置对象项 块设置要使用数据集中的哪个项。

设置 AI Vision 对象项堆叠块。#
set [AIVision v] object item to [1]

参数

描述

物品

要使用的数据集中的项目编号。

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
[If any AI Classification is detected, check if any of them are a Mobile Goal.]
if <[AIVision v] AI Classification is [MobileGoal v]?> then
print [Mobile Goal is detected.] ▶
否则
print [Mobile Goal is not detected.] ▶
结束
结束

价值观#

对象是否存在?#

对象存在? 代码块返回一个布尔值,指示是否在数据集中检测到任何对象。

  • 正确——数据集中包含检测到的对象。

  • 错误——该数据集不包含任何检测到的对象。

AI Vision 对象存在布尔块。#
<[AIVision v] object exists?>

参数

描述

此代码块没有参数。

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
print ([AIVision v] object count) ◀ and set cursor to next row
结束

人工智能分类是#

AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。

  • 正确——数据集中的项就是特定的对象。

  • 错误——数据集中的项不是特定对象。

AI视觉AI分类是一个对象布尔块。#
<[AIVision v] object is [MobileGoal v]?>

范围

描述

目的

要将该物品与哪个对象进行比较:

  • MobileGoal
  • RedRing
  • BlueRing

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
[If any AI Classification is detected, check if any of them are a Mobile Goal.]
if <[AIVision v] AI Classification is [MobileGoal v]?> then
print [Mobile Goal is detected.] ▶
否则
print [Mobile Goal is not detected.] ▶
结束
结束

对象计数#

对象计数 模块返回数据集中检测到的对象数量,以整数形式表示。

设置 AI Vision 对象项堆叠块。#
([AIVision] object count)

参数

描述

此代码块没有参数。

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
print ([AIVision v] object count) ◀ and set cursor to next row
结束

对象属性#

使用 获取对象数据 后,每个对象都包含六个属性(如下所示)。

AI视觉对象属性报告器模块。#
([AIVision v] object [width v])

某些属性值基于使用“获取对象数据”模块时,检测到的对象在 AI 视觉传感器视野中的位置。AI 视觉传感器的分辨率为 320 x 240 像素。

范围

描述

财产

要使用检测到的对象的哪个属性:

宽度#

width 函数返回检测到的对象的宽度(以像素为单位),数值为 1 到 320 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为宽度。#
([AIVision v] object [width v])

例子

当开始
[Spin the Arm Motor up so that the AI Vision Sensor is not blocked.]
spin [ArmMotor v] [up v] for [270] [degrees v] ▶
get [AI Classifications v] data from [AIVision v]
[Check if any AI Classifications were detected in the last snapshot.]
if <[AIVision v] object exists?> then
[Only if an AI Classification is detected, then print data from the largest AI Classification.]
print [Largest object's width:] ▶
print ([AIVision v] object [width v]) ◀ and set cursor to next row
结束
高度#

height 返回检测到的对象的高度(以像素为单位),数值为 1 到 240 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为高度。#
([AIVision v] object [height v])
centerX#

centerX 返回检测到的对象中心的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为 centerX。#
([AIVision v] object [centerX v])
中心Y#

centerY 返回检测到的对象中心的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为 centerY。#
([AIVision v] object [centerY v])
originX#

originX 返回检测到的对象边界框左上角的 x 坐标(以像素为单位),数值为 0 到 320 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为 originX。#
([AIVision v] object [originX v])
originY#

originY 返回检测到的对象边界框左上角的 y 坐标(以像素为单位),数值为 0 到 240 之间的整数。

AI Vision 对象属性堆栈块,其参数设置为 originY。#
([AIVision v] object [originY v])

传感#

光学的#

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

光学检测到物体? 模块返回一个布尔值,指示传感器是否检测到物体。

  • 正确——光学传感器正在检测到物体。

  • 错误——光学传感器未检测到物体。

<[FrontOptical v] found an object?>

参数

描述

此代码块没有参数。

光学器件能检测颜色吗?#

光学检测颜色? 模块返回一个布尔值,指示传感器是否检测到指定的颜色。

  • 正确——光学传感器检测到了指定的颜色。

  • 错误——光学传感器未检测到指定颜色。

注意: 光学传感器正在查找与指定颜色匹配的色调范围。有关检测特定色调范围的信息,请参阅光学色调模块

<[FrontOptical v] detects [red v]?>

参数

描述

颜色

要查找的颜色:

  • 红色 – 检测到的色调值介于 340° 至 20° 之间。2
  • – 检测到的色调值介于 80° 至 140° 之间。4
  • – 检测到的色调值介于 200° 至 240° 之间。6
  • – 检测到的色调值介于 40° 至 60° 之间。8
  • – 检测到的色调值介于 20° 至 40° 之间。10
  • – 检测到的色调值介于 240° 至 280° 之间。12
  • – 检测到的色调值介于 140° 至 200° 之间

光学亮度#

光学亮度模块以百分比形式返回物体反射的光量。

([FrontOptical v] brightness in %)

参数

描述

此代码块没有参数。

光学色调#

光学色调模块返回检测到的颜色的色调值。

该值范围为 0 到 359 度,与色轮相对应:

VEX 色轮,显示围绕圆周的颜色度数,红色为 0 度,随着数值增加,颜色依次过渡到彩虹的颜色。

([FrontOptical v] hue in degrees)

参数

描述

此代码块没有参数。

光学#

当光学传感器检测到或丢失物体时,when Optical 模块会运行所附的堆栈。

when [FrontOptical v] [detects v] an object :: hat events

参数

描述

状态

当连接的积木栈运行时:

  • 检测到 - 检测到一个之前未检测到的对象
  • 丢失 - 不再检测到一个已检测到的对象

旋转#

设置旋转传感器位置#

设置旋转传感器位置 模块将旋转传感器的当前位置设置为以度为单位的值。

set [PusherRotation v] position to [0] degrees

参数

描述

位置

旋转传感器的设置位置。

示例

当开始
[Make lower Pusher position the new 0 degrees rotation position.]
spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
set [PusherRotation v] position to [0] degrees

旋转传感器角度#

旋转传感器角度模块返回传感器的当前角度,范围为 0 到 359.99 度。

([PusherRotation v] angle in degrees)

参数

描述

此代码块没有参数。

示例

当开始
[Make lower Pusher position the new 0 degrees rotation position.]
spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
print ([PusherRotation v] angle in degrees) ▶

旋转传感器位置#

旋转传感器位置模块返回以度或圈数表示的总旋转位置。

([PusherRotation v] position in [degrees v] :: custom-sensing)

参数

描述

单位

计量单位:

示例

当开始
[Make lower Pusher position the new 0 degrees rotation position.]
spin [PusherMotor v] [lower v] for [270] [degrees v] ▶
print ([PusherRotation v] position in [degrees v] :: custom-sensing) ▶

全球定位系统#

GPS定位#

GPS 位置 模块使用 GPS(游戏定位系统™)传感器返回机器人转弯参考点相对于场地中心的偏移位置。

([GPS v] position [X v] in [mm v])

参数

描述

要报告哪个坐标轴:

  • X
  • Y

单位

表示位置的单位:

  • 毫米
  • 英寸

GPS航向#

GPS航向模块根据GPS(游戏定位系统™)传感器从VEX GPS场码读取的0.00到359.99度的读数,返回机器人当前面向的航向。

([GPS v] heading in degrees)

参数

描述

此代码块没有参数。