(七)阅读教程Understanding ROS 2 actions笔记

Goal: Introspect actions in ROS 2.

Background:

【Actions are one of the communication types in ROS 2 intended for long running tasks. They consist of three parts: a goal, a result, and feedback.】

actions是ROS2中为了长时间运行任务的一个通信模式。它们由三部分组成:一个目标,一个结果,个反馈。

【Actions are built on topics and services. Their functionality is similar to services, except actions are preemptable (you can cancel them while executing). They also provide steady feedback, as opposed to services which return a single response.】

Actions是建立在topics和services上的。Actions在功能上和services是相似的,不同的是actions是可以抢占的(可以在执行时取消)。与services返回一个单独的响应相反,Actions提供持续的反馈。

【Actions use a client-server model, similar to the publisher-subscriber model (described in the topics tutorial). The “action client” node sends a goal to an “action server” node that acknowledges the goal and returns a stream of feedback and a result.】

Actions使用一个客户-服务模式,与(topic tutorial中描述的)发布-订阅模式相似。“action client(活动客户端)”节点发送一个目标到“action service(活动服务端)”节点,(活动服务端节点)确认该目标并返回一个反馈流和一个结果。

【看起来就像是——老师出了一道题,我收到后确认一下抄题抄对没;然后开始计算,一边算一边告诉老师我算着呢哈,你看我算到xxx了;最后老师问:你算出来个啥结果?我回复一个最终结果。】

 

Tasks:

1、Setup

Start up the two turtlesim nodes, /turtlesim and /teleop_turtle.
 

2、Use actions

【When you launch the /teleop_turtle node, you will see the following message in your terminal:】

【Let’s focus on the second line, which corresponds to an action. (The first instruction corresponds to the “cmd_vel” topic, discussed previously in the topics tutorial.)】

让我们看第二行,它对应了一个action。(第一条说明对应了“cmd_vel”topic,这个在之前的topics 教程中已经讨论过了)

【Notice that the letter keys G|B|V|C|D|E|R|T form a “box” around the F key on your keyboard. Each key’s position around F corresponds to that orientation in turtlesim. For example, the E will rotate the turtle’s orientation to the upper left corner.】

我们注意到,字母按键 G|B|V|C|D|E|R|T  在键盘上形成了一个围绕 F 键的框。每个按键的位置围绕 F 按键对应着在turtlesim中的方向。例如, E 将会让乌龟的方向旋转到左上角。

【Pay attention to the terminal where the /turtlesim node is running. Each time you press one of these keys, you are sending a goal to an action server that is part of the /turtlesim node. The goal is to rotate the turtle to face a particular direction. A message relaying the result of the goal should display once the turtle completes its rotation:】

注意 /turtlesim node 正在运行的终端,每次你按下这些按键之一,你将会发送一个目标到一个action服务,它是/turtlesim node的一部分。这个目标会使海龟转到面向这个指定的方向。乌龟完成旋转后,将显示一条有关目标结果的消息:

(黄色的警告是因为我按键太快啦,上一次还没转完)

【The F key will cancel a goal mid-execution, demonstrating the preemptable feature of actions.】

F键将会取消一个正在执行中的goal,这体现了actions具有抢占性。

【Try pressing the C key, and then pressing the F key before the turtle can complete its rotation. In the terminal where the /turtlesim node is running, you will see the message:】

试着去按下C键,然后在海龟完成转向之前按下F键。在/terminal 节点运行的终端将会看到如下消息:

【Not only can the client-side (your input in the teleop) preempt goals, but the server-side (the /turtlesim node) can as well. When the server-side preempts an action, it “aborts” the goal.】

不仅客户端(你在teleop中输入)可以抢占goals,服务端(/turtlesim node)也可以。当服务端抢占了一个action,我们说它终止了goal。

【Try hitting the D key, then the G key before the first rotation can complete. In the terminal where the /turtlesim node is running, you will see the message:】

尝试按下D键,然后再第一次旋转完成前按下G键。在/turtlesim node的终端中我们将会看到以下消息:

【The server-side aborted the first goal because it was interrupted.】

服务端终止了第一个goal,因为它被打断了。

 

3、ros2 node info

To see the /turtlesim node’s actions, open a new terminal and run the command:

ros2 node info /turtlesim

 【Which will return a list of /turtlesim’s subscribers, publishers, services, action servers and action clients:】

这将会返回一个/turtlesim的 (subscribers)订阅者、(publishers)发布者、(services)服务、(action servers)动作服务者和(action clients)动作客户端 的列表:

【Notice that the /turtle1/rotate_absolute action for /turtlesim is under Action Servers. This means /turtlesim responds to and provides feedback for the /turtle1/rotate_absolute action.】

我们可以注意到 /turtlesim 的action /turtle1/rotate_absolute 是在Action Servers下的。这意味着 /turtlesim 会响应/turtle1/rotate_absolute action并且提供反馈。

【The /teleop_turtle node has the name /turtle1/rotate_absolute under Action Clients meaning that it sends goals for that action name.】

Action Clients 下,/teleop_turtle node 的名字是 /turtle1/rotate_absolute,这个名字表示它发送 goals 给这个action 名。

ros2 node info /teleop_turtle

 

4、ros2 action list

To identify all the actions in the ROS graph, run the command:

ros2 action list

 Which will return:

