What is a node in ROS2?
Atlasbot · 16/8/2026 · 10 min read
If the package is a "source code encapsulation unit" then node is a "running unit" — a specific execution process, which does exactly one task throughout the robot system: read the data from a sensor, run the SLAM algorithm, or send commands down the motor.
Key concepts
A node is a program (usually written in Python or C++) that initializes the connection to ROS2, registers the publishers/subscribers/services it needs, and then runs an event loop (spin) to process incoming data. The ROS2 design philosophy encourages doing one thing well (Unix philosophy: "do one thing well") — rather than writing a massive program that does all, splits into many small nodes, is easy to debug, is easy to replace independently, and can be reused on another project.
A real-world AMR robot can run simultaneously: LiDAR node driver, IMU node driver, odometry node, SLAM node, Nav2 node (actually multiple subnodes on its own), motor control node — each is a separate process, which can restart one node without affecting the other.
In summary: The Node does not "contain" ROS2 — it only uses the ROS2 client library (
rclpy/rclcpp) to participate in the ROS graph, just as a normal program imports a library to use.
How it works
A minimal Python node — only initializes and "lives" until stopped (Ctrl + C):
import rclpy
from rclpy.node import Node
class MinimalNode(Node):
def __init__(self):
super().__init__('minimal_node') # node name shown in ROS graph
self.get_logger().info('Node đã khởi động')
def main():
rclpy.init()
node = MinimalNode()
rclpy.spin(node) # main loop — pending and event handling (message to, timer...)
rclpy.shutdown()
if __name__ == '__main__':
main()
rclpy.spin(node) is the most important — line that keeps the process alive and constantly checks for any events to process (new message on topic subscribed, timer firing, request service incoming...). Without calling spin() the initialized node will exit immediately, without any data being received in time.
Technical details
Parameters
Rules for naming valid nodes and namespaces in ROS2:
| Rules | Request |
|---|---|
| Allow characters | Characters, numbers, underscores — do not start with numbers |
| Namespace | Hierarchical prefixes, e.g., /robot1/lidar_node — use the sign / to stratify |
| Runtime Renaming (remap) | ros2 run pkg node_exe --ros-args -r __node:=ten_moi — without code editing |
Namespace is an important tool for running multiple copies of the same type of node (e.g. the same LiDAR code driver) without conflicting — names each copy just differs from the namespace.
Practical applications
In the AMR multiple robot management system (fleet), the same package driver/node is deployed to multiple robots, but each robot runs in its own namespace (e.g., /robot_01/, /robot_02/) — the same line of code self.get_logger().info(...) but when viewed on a central monitor, the data and logs of each robot are completely separated by the namespace, without writing code that distinguishes which robot is running right in the node logic.
Practical example
$ ros2 node list
Output:
/lidar_driver
/imu_driver
/odometry_publisher
/nav2_controller_server
$ ros2 node info /lidar_driver
Output:
/lidar_driver
Subscribers:
Publishers:
/scan: sensor_msgs/msg/LaserScan
/diagnostics: diagnostic_msgs/msg/DiagnosticArray
Service Servers:
/lidar_driver/get_parameters: rcl_interfaces/srv/GetParameters
Service Clients:
Action Servers:
Action Clients:
ros2 node info is the first diagnostic tool when 1 node is suspected to not be working properly — which tells exactly which node is publishing/subscribe topic, which service, which helps to quickly identify whether the problem lies in one node or in another node waiting to receive data from it.
Common mistakes
- Calling
rclpy.spin(node)— as stated in Operation Principles section, node initialization complete immediate exit, no time to process any message/timer — if node "disappears" immediately after run, check this line first. - Node name duplication when running multiple instances of the same type — 2 named nodes on the same system cause confusion when debugging through
ros2 node info(unknown instance view) — always uses namespace or name remap when running multiple copies. - Don't call
rclpy.shutdown()at the end, especially in— short-term test/scripts can cause a resource leak if the script initiates/hydronodes multiple times in the same process. - The blocking code inside the callback— default
rclpy.spin()runs single-threaded executor, a block callback (e.g.,time.sleep()long or pending I/O) will cause the entire node to "shape", and no other message/timer can be handled until the callback is completed — requiring the use of multi-threading or callback group (see separate article in the Advanced ROS2 section) if the task is long running.
Conclusion
The Node is the basic executable unit of every ROS2 — system that master the initialization/spin/shutdown life cycle and proper naming/namespace is the foundation before writing any publisher/subscriber. The next article in the column is about the Topic — the most common channel that nodes use to exchange data with each other.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.