VnRobo
AboutPricingBlogContact
🇻🇳VISign InStart Free Trial
🇻🇳VI
VnRobo logo

AI infrastructure for next-generation industrial robots.

Product

  • Features
  • Pricing
  • Knowledge Base
  • Services

Company

  • About Us
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 VnRobo. All rights reserved.

Made with♥in Vietnam
VnRobo
AboutPricingBlogContact
🇻🇳VISign InStart Free Trial
🇻🇳VI
  1. Home
  2. Blog
  3. Introduction to ROS 2: Next-Generation Robot Programming Framework
otherroboticsros2

Introduction to ROS 2: Next-Generation Robot Programming Framework

ROS 2 provides powerful distributed architecture, real-time support, and security — ideal for industrial and autonomous robots.

Nguyen Anh TuanJune 15, 20255 min readUpdated: Jun 16, 2026

What is ROS 2?

ROS 2 (Robot Operating System 2) is open-source framework completely redesigned from ROS 1, targeting commercial and industrial robot applications. Unlike ROS 1 which depends on central master node (roscore), ROS 2 uses DDS (Data Distribution Service) as middleware, enabling true distributed architecture.

Simple analogy: if ROS 1 is like telephone system needing central switchboard, ROS 2 is like internet — each node can communicate directly with others without needing "switchboard".

ROS 2 distributed architecture with DDS middleware
ROS 2 distributed architecture with DDS middleware

Why Switch to ROS 2?

1. Real-Time Support

ROS 2 built on DDS with flexible QoS (Quality of Service). Allows configuring reliability, latency, bandwidth for each topic separately — critical for industrial robot control.

Real example: When controlling welding robot arm, encoder data must arrive within 1ms. With ROS 2, set /joint_states topic to QoS profile RELIABLE + KEEP_LAST(1) for guaranteed delivery. Meanwhile, camera topic can use BEST_EFFORT since dropping few frames won't hurt.

2. Built-in Security

ROS 2 integrates SROS2 (Secure ROS 2) with TLS/DTLS encryption for inter-node communication. In factory network, this is mandatory when robots communicate over internal network.

Basic security setup:

# Create keystore and certificates for nodes
ros2 security create_keystore ~/sros2_keystore
ros2 security create_enclave ~/sros2_keystore /my_robot/camera_node
ros2 security create_enclave ~/sros2_keystore /my_robot/motor_node

# Activate security when running
export ROS_SECURITY_KEYSTORE=~/sros2_keystore
export ROS_SECURITY_ENABLE=true
export ROS_SECURITY_STRATEGY=Enforce

3. Multi-Platform Support

ROS 2 officially supports Ubuntu, Windows, and macOS. Develop on Windows laptop, deploy to ARM64 robot on Ubuntu without code changes. Major advantage over ROS 1 which only works well on Ubuntu.

4. Lifecycle Node Management

ROS 2 introduces Lifecycle Nodes — managing node state (Unconfigured → Inactive → Active → Finalized). Very important in production: configure all nodes beforehand, then activate simultaneously when robot ready.

from rclpy.lifecycle import Node as LifecycleNode

class CameraNode(LifecycleNode):
    def __init__(self):
        super().__init__('camera_node')

    def on_configure(self, state):
        # Initialize camera driver, load calibration
        self.camera = cv2.VideoCapture(0)
        self.get_logger().info('Camera configured')
        return TransitionCallbackReturn.SUCCESS

    def on_activate(self, state):
        # Start publishing frames
        self.timer = self.create_timer(0.033, self.publish_frame)
        return TransitionCallbackReturn.SUCCESS

    def on_deactivate(self, state):
        # Stop publishing, keep camera open
        self.destroy_timer(self.timer)
        return TransitionCallbackReturn.SUCCESS

Basic Architecture

Typical ROS 2 system has 4 communication primitives:

Primitive Description Use Case
Topic Async Pub/Sub Sensor data, robot state
Service Sync Request/Response Get parameter, trigger action
Action Goal + Feedback + Result Navigation, arm movement
Parameter Key-value runtime config Tune PID, change speed

Graph Concept

Each ROS 2 node is independent process. They communicate over DDS network without knowing each other's location — same machine or different machines work identically. Called location transparency.

# View entire current graph
ros2 node list
ros2 topic list
ros2 topic echo /scan  # See LiDAR data real-time

ROS 2 computation graph with nodes, topics and services
ROS 2 computation graph with nodes, topics and services

Getting Started with ROS 2 Humble

