Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ROS Robotics Projects,

You're reading from   ROS Robotics Projects, Build and control robots powered by the Robot Operating System, machine learning, and virtual reality

Arrow left icon
Product type Paperback
Published in Dec 2019
Publisher Packt
ISBN-13 9781838649326
Length 456 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ramkumar Gandhinathan Ramkumar Gandhinathan
Author Profile Icon Ramkumar Gandhinathan
Ramkumar Gandhinathan
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Getting Started with ROS FREE CHAPTER 2. Introduction to ROS-2 and Its Capabilities 3. Building an Industrial Mobile Manipulator 4. Handling Complex Robot Tasks Using State Machines 5. Building an Industrial Application 6. Multi-Robot Collaboration 7. ROS on Embedded Platforms and Their Control 8. Reinforcement Learning and Robotics 9. Deep Learning Using ROS and TensorFlow 10. Creating a Self-Driving Car Using ROS 11. Teleoperating Robots Using a VR Headset and Leap Motion 12. Face Detection and Tracking Using ROS, OpenCV, and Dynamixel Servos 13. Other Books You May Enjoy

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.

You have been reading a chapter from
ROS Robotics Projects, - Second Edition
Published in: Dec 2019
Publisher: Packt
ISBN-13: 9781838649326
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image