Skip to main content

Module 1: The Robotic Nervous System (ROS 2)

Learning Objectives

  • Understand the fundamentals of ROS 2 middleware
  • Learn about nodes, topics, services, and actions
  • Implement basic node communication
  • Bridge Python agents to ROS controllers

Overview

This module introduces the Robot Operating System 2 (ROS 2), which serves as the nervous system for robotic applications. ROS 2 provides the infrastructure needed to develop complex robotic systems with modular components that communicate seamlessly.

Content

ROS 2 (Robot Operating System 2) is not an operating system but rather a middleware framework that provides services designed for a heterogeneous computer cluster. It includes hardware abstraction, device drivers, libraries, visualizers, message-passing, package management, and more.

ROS 2 Architecture Diagram

                    ROS 2 Ecosystem
┌─────────────────────┐
│ ROS 2 Middleware │
└─────────────────────┘

┌─────────────────┼─────────────────┐
│ │ │
┌────▼────┐ ┌─────▼─────┐ ┌─────▼─────┐
│ Node │ │ Node │ │ Node │
│ A │ │ B │ │ C │
└─────────┘ └───────────┘ └───────────┘
│ │ │
│ publishes │ subscribes │ provides
│ to topic X │ to topic X │ service Y
│ ┌───────────▼───────────┐ │
└──────▶│ │◀──┘
│ DDS Middleware │
│ │
└─────────────────────┘

The key features of ROS 2 include:

  • Distributed computing architecture
  • Support for multiple programming languages
  • Real-time capabilities
  • Improved security features
  • Better support for industrial use cases

Communication Patterns

Publisher-Subscriber Pattern:

Node A (Publisher) ────── Topic ──────► Node B (Subscriber)
┌─────────┐ ┌──────────┐
│publish()│───────── message ──────▶│callback()│
└─────────┘ └──────────┘

Service-Client Pattern:

Node A (Client)                    Node B (Service)
┌─────────┐ ┌──────────┐
│request()│─── request ──────────▶│handler() │
└────┬────┘ └─────┬────┘
│ │
┌────▼────┐ ┌─────▼────┐
│receive()│◀── response ──────────│respond() │
└─────────┘ └──────────┘

Exercises

Exercise 1: Set up a basic ROS 2 workspace

Follow the official ROS 2 installation guide for your operating system and create a basic workspace with the following structure:

  • Create a ros2_ws directory
  • Create a src subdirectory
  • Source the ROS 2 environment
  • Verify the installation with ros2 topic list
Exercise 2: Create two communicating nodes

Using the Python examples provided in this module, create two nodes that communicate via a topic:

  • One node should publish a counter value every second
  • The other node should subscribe to this topic and print the received values
  • Verify that the nodes can communicate properly
Exercise 3: Implement a service call

Create a service server and client:

  • The service should take two numbers as input
  • The server should return their sum
  • The client should call the service and print the result

Summary

This module covered the foundational concepts of ROS 2, including its architecture and communication patterns. You now understand how to create and connect nodes, which form the building blocks of robotic applications.

Accessibility Features

This module includes the following accessibility features:

  • Semantic HTML structure with proper heading hierarchy (H1, H2, H3)
  • Sufficient color contrast for text and background
  • Clear navigation structure with logical tab order
  • Alternative text for code examples and diagrams
  • Descriptive headings and section titles
  • Keyboard navigable interactive elements