信息#

介绍#

两台 VEX AIM 编程机器人可以连接起来,在项目进行过程中进行通信。通过使用消息模块,机器人可以发送和接收信息,从而协调彼此的行动。

消息存储在先进先出(FIFO)队列中。即使有更新的消息,也会优先处理最先收到的消息。

**注意:**为了发送和接收消息,两个机器人必须同时运行处理消息的项目。

以下是所有模块的列表:

发送消息#

发送消息块向另一个链接的机器人发送一个字符串。

发送消息 [message]

参数

描述

信息

发送给其他链接机器人的字符串。

例子

机器人 1

当屏幕 [pressed v]
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]

机器人 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

发送带有数据的消息#

发送带有数据的消息块向另一个链接的机器人发送一个字符串和一个数字。

发送带有数据 [0]消息 [message]

参数

描述

信息

发送给其他关联机器人的值。该值必须是字符串。

数据

发送给另一个机器人的数字。

例子

机器人 1

当屏幕 [pressed v]
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]

机器人 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

获取最新消息#

获取最新消息块存储从其他链接机器人接收到的最新字符串。

获取最新消息

参数

描述

该块没有参数。

例子

机器人 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]

机器人 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

获取带有数据的最新消息#

获取带有数据的最新消息块存储从其他链接机器人接收到的最新字符串和数字。

获取带有数据的最新消息

参数

描述

该块没有参数。

例子

机器人 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]

机器人 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

最新消息#

最新消息块返回上次使用获取最新消息获取带有数据的最新消息 块时存储的最新字符串。

(最新消息)

参数

描述

该块没有参数。

例子

机器人 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
[Change the string to display a different message.]
发送消息 [Hello, Robot 2!]

机器人 2

当开始
[Code for Robot 2.]
[Display what message Robot 1 sends.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
获取最新消息
在屏幕上打印 (最新消息)▶

最新数据#

最新数据块返回上次使用获取带有数据的最新消息 块时存储的最新数字。

(最新数据)

参数

描述

该块没有参数。

例子

机器人 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Continuously send the current heading to Robot 2.]
在屏幕上打印 [Robot 1]▶
永久循环
发送带有数据 (归位角度值)消息 [message]

机器人 2

当开始
[Code for Robot 2.]
[Turn to match Robot 1's heading.]
在屏幕上打印 [Robot 2]▶
永久循环
如果 <有消息吗?> 那么
获取带有数据的最新消息
归位至 (最新数据) 度 ▶

有消息吗?#

消息可用吗? 块返回一个布尔值,指示其他链接的机器人是否曾经使用过 发送消息发送带有数据的消息 块。

<有消息吗?>

参数

描述

该块没有参数。

例子

机器人 1

当屏幕 [pressed v] :: hat events
[Code for Robot 1.]
[Press the screen to send a message to Robot 2.]
在屏幕上打印 [Robot 1]▶
发送消息 [message]

机器人 2

当开始
[Code for Robot 2.]
[Display a message when Robot 1 sends a message.]
在屏幕上打印 [Robot 2]▶
在屏幕上设定光标至下一行
等到 <有消息吗?>
在屏幕上打印 [Received!]▶

已连接?#

**是否连接?**块返回一个布尔值,指示机器人当前是否与另一个机器人相连。

  • 没错——这个机器人与另一个机器人相连。

  • 错误——该机器人未与其他机器人连接。

<已连接?>

参数

描述

该块没有参数。

例子

当开始
[Turn off one of the linked robots to see the message change.]
永久循环
清屏
在屏幕上打印 <已连接?>▶

链接机器人名称#

“链接机器人名称”模块返回一个字符串,其中包含已链接机器人的名称。如果没有链接任何机器人,则返回“None”。

(linked robot name)

参数

描述

该块没有参数。

例子

当开始
[Display the name of the robot that's linked.]
在屏幕上打印 (linked robot name)▶