ROS 2 Humble Hawksbill is LTS version (support until 2027), suitable for production projects. Installation on Ubuntu 22.04:

# Add ROS 2 repository
sudo apt update && sudo apt install -y software-properties-common
sudo add-apt-repository universe
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

# Install
sudo apt update
sudo apt install ros-humble-desktop

# Source environment
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc

Create Workspace and First Package

# Create workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src

# Create Python package
ros2 pkg create --build-type ament_python my_robot_pkg --dependencies rclpy std_msgs

# Build
cd ~/ros2_ws
colcon build --symlink-install

# Source workspace
source install/setup.bash

Simple Publisher Node

# my_robot_pkg/my_robot_pkg/sensor_publisher.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import Float32

class SensorPublisher(Node):
    def __init__(self):
        super().__init__('sensor_publisher')
        self.publisher = self.create_publisher(Float32, '/temperature', 10)
        self.timer = self.create_timer(1.0, self.timer_callback)
        self.get_logger().info('Sensor publisher started')

    def timer_callback(self):
        msg = Float32()
        msg.data = self.read_temperature()
        self.publisher.publish(msg)

    def read_temperature(self):
        # Read from real sensor or simulate
        return 25.5

def main():
    rclpy.init()
    node = SensorPublisher()
    rclpy.spin(node)
    node.destroy_node()
    rclpy.shutdown()

ROS 2 Ecosystem

Real power of ROS 2 lies in package ecosystem:

  • Nav2 (Navigation2): Complete navigation stack for AMR — SLAM, path planning, obstacle avoidance
  • MoveIt2: Motion planning for robot arm — inverse kinematics, collision detection, trajectory optimization
  • ros2_control: Hardware abstraction layer — write controller once, run on any robot
  • Gazebo / Isaac Sim: Simulation — test code before running on real robot
  • micro-ROS: Run ROS 2 on microcontroller (ESP32, STM32) — connect embedded layer

ROS 1 vs ROS 2 Comparison

Criteria ROS 1 ROS 2
Middleware Custom (TCPROS) DDS (industry standard)
Master Node Required (roscore) Not needed
Real-Time Not supported QoS profiles
Security None SROS2 (TLS/DTLS)
Multi-Robot Difficult (namespace) Easy (DDS domain)
OS Ubuntu only Ubuntu, Windows, macOS
Lifecycle None Lifecycle nodes

Conclusion

ROS 2 has matured enough for production use. With rich ecosystem (Navigation2, MoveIt2, ros2_control), it's top choice for any robot project from research to commercial.

Next Steps:

  • Install ROS 2 Humble and try turtlesim demo
  • Read SLAM and Navigation to understand robot autonomy
  • Explore Micro-ROS for microcontroller integration
  • Learn Python robot control with ROS 2

Related Articles

  • SLAM and Navigation: How Robots Localize and Move
  • Micro-ROS: Connecting Microcontrollers to ROS 2 Ecosystem
  • LiDAR and 3D Mapping: Building Environment Maps for Robots
NT

Nguyễn Anh Tuấn

Robotics & AI Engineer. Building VnRobo — sharing knowledge about robot learning, VLA models, and automation.

Khám phá VnRobo

Fleet MonitoringROS 2 IntegrationAMR Solutions

Related Posts

Tutorial
Robotics
ros2roboticstutorial
other

Viết Hardware Interface cho ros2_control

Hướng dẫn tạo custom hardware interface — kết nối ros2_control với motor driver qua serial/CAN bus.

3/18/202610 min read
NT
Micro-ROS: Kết nối microcontroller với hệ sinh thái ROS 2
roboticsros2embedded
other

Micro-ROS: Kết nối microcontroller với hệ sinh thái ROS 2

Micro-ROS cho phép chạy ROS 2 trên microcontroller như ESP32 và STM32, mở rộng hệ sinh thái ROS 2 xuống tầng embedded.

9/15/20254 min read
NT
Tutorial
Robotics
ros2monitoringrobot-fleet
other

Cách giám sát robot ROS 2 từ xa: Hướng dẫn đầy đủ 2026

Hướng dẫn từng bước giám sát robot ROS 2 từ bất kỳ đâu — pin, CPU, trạng thái, heartbeat, alerts. Code chạy được, setup 10 phút. Miễn phí 3 robots.

4/14/20267 min read
NT
VnRobo logo

AI infrastructure for next-generation industrial robots.

Product

  • Features
  • Pricing
  • Knowledge Base
  • Services

Company

  • About Us
  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 VnRobo. All rights reserved.

Made with♥in Vietnam