ROS installation on GNU / Linux

Posted by Daniel Rincón on July 10, 2020

When I entered university to study Electronic Engineering, I was very anxious to know that I was going to learn to make robots. At the end of my degree I realized that despite having done one or another robot, I still had a lot to learn about robotics. That is why I decided to focus my degree project in this field of electronics and in the middle of that path I found this powerful ROS tool. ROS for its acronym in English (Robot Operating System) is a software that allows us to do an infinity of things related to robotics, that is why I have prepared a tutorial for the installation in GNU / Linux in its available versions: Ubuntu and Debian. Also prepare a small robot with its respective environment to test the operation of ROS, I hope that you stay reading until the end and see what ROS can do.

Part 1: ROS Installation

For the ROS installation, I have relied on the official ROS Noetic (para Debian 10 y Ubuntu 20.04) and ROS Melodic (para Debian 9 y Ubuntu 18.04) tutorials. The first thing we should do is update the database of the system repositories, as we see below:

sudo sh -c 'echo "deb http://deb.debian.org/debian $(lsb_release -sc) contrib non-free" > /etc/apt/sources.list'
sudo sh -c 'echo "deb-src http://deb.debian.org/debian $(lsb_release -sc) contrib non-free" > /etc/apt/sources.list'

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe restricted multiverse"


sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update
sudo sh -c 'echo "deb http://deb.debian.org/debian $(lsb_release -sc) contrib non-free" > /etc/apt/sources.list'
sudo sh -c 'echo "deb-src http://deb.debian.org/debian $(lsb_release -sc) contrib non-free" > /etc/apt/sources.list'

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe restricted multiverse"


sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update

With the updated packages we are going to select the most complete ROS installation (this in order to have the 2D and 3D simulators), with the following command.

sudo apt install ros-noetic-desktop-full
sudo apt install ros-melodic-desktop-full

* Note for Debian 9 and Ubuntu 18.04 users: For these 2 distributions an additional step is necessary, it is necessary to initialize rosdep. 

sudo rosdep init
rosdep update

Now we are going to configure ROS in the system environment, this in order to have it installed globally.

echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

 

Part 2: Dependency Installation

 

To test ROS with the robot you make, we must install some dependencies, these are ros_control and ros_controllers, a couple of packages that facilitate robot control. You can read more about this package on the official ros_control page. In addition to a python package called getch it is used to read the keyboard, this is necessary because the robot is going to move when we press certain keys. We also need to install git to download the repository.

sudo apt install ros-noetic-ros-control ros-noetic-ros-controllers
python3 -m pip install getch
sudo apt install git
sudo apt install ros-melodic-ros-control ros-melodic-ros-controllers
python -m pip install getch
sudo apt install git

 

Part 3: Virtual Environment Configuration

 

Now what we are going to do is create a virtual environment or workspace (following this tutorial: Setting up the ROS environment) where we are going to install a small robot that I designed to show you how ROS works in a simulation.

This environment we will call catkin_tutorial, basically to create the environment, we need to create a folder and there one called src, so the ROS compiler will detect that it will be used as a ROS environment. When we have done this we are going to compile inside the folder that we created using the catkin_make command. Below we can see the commands used.

mkdir -p ~/catkin_tutorial/src
cd ~/catkin_tutorial/
catkin_make

At this point we have already successfully compiled our environment, it is time to add a robot, and as I already mentioned I have prepared an environment and a simple robot for testing is in my GitHub repository (robot_example), to make use of it we are going to clone it into the src folder (all the robots and codes that we are going to use in ROS must go in this folder) and then compile again, we proceed to do it with the following commands:

cd ~/catkin_tutorial/src/
git clone https://github.com/danielr460/robot_example
cd ~/catkin_tutorial/
catkin_make

Now we are going to add an environment that I prepared for the simulator, basically it is a flat green terrain and a sky with clouds, it is necessary to copy it in the simulator's configuration folder (Gazebo), to copy it we can do it in the following way:

cp -R src/robot_example/models/ground_plane_grass/ ~/.gazebo/models/
ls ~/.gazebo/models/
--> ground_plane_grass

 

Part 4: Simulation

 

For the simulation of the robot_example we need to open several terminals to run the robot.

In the first terminal, we are going to run roscore which is the core of ROS. ROS has a connection system through nodes (in a similar way to which the internet works) when executing this command all the following nodes will communicate with each other through this core.

roscore

Now we are going to execute in the second terminal the code that opens the simulator and also contains the robot. When Gazebo appears we will give the simulator play and it will be available to see the simulation.

cd ~/catkin_tutorial
source devel/setup.bash
roslaunch robot_example gazebo.launch

Subsequently, we are going to execute the control code in a third terminal, basically it is a code that will be read when we press the keyboard and each time we click on one of the arrows the robot will perform some action (if it is the arrow on the right the robot It will move forward, if it is left behind and if it is up or down the robot will brake). After executing this command we have to press the keys in the terminal where we execute it so that ROS recognizes that a key was pressed.

cd ~/catkin_tutorial
source devel/setup.bash
roslaunch robot_example control.launch

Finally, we can see a video with everything described plus a small sample of the robot simulation.