Beginner's tutorial for ROS 2

> #ros2-foxy

> In this blog, we will first install ROS 2, create a ROS 2 workspace, create a ROS 2 package and then learn a few basic things about it.

Author : Aryaman Shardul

Note : These instructions are for ROS 2 Foxy and were tested on Ubuntu 20.4 LTS. I have installed via Debian packages.

Table of Contents

What is ROS 2

ROS 2 Installation instructions

Setting up the locale and resources

Installing the ROS 2 packages

The desktop installtion comes with all the required tools, debugging features and GUI whereas the ROS base installation comes with only the core packages which are required and nothing more. Therefore, I would recommend to go with the desktop installation option.

  1. Desktop install: sudo apt install ros-foxy-desktop
    or
  2. ROS base install: sudo apt install ros-foxy-ros-base

We are done with the installation of ROS 2.

Setting up the environment

Autocomplete using argcomplete (Optional)

Checking whether ROS 2 has been installed or not

Setting up the ROS 2 workspace

We have already installed ROS 2 and configured it's environment above. Now in this section, we will be setting up a ROS2 workspace.

A ROS 2 workspace is a directory containing all the ROS 2 packages.

ros2_ws

Note : colcon build --symlink-install saves you from having to rebuild every time you tweak python scripts.

With this you have set up your ROS 2 workspace. Now it's time to create your first ROS 2 package.

Creating a ROS 2 package

A ROS 2 package is like a container for all the ROS 2 nodes, dependencies, etc.

Now ROS 2 CMake and Python packages both have different basic requirements. A CMake package contains a bare minimum of package.xml and CMakeLists.txt files whereas a python package conatins setup.py, setup.cfg, package.xml and resource/package_name files.

Whereas for Python package, enter the following command.
ros2 pkg create --build-type ament_python

my_package

Again note that the above two commands must be entered in the root of your workspace.

Congratulations you have successfully built a ROS 2 package.

What is new in ROS 2

Provides support to different Operating Systems

Ros or Ros1 was meant for Ubuntu, Fedora and Arch Linux. But Ros2 provides support for macOS and Windows too.

ROS 2 Nodes

The process of advertising and de-advertising a node in ROS used the ROS Master. The entire process was based on a single node. But ROS 2 uses a Fast DDS Discovery Server due to which the entire process does not depend only on a single node.

What is a Fast DDS Discovery Server

ds_explanation

Client Libraries

Launch Files

Conclusion

References