🤖
ROS2 Tutorial
Koki Muramoto
2025/9/21
About ROS2
This section provides a brief overview of key ROS 2 concepts: Nodes, Topics, Rviz2 (visualization tool), Services, Actions, and Rosbag2 (logging data).
Additionally, for systems using image or LiDAR sensors, you'll encounter other important concepts like Components, Interface, Lifecycle Management, and Gazebo.
Here we'll focus on the fundamental topics of Nodes, Topics, Services, and Actions.
Node
A Node is a computational process that forms part of a graph, communicating with other nodes through Topics, Services, Actions, and parameters. Best practice recommends allocating a single function to each node.
(Though in reality, this isn't always straightforward...) While conceptually similar to threading in mbed implementations like those used in Summer Robo projects, the two are technically different. (This is because nodes can also be processed in a multi-threaded manner.)
Each Node also has a unique node name. Additionally, you can use namespaces to hierarchically organize nodes.
This allows distinguishing between multiple instances of the same type of node—for example, /robot1/camera and /robot2/camera when configuring multiple robots.
Inter-node Communication and Grafical Structure
Before delving into specific communication methods, let's cover an overview of inter-node communication.
A ROS 2 system is configured as a network of interconnected nodes. Each node possesses the following four interfaces:
・Topics
・Services
・Actions
・Parameters
Through these interfaces, nodes exchange data. This enables communication between nodes even if they aren't directly connected—provided they share the same Topic name or Service name. This architecture achieves loose coupling in the system. For instance, replacing a camera node with a different manufacturer's version works seamlessly as long as the downstream image processing nodes receive messages via the same Topic names.
Topics
In ROS 2, Topics serve as publish/subscribe interfaces where nodes exchange messages. They are used to facilitate asynchronous data transfer between nodes. The primary types of data exchanged are continuous streams—often time-series related or sensor data.
Practical examples include images from RealSense cameras, LiDAR point cloud data, velocity commands, odometry, etc. The following GIF is taken from the official documentation to illustrate how communication works.
Rviz2
Short for Robot Visualizer 2, it's now officially called Rviz2. It can display standard message types provided by ROS.
It's primarily used for visualizing LiDAR data, self-positioning, and path planning rendering.
While you can create your own plugins to develop new visualizers, there are also excellent open-source visualization plugins like jsdk_visualizer that would be worth using.
Image and Example: Robot Sensor Position Display..
Point cloud visualization etc.
For usage guides on each component, please refer to the external articles below.
Service
Used for synchronous communication. It establishes a server-client relationship that guarantees reliable message delivery.
Server Receives requests, processes them, and returns responses
Client Sends requests and waits for responses
srv File Defines the data types (Request and Response) used in communications
Action
For asynchronous communication. When you need to monitor the progress of an ongoing process, you should implement Action servers—examples include movement to specified locations etc.
Server Receives requests, provides feedback during processing, then returns responses
Client Sends requests and waits for responses
Action File Defines the data types (Request, Feedback, and Response) used in communications
Below are the essential CLI utilities commonly used with ROS 2. As of October 2025, this information is current. Please update if anything is missing or outdated.
Setting up a ROS 2 environment
Initializes ROS 2 commands and registers CLI entry points. For now, you can think of these as necessary rituals.
source /opt/ros/jazzy/setup.bash
Registers the entry point for the repository containing your source code. This is optional if you're just starting out.
source ~/your_ws/install/setup.bash
ROS 2 Command Line Interface Topics (most frequently used)
Lists all currently visible topics through this CLI interface.
ros2 topic list
Displays the contents of data for a specified topic name.
ros2 topic echo <topic_name>
Sends data to a specified topic name.
ros2 topic pub <topic_name> <data_type> "<data_content>"
Reports the frequency of data reception for a given topic.
ros2 topic hz <topic_name>
Inspects the data type associated with a specified topic name.
ros2 topic info <topic_name>
Shows the actual contents of the data type for a specified topic.
ros2 interface show <data_type>
Displays the current bandwidth usage of a specified topic.
ros2 topic bw <topic_name>
Identifies which topics use a specific data type.
ros2 topic find <topic_name>
Nodes
Runs a node from a package
ros2 run <package_name> <executable_node_name>
Lists all currently running nodes.
ros2 node list
Parameter remapping
ros2 run <package_name> <executable_node_name> --ros-args --remap <original_value:=new_value>
Example:
ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
Displays information about a node's publishers, subscribers, services, and actions.
ros2 node info <node_name>
Service Management
Lists available service servers
ros2 service list
Adds the -t option to display service types as well.
ros2 service list -t
Displays the data type of a specific service server.
ros2 service type <service_name>
Shows information about a specified service, returning both the client name and service name.
ros2 service info <service_name>
Identifies which services implement a given service type.
ros2 service find <service_type_name>
Invokes a specified service.
ros2 service call <service_name> <service_type> <data_content_for_invocation>
Parameters
Lists all parameters and their configurations for a given node.
ros2 param list
Retrieves the value for a specified parameter name within a given node.
ros2 param get <node_name> <parameter_name>
Sets the value of a specified parameter to a desired value within a specific node.
ros2 param set <node_name> <parameter_name> <value_to_set>
Displays all parameters configured for a specific node.
ros2 param dump <node_name>
As a convenience, you can also export these as yaml files. For example:
ros2 param dump /turtlesim > turtlesim.yaml
Applies parameter values from a configuration file to specified nodes.
ros2 param load <node_name> <path_to_parameter_file>
Configures parameters at runtime using a parameter configuration file.
ros2 run <package_name> <executable_node_name> --ros-args --params-file <file_path>
Actions
Lists running action servers
ros2 action list
Inspects the action type for a specific action server (client).
ros2 action type <action_server_name>
Displays information about both the action server and client that handle a specified action.
ros2 action info <action_name>
Invokes a specified action server.
ros2 action send_goal <action_name> <action_type> <data_content_for_invocation>
Checks the definition for a specific action type.
ros2 interface show <type_name>
Useful Commands
Returns a list of available runnable entry points.
ros2 pkg executables <package_name>
Allows you to check registered package names. Note: If you're in a development workspace and have forgotten to source, this command won't display package names properly.
ros2 pkg list
ROS 2 Package Creation Command
We strongly recommend referencing the following guide:
https://qiita.com/naga-karupi/items/f7e1dc4cfe65e5783181
ros2 pkg create <package_name> --dependencies <dependent_packages> --node-name <node_name> --build-type ament_cmake or ament_python --library-name <library_name>