ROS 2 Core Architecture and Sensor Integration: From Node Design to Migrating from ROS 1
A practical guide to ROS 2's node-based architecture, communication primitives, and key differences from ROS 1. Learn how to integrate ToF depth sensors, IMUs, and motor controllers, and how to plan a smooth migration path between the two frameworks.
Why Robot Software Frameworks Matter
A robot system is essentially a tightly coupled combination of hardware and software. It must process multiple sensor streams, execute real-time motion control, perform path planning and decision-making, and remain stable and safe over long operating periods. Traditional embedded development typically bundles all of these functions into a single monolithic program. As features accumulate, the code becomes bloated and hard to maintain, and even a minor change can trigger unpredictable cascading failures.
Robot software frameworks fundamentally change this situation. They are not operating systems in the traditional sense, but middleware layers running on top of the host OS, providing shared infrastructure for robot software development. The core idea is to decompose complex robot functionality into independent, reusable, independently executable modules that collaborate through well-defined communication protocols. This modular design reduces the complexity of each module, allows teams to develop different features in parallel, and lets any module be replaced or upgraded individually—substantially improving development efficiency and system robustness.
Inside ROS 2: Architecture and Communication
1. Nodes: The Smallest Unit of Execution
In ROS 2, the node is the basic building block of the system. A node is typically an independently running process responsible for a single specific task. For example, an intelligent mobile robot project might include a LiDAR data acquisition node, an odometry node, a path planning node, and a motor control node. Each node can be started and stopped independently, providing fault isolation—a crash in one node does not bring down the entire system.
Nodes are loosely coupled and can even be written in different programming languages. As long as they follow the same interface conventions, they communicate seamlessly. This design resembles microservice architecture and provides a solid foundation for building large, distributed robot systems.
2. Topics, Services, and Actions
To meet diverse data-exchange requirements, ROS 2 provides three complementary communication primitives.
Topic communication is an asynchronous publish/subscribe model for continuous data streams. Take sensor data distribution as an example: a time-of-flight (ToF) depth camera driver node continuously publishes depth images to a topic such as /depth_image, while SLAM, obstacle detection, and 3D reconstruction nodes simply subscribe to that topic to receive the stream in real time. This one-to-many, many-to-many pattern greatly increases flexibility—publishers don’t need to know how many subscribers exist, and subscribers don’t need to know where the data comes from.
Service communication suits synchronous request/response interactions, using a client/server model. For instance, a robot dispatch system can expose a “grasp target object” service. When the robotic arm control node needs to execute a task, it sends a request containing the target object’s type and position, and the server returns the result once execution completes. The synchronous nature of services guarantees deterministic behavior, making them ideal for control commands that require immediate feedback.
Action communication is designed for long-running tasks that may need to be cancelled. For example, when a mobile robot navigates, the action client (the task initiator) sends goal coordinates to the action server (the navigation executor). After accepting the goal, the action server continuously reports progress—distance traveled, current speed, estimated remaining time—while the client can send a cancel request at any time. This goal–feedback–result model provides strong support for real-time monitoring and intervention in complex tasks.
3. Lifecycle Nodes and Dynamic Management
In complex scenarios, systems need to load and unload functional modules dynamically, making lifecycle management essential. By introducing an explicit state machine, ROS 2 lets nodes transition between states such as unconfigured, inactive, active, and finalized. This enables runtime loading of new algorithm plugins, parameter reconfiguration, or safe shutdown of outdated modules—crucial for long-running, adaptable systems.
ROS 1 vs. ROS 2: Architectural Differences and Migration Path
The evolution from ROS 1 to ROS 2 is more than a version bump—it is a comprehensive architectural upgrade aimed at meeting modern requirements for real-time performance, security, and large-scale deployment.
1. From Centralized to Distributed
ROS 1 relies on a centralized ROS Master: node discovery, topic registration, and parameter management all depend on this central node. The architecture is simple and intuitive but carries a single point of failure—if the master crashes, the entire system goes down.
ROS 2 eliminates the master entirely, adopting a fully distributed architecture based on the Data Distribution Service (DDS). Every node has service discovery capability and can establish logical connections directly with peers, with no intermediary. This decentralized design removes the single point of failure, improves overall reliability, and adapts to more complex network topologies.
2. Communication Quality and Real-Time Guarantees
In industrial automation and autonomous driving, transmission latency directly affects safety. ROS 1’s communication, built on TCP/UDP, lacks quality-of-service (QoS) controls and may suffer delays or data loss under heavy load.
ROS 2, built on the DDS standard, makes QoS a core feature. Developers can precisely configure reliability (whether message loss is acceptable), message priority, data freshness (history depth), and durability according to the application. For example, safety-critical control commands can use a “high reliability, strict ordering, low latency” policy, while sensor point cloud streams can use a “tolerate some loss, prioritize low latency” policy. This flexible resource scheduling lets ROS 2 serve everything from research labs to industrial environments.
3. Security and Cross-Platform Support
Industrial applications demand strong network security. ROS 1 has no built-in encryption or authentication, relying entirely on network isolation—risky in open environments. ROS 2 integrates the DDS-Security specification into the communication layer, providing end-to-end authentication, access control lists, and encrypted data transfer, safeguarding confidentiality, integrity, and availability at the foundation level.
ROS 1 primarily runs on Linux, with limited support for resource-constrained embedded systems and Windows. ROS 2 abstracts the communication layer to support more operating systems: developers can build host-side UIs on Windows, run motion control algorithms on real-time operating systems, and deploy sensor drivers on low-power embedded chips—well suited to heterogeneous computing platforms.
4. Build Systems and Ecosystem
ROS 1 uses Catkin, whose steep learning curve has long been a barrier for beginners. ROS 2 uses the Ament build system, which offers cleaner package management and noticeably faster builds. ROS 2 also unifies the build workflow for Python and C++ packages, reducing maintenance costs in multi-language projects.
Note that ROS 1 and ROS 2 are not directly compatible. During migration, ROS 1 nodes cannot communicate directly with ROS 2 nodes. However, dedicated bridge components can forward messages between the two, helping existing systems transition smoothly to the new platform.
Integrating Common Sensors and Actuators
On the hardware side, ROS 2 simplifies integration through standardized driver interfaces and a rich ecosystem of third-party libraries. The three device types below are the most common hardware modules in intelligent mobile robots.
1. ToF Depth Sensor Integration
ToF depth sensors play an important role in modern robot vision. By measuring the flight time of light pulses, they compute distances to objects and generate high-precision 3D point clouds, unaffected by ambient lighting.
When integrating such a sensor, the driver node’s first task is low-level data parsing. Sensors typically output RAW depth data over MIPI or USB interfaces, and the driver node must convert it into ROS 2’s standardized point cloud message format. Even more critical: loading camera intrinsics and publishing coordinate frame transforms must be accurate, otherwise downstream obstacle avoidance and mapping algorithms cannot produce physically meaningful results. The driver node can publish raw depth images and point clouds simultaneously over topics for multiple algorithm nodes to subscribe to.
2. IMU Data and Fusion
An inertial measurement unit (IMU) measures three-axis acceleration and angular velocity, serving as a core sensor for attitude estimation and dead-reckoning navigation. The driver node must not only read and parse the data but also perform noise filtering and bias correction.
In practice, raw IMU data alone rarely meets navigation accuracy requirements. The driver layer should apply fusion algorithms such as Kalman filtering and output attitude quaternions as results. Since IMU data is published at high rates, the driver node must set appropriate topic queue depths and QoS policies to avoid message congestion or data loss at high data rates.
3. Motor Control Nodes
Motor control is the key execution layer for robot motion, involving closed-loop regulation of the current (servo) loop, velocity loop, and position loop. A ROS 2 node typically acts as the host-side controller, sending motion commands to firmware on the motor driver board via serial, CAN, or EtherCAT.
In this structure, the motor control node receives high-level velocity commands from navigation algorithms, converts them into concrete current or voltage control values, and sends them to the hardware. It also periodically reads encoder feedback as the input signal for closed-loop control. For multi-axis systems requiring precise synchronization, the node should use DDS time synchronization to ensure commands reach all axes simultaneously, preventing uneven mechanical stress.
4. Multi-Sensor Time Synchronization and Fusion
In multi-sensor fusion systems, time synchronization is a prerequisite for valid data. Because sensors have different output frequencies and transmission delays, simply stacking data often leads to incorrect conclusions. Using ROS 2’s time synchronization facilities in its distributed architecture, developers can approximately align data from different topics using header timestamps, accurately reconstructing the environment’s state at a given physical moment. This capability is especially critical for building accurate, consistent perception models in high-speed motion scenarios.
Putting It into Practice and Looking Ahead
With these core components, development teams can build a complete, efficient robot development workflow. Whether it’s a differential-drive robot for research and education or an autonomous mobile robot (AMR) for complex industrial environments, ROS 2 demonstrates strong adaptability.
In practice, a typical workflow looks like this: first, define communication interfaces suited to the project’s needs; second, develop reusable hardware driver modules and algorithm components; third, use containerization to package the runtime environment, ensuring consistent deployment across machines; and finally, monitor system status in real time with visualization tools and continuously tune node parameters based on log data.
As robot applications evolve toward richer, more intelligent scenarios, ROS 2—now a cornerstone framework of open-source robotics—continues to absorb advanced concepts including real-time computing, cloud collaboration, and edge intelligence. Its strengths in multi-robot coordination, heterogeneous computing, and AI integration will be a key accelerant for deploying the next generation of intelligent robots at scale. For developers, mastering ROS 2’s core mechanisms and migrating to the new architecture early is a crucial step toward staying competitive in future intelligent systems development.
