ROS actionlib

  actionlib是ROS中一个很重要的功能包集合,尽管在ROS中已经提供了srevice机制来满足请求—响应式的使用场景,但是假如某个请求执行时间很长,在此期间用户想查看执行的进度或者取消这个请求的话,service机制就不能满足了,但是actionlib可满足用户这种需求。例如,控制机器人运动到地图中某一目标位置,这个过程可能复杂而漫长,执行过程中还可能强制中断或反馈信息,这时actionlib就能大展伸手了。

client-server

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

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

action Interface

  ROS Messages:

  • goal - Used to send new goals to servers. 代表一个任务,可以被ActionClient发送到ActionServer。

  • cancel - Used to send cancel requests to servers.

  • status - Used to notify clients on the current state of every goal in the system.

  • feedback - Used to send clients periodic auxiliary information for a goal. 服务端定期告知Client当前Goal执行过程中的情况。

  • result - Used to send clients one-time auxiliary information upon completion of a goal.

ROS系统在action文件(文件名后缀为.action)中定义了上述goal、result、feedback等消息。

SimpleActionServer类

SimpleActionServer类的构造函数有多种重载形式:

SimpleActionServer(std::string name, ExecuteCallback execute_callback, bool auto_start)
SimpleActionServer(std::string name, bool auto_start)
SimpleActionServer(ros::NodeHandle n, std::string name, ExecuteCallback execute_callback, bool auto_start) 
SimpleActionServer(ros::NodeHandle n, std::string name, bool auto_start)

Server State Transitions

Goals请求由ActionClient发出,ActionServer接收后会创建一个有限状态机来跟踪goal的状态:  

  goal状态的转变主要由server端程序发起,可以使用下面一系列的命令:

  • setAccepted - After inspecting a goal, decide to start processing it.

  • setRejected - After inspecting a goal, decide to never process it because it is an invalid request (out of bounds, resources not available, invalid, etc).

  • setSucceeded - Notify that goal has been successfully processed.

  • setAborted - Notify that goal encountered an error during processsing, and had to be aborted.

  • setCanceled - Notify that goal is no longer being processed, due to a cancel request.

  客户端也能异步发起状态转变:

  • CancelRequest: The client notifies the action server that it wants the server to stop processing the goal.

  状态机有下面多种状态:

  中间状态:

  • Pending - The goal has yet to be processed by the action server

  • Active - The goal is currently being processed by the action server

  • Recalling - The goal has not been processed and a cancel request has been received from the action client, but the action server has not confirmed the goal is canceled

  • Preempting - The goal is being processed, and a cancel request has been received from the action client, but the action server has not confirmed the goal is canceled

  最终状态:

  • Rejected - The goal was rejected by the action server without being processed and without a request from the action client to cancel

  • Succeeded - The goal was achieved successfully by the action server

  • Aborted - The goal was terminated by the action server without an external request from the action client to cancel

  • Recalled - The goal was canceled by either another goal, or a cancel request, before the action server began processing the goal

  • Preempted - Processing of the goal was canceled by either another goal, or a cancel request sent to the action server

参考资料

http://wiki.ros.org/actionlib_tutorials/Tutorials

https://blog.csdn.net/luohuiwu/article/details/96484081

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

abcwoabcwo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值