Core Concepts
Understanding the fundamental concepts of ROS 2 is crucial for effective development. This section will cover the primary building blocks of a ROS 2 system.
Nodes
A node is an executable process that performs computation. In ROS 2, every functional unit of your robot's software is typically encapsulated within a node. For example, one node might be responsible for reading data from a LIDAR sensor, another for processing camera images, and yet another for controlling a robotic arm.
Nodes are designed to be modular and single-purpose, allowing for easy debugging, replacement, and reuse.
Topics
Topics are the main mechanism for asynchronous, many-to-many communication in ROS 2. Nodes publish data to topics, and other nodes can subscribe to topics to receive that data. This publish/subscribe model is ideal for streaming data, such as sensor readings, robot odometry, or video feeds.
- Publisher: A node that sends data to a topic.
- Subscriber: A node that receives data from a topic.
- Messages: The data structure exchanged over topics. Each topic has a specific message type defined by a
.msgfile.
Services
Services provide a synchronous request/reply communication mechanism. Unlike topics, which are for continuous data streams, services are used for discrete requests that elicit a response. For example, a robot might offer a "localize" service that, when called, returns the robot's current position, or a "set_gripper_state" service to open or close a gripper.
- Service Server: A node that provides a service and waits for requests.
- Service Client: A node that sends a request to a service server and waits for a response.
- Service Definition: Defined by
.srvfiles, which specify the structure of both the request and the response.
Actions
Actions are a higher-level, asynchronous communication method used for long-running tasks with regular feedback. They are built on top of topics and services and are particularly useful for tasks like navigating to a goal, performing a complex manipulation sequence, or picking up an object. An action client sends a goal, and the action server executes it, providing periodic feedback (progress updates) and eventually a result.
- Action Server: A node that provides an action, executes goals, sends feedback, and returns a result.
- Action Client: A node that sends a goal to an action server, receives feedback, and eventually gets a result.
- Action Definition: Defined by
.actionfiles, which specify the structure of the goal, feedback, and result.
Parameters
Parameters allow nodes to expose configurable values. These values can be changed at runtime without recompiling the node. Parameters are typically used for static configuration settings, such as sensor calibration values, PID gains for a motor controller, or behavioral thresholds.
Parameters can be set and retrieved programmatically by other nodes, or manually via command-line tools.
ROS 2 Graph
The collection of all active nodes, topics, services, and actions, and their connections, forms the ROS 2 Graph. Tools like rqt_graph can visualize this graph, helping developers understand the data flow and communication patterns within their robot system.
These core concepts form the backbone of any ROS 2 application, enabling modular, distributed, and robust robotic software development.