Module 1: ROS 2 Fundamentals
π Learning Outcomesβ
By the end of this module, you will be able to:
- Architect distributed robot applications using ROS 2's publisher/subscriber, service, and action patterns
- Develop production-quality ROS 2 nodes in Python and C++
- Configure Quality of Service (QoS) policies for reliable real-time communication
- Build custom message and service types for domain-specific applications
- Orchestrate complex multi-node systems using launch files
- Debug ROS 2 applications using command-line introspection tools
π― Module Overviewβ
Duration: 3 weeks (21 days) Prerequisites: Python programming, Linux command line, Physical AI foundations (Weeks 1-2)
ROS 2 (Robot Operating System 2) is the industry-standard middleware for building robot software. Unlike its predecessor ROS 1, ROS 2 is built for:
- Production deployment (not just research)
- Real-time communication with deterministic timing
- Multi-robot systems with distributed computing
- Security with DDS (Data Distribution Service) authentication
This module takes you from zero ROS 2 knowledge to building production-grade robotics applications.
Weekly Breakdownβ
Week 3: ROS 2 Architecture & Communicationβ
Topics:
- ROS 2 architecture: nodes, topics, services, actions
- DDS middleware and Quality of Service (QoS)
- Publish/subscribe pattern for sensor data streaming
- Request/response pattern with services
- Long-running tasks with actions
Hands-On:
- Install ROS 2 Humble
- Create your first publisher and subscriber nodes
- Implement a service for robot state queries
- Build an action server for navigation
Assessment: Build a teleoperation system with keyboard input published to /cmd_vel topic
Week 4: Building ROS 2 Applicationsβ
Topics:
- Creating ROS 2 packages with Python and C++
- Parameter management and dynamic reconfiguration
- Coordinate transforms with
tf2 - Time synchronization and clock management
- ROS 2 logging and diagnostics
Hands-On:
- Build a sensor fusion package combining camera and odometry
- Configure parameters via YAML files
- Publish transforms for a robot arm
- Debug nodes using
ros2 topic echoandros2 node info
Assessment: Sensor fusion node that combines IMU and wheel odometry for dead reckoning
Week 5: Advanced ROS 2 & Production Deploymentβ
Topics:
- Custom message and service definitions
- Launch files for multi-node orchestration
- Lifecycle nodes and managed composition
- ROS 2 bags for recording and playback
- Integration with Gazebo simulation
Hands-On:
- Define custom messages for robot state
- Write launch files with conditional logic
- Implement lifecycle nodes with state transitions
- Record sensor data to ROS bags
- Connect ROS 2 nodes to Gazebo robot
Assessment: Complete mobile robot system with navigation, perception, and control nodes launched via single launch file
Key Technologiesβ
ROS 2 Communication Patternsβ
Why ROS 2?β
| Feature | ROS 1 | ROS 2 |
|---|---|---|
| Real-time | β Best-effort | β DDS with QoS |
| Multi-robot | β οΈ Requires custom networking | β Native support |
| Security | β None | β DDS security |
| Production | β οΈ Research-focused | β Industrial-grade |
| Platforms | π§ Linux only | β Linux, Windows, macOS |
| Language | Python 2, C++ | Python 3, C++14+ |
Recommended Scheduleβ
Week 3: Architecture & Communication (7 days)β
- Day 1-2: Install ROS 2, understand architecture, run tutorials
- Day 3-4: Build publisher/subscriber nodes (Python)
- Day 5: Implement service client/server
- Day 6: Create action server for long-running tasks
- Day 7: Assessment project + review
Week 4: Building Applications (7 days)β
- Day 8-9: Create ROS 2 packages, parameter management
- Day 10-11: Work with
tf2for coordinate transforms - Day 12-13: Sensor fusion project
- Day 14: Assessment + debugging practice
Week 5: Advanced & Production (7 days)β
- Day 15-16: Custom messages and services
- Day 17-18: Launch files and lifecycle nodes
- Day 19-20: ROS bags and Gazebo integration
- Day 21: Final assessment + module review
Module Assessment: Mobile Robot Navigation Systemβ
Objective: Build a complete ROS 2 application for a simulated mobile robot
Requirements:
- Teleoperation Node: Keyboard control publishing to
/cmd_vel - Sensor Fusion Node: Combine camera and odometry data
- Obstacle Avoidance Node: Reactive control using laser scan
- State Publisher: Broadcast robot pose to
/tf - Launch File: Start all nodes with single command
- ROS Bag: Record 1 minute of sensor data
Success Criteria:
- Robot navigates 10 meters without collisions
- All nodes communicate via proper QoS settings
- Launch file includes parameter configuration
- Code follows ROS 2 best practices (naming, structure, logging)
Deliverables:
- Source code (ROS 2 workspace with packages)
- Launch file
- README with setup instructions
- Demo video (2-3 minutes)
Code Example: Publisher/Subscriber Patternβ
# publisher_node.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class PublisherNode(Node):
def __init__(self):
super().__init__('publisher_node')
self.publisher_ = self.create_publisher(String, 'topic', 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: {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 = PublisherNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
# subscriber_node.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class SubscriberNode(Node):
def __init__(self):
super().__init__('subscriber_node')
self.subscription = self.create_subscription(
String,
'topic',
self.listener_callback,
10)
def listener_callback(self, msg):
self.get_logger().info(f'Received: "{msg.data}"')
def main(args=None):
rclpy.init(args=args)
node = SubscriberNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Run the nodes:
# Terminal 1
ros2 run my_package publisher_node
# Terminal 2
ros2 run my_package subscriber_node
# Inspect topics
ros2 topic list
ros2 topic echo /topic
ros2 topic hz /topic
Key Takeawaysβ
After completing Module 1, you should understand:
β ROS 2 is a middleware, not an operating systemβit sits between your application code and the OS β Nodes are the building blocksβeach node does one thing well β Topics for data streamsβsensor readings, robot state β Services for requestsβquery current pose, trigger calibration β Actions for long tasksβnavigation, grasping, multi-step plans β QoS policies matterβreliable vs. best-effort, durability, lifespan β Launch files orchestrate complexityβstart dozens of nodes with one command
What's Next?β
With ROS 2 fundamentals mastered, you're ready to simulate and test your robots:
π Module 2: Robot Simulation β Build high-fidelity simulations in Gazebo