When should I use topics vs services vs actionlib actions (vs dynamic_reconfigure)?
Please help in writing up a ROS best practice.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Please help in writing up a ROS best practice.
Topics should be used for continuous data streams (sensor data, robot state, ...).
Services should be used for remote procedure calls that terminate quickly, e.g. for querying the state of a node or doing a quick calculation such as IK. They should never be used for longer running processes, in particular processes that might be required to preempt if exceptional situations occur and they should never change or depend on state to avoid unwanted side effects for other nodes.
Actions should be used for everything that moves the robot or that runs for a longer time such as perception routines that are triggered by some node and need a couple of seconds to terminate. The most important property of actions is that they can be preempted and preemption should always be implemented cleanly by action servers. Another nice property of actions is that they can keep state for the lifetime of a goal, i.e. if executing two action goals in parallel on the same server, for each client a separate state instance can be kept since the goal is uniquely identified by its id.
This has been added to ROS/Patterns here: http://www.ros.org/wiki/ROS/Patterns/Communication#Communication_via_Topics_vs_Services_vs_X...
First one should differentiate between topics and service/actionlib.
Topics: Continuous data flow. Data might be published and subscribed at any time independent of any senders/receivers. Many to many connection. Callbacks receive data once it is available. The publisher decides when data is sent.
Service/Actionlib: On-demand connection for one specific task. Service calls/Actionlib tasks are processed when the client decides to request so. Tasks take time to complete.
Service/Actionlib are thus very similar and can actually be used interchangeably in their functionality. However, they serve different purposes:
Service: Simple blocking call. Mostly used for comparably fast tasks as requesting specific data. Semantically for processing requests.
Actionlib: More complex non-blocking background processing. Used for longer tasks like execution of robot actions. Semantically for real-world actions.
This has been added to ROS/Patterns here: http://www.ros.org/wiki/ROS/Patterns/Communication#Communication_via_Topics_vs_Services_vs_X...
I've been wondering the same. I would borrow network terminologies. Correct me if wrong:
topic
- UDP broadcast (any node can receive, no connection b/w server established)service
- TCP broadcast (any node can receive, connection b/w server established)actionlib
- TCP multicast (node needs special assignments to receive, connection b/w server established)This is the best answer I found. http://answers.ros.org/question/24999...
Asked: 2011-11-07 11:37:43 -0600
Seen: 37,437 times
Last updated: Sep 06 '12