For Robotics Students: Understanding Nodes, Topics, Services and Actions in ROS 2
A ROS 2 system is a graph of nodes that talk to each other in three ways. Topics carry continuous data streams such as sensor readings. Services handle quick request/response calls. Actions handle long-running tasks that send feedback and can be canceled. On top of that, tf2 keeps track of where every coordinate frame of the robot is over time. If you understand these five ideas, you can read almost any ROS 2 codebase.
This guide is for students in a robotics course, members of a college competition team, or anyone teaching themselves ROS 2. Definitions and commands come from the official ROS 2 Lyrical Luth documentation (the current LTS), which you can also query directly in the ROS 2 knowledge base.
Nodes: one job per node
The documentation defines a node as a participant in the ROS 2 graph that uses a client library to communicate with other nodes. Nodes are typically the unit of computation, and each node should do one logical thing. One node reads a lidar, another plans a path, a third drives the motors. Nodes can run in the same process, in different processes, or on different machines. They find each other through a distributed discovery process.
A real node is often several things at once: a publisher, a subscriber, a service server or client, and an action server or client. It can also expose parameters to change its behavior at run time. You start a node by running an executable from a package with ros2 run <package_name> <executable_name>, for example ros2 run turtlesim turtlesim_node. The executable name is not always the same as the node name on the graph, and ros2 node list shows the actual node names (here, /turtlesim).
Parameters deserve a quick note because they show up in every real project. ros2 param list shows the parameters of the running nodes, and ros2 param get <node_name> <parameter_name> reads one value. Lyrical adds two conveniences. ros2 param get <param name> with no node name reads that parameter from all nodes, which is handy for checking that every node uses simulated time. And a single ros2 param get or ros2 param set call can now handle several parameters on one node.
Topics: continuous data streams
Topics are for continuous data such as sensor data and robot state. The docs describe ROS 2 as a strongly-typed, anonymous publish/subscribe system. Each part of that phrase matters:
- Publish/subscribe: publishers and subscribers find each other through a shared topic name. A topic can have zero or more of each, and every subscriber receives what any publisher sends.
- Anonymous: a subscriber does not generally know or care which publisher sent the data, so you can swap nodes without touching the rest of the system.
- Strongly typed: every field has a type that is enforced, so publishers and subscribers must agree on the message type.
To try it with turtlesim, run ros2 topic list -t to see each topic with its type in brackets. Then run ros2 topic echo /turtle1/cmd_vel while you drive the turtle with ros2 run turtlesim turtle_teleop_key. ros2 topic info /turtle1/cmd_vel shows how many publishers and subscriptions are connected.
Services: ask a question, get an answer
A service is a remote procedure call. One node asks another to compute something and waits for the result. The docs say services are expected to return quickly, and they should never be used for long-running processes. Good examples are querying the state of a node or doing a quick calculation such as inverse kinematics. There should only ever be one service server per service name, but any number of clients can use it.
With turtlesim running, ros2 service list -t lists the services and their types. ros2 service call /clear std_srvs/srv/Empty clears the drawing, and ros2 service call /spawn turtlesim_msgs/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}" adds a second turtle.
Actions: long tasks with feedback
An action is a long-running remote procedure call with feedback and the ability to cancel or preempt the goal. The docs use the example of a state machine telling the navigation subsystem to drive to a waypoint, which can take seconds or minutes. Along the way the navigation subsystem reports progress, and the caller can cancel. An action definition has three sections: goal, result and feedback. As with services, there should be only one action server per action name.
In turtlesim, ros2 action list -t shows /turtle1/rotate_absolute with type turtlesim_msgs/action/RotateAbsolute. Send a goal with ros2 action send_goal /turtle1/rotate_absolute turtlesim_msgs/action/RotateAbsolute "{theta: 1.57}". Add --feedback to see the remaining rotation as the turtle turns. The theta value is an absolute heading in radians, not a relative turn.
Which interface should I use? (summary of the ROS 2 docs)
| Interface | Use it for | Example from the docs |
|---|---|---|
| Topic | Continuous data streams, many-to-many | Sensor data, robot state |
| Service | Quick request/response that terminates fast | Querying a node's state, an IK calculation |
| Action | Long-running, preemptable behavior with feedback | Driving to a waypoint, slow perception routines |
tf2: where is everything right now?
Robots have many 3D coordinate frames that move over time: a world frame, a base frame, a gripper frame, a head frame. The docs describe tf2 as the transform library, which lets the user keep track of multiple coordinate frames over time. It stores the frames in a tree buffered in time and lets you transform points and vectors between any two frames at any point in time. It answers questions like “What is the pose of the object in my gripper relative to my base?”
To see it work, install the demo (on Ubuntu: sudo apt-get install ros-lyrical-rviz2 ros-lyrical-turtle-tf2-py ros-lyrical-tf2-ros ros-lyrical-tf2-tools ros-lyrical-turtlesim). Then run ros2 launch turtle_tf2_py turtle_tf2_demo.launch.py. A second turtle follows the one you drive, using a world, a turtle1 and a turtle2 frame. ros2 run tf2_tools view_frames writes the frame tree to frames.pdf (Linux only), and ros2 run tf2_ros tf2_echo world turtle1 prints a transform live.
Publishing a fixed transform without writing a node
Static transforms describe parts that don't move relative to each other, such as a camera bolted to a chassis. The tutorial notes that you shouldn't have to write this code yourself, because tf2_ros ships an executable for it:
- Euler angles: ros2 run tf2_ros static_transform_publisher --x 0 --y 0 --z 1 --yaw 0 --pitch 0 --roll 0 --frame-id world --child-frame-id mystaticturtle publishes a 1 meter offset in z, with no rotation, between world and mystaticturtle.
- Quaternion: the same transform can be written with --qx 0 --qy 0 --qz 0 --qw 1 instead of yaw/pitch/roll.
- Axes: in ROS 2, roll, pitch and yaw are rotations about the x, y and z axes respectively.
- Launch files: the tool works on the command line and as a node inside launch files.
A 30-minute practice plan
1) Start turtlesim and the teleop node, then run ros2 node list. 2) Echo /turtle1/cmd_vel while driving. 3) Call /spawn. 4) Send a rotate_absolute goal with --feedback. 5) Run the tf2 demo and open frames.pdf. You will have used all four interface types and tf2 in one sitting.
Ask the official ROS 2 docs your homework-style questions
Kopik's ROS 2 base indexes the Lyrical Luth concepts and tutorials and answers with the exact passage it used. Try “What is tf2 actually for?” or “How do I just publish a fixed, unmoving transform between two frames without writing my own node?”
You can browse other expert bases in the catalog. The ROS 2 base sticks to the core documentation and does not cover higher-level stacks such as Nav2 or MoveIt 2.
Frequently asked questions
What is the difference between a topic and a service in ROS 2?
Topics are for continuous data streams with any number of publishers and subscribers. Services are remote procedure calls for a single, quick request with a response, served by one service server per service name.
When should I use an action instead of a service?
Use an action for anything long-running or that moves the robot, especially when you need feedback or the ability to cancel. The docs say services should never be used for long-running processes.
What is tf2 used for in ROS 2?
tf2 keeps track of multiple coordinate frames over time in a tree buffered in time, and transforms points, vectors and poses between any two frames at any desired point in time.
How do I publish a static transform from the command line?
Use ros2 run tf2_ros static_transform_publisher with --x --y --z, either --yaw --pitch --roll or --qx --qy --qz --qw, and --frame-id and --child-frame-id.
Why does ros2 topic echo show nothing?
According to the tutorial FAQ, that is expected if nothing is publishing yet. echo waits for a publisher. Start turtle_teleop_key and move the turtle to see data appear.
What are the states of a ROS 2 lifecycle node?
The documentation names Unconfigured, Inactive, Active and Finalized, noting that the rclcpp_lifecycle::LifecycleNode class often includes functions for the transitions between these states.
Get the Kopik newsletter
New knowledge bases, RAG guides and product news. One email every week or two, unsubscribe in one click.
By subscribing you agree to receive our newsletter. We never share your address.