Skip to content

ROS 2The ROS 2 Graph

Services and Actions

A topic streams, a service asks once and waits for one reply, and an action runs a long task with feedback and can be canceled.

Not started Jump to practice

Topics stream data. Sometimes a node needs to ask a question, or start a long job.

Key idea

A service is one request and one reply, like asking a question. An action is for long jobs: you send a goal, get steady feedback, receive a result, and can cancel along the way.
ToolPatternGood for
TopicStream, many listenersSensor data, robot state
ServiceAsk once, get one answer"Reset the odometry", "what is the map?"
ActionGoal, feedback, result, cancel"Drive to the kitchen", "move the arm there"

Why it works

Picking the right tool keeps the robot responsive. A service call to a two-minute job would leave the caller with no news and no way to stop it.

Worked example: Pick one

Dock to the charger, which takes about a minute, and let the user stop it.
  1. Long, needs progress and a way to stop.

Answer: An action.

Common mistake

Using a service for a long task, so the caller waits with no progress and cannot cancel.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of ROS 2 and Simulation.

Sources and further reading