机器人专用模块#
介绍#
Hero Bot Flex 包含一个爪形电机、一个臂形电机、一个 AI 视觉传感器、一个距离传感器和一个游戏定位系统 (GPS) 传感器。
所有标准 VEXcode VR 模块均可在 V5 26-27 覆盖 Playground 中使用。
以下是所有可用的机器人专用模块列表:
驱动系统——控制机器人的移动和转向。
操作
设置
价值观
驱动完成 — 报告机器人是否已完成移动。
drive is moving — 报告机器人是否正在移动。
驱动航向 — 报告机器人的当前航向,范围从 0 到 359.99 度。
驱动旋转 — 报告机器人的当前旋转方向。
驱动速度 — 报告机器人的行驶速度。
运动控制——移动并跟踪机器人的电机。
操作
spin motor – 使电机正转或反转永不停息。
spin motor for – 使电机旋转指定的角度或圈数。
旋转电机到位置 – 将电机旋转到指定位置。
停止电机 – 停止电机旋转。
设置
价值观
人工智能视觉——使用人工智能视觉传感器捕捉和分析物体。
感知——利用机器人的各种传感器。
距离
全球定位系统
本页示例使用游乐场赛前检查清单中的起始位置 C。
传动系统#
动力系统控制着VR机器人的行驶和转向。动力系统可以前进或后退、左转或右转、转向特定航向并跟踪其旋转。
行动#
驾驶#
驱动 模块使机器人能够无限向前或向后移动。机器人将持续移动,直到收到其他指令,例如转向或停止。
驱动 [向前 v]
参数 |
描述 |
|---|---|
方向 |
机器人移动方向:前进或后退。 |
例子
当开始 :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
驱动 [向前 v]
等待 (0.5) 秒
驱动停止
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
驱动#
驱动堆栈模块控制机器人前进或后退一段特定距离。程序会等待机器人完成移动后,才会运行堆栈中的下一个模块。
驱动 [向前 v] (200) [毫米 v] ▶
参数 |
描述 |
|---|---|
方向 |
机器人移动方向:前进或后退。 |
距离 |
机器人行驶的距离。可以是整数,也可以是小数。 |
单元 |
距离单位:mm(毫米)或英寸 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始 :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
转动#
转向 积木块会让机器人无限向左或向右转向。机器人会一直转向,直到收到其他动作指令,例如行驶或停止。
[右 v] 转
参数 |
描述 |
|---|---|
方向 |
机器人转向的方向:向左或向右。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
[左 v] 转
wait (0.78) seconds
驱动停止
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
转向#
“转向”堆栈模块会使机器人向左或向右旋转指定的角度。旋转角度是相对于机器人的当前位置而言的。程序会等待机器人完成旋转后,才会运行堆栈中的下一个模块。
[右 v] 转 (90) 度 ▶
参数 |
描述 |
|---|---|
方向 |
机器人转向的方向:向左或向右。 |
角度 |
机器人旋转的角度数。可以是整数,也可以是小数。 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
转向标题#
航向角是指机器人面向的方向,以度为单位。转向航向角 代码块可以将机器人转向 -359 度到 359 度之间的特定航向角。机器人会选择到达目标航向角的最短路径。
起始航向为0度。
该项目将等待机器人完成转向后,才会运行堆栈中的下一个模块。
归位至 (90) 度 ▶
参数 |
描述 |
|---|---|
标题 |
机器人应面向的航向,范围从 -359 度到 359 度。 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
turn to heading (-110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
转向旋转#
旋转到旋转 堆栈块使机器人旋转到特定角度。
旋转角度是指机器人转动的幅度,以度为单位。在项目开始时,旋转角度值设置为 0 度。也可以使用 set drive rotation 代码块来设置旋转角度。
旋转角度是绝对值。这意味着转弯方向取决于机器人当前的旋转角度。向右转弯会增加旋转角度,向左转弯会减少旋转角度。
例如,如果机器人从0度开始,你将其旋转720度,它会向右转两次。如果你再将其旋转360度,它会向左转一次,因为360小于720。
该项目将等待机器人完成转向后,才会运行堆栈中的下一个模块。
转向至 (90) 度 ▶
参数 |
描述 |
|---|---|
旋转 |
机器人将要旋转的角度值,以度为单位。可以是整数或小数。 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
turn to rotation (-110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
停止驾驶#
停止驱动堆栈块会停止机器人的运动。
驱动停止
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
驱动 [向前 v]
等待 (0.5) 秒
驱动停止
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
设置#
设定驱动速度#
设置驱动速度 代码块告诉机器人以多快的速度行驶。百分比越高,机器人行驶速度越快;百分比越低,机器人行驶速度越慢。
每个项目开始时,机器人默认以 50% 的速度行驶。
**注意:**速度越高,机器人行驶速度越快,但精度可能越低;速度越低,机器人行驶速度越慢,但精度可能越高。
设定驱动速度为 (50) [% v]
参数 |
描述 |
|---|---|
速度 |
行驶速度,范围从 0% 到 100%。 |
单元 |
速度单位:% |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
设定驱动速度为 (100) [% v]
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
设定转弯速度#
设置转弯速度 代码块告诉机器人转弯的速度。百分比越高,机器人转弯越快;百分比越低,机器人转弯越慢。
每个项目开始时,机器人默认以 50% 的速度旋转。
**注意:**速度越高,机器人转弯越快,但精度可能越低;速度越低,机器人转弯越慢,但精度可能越高。
设定转向速度为 (50) [% v]
参数 |
描述 |
|---|---|
速度 |
转弯速度从 0% 到 100%。 |
单元 |
速度单位:% |
例子
当开始 :: hat events
[Turn to face the Neutral Goal faster.]
设定转向速度为 (100) [% v]
turn [left v] for (110) degrees ▶
设置驱动航向#
航向角是指机器人朝向的方向,以度为单位。设置驱动航向堆栈块会将机器人的当前航向角更改为新的航向角值。
例如,如果机器人转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度航向。然后,机器人可以根据新的航向转向其他位置。
设定底盘归位至 (0) 度
参数 |
描述 |
|---|---|
标题 |
要设置的机器人航向值(以度为单位)。 |
例子
当开始 :: hat events
[Make facing the Neutral Goal the new heading.]
set drive heading to (110) degrees
归位至 (0) 度 ▶
设置驱动旋转#
旋转角度是指机器人转动的程度,以度为单位。在项目开始时,旋转角度值设置为 0 度。设置驱动旋转角度 代码块会将机器人的当前旋转角度更改为新值。
例如,如果机器人向右转了两圈,它的旋转角度将为 720 度。将旋转角度设置为 0 度会将旋转角度从 720 度重置为 0 度。然后,机器人可以根据这个新的旋转角度进行旋转。
设定底盘转向至 (0) 度
参数 |
描述 |
|---|---|
旋转 |
机器人旋转角度的设定值,单位为度。可以是整数或小数。 |
例子
当开始 :: hat events
[Make facing the Neutral Goal the new rotation.]
set drive rotation to (110) degrees
转向至 (0) 度 ▶
设置驱动超时#
设置驱动超时 代码块用于设置机器人尝试完成一次动作的秒数。如果机器人无法在规定时间内完成,它将停止尝试并执行代码块中的下一个。这样可以防止机器人卡在某个动作上。
设定驱动超时为 (1) 秒
参数 |
描述 |
|---|---|
时间 |
机器人尝试完成一次动作的秒数。该值可以是整数或小数。 |
例子
当开始 :: hat events
[Turn to face the Neutral Goal.]
set drive timeout to (0.8) seconds
turn [left v] for (180) degrees ▶
价值观#
驾驶已完成#
“驱动完成”布尔模块用于报告机器人是否已停止移动。这可用于根据机器人的移动状态来控制其他行为的执行时间。
正确 — 机器人已停止移动。
错误 — 机器人仍在移动。
该模块与具有 and don’t wait 参数的传动系统模块配合使用。
<驱动已结束?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
drive [forward v] for (25) [inches v] ◀ and don't wait
等到 <驱动已结束?>
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
车辆正在行驶#
“驱动正在移动”布尔模块用于报告机器人是否正在移动。这可用于根据机器人的移动状态来控制其他行为的执行时间。
正确 — 机器人正在移动。
错误 — 机器人没有移动。
该模块与具有 and don’t wait 参数的传动系统模块配合使用。
<驱动进行中?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Raise the Arm once stopped near the Goal.]
turn [left v] for (110) degrees ▶
drive [forward v] for (25) [inches v] ◀ and don't wait
当 <驱动进行中?>
wait (0.005) seconds
结束
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
行驶方向#
航向角是指机器人朝向的方向,以度为单位。驱动航向报告模块会报告 0 到 359.99 度的航向角。
机器人的初始航向为0度。
(底盘归位角度值)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Turn to the Goal, then show heading.]
[右 v] 转 (450) 度 ▶
在屏幕上打印 (底盘归位角度值)◀ 并设定光标为下一行
驱动旋转#
旋转角度是指机器人转动的程度,以度为单位。项目开始时,旋转角度值设置为 0 度。“驱动旋转”报告模块会报告机器人当前的旋转角度。
向右转会增加旋转角度,向左转会减少旋转角度。例如,向右转两圈,旋转角度将达到 720 度。
(底盘转向角度值)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Spin to find a Pin, then show rotation.]
[右 v] 转 (450) 度 ▶
在屏幕上打印 (底盘转向角度值)◀ 并设定光标为下一行
驱动速度#
驱动速度报告模块会报告机器人的行驶速度。
(驱动速度 [% v])
参数 |
描述 |
|---|---|
单元 |
速度单位:% |
例子
当开始 :: hat events
[Show speed while driving to the Goal.]
drive [forward v] for (150) [mm v] ▶
在屏幕上打印 (驱动速度 [% v])◀ 并设定光标为下一行
运动#
Flex 使用 ArmMotor 来升降机械臂,使用 ClawMotor 来打开和关闭机械爪。
每个电机都有自己的方向选项。方向名称描述了该电机在Flex上的运动方式。
行动#
旋转马达#
旋转电机 模块可以使电机沿两个方向之一持续旋转。电机将持续旋转,直到收到其他指令,例如改变旋转方向或停止。
[ArmMotor v] [向上 v] 转
参数 |
描述 |
|---|---|
发动机 |
旋转电机:机械臂电机或爪式电机。 |
方向 |
电机旋转方向:
|
例子
当开始
[Raise the Arm before driving toward a Pin.]
[ArmMotor v] [向上 v] 转
等待 (1) 秒
[ArmMotor v] 停止
用于旋转马达#
“旋转电机”堆叠模块会使电机旋转一段特定距离。旋转距离是相对于电机当前位置的。程序会等待电机旋转完毕后,才会运行堆叠中的下一个模块。
spin [ArmMotor v] [up v] for (90) [degrees v] ▶
参数 |
描述 |
|---|---|
发动机 |
旋转电机:机械臂电机或爪式电机。 |
方向 |
电机旋转方向:
|
距离 |
电机旋转的距离。角度使用整数。圈数可以使用整数或小数。 |
单元 |
距离单位:度或圈。 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始
[Raise the Arm to carry the Pin to the Goal.]
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
旋转电机定位#
旋转电机定位 堆栈模块使电机旋转到特定位置。
电机的位置是指它旋转的距离,以度或圈数来衡量。一圈等于360度。在项目开始时,ArmMotor 的位置设置为0度。ClawMotor 是个例外——它的初始位置为467度(完全闭合)。也可以使用 set motor position 代码块来设置电机位置。
位置值是绝对值。这意味着旋转方向取决于电机的当前位置。
例如,如果电机从0度开始旋转到720度,它将正转两圈。如果它接着旋转到360度,它将反转一圈,因为360小于720。
[ArmMotor v] 转至 (90) [度 v] ▶
参数 |
描述 |
|---|---|
发动机 |
旋转电机:机械臂电机或爪式电机。 |
位置 |
电机旋转到的位置值。角度使用整数。圈数可以使用整数或小数。 |
单元 |
位置单位:度或圈。 |
不要等待 |
选择箭头(▶)展开代码块,显示无需等待,这样堆栈中的下一个代码块就会立即运行。 |
例子
当开始
[Raise the Arm, then release the Pin.]
spin [ArmMotor v] to position (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
停止电机#
停止电机 堆栈块停止选定的电机。
[ArmMotor v] 停止
参数 |
描述 |
|---|---|
发动机 |
要停止的电机:机械臂电机或爪式电机。 |
例子
当开始
[Raise the Arm partway to hold the Pin.]
[ArmMotor v] [向上 v] 转
等待 (1) 秒
[ArmMotor v] 停止
设置#
设定电机速度#
“设置电机转速”模块用于控制电机的转速。百分比越高,电机转速越快;百分比越低,电机转速越慢。
每个项目开始时,每个电机默认以 50% 的速度旋转。
**注意:**更高的速度会使电机转速更快,但精度可能会降低。更低的速度会使电机转速更慢,但精度可能会更高。
set [ArmMotor v] velocity to [50] [% v]
参数 |
描述 |
|---|---|
发动机 |
用于设置以下电机速度的电机:机械臂电机或爪电机。 |
速度 |
电机旋转的速度。百分比使用0%到100%之间的整数。 |
单元 |
速度单位:%。 |
例子
当开始
[Raise the Arm fast to release the Pin.]
set [ArmMotor v] velocity to [100] [% v]
spin [ArmMotor v] [up v] for (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
设置电机超时#
设置电机超时 代码块用于设置电机尝试完成一次运动的超时时间。如果电机无法在规定时间内完成,它将停止尝试并执行代码块堆栈中的下一个代码块。这样可以防止电机卡在某个运动中。
设定 [ArmMotor v] 超时为 [1] 秒
参数 |
描述 |
|---|---|
发动机 |
设置电机超时时间为:ArmMotor 或 ClawMotor。 |
时间 |
电机尝试完成一次运动的秒数。该值可以是整数或小数。 |
例子
当开始
[Score a Pin in a Neutral Goal.]
turn [left v] for (110) degrees ▶
设定 [ArmMotor v] 超时为 [1] 秒
spin [ArmMotor v] [up v] for (1800) [degrees v] ▶
驱动 [向前 v] (25) [英寸 v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
位置#
电机位置#
电机的位置是指它旋转的距离,以度或圈数来衡量。一圈等于360度。电机位置报告模块会报告电机的当前位置。
项目开始时,机械臂电机(ArmMotor)的位置设置为 0 度。爪式电机(ClawMotor)是个例外——它的初始位置为 467 度(完全闭合)。如果电机正向旋转一整圈,位置增加;如果电机反向旋转,位置减少。
([ArmMotor v] position in [degrees v])
参数 |
描述 |
|---|---|
发动机 |
用于报告以下部件位置的电机:机械臂电机 或 爪电机。 |
单元 |
报告电机位置的单位:度或圈。 |
例子
当开始
[Raise the Arm, then release the Pin.]
while <([ArmMotor v] position in [degrees v]) < (800)>
[ArmMotor v] [向上 v] 转
wait (0.002) seconds
结束
[ArmMotor v] 停止
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
设置电机位置#
电机的位置是指它旋转的距离,以度或圈数来衡量。一圈等于360度。设置电机位置堆栈块会将电机的当前位置更改为新值。
例如,如果电机旋转了 180 度,将位置设置为 0 度会将该位置从 180 度重置为 0 度。然后,电机可以根据这个新值旋转到其他位置。
设定 [ArmMotor v] 转位至 (0) [度 v]
参数 |
描述 |
|---|---|
发动机 |
用于设置以下部件位置的电机:机械臂电机 或 爪电机。 |
位置 |
要设置的电机位置值。角度使用整数。圈数可以使用整数或小数。 |
单元 |
位置单位:度或圈。 |
例子
当开始
[Reset encoder, raise Arm, place Pin.]
设定 [ArmMotor v] 转位至 (0) [度 v]
spin [ArmMotor v] to position (800) [degrees v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
价值观#
电机已完成#
“电机已完成”布尔模块用于报告电机是否已停止运转。这可用于根据电机的运转状态来控制其他行为的执行时间。
正确 — 电机已停止运转。
错误 — 电机仍在运转。
该模块与以下具有and don’t wait参数的运动模块配合使用:spin motor for 和 spin motor to position。
<[ArmMotor v] 已结束?>
参数 |
描述 |
|---|---|
发动机 |
报告其是否已完成运动的电机:ArmMotor 或 ClawMotor。 |
例子
当开始
[Raise the Arm while driving to the Goal.]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
等待 (0.1) 秒
while <not <[ArmMotor v] is done?>>
驱动 [向前 v]
wait (0.005) seconds
结束
驱动停止
电机正在旋转#
“电机是否旋转”布尔模块用于报告电机是否正在旋转。这可以根据电机的运动状态来控制其他行为的执行时间。
正确——电机正在旋转。
错误 — 电机没有转动。
该模块与以下具有and don’t wait参数的运动模块配合使用:spin motor for 和 spin motor to position。
<[ArmMotor v] 正在转?>
参数 |
描述 |
|---|---|
发动机 |
报告电机是否正在旋转的参数:ArmMotor 或 ClawMotor。 |
例子
当开始
[Raise the Arm while driving to the Goal, then release the Pin.]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
等待 (0.1) 秒
while <[ArmMotor v] is spinning?>
drive [forward v] for (20) [mm v] ▶
结束
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
电机速度#
电机速度报告模块以百分比形式报告电机的旋转速度,范围从 -100% 到 100%。
([ArmMotor v] velocity in [% v] :: custom-motion)
参数 |
描述 |
|---|---|
发动机 |
要报告以下电机的速度:机械臂电机或爪电机。 |
单元 |
电机速度的报告单位:%。 |
例子
当开始
[Show Arm Motor velocity while raising.]
set [ArmMotor v] velocity to [100] [% v]
spin [ArmMotor v] to position (800) [degrees v] ◀ and don't wait
wait (0.2) seconds
print ([ArmMotor v] velocity in [% v] :: custom-motion) on screen ◀ and set cursor to next row
人工智能视觉#
行动#
获取对象数据#
获取对象数据 模块将来自 AI 视觉传感器帧的数据过滤为单个签名——传感器可以识别的事物的保存描述,例如场上的游戏元素。
数据集按宽度从大到小的顺序存储对象,索引从 0 开始。可以使用 AI Vision 对象属性 代码块访问每个对象的属性。如果没有检测到匹配的对象,则返回空数据集。
get [AI Classifications v] data from [AIVision v]
范围 |
描述 |
|---|---|
签名 |
筛选数据集,仅包含给定签名的数据。可用签名包括:
|
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn to face the Pin.]
set turn velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerX v]) < (140)> then
[左 v] 转
else if <([AIVision v] object [centerX v]) > (180)> then
[右 v] 转
否则
驱动停止
退出循环
结束
结束
结束
设置#
设置对象项#
设置对象项 块设置要使用数据集中的哪个项。
set [AIVision v] object item to [1]
参数 |
描述 |
|---|---|
物品 |
要使用的数据集中的项目编号。 |
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
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 specific game element.]
if <[AIVision v] object is [RedBluePin v]?> then
print [RedBluePin detected.] ▶
否则
print [No RedBluePin detected.] ▶
结束
结束
价值观#
对象存在#
对象存在 代码块返回一个布尔值,指示是否在数据集中检测到任何对象。
正确——数据集中包含检测到的对象。
错误——该数据集不包含任何检测到的对象。
<[AIVision v] object exists?>
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
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
结束
对象是#
object is 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
正确——数据集中的项就是特定的对象。
错误——数据集中的项不是特定对象。
<[AIVision v] object is [RedBluePin v]?>
范围 |
描述 |
|---|---|
目的 |
要将该物品与哪个物体进行比较:
|
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <[AIVision v] object is [RedBluePin v]?> then
print [RedBluePin detected.] ▶
否则
print [No RedBluePin detected.] ▶
结束
结束
对象是 AprilTag#
object is AprilTag 块返回一个布尔值,指示检测到的对象是否是与特定 ID 匹配的 AprilTag。
正确 – 检测到的对象是具有给定 ID 的 AprilTag。
错误 – 检测到的对象不是具有给定 ID 的 AprilTag。
<[AIVision v] object is AprilTag [0] ?>
范围 |
描述 |
|---|---|
AprilTag ID |
要与检测到的 AprilTag 进行比较的 ID 号。 |
例子
当开始
[Report if AprilTag 3 is detected.]
get [AprilTags v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <[AIVision v] object is AprilTag [3] ?> then
print [That is 3!] ▶
否则
print [That isn't 3!] ▶
结束
结束
对象计数#
对象计数 模块返回数据集中检测到的对象数量,以整数形式表示。
([AIVision] object count)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
print ([AIVision v] object count) ◀ and set cursor to next row
结束
对象属性#
使用 get object data 块后,存储的每个对象都包含六个属性(如下所示)。
([AIVision v] object [width v])
所有属性值均描述了在调用“获取对象数据”模块时,AI视觉传感器视野中检测到的对象的位置和大小。这些值以像素为单位,基于传感器320×240像素的分辨率。
范围 |
描述 |
|---|---|
财产 |
要使用检测到的对象的哪个属性: |
宽度#
width 属性以像素为单位报告检测到的对象宽度,数值为 1 到 320 之间的整数。
([AIVision v] object [width v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [width v]) > (140)> then
驱动停止
退出循环
否则
驱动 [向前 v]
结束
结束
结束
高度#
height 属性以像素为单位报告检测到的对象的高度,数值为 1 到 240 之间的整数。
([AIVision v] object [height v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [height v]) > (200)> then
驱动停止
退出循环
否则
驱动 [向前 v]
结束
结束
结束
centerX#
centerX 属性以像素为单位报告检测到的对象中心的 x 坐标,数值为 0 到 320 之间的整数。
([AIVision v] object [centerX v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn and approach the next Cup and Pin.]
set turn velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerX v]) < (140)> then
turn [left v] for (5) degrees ▶
否则
驱动 [向前 v] (25) [英寸 v] ▶
退出循环
结束
结束
结束
中心Y#
centerY 属性以像素为单位报告检测到的对象中心的 y 坐标,数值为 0 到 240 之间的整数。
([AIVision v] object [centerY v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [centerY v]) > (230)> then
驱动停止
退出循环
否则
驱动 [向前 v]
结束
结束
结束
originX#
originX 属性以像素为单位报告检测到的对象边界框左上角的 x 坐标,数值为 0 到 320 之间的整数。
([AIVision v] object [originX v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Turn and approach the next Cup and Pin.]
set turn velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [originX v]) < (100)> then
turn [left v] for (5) degrees ▶
否则
驱动 [向前 v] (25) [英寸 v] ▶
退出循环
结束
结束
结束
originY#
originY 属性以像素为单位报告检测到的对象边界框左上角的 y 坐标,数值为 0 到 240 之间的整数。
([AIVision v] object [originY v])
例子
当开始
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
turn [left v] for (70) degrees ▶
[Approach the next Cup and Pin.]
set drive velocity to (30) [% v]
永久循环
get [AI Classifications v] data from [AIVision v]
if <[AIVision v] object exists?> then
if <([AIVision v] object [originY v]) > (140)> then
驱动停止
退出循环
否则
驱动 [向前 v]
结束
结束
结束
传感#
距离#
距离测量结果显示物体#
检测到物体的距离布尔模块报告距离传感器当前是否检测到 2000 毫米范围内的物体。
正确 — 距离传感器检测到物体。
错误 — 距离传感器未检测到物体。
<[FrontDistance v] 发现对象?>
参数 |
描述 |
|---|---|
距离传感器 |
要使用的距离传感器。请从适用于 Flex 的距离传感器中进行选择。 |
例子
当开始 :: hat events
[Turn until something is detected, then release the Pin.]
[右 v] 转
等到 <[FrontDistance v] 发现对象?>
驱动停止
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
物距#
物体距离报告模块报告距离传感器与最近检测到的物体之间的距离。
([FrontDistance v] 距离 [毫米 v])
参数 |
描述 |
|---|---|
距离传感器 |
要使用的距离传感器。请从适用于 Flex 的距离传感器中进行选择。 |
单元 |
距离单位:毫米或英寸。 |
例子
当开始 :: hat events
[Drive until 200 mm from the Goal, then release the Pin.]
驱动 [向前 v]
wait until <([FrontDistance v] distance in [mm v]) < (200)>
驱动停止
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
全球定位系统#
GPS定位#
GPS 位置 模块使用 GPS(游戏定位系统™)传感器返回机器人转弯参考点相对于场地中心的偏移位置。
([GPS v] position [X v] in [mm v])
参数 |
描述 |
|---|---|
轴 |
要报告哪个坐标轴:
|
单位 |
表示位置的单位:毫米 或 英寸 |
例子
当开始 :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
驱动 [向前 v]
wait until <([GPS v] position [X v] in [mm v]) > (-1370)>
驱动停止
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
GPS航向#
GPS航向模块根据GPS(游戏定位系统™)传感器从VEX GPS场码读取的0.00到359.99度的读数,返回机器人当前面向的航向。
([GPS v] heading in degrees)
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始 :: hat events
[Raise the Arm, drive to the Goal, release the Pin.]
spin [ArmMotor v] [up v] for (300) [degrees v] ▶
drive [forward v] for (10) [inches v] ▶
spin [ClawMotor v] [open v] for (180) [degrees v] ▶
[Turn left to face the Neutral Goal.]
set turn velocity to (30) [% v]
[左 v] 转
wait until <([GPS v] heading in degrees) < (18)>
驱动停止