common: actionlib | bfl | filters | nodelet | nodelet_topic_tools | nodelet_tutorial_math | pluginlib | tinyxml | xacro | yaml_cpp

Package Summary

The actionlib package provides a standardized interface for interfacing with preemptible 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.

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.

Detailed Description

For a full discussion of how actionlib operates "under the hood", please see the Detailed Description.

Client-Server Interaction

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.

client_server_interaction.png

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 an action specification. This defines the Goal, Feedback, and Result messages with which clients and servers communicate:

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).

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.

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.

.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 (---).

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 looks 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 need to be generated in order for the client and server to communicate. This generation can be automatically triggered during the make process by adding the following to your CMakeLists.txt file.

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

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

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

Note that this must be called before rosbuild_init(). Additionally, the package's manifest.xml must include the following dependency:

<depend package="actionlib_msgs"/>

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

  • DoDishesAction.msg

  • DoDishesActionGoal.msg

  • DoDishesActionResult.msg

  • DoDishesActionFeedback.msg

  • DoDishesGoal.msg

  • DoDishesResult.msg

  • DoDishesFeedback.msg

These messages are then used internally by actionlib to communicate between the ActionClient and ActionServer.

And, as always, you're still going to have to generate messages:

rosbuild_genmsg()

Using the ActionClient

C++ SimpleActionClient

Full API Reference for the C++ SimpleActionClient

Quickstart Guide:
Suppose you have defined DoDishes.action in the chores package. The following snippet shows how to send a goal to a DoDishes ActionServer called "do_dishes".

   1 #include <chores/DoDishesAction.h>
   2 #include <actionlib/client/simple_action_client.h>
   3 
   4 typedef actionlib::SimpleActionClient<chores::DoDishesAction> Client;
   5 
   6 int main(int argc, char** argv)
   7 {
   8   ros::init(argc, argv, "do_dishes_client");
   9   Client client("do_dishes", true); // true -> don't need ros::spin()
  10   client.waitForServer();
  11   chores::DoDishesGoal goal;
  12   // Fill in goal here
  13   client.sendGoal(goal);
  14   client.waitForResult();
  15   if (client.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
  16     printf("Yay! The dishes are now clean")
  17   print("Current State: %s\n", client.getState().toString().c_str());
  18   return 0;
  19 }

Python SimpleActionClient

Full API reference for the Python SimpleActionClient

Suppose the DoDishes.action exists in the chores package. The following snippet shows how to send a goal to a DoDishes ActionServer called "do_dishes" using Python.

   1 #! /usr/bin/env python
   2 
   3 import roslib; roslib.load_manifest(PKG)
   4 import rospy
   5 import actionlib
   6 
   7 from chores.msg import *
   8 
   9 if __name__ == '__main__':
  10     rospy.init_node('do_dishes_client')
  11     client = actionlib.SimpleActionClient('do_dishes', DoDishesAction)
  12     client.wait_for_server()
  13 
  14     goal = DoDishesGoal()
  15     # Fill in the goal here
  16     client.send_goal(goal)
  17     client.wait_for_result()

Implementing an ActionServer

C++ SimpleActionServer

Full API Reference for the C++ SimpleActionServer

Quickstart Guide:
Suppose you have defined DoDishes.action in the chores package. The following snippet shows how to write a DoDishes ActionServer called "do_dishes".

   1 #include <chores/DoDishesAction.h>
   2 #include <actionlib/server/simple_action_server.h>
   3 
   4 typedef actionlib::SimpleActionServer<chores::DoDishesAction> Server;
   5 
   6 void execute(const chores::DoDishesGoalConstPtr& goal, Server* as)
   7 {
   8   // Do lots of awesome groundbreaking robot stuff here
   9   as->setSucceeded();
  10 }
  11 
  12 int main(int argc, char** argv)
  13 {
  14   ros::init(argc, argv, "do_dishes_server");
  15   ros::NodeHandle n;
  16   Server server(n, "do_dishes", boost::bind(&execute, _1, &server));
  17   ros::spin();
  18   return 0;
  19 }

Python SimpleActionServer

Full API Reference for the Python SimpleActionServer

Quickstart Guide:
Suppose you have defined DoDishes.action in the chores package. The following snippet shows how to write a DoDishes ActionServer called "do_dishes".

   1 #! /usr/bin/env python
   2 
   3 import roslib; roslib.load_manifest(PKG)
   4 import rospy
   5 import actionlib
   6 
   7 from chores.msg import *
   8 
   9 class DoDishesServer:
  10   def __init__(self):
  11     self.server = actionlib.SimpleActionServer('do_dishes', DoDishesAction, self.execute)
  12 
  13   def execute(self, goal):
  14     # Do lots of awesome groundbreaking robot stuff here
  15     self.server.set_succeeded()
  16 
  17 
  18 if __name__ == '__main__':
  19   rospy.init_node('do_dishes_server')
  20   server = DoDishesServer()
  21   rospy.spin()

Tutorials

Please refer to the Tutorials page

Wiki: actionlib (last edited 2010-07-15 16:48:10 by VijayPradeep)