ROS2 Foundations and Setup

ROS2 Introduction

What is ROS 2

ROS 2 (Robot Operating System 2) is an open-source robotics middleware and tooling ecosystem. It is not an operating system by itself. Instead, it provides communication libraries, developer tools, and runtime conventions that help you build distributed robotic applications.

Definition of ROS 2

ROS 2 provides the infrastructure needed for robotics software, including:

  • Inter-process communication
  • Hardware abstraction through drivers
  • Package and dependency management
  • Distributed execution across multiple machines

In practice, ROS 2 lets developers connect sensors, algorithms, and actuators into modular systems.

Design objectives for ROS 2

ROS 2 was designed for modern robotic systems with stronger production requirements:

ObjectiveWhy it matters
Real-time friendlinessBetter support for low-latency workloads
Distributed deploymentNodes can run across processes and machines
Reliability and maintainabilityBetter fit for production than ROS 1-era assumptions
SecuritySupports encryption, authentication, and access control
Cross-platform supportRuns on Linux, Windows, macOS, and embedded targets

ROS 2 Core values

  1. Modular design: software is split into reusable packages.
  2. Distributed communication: supports multi-process and multi-machine systems.
  3. Rich ecosystem: many community-maintained packages and tools.
  4. Active community: broad contribution from developers and companies.

ROS 2 Core concept

Node (Nodes)

A node is the smallest computational unit in ROS 2. Each node is a process that uses ROS 2 APIs to communicate with other nodes.

Node design principles:

  • Single responsibility: one node should focus on one function.
  • Low coupling: nodes communicate through interfaces instead of tight dependencies.
  • Composability: complex systems are built by combining many nodes.

Topics (Topics)

A topic is an asynchronous publish/subscribe channel between nodes.

Topic communication features:

FeatureDescription
AsynchronousPublishers and subscribers do not block each other
One-to-manyMultiple subscribers can consume the same topic
Loosely coupledNodes only need to agree on topic name and message type
Streaming friendlyGood for sensor streams and continuous control

Typical topics:

Topic NameMessage TypePurpose
/cmd_velgeometry_msgs/msg/TwistVelocity command
/odomnav_msgs/msg/OdometryOdometry data
/scansensor_msgs/msg/LaserScanLidar scan data
/camera/image_rawsensor_msgs/msg/ImageRaw image stream

Services (Services)

Services provide synchronous request/response communication.

Service communication characteristics:

FeatureDescription
Request/responseClient sends a request and waits for a response
Synchronous patternUseful when completion status is required
One-to-one interactionTypically one client and one service endpoint
Best for short tasksNot suitable for long-running jobs

Typical services:

Service NameService TypePurpose
/spawnturtlesim/srv/SpawnSpawn a new turtle
/teleport_absoluteturtlesim/srv/TeleportAbsoluteMove turtle to a target pose
/resetstd_srvs/srv/EmptyReset simulation state

Actions

Actions are used for long-running tasks that need progress feedback and cancellation.

Three streams in an action interface:

StreamPurpose
GoalDefines the requested task
FeedbackReports progress during execution
ResultReturns the final outcome

Typical actions:

Action NameAction TypePurpose
/navigate_to_posenav2_msgs/action/NavigateToPoseNavigate to target pose
/spinturtlesim/action/RotateAbsoluteRotate by target angle

Parameters (Parameters)

Parameters are node configuration values. They can be set at startup and updated at runtime.

Example:

bash
ros2 param set /camera_node exposure_mode manual

Common parameter types:

TypeDescriptionExample
boolBooleantrue
intInteger42
doubleFloating-point number3.14
stringText"camera_link"
byte[]Byte array[0x01, 0x02]
bool[]Boolean array[true, false]
int[]Integer array[1, 2, 3]
double[]Floating-point array[0.1, 0.2]
string[]String array["a", "b"]

ROS 2 Structure

Layer structure

ROS 2 uses a layered architecture from OS to application:

Typical layers:

  1. Operating system layer (Linux/Windows/macOS/RTOS)
  2. DDS implementation layer
  3. RMW abstraction layer
  4. Client library layer (rclcpp, rclpy, etc.)
  5. Application layer (your robot nodes)

Client Library (Client Libraries)

ROS 2 supports multiple client libraries:

LibraryLanguageTypical use
rclcppC++High-performance production nodes
rclpyPythonFast prototyping and scripting
rclcCMicro-ROS and constrained devices
rcljavaJavaJVM ecosystem integration
rclnodejsJavaScript / Node.jsWeb and tooling integration

RMW and DDS

RMW (ROS Middleware interface) decouples ROS 2 APIs from specific DDS vendors.

Benefits:

  1. Swap DDS implementations with minimal application changes.
  2. Reuse the same ROS 2 code across different middleware backends.
  3. Leverage DDS features such as discovery and QoS.

Common DDS backends:

RMW implementationDDS backendLicense modelNotes
rmw_cyclonedds_cppCyclone DDSOpen sourceCommon default choice
rmw_fastrtps_cppFast DDSOpen sourceWidely used and feature-rich
rmw_connextddsRTI Connext DDSCommercialIndustrial-grade option

Core DDS capabilities used by ROS 2:

  1. Automatic discovery
  2. QoS policy control
  3. Efficient transport and serialization
  4. Strong type contracts for message exchange

Major differences between ROS 1 and ROS 2

Structure comparison

ROS 1 depends on a centralized ROS Master for discovery, while ROS 2 uses DDS-based decentralized discovery.

Detailed comparative tables

DimensionROS 1ROS 2
MiddlewareCustom TCPROS/UDPROSDDS-based standard middleware
DiscoveryROS Master (centralized)DDS discovery (decentralized)
Build systemCatkinColcon + Ament
Python supportPython 2/3 (Noetic era transition)Python 3
OS supportPrimarily LinuxLinux, Windows, macOS, RTOS
Real-time supportLimitedImproved real-time support
Multi-robot supportExtra setup requiredBetter native isolation (ROS_DOMAIN_ID)
SecurityMinimal built-in securitySROS2 security framework
Release lineNoetic is final ROS 1 releaseActive releases (Humble, Iron, Jazzy, etc.)

Detailed information on key improvements

  1. Decentralization
  • ROS 1: depends on ROS Master for discovery.
  • ROS 2: DDS discovery removes single-point dependence.
  1. Real-time capability
  • ROS 1: not designed for strict real-time workloads.
  • ROS 2: improved determinism through DDS QoS and executor design.
  1. Multi-robot collaboration
  • ROS 1: requires additional engineering to isolate robots.
  • ROS 2: ROS_DOMAIN_ID simplifies logical separation.
  1. Cross-platform support
  • ROS 1: Linux-focused.
  • ROS 2: stronger support across Linux, Windows, macOS, and embedded targets.

ROS 2 Release

Version history

ROS 2 uses named releases. Common milestones include:

  • Ardent
  • Bouncy
  • Crystal
  • Dashing
  • Eloquent
  • Foxy
  • Galactic
  • Humble
  • Iron
  • Jazzy

Humble is a long-term support (LTS) release and is widely adopted in education and production entry projects.