Introduction to ROS (Robot Operating System)
Short answer: ROS (Robot Operating System) is an open source framework of tools, libraries and conventions for building robot software. It is not a true operating system; it is middleware that lets many small programs (nodes) exchange messages and work together.
Why use ROS?
- Reuse proven packages for navigation, mapping, vision and arm control instead of rewriting them.
- Split a robot into independent parts that you can develop and test separately.
- Use simulators and visualization tools before touching hardware.
- Join a large community and ecosystem used in research and industry.
ROS 1 vs ROS 2
| ROS 1 | ROS 2 | |
|---|---|---|
| Status | Reached end of life; legacy projects only | Actively developed; the choice for new work |
| Communication | Custom, needs a central master | DDS-based, no master, better for multiple robots |
| Real-time and security | Limited | Designed with real-time and security in mind |
| Platforms | Mainly Linux | Linux, Windows, macOS |
Start with ROS 2 unless a project requires ROS 1.
Core concepts
| Concept | Meaning |
|---|---|
| Node | A small program doing one job, such as reading a camera or planning a path |
| Topic | A named channel where nodes publish and subscribe to messages (one-to-many streaming) |
| Message | A typed data structure sent on a topic, for example an image or a velocity command |
| Service | Request and response between two nodes |
| Action | A long-running goal with feedback, such as "navigate to this point" |
| Parameter | A configurable setting of a node |
| Package | A unit of code, configuration and launch files |
How the pieces fit
[camera node] --/image--> [object detector] --/detections--> [planner] --/cmd_vel--> [motor driver]
Each box is a node. Arrows are topics. The robot's behavior emerges from these nodes cooperating. This follows the sense, think, act loop described in how robots work.
A publisher in Python (ROS 2)
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class Talker(Node):
def __init__(self):
super().__init__('talker')
self.pub = self.create_publisher(String, 'chatter', 10)
self.create_timer(1.0, self.tick)
def tick(self):
msg = String()
msg.data = 'Hello from ROS 2'
self.pub.publish(msg)
rclpy.init()
rclpy.spin(Talker())
A subscriber
class Listener(Node):
def __init__(self):
super().__init__('listener')
self.create_subscription(String, 'chatter', self.on_msg, 10)
def on_msg(self, msg):
self.get_logger().info('Heard: ' + msg.data)
Handy command-line tools
ros2 node list # running nodes
ros2 topic list # available topics
ros2 topic echo /chatter # print messages
ros2 run demo_nodes_cpp talker
ros2 launch my_pkg robot.launch.py
Useful tools and packages
- RViz: 3D visualization of sensors and robot state.
- Gazebo: physics simulator to test robots virtually.
- Nav2: navigation stack for mobile robots.
- MoveIt: motion planning for robot arms.
- rosbag: record and replay sensor data.
Languages
ROS officially supports C++ and Python; see programming languages for robotics.
How to start
- Install a current ROS 2 release on Ubuntu (or use a Docker image).
- Work through the official tutorials: nodes, topics, services and launch files.
- Simulate a robot such as TurtleBot in Gazebo.
- Write your own nodes, then connect real sensors and motors.
Frequently asked questions
Should I learn ROS 1 or ROS 2?
Learn ROS 2. ROS 1 has reached the end of its supported life, while ROS 2 is actively developed and offers improved security, real-time support and multi-robot communication.
Which operating system does ROS 2 run on?
ROS 2 officially targets Ubuntu Linux, with support for Windows and macOS varying by release. Use the distribution recommended in the documentation for your ROS 2 version.
Next steps
See the field overview in what robotics is and real uses in applications of robotics.
