Introduction to ROS2
Week 10 • CMPSC 304 Robotic Agents
Press Space or → to advance
The Problem: Building Robot Software Is Hard
Without ROS
- Write your own sensor drivers
- Write your own motor controllers
- Write your own communication layer
- Write your own navigation algorithms
- Everything is custom, every time
With ROS
- Standardized sensor interfaces
- Reusable motor controllers
- Built-in publish/subscribe messaging
- Full navigation stack available
- Write once, reuse everywhere
ROS = Robot Operating System — not actually an OS, but middleware that connects robot software components.
ROS in the Real World
- Research: Most university and research lab robots run ROS
- Industry: Warehouse robots, agricultural robots, inspection drones
- Self-driving cars: Autoware (built on ROS2) powers autonomous vehicles
- Space: NASA uses ROS for rover prototyping and ISS experiments
Why ROS2? ROS2 is the current generation. Improvements over ROS1: real-time support, better security, no single point of failure, multi-platform (Linux, macOS, Windows).
How ROS Fits Our Course
Arduino
Hardware
→
PLC
Deterministic
→
FANUC
Industrial
→
ROS2
Autonomous
| You Already Know | ROS2 Equivalent |
| Arduino sensors | ROS topics (sensor data streams) |
| Arduino motor control | ROS nodes (individual processes) |
| PLC scan cycle | ROS publish/subscribe loop |
| FANUC teach pendant | ROS command-line tools |
| FANUC program timeline | ROS launch files |
Core Concept: Nodes
A node is a single process that does one job.
Lidar
Driver
Camera
Driver
SLAM
Mapper
Path
Planner
Motor
Controller
- Each node is independent — it can be started, stopped, or replaced individually
- Nodes communicate with each other through topics
- A robot is a graph of connected nodes
ros2 node list # See all running nodes
Core Concept: Topics
A topic is a named channel for sending messages between nodes.
- Publishers send data to a topic
- Subscribers receive data from a topic
- Multiple nodes can publish or subscribe to the same topic
ros2 topic list # See all active topics
ros2 topic echo /scan # View messages on a topic
Core Concept: Messages
A message is structured data sent over a topic. Each topic has a specific message type.
Twist (velocity)
Topic: /cmd_vel
linear:
x: 0.2 # forward m/s
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.5 # turn rad/s
LaserScan (lidar)
Topic: /scan
angle_min: -3.14
angle_max: 3.14
ranges:
- 2.45 # distance (m)
- 2.41
- 1.03 # obstacle!
- 0.52
...
The Publish/Subscribe Pattern
Nodes don't talk to each other directly. They communicate through topics — publishers don't know who is listening, and subscribers don't know who is sending.
Why is this useful?
- Modularity: Swap a real lidar for a simulated one — subscribers don't change
- Scalability: Add a new node that listens to
/scan without modifying existing code
- Testing: Record and replay topic data for debugging
Think about it: In your Arduino projects, the sensor code and motor code were tightly coupled in one file. ROS separates them into independent nodes connected by topics.
Simulation with Gazebo
What Gazebo Provides
- Physics engine (gravity, collisions, friction)
- Simulated sensors (lidar, camera, IMU)
- 3D environments with obstacles
- Sensors publish to the same ROS topics as real hardware
Why Simulate First?
- ✓ No hardware damage from bugs
- ✓ Everyone gets their own robot
- ✓ Reset instantly after crashes
- ✓ Test algorithms before real deployment
Key insight: Code you write for a simulated TurtleBot 4 in Gazebo will also run on a real TurtleBot 4 — because both use the same ROS2 topics and messages.
TurtleBot 4: Our Robot Platform
TurtleBot 4 — built on the iRobot Create 3 base, designed for ROS2 education and research.
Hardware
- iRobot Create 3 base (differential drive)
- RPLIDAR A1 — 360° 2D lidar
- OAK-D stereo camera (depth + RGB)
- IMU, cliff sensors, bump sensors
- Raspberry Pi 4
Key ROS2 Topics
/scan — lidar distance data
/odom — position estimate
/cmd_vel — velocity commands
/imu — orientation data
/oakd/rgb/preview/image_raw — camera
# Launch TurtleBot 4 in Gazebo
ros2 launch turtlebot4_ignition_bringup turtlebot4_ignition.launch.py
Essential ROS2 Commands
| Command |
What It Does |
ros2 node list |
List all running nodes |
ros2 topic list |
List all active topics |
ros2 topic echo /scan |
Print messages from a topic in real time |
ros2 topic echo /scan --once |
Print one message and stop |
ros2 run <pkg> <node> |
Start a single node |
ros2 launch <pkg> <file> |
Start multiple nodes at once |
Tip: You only need these 6 commands for the rest of the semester. Everything else builds on them.
What's Coming Next
| Week | Topic | What You'll Do |
| 10 | ROS2 Basics | Set up environment, drive TurtleBot 4, explore topics |
| 11 | SLAM & Mapping | Build a map by driving the robot around |
| 12 | Localization & Navigation | Robot finds itself on a map, plans paths to goals |
| 13 | Autonomous Navigation | Robot avoids obstacles and replans paths |
Today: Set up your Docker environment and drive a simulated robot.
Key Takeaways
- ROS2 is middleware that connects robot software using publish/subscribe messaging
- Nodes are independent processes that each do one job
- Topics are named channels that carry messages between nodes
- Gazebo simulates physics and sensors — code works the same on real hardware
- TurtleBot 4 is our robot platform — lidar, camera, odometry, and velocity control
- You only need 6 commands to inspect and control the entire system