ROS actionlib-----简介

本文深入介绍了ROS中的ActionLib,一种支持长时间运行任务的机制。它不仅涵盖了ActionLib的基本原理,还详细解析了ActionClient和ActionServer的工作机制及状态转换过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 引入背景

    actionlib是ROS中一个很重要的功能包集合,尽管在ROS中已经提供了srevice机制来满足请求-响应式的使用场景,但是加入某个请求执行时间很长,在此期间用户想查看执行的进度或者取消这个请求的话,service机制就不能满足了,但是actionlib可满足用户这种需求。


2 actionlib工作机制

    actionlib使用client-server工作模式,ActionClient 和ActionServer通过"ROS Action Protocol"进行通信,"ROS Action Protocol"以ROS消息方式进行传输。此外ActionClient 和ActionServer给用户提供了一些简单的接口,用户使用这些接口可以完成goal请求(client边)和goal执行(server边)。

   ActionClient 和ActionServer的应用场景中通讯机制大致如下图所示:

3 ROS Action  Protocol

   ActionClient 和ActionServer之间使用action protocol通信,action protocol就是预定义的一组ROS message,这些message被放到ROS topic上在 ActionClient 和ActionServer之间进行传实现二者的沟通。

 


3.1 Goal IDs

   goal ID是action message中一个字符串字段,这使得ActionClient 和ActionServer之间传输的message与Goal完全对应起来不会导致通信失配错误。goal ID通常由node name,counter和timestamp组成。

3.2 Message

3.2.1 goal topic: Sending Goals

    goal topic使用自动创建的ActionGoal message (example: actionlib/TestActionGoal), goal topic被用于向action server发送新的goal。 ActionGoal message封装了一条goal message并包含Goal ID。

   当acttion client发送goal时候将创建独一无二的goal ID和时间戳。但是也允许留空它们,这时action server将填充它们:

  • Empty stamp: action server收到这个时候,时间戳将设置为now()

  • Empty id: action server收到这个时候,ID自动随机创建。不过这个ID由于action client无法知道其对应的goal,所以意义不大。

3.2.2 cancel topic: Cancelling Goals

    cancel topic使用消息 actionlib_msgs/GoalID , 每个cancel message都有一个时间戳和goal ID,基于这些字段信息对应goal将会被取消。


cancel_policy.png


3.2.3 status topic: Server 端goal状态更新

    status topic使用消息 actionlib_msgs/GoalStatusArray, 通知action clients有关 server goal status信息。 action server将会以固定速率发送该消息(一般是10 Hz)。

    action server将一直跟踪actionclient请求的每一个目标,知道目标状态为完成。但是为了提高通信可靠性,通常在目标状态变为完成后几分钟,server才发送完成状态。

3.2.4 feedback topic: Asynchronous goal information

     feedback topic使用自动创建的ActionFeedback消息, 在处理goal过程中server周期性通知client状态。因为ActionFeedback也有一个 goal ID, 所以action client 能决定是否丢弃收到的feedback messages,发送feedback  message非强制是可选的。

3.2.5 result topic: Goal information upon completion

   result topic使用自动生成的ActionResult message (如actionlib/TestActionResult), 通过它server端实现者可以发送goal完成结果给client。 ActionResult也有一个 goal ID, 所以action client 能决定是否丢弃收到的result messages。 虽然result可以是empty message, 但在goal完成后是强制要求必须发送的。 因此,当server端goal状态机过渡到完成状态 (Rejected, Recalled, Preempted, Aborted, Succeeded)时,result message必须发送出去。

4 action server和action client状态机


箭头上的蓝色字是一些命令,server端user code也可以通过命令触发,白色的框由action server library自行切换。



 

renyanpeng@renyanpeng-Legion-R9000P-ARX8:~$ dpkg -l | grep ros-jazzy ii ros-jazzy-action-msgs 2.0.2-2noble.20241227.214418 amd64 Messages and service definitions common among all ROS actions. ii ros-jazzy-action-tutorials-cpp 0.33.5-1noble.20241227.232513 amd64 C++ action tutorial cpp code ii ros-jazzy-action-tutorials-interfaces 0.33.5-1noble.20241227.215054 amd64 Action tutorials action ii ros-jazzy-action-tutorials-py 0.33.5-1noble.20241227.231047 amd64 Python action tutorial code ii ros-jazzy-actionlib-msgs 5.3.5-1noble.20241227.215410 amd64 A package containing some message definitions used in the implementation of ROS 1 actions. ii ros-jazzy-actuator-msgs 0.0.1-4noble.20241227.215717 amd64 ROS 2 message interface for Actuators. ii ros-jazzy-ament-cmake 2.5.3-1noble.20241218.082541 amd64 The entry point package for the ament buildsystem in CMake. ii ros-jazzy-ament-cmake-auto 2.5.3-1noble.20241218.082855 amd64 The auto-magic functions for ease to use of the ament buildsystem in CMake. ii ros-jazzy-ament-cmake-copyright 0.17.1-1noble.20241218.082836 amd64 The CMake API for ament_copyright to check every source file contains copyright reference. ii ros-jazzy-ament-cmake-core 2.5.3-1noble.20241218.075647 amd64 The core of the ament buildsystem in CMake. ii ros-jazzy-ament-cmake-cppcheck 0.17.1-1noble.20241218.082921 amd64 The CMake API for ament_cppcheck to perform static code analysis on C/C++ code using Cppcheck. ii ros-jazzy-ament-cmake-cpplint 0.17.1-1noble.20241218.082938 amd64 The CMa
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值