Chapter 2 — The Robotic Nervous System: ROS 2 Fundamentals
Overview
This chapter introduces Robot Operating System 2 (ROS 2) as the middleware layer that connects sensors, perception algorithms, planners, and motor controllers into a coherent, distributed system. You will learn ROS 2 architecture, core concepts (nodes, topics, services, actions), and practical implementation using Python (rclpy). By the end of this chapter, you will design and build a multi-node ROS 2 system that simulates a humanoid robot's control pipeline.
Duration: Weeks 3-5
Focus: Middleware for robot control and inter-process communication
Learning Objectives
Conceptual Understanding
- Understand ROS 2 architecture and why middleware is essential for robotics
- Grasp the difference between topics (streams), services (RPC), and actions (goals)
- Understand the publish-subscribe pattern and its advantages for distributed systems
- Learn why ROS 2 is superior to ROS 1 for real-time and deterministic systems
- Understand URDF (Unified Robot Description Format) and kinematic chains
- Learn how to describe humanoid robot morphology in machine-readable format
Practical Skills
- Install and configure ROS 2 (Humble/Iron) on Ubuntu 22.04
- Create ROS 2 packages with proper structure and dependencies
- Write ROS 2 nodes in Python using
rclpy - Create custom message and service definitions
- Implement publish-subscribe communication between nodes
- Implement request-response (service) communication
- Use ROS 2 launch files to orchestrate multi-node systems
- Use parameter servers and dynamic parameter reconfiguration
- Parse and validate URDF files for humanoid robots
- Visualize robot morphology using RViz
- Debug ROS 2 systems using
ros2command-line tools
Capstone Relevance
- Students will use ROS 2 nodes to coordinate their capstone system
- Perception pipeline (sensors → fusion) will run as ROS 2 nodes
- Motion planning will be a ROS 2 service
- Motor commands will be published as ROS 2 topics
Chapter Structure
This chapter is organized into three main topics:
- Topic 1: ROS 2 Architecture & Core Concepts — Why middleware, ROS 1 vs ROS 2, computation graph, QoS
- Topic 2: Nodes, Topics, Services, and Actions — Deep dive into communication patterns with code examples
- Topic 3: URDF, RViz, Launch Files & Debugging — Practical tools for development and visualization
The chapter covers three modules with 16 subsections:
Module 1: ROS 2 Architecture & Core Concepts (Weeks 3-4, First Half)
- What is ROS 2? The Middleware Problem — Why robots need middleware, ROS 1 vs ROS 2, DDS foundation
- Nodes: The Building Blocks — Node lifecycle, executors, creating minimal nodes
- Topics: Publish-Subscribe Communication — Message streams, QoS policies, sensor fusion
- Services: Request-Response Communication — When to use services, implementation patterns
- Actions: Goal-Oriented Communication — Long-running tasks with feedback and cancellation
- Parameter Server: Configuration Management — Runtime configuration, dynamic reconfiguration
- Hands-On Lab: Build Your First ROS 2 System — 3-node system integration project
Module 2: Practical ROS 2 Development (Weeks 4-5)
- Launch Files: Orchestrating Multi-Node Systems — XML/YAML syntax, modular design
- Message and Service Definitions — Custom messages, services, actions
- Debugging ROS 2 Systems — CLI tools, visualization, troubleshooting
- ROS 2 Logging and Node Lifecycle — Logging levels, lifecycle management
- URDF: Describing Robot Morphology — Kinematic chains, joints, links, frames
- RViz: Visualizing Robots and Sensor Data — 3D visualization, TF frames, markers
- Hands-On Lab: Design a Humanoid URDF — Create and validate humanoid robot description
- Time in ROS 2: Clocks and Timing — System time vs simulation time, timing utilities
Module 3: Integration & Capstone Preparation (Week 5, Latter Half)
- Building a Humanoid Control Architecture — System design patterns
- Sensor Drivers: Integrating Hardware — Hardware abstraction, driver patterns
- Motor Controllers: Actuating Robots — Motor command interfaces, safety limits
- Capstone Preview: The Autonomous Humanoid System — Integration roadmap
- Hands-On Lab: Integration Challenge — Complete 5+ node system
Reading Materials
Primary Resources
- ROS 2 Official Documentation: https://docs.ros.org/en/humble/
- ROS 2 Design: https://design.ros2.org/
- rclpy (Python Client Library): https://docs.ros.org/en/humble/Concepts/Intermediate/About-ROS2-Client-Libraries.html
- URDF Format Specification: http://wiki.ros.org/urdf/XML
Secondary Resources
- Real-Time Robotics: Time and Determinism — Research paper on ROS 2 real-time capabilities
- Message Design in ROS: Best practices for custom messages
- Robot Architecture: From Design to Deployment — Chapter on middleware
Reference
- ROS 2 Command Cheat Sheet
- URDF Validator and Tools
- rqt Tools User Guide
Technical Requirements
Software Stack
- ROS 2 Humble or Iron (Ubuntu 22.04 LTS)
- Python 3.10+
- RViz (visualization)
- rqt tools (debugging)
- Visual Studio Code with ROS 2 extension (recommended)
Hardware
- Linux PC with Ubuntu 22.04 (dual-boot or VM acceptable)
- 4+ GB RAM minimum, 8+ GB recommended
- 100 GB free disk space
- No specialized hardware needed for Chapter 2 (simulation only)
External Dependencies
rclpy(Python ROS 2 client library)std_msgs,geometry_msgs,sensor_msgs(standard message types)tf2,tf2_ros(coordinate transformation library)OpenCV(optional, for visualizations)
Key Takeaways
By the end of this chapter, you will understand:
- ROS 2 is a distributed middleware that enables complex robot software
- Nodes communicate via topics (streaming), services (RPC), and actions (goals)
- Proper system architecture is essential: separate perception, planning, control
- URDF describes robot morphology; RViz visualizes it
- Launch files orchestrate multi-node systems
- Debugging tools (
ros2CLI,rqt) are essential for system integration - Real-time constraints must be respected: control loop frequency matters
- Sim-to-real requires careful time management and sensor driver abstraction
Next Chapter Prerequisites
Before moving to Chapter 3 (Digital Twins), ensure you have:
- ✅ Working ROS 2 installation
- ✅ Ability to write, launch, and debug multi-node systems
- ✅ Understanding of URDF and robot kinematics
- ✅ Comfort with publish-subscribe and request-response patterns
- ✅ Capstone system architecture designed in Chapter 2
Use the sidebar to navigate through the individual topics for deep dives and hands-on guidance.