Skip to content

ROS 2

Practical

ROS 2 (Robot Operating System 2) is an open-source robotics middleware that provides tools, libraries, and conventions for building robot applications. Despite its name, it’s not an operating system but a framework that runs on top of Linux (primarily), Windows, and macOS.

Why ROS 2?

ROS 2 addresses limitations of ROS 1 for production robotics:

AspectROS 1ROS 2
CommunicationCustom (TCPROS)DDS (industry standard)
Real-timeNot supportedSupported
SecurityNone built-inDDS Security
Multi-robotDifficultNative support
PlatformsLinux onlyLinux, Windows, macOS, RTOS
LifecycleNoneManaged node lifecycle

Core Concepts

Nodes

Independent processes that perform computation. A robot typically runs many nodes:

┌─────────┐ ┌──────────┐ ┌─────────┐ ┌──────────┐
│ Camera │ │ SLAM │ │ Planner │ │ Controller│
│ Node │ │ Node │ │ Node │ │ Node │
└─────────┘ └──────────┘ └─────────┘ └──────────┘

Topics

Publish/subscribe messaging for streaming data:

Camera Node ──► /camera/image ──► SLAM Node
Image Viewer

Services

Request/response for synchronous operations:

Client ──► /get_map (Request) ──► Server
◄── Map Data (Response) ◄──

Actions

For long-running tasks with feedback:

Client ──► /navigate_to_pose ──► Action Server
◄── Progress Feedback ◄──
◄── Final Result ◄──────

Architecture

┌─────────────────────────────────────────────────────────────────┐
│ Your ROS 2 Application │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ rclcpp │ │ rclpy │ │ Other Clients │ │
│ │ (C++ API) │ │(Python API) │ │ (Rust, Java, etc.) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ RCL (ROS Client Library) │
├─────────────────────────────────────────────────────────────────┤
│ RMW (ROS Middleware Interface) │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ FastDDS │ │ CycloneDDS │ │ Zenoh, Other Impls │ │
│ │ (Default) │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

Getting Started

  1. Set up sources

    Terminal window
    sudo apt update && sudo apt install -y software-properties-common
    sudo add-apt-repository universe
    sudo apt update && sudo apt install curl -y
    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
  2. Install ROS 2

    Terminal window
    sudo apt update
    sudo apt install ros-jazzy-desktop # Recommended LTS
    # Or: ros-humble-desktop for legacy projects
  3. Source the setup

    Terminal window
    source /opt/ros/jazzy/setup.bash
    # Add to ~/.bashrc for persistence
    echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
  4. Verify installation

    Terminal window
    ros2 run demo_nodes_cpp talker
    # In another terminal:
    ros2 run demo_nodes_cpp listener

Essential Commands

Terminal window
# List running nodes
ros2 node list
# List topics
ros2 topic list
# Echo topic data
ros2 topic echo /scan
# Get topic info
ros2 topic info /camera/image_raw
# Call a service
ros2 service call /get_map nav_msgs/srv/GetMap
# Launch a system
ros2 launch my_robot bringup.launch.py
# Record data
ros2 bag record -a
# Play back data
ros2 bag play my_recording

Creating a Simple Node

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(String, 'topic', 10)
self.timer = self.create_timer(0.5, self.timer_callback)
def timer_callback(self):
msg = String()
msg.data = 'Hello, ROS 2!'
self.publisher_.publish(msg)
self.get_logger().info(f'Publishing: "{msg.data}"')
def main():
rclpy.init()
node = MinimalPublisher()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()

Key Packages for Robotics

PackagePurpose
nav2Navigation stack
moveit2Motion planning for manipulation
ros2_controlHardware abstraction
tf2Coordinate transforms
rviz23D visualization
rosbag2Data recording/playback
gazebo_ros2Simulation integration

ROS 2 + NVIDIA

Isaac ROS

NVIDIA’s GPU-accelerated ROS 2 packages bring 10-100x speedups for perception tasks on Jetson.

NITROS

Zero-copy GPU memory sharing between ROS 2 nodes — no CPU bottleneck.

Learn More

Sources