ROS动作actionlib中ActionServer和ActionClient的状态机

本文件是讲解actionlib的内部运作机制,对想进一步应用actionlib的用户有帮助,特别是简单的例程已无法满足需求的用户!

Part1:Action Service

ROS动作actionlib中ActionServer和ActionClient的状态机

 

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.

以上命令具体到代码段,以navigation/move_base/src/move_base.cpp为例:

as_->setAborted(move_base_msgs::MoveBaseResult(), "Aborting on goal because it was sent with an invalid quaternion");
//将move_base的结果状态status置为Aborted,并且设置text内容为Aborting on goal because it was sent with an invalid quaternion,反馈Aborted的原因;



 as_->setSucceeded(move_base_msgs::MoveBaseResult(), "Goal reached.");
//将move_base的结果状态status置为Succeeded,并且设置text内容为Goal reached.;

状态机有下面多种状态:

  中间状态:

  • 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

在程序中各种状态的值:actionlib_msgs/GoalStatus.msg

 

uint8 PENDING         = 0   # The goal has yet to be processed by the action server
uint8 ACTIVE          = 1   # The goal is currently being processed by the action server
uint8 PREEMPTED       = 2   # The goal received a cancel request after it started executing
                            # and has since completed its execution (Terminal State)
uint8 SUCCEEDED       = 3   # The goal was achieved successfully by the action server 
                            # (Terminal State)
uint8 ABORTED         = 4   # The goal was aborted during execution by the action server 
                            
                            # due  to some failure (Terminal State)
uint8 REJECTED        = 5   # The goal was rejected by the action server without being 
                              
                            # because the goal was unattainable or invalid (Terminal 
                              State)
uint8 PREEMPTING      = 6   # The goal received a cancel request after it started executing
                            #    and has not yet completed execution
uint8 RECALLING       = 7   # The goal received a cancel request before it started executing,
                            #    but the action server has not yet confirmed that the goal is canceled
uint8 RECALLED        = 8   # The goal received a cancel request before it started executing
                            #    and was successfully cancelled (Terminal State)
uint8 LOST            = 9   # An action client can determine that a goal is LOST. This should not be
                            #    sent over the wire by an action server

ROS Messages中/move_base/status可以反馈以上所有状态,但是/move_base/result只会反馈最终状态!

 

Part2:Action Client

在actionlib中,我们将服务器状态机作为主机,然后将客户端状态机作为试图跟踪服务器状态的辅助/耦合状态机:

ROS动作actionlib中ActionServer和ActionClient的状态机

服务器触发状态转换:

  • Reported [State]: Since the client is trying to track the server's state, most transitions are triggered by the server reporting its state to the ActionClient.
  • Receive Result Message: In this case, the server sends a result message to the client. Receiving a result will always signal the end of tracking a goal.

客户端触发状态转换:

 

  • Cancel Goal: Request the server to stop processing this goal

 

注意:在SimpleAction中,多个client可以连接一个service,第二个客户端可以取消goal时,会取消第一个客户端创建的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

  

 

 

 

 

 

参考文献:

actionlib/DetailedDescription 

http://library.isr.ist.utl.pt/docs/roswiki/actionlib(2f)DetailedDescription.html

actionlib_msgs/GoalStatus Message

http://docs.ros.org/kinetic/api/actionlib_msgs/html/msg/GoalStatus.html

ros actionlib多客户端加单服务器的同步问题

https://blog.****.net/goodchoes/article/details/51043554

ROS actionlib学习(三)

https://www.cnblogs.com/21207-iHome/p/8304658.html