A comprehensive beginner-friendly ROS 2 package demonstrating fundamental concepts using the turtlesim simulator. This package includes examples of publishers, subscribers, services, clients, and launch files.
This package is designed as a complete learning resource for ROS 2 beginners. It demonstrates:
- Topic Publishers - Sending velocity commands to control turtle movement
- Topic Subscribers - Receiving and displaying turtle pose information
- Service Servers - Providing rotation services
- Service Clients - Calling rotation services
- Launch Files - Starting multiple nodes simultaneously
By working through this package, you will learn:
- How to create and structure a ROS 2 workspace
- How to create a Python-based ROS 2 package
- How to implement publishers and subscribers
- How to create and use services
- How to write launch files for complex systems
- ROS 2 best practices and conventions
- Ubuntu 22.04 (Jammy Jellyfish)
- ROS 2 Humble installed and configured
- Python 3.10+
- Basic understanding of Python programming
- Terminal/command line familiarity
Verify your ROS 2 installation:
ros2 --versionYou should see output similar to: ros2 cli version: 0.18.x
After completing these exercises, you should be able to:
- Create ROS 2 workspaces and packages
- Write publisher nodes that send messages
- Write subscriber nodes that receive messages
- Create service servers that handle requests
- Create service clients that call services
- Write launch files to manage multiple nodes
- Use ROS 2 command-line tools for debugging
- Understand the publish-subscribe pattern
- Understand the request-response pattern
- Exercise 1: Setting Up Your Workspace
- Exercise 2: Creating a Topic Publisher
- Exercise 3: Creating a Topic Subscriber
- Exercise 4: Creating a Service Server
- Exercise 5: Creating a Service Client
- Exercise 6: Creating Launch Files
Use this checklist to verify you've completed everything:
- Workspace created and built successfully
- Package created with correct dependencies
- Velocity publisher moves turtle in a circle
- Pose subscriber prints turtle position
- Rotate service can be called manually
- Rotate client works from command line
- Basic launch file starts all nodes
- All nodes appear in
ros2 node list - All topics appear in
ros2 topic list
Once you've completed all exercises:
- Experiment: Modify the velocity values to create different movement patterns
- Extend: Add new features (e.g., move to specific coordinates)
- Optimize: Can you reduce code duplication?
- Document: Add detailed comments explaining your code
- Share: Help others who are stuck!
turtle_controller/
├── launch/
│ ├── turtle_system_launch.py # Basic launch file
│ └── turtle_complete_launch.py # Comprehensive launch file
├── turtle_controller/
│ ├── __init__.py
│ ├── velocity_publisher.py # Publishes velocity commands
│ ├── pose_subscriber.py # Subscribes to turtle pose
│ ├── rotate_service.py # Service server for rotation
│ └── rotate_client.py # Service client for rotation
├── package.xml # Package metadata
├── setup.py # Python package setup
├── setup.cfg # Package configuration
└── README.md # This file
# List all nodes
ros2 node list
# List all topics
ros2 topic list
# See topic info
ros2 topic info /turtle1/cmd_vel
# Echo topic messages
ros2 topic echo /turtle1/pose
# List services
ros2 service list
# See service type
ros2 service type /rotate_turtle
# View computational graph
rqt_graph