This repository contains a series of coding tutorials based on the 3 communication protocols in ROS2:
These classes, clients, and servers are embedded within a Node
which processes / sends / receives different types of data being sent over the ROS2 network.
Figure 1: Nodes in ROS2 combine different communication protocols to achieve complex tasks.
Any number of these communicators may combined within a Node
to achieve a desired task. The type of communication method depends on the type of data being transmitted, and how it is expected to be processed:
Table 1: Properties of ROS2 Communication Protocols.
Sender | Receiver | Node Interaction | Periodicity | Example(s) |
---|---|---|---|---|
Publisher | Subscriber | One ➡️ Many | Frequent | Sensor data, joystick inputs 🕹️ |
Client | Service | One |
Upon request | Retreiving map updates 🗺️ |
(Action) Client | (Action) Server | One |
Upon request, with frequent updates. | Moving a robot to a target location 🎯 |
The Publisher
and Subcriber
protocol is analogous to the role of a news agency, or book store. A printing press will publish magazines and/or books that are sent to a store. They are made publically available for people to purchase of their own volition. The type of data being communicated is fast, frequent, and numerous.
Figure 2: Publishers make data publicly available for any number of subscribers.
The Client
and Service
protocol is more akin to a postal service. A request is sent by a Client
directly to a Server
, who will process said request and send a reponse. The type of data being communicated is fast, infrequent, and sparse.
Figure 3: Clients and services exchange information privately and directly.
The Action Client
and Action Server
protocol is analogous to requesting transport with Uber. The request is made, a driver confirms the response, and updates are given in real time on how close the driver is to arrival. The interaction is infrequent, like the Server
& Client
protocol, but frequent updates are provided like the Publisher
& Subscriber
.
Figure 4: Actions carry out goals over an extended period of time, providing feedback.
Make a directory for your ROS2 workspace, for example ros2_workspace
:
mkdir ros2_workspace
Navigate inside of this new folder, and create a src
directory:
cd ros2_workspace/ && mkdir src
Now navigate inside this new folder:
cd src/
and create the new package:
ros2 pkg create --dependencies rclcpp -- tutorial_ros2
Figure 5: Creating a new package for the tutorial in ROS2.
The folder structure should look something like this:
ros2_workspace/
└── src/
├── include/
| └── tutorial_ros/
├── src/
├── CMakeLists.txt
└── package.xml
The important files for a functional ROS2 package are CMakeLists.txt
and package.xml
.
More information can be found in the official ROS2 tutorial page.