Book Image

ROS Robotics Projects - Second Edition

By : Ramkumar Gandhinathan
Book Image

ROS Robotics Projects - Second Edition

By: Ramkumar Gandhinathan

Overview of this book

Nowadays, heavy industrial robots placed in workcells are being replaced by new age robots called cobots, which don't need workcells. They are used in manufacturing, retail, banks, energy, and healthcare, among other domains. One of the major reasons for this rapid growth in the robotics market is the introduction of an open source robotics framework called the Robot Operating System (ROS). This book covers projects in the latest ROS distribution, ROS Melodic Morenia with Ubuntu Bionic (18.04). Starting with the fundamentals, this updated edition of ROS Robotics Projects introduces you to ROS-2 and helps you understand how it is different from ROS-1. You'll be able to model and build an industrial mobile manipulator in ROS and simulate it in Gazebo 9. You'll then gain insights into handling complex robot applications using state machines and working with multiple robots at a time. This ROS book also introduces you to new and popular hardware such as Nvidia's Jetson Nano, Asus Tinker Board, and Beaglebone Black, and allows you to explore interfacing with ROS. You'll learn as you build interesting ROS projects such as self-driving cars, making use of deep learning, reinforcement learning, and other key AI concepts. By the end of the book, you'll have gained the confidence to build interesting and intricate projects with ROS.
Table of Contents (14 chapters)

Installing ROS Melodic on Ubuntu 18.04 LTS

As we have already discussed, there are a variety of ROS distributions available to download and install, so choosing the exact distribution for our needs may be confusing. The following are the answers to some of the questions that are asked frequently while choosing a distribution:

  • Which distribution should I choose to get maximum support?

Answer: If you are interested in getting maximum support, choose an LTS release. It will be good if you choose the second-most recent LTS distribution.

  • I need the latest features of ROS; which should I choose?

Answer: Go for the latest version; you may not get the latest complete packages immediately after the release. You may have to wait a few months after the release. This is because of the migration period from one distribution to another.

In this book, we are dealing with two LTS distributions: ROS Kinetic, which is a stable release, and ROS Melodic, the latest one. Our chapters will use ROS Melodic Morenia.

Getting started with the installation

Go to the ROS installation website (http://wiki.ros.org/ROS/Installation). You will see a screen listing the latest ROS distributions:

Latest ROS distributions on the website

You can get the complete installation instructions for each distribution if you click on ROS Kinetic Kame or ROS Melodic Morenia.

We'll now step through the instructions to install the latest ROS distribution.

Configuring Ubuntu repositories

We are going to install ROS Melodic on Ubuntu 18.04 from the ROS package repository. The repository will have prebuilt binaries of ROS in .deb format. To be able to use packages from the ROS repository, we have to configure the repository options of Ubuntu first.

The details of the different kinds of Ubuntu repositories can be found at https://help.ubuntu.com/community/Repositories/Ubuntu.

To configure the repository, perform the following steps:

  1. First, search for Software & Updates in the Ubuntu search bar:
Ubuntu Software & Updates
  1. Click on Software & Updates and enable all of the Ubuntu repositories, as shown in the following screenshot:
The Ubuntu Software & Updates center

Now that we've enabled the preceding set conditions, we can move on to the next step.

Setting up source.list

The next step is to allow ROS packages from the ROS repository server, called packages.ros.org. The ROS repository server details have to be fed into source.list, which is in /etc/apt/.

The following command will do this for ROS Melodic:

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Let's set up the keys now.

Setting up keys

When a new repository is added to Ubuntu, we should add the keys to make it trusted and to be able to validate the origin of the packages. The following key should be added to Ubuntu before starting installation:

$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116 

Now, we are sure that we are downloading from an authorized server.

Installing ROS Melodic

Now, we are ready to install ROS packages on Ubuntu. Follow these steps to do so:

  1. The first step is to update the list of packages on Ubuntu. You can use the following command to update the list:
$ sudo apt-get update 

This will fetch all the packages from the servers that are in source.list.

  1. After getting the package list, we have to install the entire ROS package suite using the following command:
$ sudo apt-get install ros-melodic-desktop-full 

This will install most of the important packages in ROS. You will need at least 15 GB of space in your root Ubuntu partition to install and work with ROS.

Initializing rosdep

The rosdep tool in ROS helps us easily install the dependencies of the packages that we are going to compile. This tool is also necessary for some core components of ROS.

This command launches rosdep:

$ sudo rosdep init 
$ rosdep update

Here, while the first command was called, a file called 20-default.list was created in /etc/ros/rosdep/sources.list.d/, with a list of links that connect to the respective ros-distros.

Setting up the ROS environment

Congratulations! We are done with the ROS installation, but what next?

The ROS installation mainly consists of scripts and executables, which are mostly installed to /opt/ros/<ros_version>.

To get access to these commands and scripts, we should add ROS environment variables to the Ubuntu Terminal. It's easy to do this. To access ROS commands from inside the Terminal, we have to source the /opt/ros/<ros_version>/setup.bash file.

Here's the command to do so:

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

But in order to get the ROS environment in multiple Terminals, we should add the command to the .bashrc script, which is in the home folder. The .bashrc script will be sourced whenever a new Terminal opens:

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

We can install multiple ROS distributions on Ubuntu. If there are multiple distributions, we can switch to each ROS distribution by changing the distribution name in the preceding command.

Getting rosinstall

Last but not least, there is the ROS command-line tool, called rosinstall, for installing source trees for particular ROS packages. The tool is based on Python, and you can install it using the following command:

$ sudo apt-get install python-rosinstall 

We are done with the ROS installation. Just check whether the installation is successful by running the following commands:

  • Open a Terminal window and run the roscore command:
$ roscore 
  • Run a turtlesim node in another Terminal:
$ rosrun turtlesim turtlesim_node

If everything is correct, you will see the following output:

The turtlesim node GUI and Terminal with pose information

If you respawn the turtlesim node a couple of times, you should see the turtle changing. We have now successfully installed ROS on Ubutu. Now, let's learn how to set up ROS on VirtualBox.