Module 1: ROS 2 Fundamentals (Weeks 1-5)
Overview
This module introduces the Robot Operating System 2 (ROS 2), the foundational middleware for robotics applications. You'll learn the core concepts, architecture, and practical implementation of ROS 2 systems essential for humanoid robotics development.
Learning Objectives
By the end of this module, you will be able to:
- Explain the ROS 2 architecture and its key components
- Create and manage ROS 2 packages, nodes, and communication patterns
- Implement robot models using URDF (Unified Robot Description Format)
- Work with transforms (TF) for coordinate frame management
- Design launch files for complex robot system initialization
- Debug and troubleshoot ROS 2 applications
Module Structure
Week 1: ROS 2 Architecture and Setup
- ROS 2 vs ROS 1: Key differences and improvements
- DDS (Data Distribution Service) and middleware
- Workspace setup and package management
- Basic node creation and execution
Week 2: Communication Patterns
- Topics and publishers/subscribers
- Services and clients
- Actions and clients/servers
- Parameters and configuration
Week 3: Advanced Communication and Launch Systems
- Launch files and complex system management
- Composition and node containers
- Quality of Service (QoS) settings
- Inter-process communication optimization
Week 4: Robot Modeling and URDF
- URDF (Unified Robot Description Format) basics
- Joint types and kinematic chains
- Visual and collision properties
- Robot state publisher and joint state publisher
Week 5: Transform Management and Navigation
- TF (Transforms) and TF2 concepts
- Static and dynamic transforms
- Robot localization in simulation
- Basic navigation concepts
Week 1: ROS 2 Architecture and Setup
Introduction to ROS 2
ROS 2 (Robot Operating System 2) is not an operating system but rather a flexible framework for writing robot software. It provides services designed for a heterogeneous computer cluster such as hardware abstraction, device drivers, libraries, visualizers, message-passing, package management, and more.
Key Improvements in ROS 2
- Real-time support: ROS 2 supports real-time execution, which is crucial for safety-critical robotic applications.
- Multi-robot systems: Better support for multi-robot systems and distributed architectures.
- Security: Built-in security features including authentication, authorization, and encryption.
- Quality of Service (QoS): Configurable communication policies for different types of data.
- DDS Middleware: Pluggable middleware layer using DDS (Data Distribution Service) for communication.
Setting Up Your Workspace
# Create a new workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
# Source the ROS 2 installation
source /opt/ros/humble/setup.bash # Replace 'humble' with your ROS 2 distribution
# Build the workspace
colcon build
# Source the workspace
source install/setup.bash
Creating Your First Package
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python my_robot_package
Week 2: Communication Patterns
Topics - Publisher/Subscriber Pattern
Topics in ROS 2 implement a publish/subscribe communication model where multiple nodes can publish messages to the same topic and multiple nodes can subscribe to the same topic.
# Publisher example
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)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
msg = String()
msg.data = 'Hello World: %d' % self.i
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg.data)
self.i += 1
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Services - Request/Response Pattern
Services provide a request/response communication model where a client sends a request and waits for a response from a server.
Actions - Goal/Result/Feedback Pattern
Actions are used for long-running tasks that provide feedback during execution and return a result upon completion.
Week 3: Advanced Communication and Launch Systems
Launch Files
Launch files allow you to start multiple nodes with a single command, configure parameters, and set up complex robot systems.
# launch/my_robot.launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='my_robot_package',
executable='publisher_node',
name='publisher_node'
),
Node(
package='my_robot_package',
executable='subscriber_node',
name='subscriber_node'
)
])
Week 4: Robot Modeling and URDF
Understanding URDF
URDF (Unified Robot Description Format) is an XML format for representing a robot model. It describes the kinematic and dynamic properties of a robot, as well as its visual and collision properties.
<?xml version="1.0"?>
<robot name="simple_robot">
<link name="base_link">
<visual>
<geometry>
<box size="0.5 0.5 0.2"/>
</geometry>
</visual>
<collision>
<geometry>
<box size="0.5 0.5 0.2"/>
</geometry>
</collision>
<inertial>
<mass value="1"/>
<inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1"/>
</inertial>
</link>
</robot>
Week 5: Transform Management and Navigation
TF and TF2
TF (Transforms) is a package that keeps track of multiple coordinate frames over time. It maintains the relationship between coordinate frames in a tree structure buffered in time, and allows you to transform points, vectors, etc. between any two coordinate frames at any desired point in time.
Troubleshooting Common Issues
1. Package Not Found
Issue: Package 'package_name' not found
Solution: Ensure the package is in your workspace's src directory and run colcon build followed by source install/setup.bash
2. DDS Communication Issues
Issue: Nodes in different terminals not communicating Solution: Ensure all terminals are sourcing the same ROS 2 installation and workspace
3. Permission Issues
Issue: Cannot create or modify files Solution: Check file permissions and ensure you're working in your user workspace
Hands-on Exercise
Create a simple ROS 2 package that includes:
- A publisher node that publishes a message every second
- A subscriber node that receives and logs the message
- A launch file to start both nodes
- Proper package configuration and dependencies
Test your package in a simulated environment and verify that the publisher and subscriber communicate correctly.