ROS 进阶学习笔记(18):ROS导航3:关于 ROS ActionLib 包

ROS 进阶学习笔记(18):理解ROS Action Lib

ROS 里除了基本的msg publisher/Subscriber 以外,还有以下东东需要理解:

  • Server/Client - 参见Link
  • ActionLib - 本次blog讨论

ActionLib是ROS里一个重要的部分(link:http://wiki.ros.org/APIs),既然我在学习move_base时遇到很多有关actionlib的实现,还是先把actionlib理解之后再回去搞navigation的其他包比较合适。打好基础。


查看原图

[Overview]

ROS中的服务service是一问一答的形式,你来查询了,我就返给你要的信息。
action也有服务的概念,但是它不一样的地方是:不是一问一答,而多了一个反馈,它会不断反馈项目进度。如navigation下的move_base package,你设定了目标点,反馈信息可能是机器人在规划路径上的即时位姿,直到机器人到达目标点,返回SUCCEEDED消息。有关actionlib的具体学习笔记sonictl见下:

=== 我把wiki_actionlib的读书笔记写在下面: ===

wikipage: http://wiki.ros.org/actionlib

【Summary】

The actionlib stack provides a standardized interface for interfacing with preemptable tasks. Examples of this include moving the base to a target location, performing a laser scan and returning the resulting point cloud, detecting the handle of a door, etc.

actionlib是个stack,意味着与navigation stack平级?为和pre emptable tasks 可预先中止性任务进行交互而提供标准的接口。相关的例子有:moving base to a target location,performing a laser scan and returning the resulting point cloud, detecting the handle of a door, etc.
(sonictl@csdn:看起来还是很必须的一块内容,如果希望往高级一点的ROS应用发力的话。)


1. 【Overview】

In any large ROS based system, there are cases when someone would like to send a request to a node to perform some task, and also receive a reply to the request. This can currently be achieved via ROS services.

In some cases, however, if the service takes a long time to execute, the user might want the ability to cancel the request during execution or get periodic feedback about how the request is progressing. The actionlib package provides tools to create servers that execute long-running goals that can be preempted. It also provides a client interface in order to send requests to the server.

有的大点的ROS系统项目,有些时候需要向一个节点发送一个request然后等它处理完了发回一个response.这个已经可以通过ROS里的Service的概念达到了。但有时候呢,如果这个service需要稍长一些的时间来运算之后才能反馈所需的结果,但在运行过程中,用户sonictl也许要根据运行的不同情况来决定是否取消request或者是需要周期性地获知运行状态。The actionlib 包就是提供这些工具,使得可以创建一些servers, 这些servers是用来执行需要长时间的任务的,并且是可以被preempted(预先制止)的。同时,actionlib包还提供了一个client接口,用来给server发请求。(sonictl@csdn_blog:这使我想到了move_base包可以被 cancle_goal 的功能)

2. 【Detailed Description】

For a full discussion of how actionlib operates "under the hood", please see theDetailed Description.
这里居然不就actionlib的实现机制进一步展开,而是让读者自己去看。我进去看了一下,感觉要ROS上上一台阶,应该好好理解它里面的机制。

3. 【Client-Server Interaction】

  *由于我有更重要的事情需要解决,暂时actionlib笔记就到这里等我回头来继续微笑  --- sonictl@csdn_blog
The ActionClient and ActionServer communicate via a "ROS Action Protocol", which is built on top of ROS messages. The client and server then provide a simple API for users to request goals (on the client side) or to execute goals (on the server side) via function calls and callbacks.
    上面所述的 ActionClient 和 ActionServer 通过 ROS Action Protocol (ROS Action 协议,建立在ROS messages的基础上)来通信。Client&Server 为用户提供了简单的API,通过函数的调用和回调,用来在client端request一个目标,或者,在server端来执行达成一个目标。下图说明这个机制如何运行:

这个其实是Client占主动,ActionServer占被动那意思~--- sonictl, csdn_blog

4. 【Action Specification: Goal, Feedback, & Result】

In order for the client and server to communicate, we need to define a few messages on which they communicate. This is with anaction specification. This defines the Goal, Feedback, and Result messages with which clients and servers communicate:
首先是如何定义messages来让Client&Server之间通信,这就是所谓的 action specification (Action说明书-的概念) 。它定义了Goal,Feedback,and Result messages来让Client和Server通信:

4.1 Goal
To accomplish tasks using actions, we introduce the notion of a goal that can be sent to an ActionServer by an ActionClient. In the case of moving the base, the goal would be a PoseStamped message that contains information about where the robot should move to in the world. For controlling the tilting laser scanner, the goal would contain the scan parameters (min angle, max angle, speed, etc).
为了用actions机制完成一个任务,我们引入了the notion of a goal, 这个goal可以被ActionClient发送到ActionServer. 比如在move base这个案例中,它的类型是PoseStamped,包含了机器人应该到达的哪里的信息。在激光扫描云台控制案例中,the goal会包含扫描的参数(min angle, max angle, speed 等)

Feedback
Feedback provides server implementers a way to tell an ActionClient about the incremental progress of a goal. For moving the base, this might be the robot's current pose along the path. For controlling the tilting laser scanner, this might be the time left until the scan completes.
Feedback是server用来告诉ActionClient goal执行过程中的各种情况。在moving_base案例中,它是机器人现在的位姿;在controlling the tilting laser scanner案例中, this might be the time left until the scan completes(扫描剩余时间).

Result
A result is sent from the ActionServer to the ActionClient upon completion of the goal. This is different than feedback, since it is sent exactly once. This is extremely useful when the purpose of the action is to provide some sort of information. For move base, the result isn't very important, but it might contain the final pose of the robot. For controlling the tilting laser scanner, the result might contain a point cloud generated from the requested scan.
执行结果,比如在move_base中的结果和机器人pose;在云台激光扫描中的一个请求的点云数据。等

5.【.action File】

The action specification is defined using a .action file. The .action file has the goal definition, followed by the result definition, followed by the feedback definition, with each section separated by 3 hyphens (---).
熟悉Message机制的朋友就会知道,这个跟那个类似,就是定义 action specification的消息数据类型滴~  -- sonictl_at_blog_csdn_net

These files are placed in a package's ./action directory, and look extremely similar to a service's.srv file. An action specification for doing the dishes might look like the following:

./action/DoDishes.action

# Define the goal
uint32 dishwasher_id  # Specify which dishwasher we want to use
---
# Define the result
uint32 total_dishes_cleaned
---
# Define a feedback message
float32 percent_complete

Based on this .action file, 6 messages(y? 可能是Client&Server各产生3个?) need to be generated in order for the client and server to communicate. This generation can be automatically triggered during the make process:

Catkin

Add the following to your CMakeLists.txt file before catkin_package(). 注意你要用 actionlib 的话,记得修改CMakeLists.txt 文件!

find_package(catkin REQUIRED genmsg actionlib_msgs actionlib)
add_action_files(DIRECTORY action FILES DoDishes.action)
generate_messages(DEPENDENCIES actionlib_msgs)

Additionally, the package's package.xml must include the following dependencies:

<build_depend>actionlib</build_depend>
<build_depend>actionlib_msgs</build_depend>
<run_depend>actionlib</run_depend>
<run_depend>actionlib_msgs</run_depend>

Rosbuild

If you are using rosbuild instead of catkin, instead add the following before rosbuild_init().

rosbuild_find_ros_package(actionlib_msgs)
include(${actionlib_msgs_PACKAGE_PATH}/cmake/actionbuild.cmake)
genaction()

Then, after the output paths, uncomment (or add)

rosbuild_genmsg()

Note: rosbuild_genmsg() must be called after the output paths have been set.

For 1.0 series (i.e. boxturtle) use:

rosbuild_find_ros_package(actionlib)
include(${actionlib_PACKAGE_PATH}/cmake/actionbuild.cmake)
genaction()
rosbuild_genmsg()

Additionally, the package's manifest.xml must include the following dependencies:

<depend package="actionlib"/>
<depend package="actionlib_msgs"/>

Results

For the DoDishes.action, the following messages are generated by genaction.py:

  • DoDishesAction.msg

  • DoDishesActionGoal.msg

  • DoDishesActionResult.msg

  • DoDishesActionFeedback.msg

  • DoDishesGoal.msg

  • DoDishesResult.msg

  • DoDis

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值