【This is the only action in the ROS graph right now. It controls the turtle’s rotation, as you saw earlier. You also already know that there is one action client (part of /teleop_turtle) and one action server (part of /turtlesim) for this action from using the ros2 node info <node_name> command.】

这是目前ROS图中唯一的action 。像之前所看到的,它控制着乌龟的旋转。 您还已经知道,通过使用 ros2 node info <node_name> 命令可以查看到该 action 的一个action client(/teleop_turtle 的一部分)和一个 action server(/turtlesim 的一部分)。

 

4.1 ros2 action list -t

【Actions have types, similar to topics and services. To find /turtle1/rotate_absolute’s type, run the command:】

就像topics和services一样,actions也有(不同的)类型。运行以下命令来了解/turtle1/rotate_absolute的类型:

ros2 action list -t

 Which will return:

【In brackets to the right of each action name (in this case only /turtle1/rotate_absolute) is the action type, turtlesim/action/RotateAbsolute. You will need this when you want to execute an action from the command line or from code.】

在每个action 名称右侧的括号中是action type,turtlesim / action / RotateAbsolute(在这个例子中,只有/turtle1/rotate_absolute(这一个action))。 当您要从命令行或代码执行操作时就需要用到(action type)。

 

5、ros2 action info

【You can further introspect the /turtle1/rotate_absolute action with the command:】

你可以用下面的命令来对/turtle1/rotate_absolute 这个action来进行进一步的自检:

ros2 action info /turtle1/rotate_absolute

 Which will return

【This tells us what we learned earlier from running ros2 node info on each node: The /teleop_turtle node has an action client and the /turtlesim node has an action server for the /turtle1/rotate_absolute action.】

这验证了我们之前在每个node上运行 ros2 node info 所得到的:node /teleop_turtle 有一个 action client,并且node /turtlesim 有一个提供给 action /turtle1/rotate_absolute 的action server

 

6、ros2 interface show

【One more piece of information you will need before sending or executing an action goal yourself is the structure of the action type.】

在您自己发送或者执行一个action goal之前,有一些您需要了解的信息是action type的结构。

 

【Recall that you identified /turtle1/rotate_absolute’s type when running the command ros2 action list -t. Enter the following command with the action type in your terminal:

请回想一下您通过运行ros2 action list -t 指令得到的/turtle1/rotate_absolute的类型。在您的终端输入以下命令以及action type:

ros2 interface show turtlesim/action/RotateAbsolute.action

 Which will return:


【The first section of this message, above the ---, is the structure (data type and name) of the goal request. The next section is the structure of the result. The last section is the structure of the feedback.】

这个消息的第一部分(在---上方)是goal request的结构(数据类型和名称)。 下一部分是结果的结构。 最后一部分是反馈的结构。

 

7、ros2 action send_goal

【Now let’s send an action goal from the command line with the following syntax:】

现在让我们按照以下语法从命令行发送一条action goal:

ros2 action send_goal <action_name> <action_type> <values>

<values> need to be in YAML format.

Keep an eye on the turtlesim window, and enter the following command into your terminal:

ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

You should see the turtle rotating, as well as the following message in your terminal:

【All goals have a unique ID, shown in the return message. You can also see the result, a field with the name delta, which is the displacement to the starting position.】

所有 goals 都有一个单独的ID,它已经在返回信息中显示出来了。您也可以看到结果,它是一个名字是  delta 的字段,它表示了到起始位置的位移。

【To see the feedback of this goal, add --feedback to the last command you ran. First, make sure you change the value of theta. After running the previous command, the turtle will already be at the orientation of 1.57 radians, so it won’t move unless you pass a new theta.】

通过添加 --feedback 项到最新运行的命令中来查看goal的反馈。首先,确保您已经改变了theta的值。然后运行上述指令,还海龟将已经处于1.57弧度的方向,因此除非您传递新的theta,否则它不会移动。

ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}" --feedback

 Your terminal will return the message:

……

 

【You will continue to receive feedback, the remaining radians, until the goal is complete.】

您将持续接收到反馈,(内容是)剩下的弧度,直到完成goal。

 

Summary

【Actions are like services that allow you to execute long running tasks, provide regular feedback, and are cancelable.】

actions像services一样,它允许执行长时间运行任务,提供定时的反馈,并且是可以取消的。

【A robot system would likely use actions for navigation. An action goal could tell a robot to travel to a position. While the robot navigates to the position, it can send updates along the way (i.e. feedback), and then a final result message once it’s reached its destination.】

一个机器人系统可能会使用actions进行导航。一个action goal可以告诉一个机器人去到一个位置。当机器人导航去这个位置时,它一边走一边发送更新(也就是反馈)(i.e. = that is to say),然后一到达目的地它就发送最终结果信息。

【Turtlesim has an action server that action clients can send goals to for rotating turtles. In this tutorial, you introspected that action, /turtle1/rotate_absolute, to get a better idea of what actions are and how they work.】

Turtlesim有一个 action sever,这样action clients就可以发送 goals 它来使小海龟转向。在这个教程中你对/turtle1/rotate_absolute这个action进行了自检,以更好的了解什么是actions 以及actions是怎么工作的。

 

Related content

You can read more about the design decisions behind actions in ROS 2 here.

阅读更多ROS2 中的actions背后的设计决策。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值