As explained in the previous post, the need to switch to ROS2 was essential for moving forward with a truly distributed architecture. In this post, we will take a look at how we can install and configure ROS2 on our target system.Please note, we will be publishing this tutorial with our target system in mind, which is a computer running Ubuntu18.04 LTS, having a 5th generation Intel core i3 and 12 GB of RAM.


Method of Installation:

There are two main ways that we can install ROS2:

  • By downloading the source and compiling it on the target system. This is not recommended unless you have quite some experience in building software this way. It is used mainly for custom targets, which need to meet some specific requirements. Nevertheless, if you want to take a look at this process, you can follow the instructions here.

  • The OSRF provided packaged binaries for a lot of target Debian-based systems. These can be installed fairly quickly, and also lets the user start using the software “as-is”. The general rule of thumb here is that If there exists a prepackaged binary for the target, we use it.

Note: Just like with ROS, the choice of ROS2 version largely depends on the version of Ubuntu you are running. In this post, our target system is running Ubuntu 18.04 LTS, hence we will install ROS2 Dashing. Ideally you would want the latest stable release to go with.


Before we Begin

Before we begin, we should configure our Ubuntu repositories to be able to install software from different types of repositories. Generally, the default setting is “Main” - i.e., we can only use the software that is supported by Canonical and is open-source. Since ROS is not maintained by the Canonical group, we would want to extend our software repositories to include “Universe”, “Restricted”, and “Multiverse” as well. To do this, you can go to “Softwares and Updates” and select the options mentioned above.

Setup your keys

Now, since we are really concerned with our privacy, we want to make sure that the ROS package we download are really sent by the OSRF, and not any fraudulent agency with malicious intent. So, we take the help of a key-server, which will generate a unique set of keys, one Public Key(what you are going to download on your target system), and one Private Key(that is held by OSRF). This creates a unique signature for apt-get to compare with while installing the package. Run the following command on the terminal:

 sudo apt update && sudo apt install curl gnupg2 lsb-release
 curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

Setup your sources list

Now that we are able to install software from all sources, we would like to make our target system be able to accept software from ros.org. Open up a terminal, and run the following command:

sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

What you are doing here is adding the Debian package for ROS on your sources.list.d directory so that the package is able to add new sources without changing the rest of the configuration.

Install

Now we are finally ready to begin installation. Update your package index first by running the following command:

sudo apt update

Once the package list has been updated, you can now proceed to install ROS2 Dashing. Here, you have a choice to make, largely based on what you are trying to achieve with your target system when you will use ROS2. If you can afford the memory, it is honestly the best to always go for the Desktop install, as this has all the functionalities ROS2 will have to offer to you. But mind you, this is a fairly large(~2GB) file. The differences in the choices are highlighted below:

  • Desktop: Always recommended that you install this if you are a beginner, as this is basically ROS with all its features like multiple simulators, robot libraries, perception support and a whole lot. This is the best choice if you want to start development the moment after you finish installing ROS.

  • ROS-Base: The lightest version of ROS out there. This is generally meant for edge devices, and contains the core ROS functionalities, the ROS build tools, and communication libraries. Ideal for extremely resource constrained devices. Keep in mind though, that with this version you will not get any form of GUI.

Once you have made an informed decision based on your requirements from ROS, you can install the packages by typing the command on your terminal:

sudo apt-get install ros-dashing-desktop

You will note in the previous command that we have installed the desktop version. If you want to install the other versions, replace the desktop in the previous command by ros-base such that the commands would look like this:

sudo apt-get install ros-dashing-ros-base

Congratulations! You have now successfully configured ROS2 on your target system. However, in order to start using the system, you would want to follow the next step, which does a little bit of book keeping.

Install dependencies

You can use the following command to download and install argcomplete, which is used a lot for autocompletion in ROS2:

sudo apt install python3-argcomplete

Setup the Environment

With the completion of the previous step, ROS2 is now installed in our /opt/ros/dashing directory. Now, since we are using ROS2 and ROS side-by-side, we will source the ROS2 workspace only when we need it. We cannot put both the setup files in the .bashrc file, this would only source the last entry. You can source the setup file as follows:

$ source /opt/ros/dashing/setup.bash

This concludes the installation of ROS2 on our target system.


References:

  1. ROS Installation: index.ros.org
  2. ROS Answers: answers.ros.org