Skip to main content

Services and Actions

This page compares services and actions conceptually, then walks through calling both from the command line using standard ROS 2 demo packages, so you can see the request/response and goal/feedback/result/cancel patterns in a real (if small) system.

Overview​

ROS 2 Concepts introduced services (synchronous request/response) and actions (asynchronous, goal-oriented, with feedback and cancellation) at a high level. Here you will call a real service and send a real action goal using packages commonly available in a desktop ROS 2 install, and see exactly what each part of an action interaction looks like on the wire.

Why It Matters​

Services and actions are easy to confuse from documentation alone. Seeing the actual CLI output — a service call that returns once, versus an action that streams feedback before returning a result — makes the distinction concrete and prevents modeling long tasks as services (which blocks) or one-shot queries as actions (which is unnecessary overhead).

Core Concepts​

Services at a Glance​

  • A service interaction consists of one request and one response. Multiple clients may call the same service.
  • A service uses a request/response interaction: each request produces one response. Clients may call a service synchronously or asynchronously.
  • Defined by a .srv file with a request section and a response section separated by ---.

Actions at a Glance​

  • An action interaction is organized around a goal. Multiple clients may send goals to the same action server, and the server determines how accepted goals are handled.
  • Defined by a .action file with three sections separated by ---: goal, result, and feedback.
  • The client can request cancellation of an in-progress goal. The server first accepts or rejects a goal request; an accepted goal can later succeed, abort, or be canceled.
AspectServiceAction
DurationShortPotentially long
Progress updatesNoneFeedback messages
CancellationNot supportedSupported
Built fromRequest/response over the middlewareTopics + services under the hood, exposed as one API
Typical useQuery or triggerNavigation, trajectory execution, long computations

:::info Not the same as "Arm Action" The term action on this page always means the ROS 2 communication primitive (goal/feedback/result/cancel). The Manipulation section's Arm Action page describes a workflow stage that typically uses this primitive internally (for example via control_msgs/action/FollowJointTrajectory), but the two terms are not interchangeable — see the callout in ROS 2 Concepts. :::

Hands-on Steps: Services​

The demo_nodes_cpp (or demo_nodes_py) package, commonly present on a desktop ROS 2 install, includes a simple addition service using example_interfaces/srv/AddTwoInts. If it is not installed, install it first:

sudo apt install ros-${ROS_DISTRO}-demo-nodes-cpp

Start the server in one sourced terminal:

ros2 run demo_nodes_cpp add_two_ints_server

In a second terminal, inspect and call it:

# Discover the service and its type
ros2 service list
ros2 service type /add_two_ints
ros2 interface show example_interfaces/srv/AddTwoInts

# Call it
ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 2, b: 3}"

Expected Result (Services)​

requester: making request: example_interfaces.srv.AddTwoInts_Request(a=2, b=3)

response:
example_interfaces.srv.AddTwoInts_Response(sum=5)

The call returns exactly once. There is no progress output while it runs, because it is not expected to take long.

Hands-on Steps: Actions​

The action_tutorials_cpp (or action_tutorials_py) package provides a small Fibonacci-sequence action server, using action_tutorials_interfaces/action/Fibonacci, and is commonly used to demonstrate the action pattern. If it is not installed, install it first:

sudo apt install ros-${ROS_DISTRO}-action-tutorials-cpp

Start the action server in one sourced terminal:

ros2 run action_tutorials_cpp fibonacci_action_server

In a second terminal, inspect and send a goal:

# Discover the action and its type
ros2 action list -t
ros2 interface show action_tutorials_interfaces/action/Fibonacci

# Send a goal and watch feedback and result
ros2 action send_goal --feedback /fibonacci action_tutorials_interfaces/action/Fibonacci "{order: 5}"

Expected Result (Actions)​

Sending goal:
order: 5

Goal accepted with ID: <uuid>

Feedback:
sequence: [0, 1, 1]

Feedback:
sequence: [0, 1, 1, 2]

Feedback:
sequence: [0, 1, 1, 2, 3]

Result:
sequence: [0, 1, 1, 2, 3, 5]

Goal finished with status: SUCCEEDED

Feedback arrives incrementally while the goal executes; the result arrives once at the end.

Cancellation is also part of the ROS 2 action protocol. An action client can explicitly request cancellation of an accepted goal, and the server determines whether that cancellation request is accepted.

Useful Commands​

# Services
ros2 service list -t
ros2 service type <service_name>
ros2 service call <service_name> <srv_type> "<yaml_args>"
ros2 interface show <package>/srv/<Type>

# Actions
ros2 action list -t
ros2 action info <action_name>
ros2 action send_goal [--feedback] <action_name> <action_type> "<yaml_goal>"
ros2 interface show <package>/action/<Type>

Common Problems​

  • ros2 service call waits without returning — waits without returning** — confirm that the expected server is running and responding. Use ros2 service list and ros2 service type <service_name> to verify the service. If the request YAML is invalid, the CLI normally reports a parsing or type error instead.
  • ros2 action send_goal reports that a goal was rejected — the action server chose not to accept the goal. Goal-acceptance rules are defined by the server implementation; check the server logs for details.
  • No feedback ever prints — you forgot --feedback on ros2 action send_goal, or the server does not publish feedback for this goal type.
  • Package 'action_tutorials_cpp' not found — install it with apt as shown above; it is a standard demo package but is not always included in minimal installs.
  • Type mismatch errors when calling a service/action — the package or type name does not match exactly what the server expects. See Troubleshooting.

Key Takeaways​

  • Services are for quick request/response interactions and provide no progress feedback or cancellation.
  • Actions are designed for potentially long-running goals and support goal acceptance, feedback, results, and cancellation.
  • ros2 service call and ros2 action send_goal let you exercise both patterns entirely from the CLI, without writing a client.
  • "ROS 2 action" (this page) and "Arm Action" (a Manipulation workflow stage) describe different things, even though the latter commonly uses the former.

Next​

Continue to Parameters and Launch to make node behavior configurable, or revisit ROS 2 Concepts for the underlying vocabulary.