Skip to main content
πŸ€– Physical AI
πŸ“š DocsπŸ—ΊοΈ RoadmapπŸ–₯️ Dashboard
πŸ” Login✨ Sign Up Free
Language:
AI Personalization:

Week 3 - Introduction to ROS 2

Learning Objectives​

By the end of this week, you will be able to:

  • Understand ROS 2 architecture and core concepts
  • Install and configure ROS 2 Humble on Ubuntu 22.04
  • Create and manage ROS 2 workspaces
  • Use essential ROS 2 CLI tools

Overview​

ROS 2 (Robot Operating System 2) is the industry-standard middleware for robotics development. It provides communication primitives, hardware abstraction, and tools for building complex robotic systems.

Why ROS 2?​

  • Distributed Architecture: Nodes can run on different machines
  • Real-time Support: Deterministic communication for control systems
  • Security: Built-in DDS security features
  • Modern C++/Python: Support for latest language features
  • Industry Adoption: Used by Boston Dynamics, NVIDIA, and major robotics companies

Hardware Requirements​

ComponentMinimumRecommended
CPU4 cores8+ cores
RAM8GB16GB+
Network1 Gbps Ethernet10 Gbps for multi-robot
OSUbuntu 22.04 LTSUbuntu 22.04 LTS

Installation​

ROS 2 Humble Installation​

#!/bin/bash
# ROS 2 Humble Installation Script for Ubuntu 22.04

# Set locale
sudo apt update && sudo apt install locales -y
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

# Add ROS 2 repository
sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add -
echo "deb http://packages.ros.org/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list

# Install ROS 2 Humble
sudo apt update
sudo apt install ros-humble-desktop -y

# Install development tools
sudo apt install ros-dev-tools -y

# Install rosdep
sudo apt install python3-rosdep -y
sudo rosdep init
rosdep update

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

# Verify installation
ros2 --version

Verification​

# Check ROS 2 version
ros2 --version

# Check available commands
ros2 --help

# List available packages
ros2 pkg list | head -20

Workspace Setup​

Creating a ROS 2 Workspace​

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

# Initialize workspace
colcon build --symlink-install

# Source the workspace
source install/setup.bash

# Verify workspace
echo $ROS_DOMAIN_ID

Workspace Structure​

ros2_ws/
β”œβ”€β”€ src/ # Source code
β”‚ β”œβ”€β”€ package_1/
β”‚ └── package_2/
β”œβ”€β”€ build/ # Build artifacts (generated)
β”œβ”€β”€ install/ # Installation files (generated)
└── log/ # Log files (generated)

Core Concepts​

ROS 2 Graph​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      Topics      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Node 1 β”‚ ◀──────────────▢ β”‚ Node 2 β”‚
β”‚ (Publisher)β”‚ (Messages) β”‚ (Subscriber)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚
β”‚ Services β”‚
β”‚ ◀────────────────────────────▢ β”‚
β”‚ (Request/Response) β”‚
β”‚ β”‚
β”‚ Actions β”‚
β”‚ ◀────────────────────────────▢ β”‚
β”‚ (Goal/Feedback/Result) β”‚

Key Terminology​

TermDefinition
NodeExecutable that performs computation
TopicNamed bus for data exchange (publish/subscribe)
MessageData structure for topics
ServiceSynchronous request/response communication
ActionAsynchronous goal-based communication
PackageOrganizational unit for ROS 2 code
WorkspaceDirectory containing ROS 2 packages

Essential CLI Tools​

Package Management​

# List all packages
ros2 pkg list

# Get package information
ros2 pkg info demo_nodes_cpp

# List executables in a package
ros2 pkg executables demo_nodes_cpp

# Create a new package
ros2 pkg create my_package --build-type ament_python --dependencies rclpy

Node Management​

# List running nodes
ros2 node list

# Get node information
ros2 node info /talker

# Run a node
ros2 run demo_nodes_cpp talker

Topic Management​

# List active topics
ros2 topic list

# Get topic information
ros2 topic info /chatter

# Echo topic messages
ros2 topic echo /chatter

# Publish a message
ros2 topic pub /chatter std_msgs/msg/String "data: 'Hello ROS 2'"

Code Example: Simple Publisher​

#!/usr/bin/env python3
"""
Simple ROS 2 Publisher Node
Publishes string messages to a topic
"""

import rclpy
from rclpy.node import Node
from std_msgs.msg import String

class SimplePublisher(Node):
def __init__(self):
super().__init__('simple_publisher')
self.publisher_ = self.create_publisher(
String, 'chatter', 10)
self.timer = self.create_timer(1.0, self.timer_callback)
self.counter = 0

def timer_callback(self):
msg = String()
msg.data = f'Hello ROS 2! Count: {self.counter}'
self.publisher_.publish(msg)
self.get_logger().info(f'Publishing: {msg.data}')
self.counter += 1

def main(args=None):
rclpy.init(args=args)
node = SimplePublisher()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()

if __name__ == '__main__':
main()

Resources​

Documentation​

Tools​

Exercises​

  1. Installation Verification: Complete ROS 2 installation and verify with ros2 --version
  2. Workspace Creation: Create a ROS 2 workspace and build it
  3. Publisher Node: Create and run the simple publisher node
  4. CLI Exploration: Use ros2 node list, ros2 topic list, and ros2 topic echo

Next Steps​

Proceed to Week 4 - ROS 2 Nodes and Topics for deeper exploration of ROS 2 communication.