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
Conferences
Free Learning
Arrow right icon
ROS Robotics Projects,
ROS Robotics Projects,

ROS Robotics Projects,: Build and control robots powered by the Robot Operating System, machine learning, and virtual reality , Second Edition

Arrow left icon
Profile Icon Ramkumar Gandhinathan
Arrow right icon
₹800 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.3 (3 Ratings)
Paperback Dec 2019 456 pages 2nd Edition
eBook
₹799 ₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹800p/m
Arrow left icon
Profile Icon Ramkumar Gandhinathan
Arrow right icon
₹800 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.3 (3 Ratings)
Paperback Dec 2019 456 pages 2nd Edition
eBook
₹799 ₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹800p/m
eBook
₹799 ₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

ROS Robotics Projects,

Getting Started with ROS

Robotics is one of the upcoming technologies that can change the world. Robots can replace people in many ways, and we are all afraid of them stealing our jobs. One thing is for sure: robotics will be one of the influential technologies of the future. When a new technology gains momentum, the opportunities in that field also increase. This means that robotics and automation can generate a lot of job opportunities in the future.

One of the main areas in robotics that can provide mass job opportunities is robotics software development. As we all know, software gives life to a robot or any machine. We can expand a robot's capabilities through software. If a robot exists, its capabilities, such as control, sensing, and intelligence, are realized using software.

Robotics software involves a combination of related technologies, such as computer vision, artificial intelligence, and control theory. In short, developing software for a robot is not a simple task; it can require expertise in many fields.

If you're looking for mobile application development in iOS or Android, there is a Software Development Kit (SDK) available to build applications in it, but what about robots? Is there any generic software framework available? Yes. One of the more popular robotics software frameworks is called the Robot Operating System (ROS).

In this chapter, we will take a look at an abstract concept of ROS and how to install it, along with an overview of simulators and its use on virtual systems. We will then cover the basic concepts of ROS, along with the different robots, sensors, and actuators that support ROS. We will also look at ROS with respect to industries and research. This entire book is dedicated to ROS projects, so this chapter will be a kick-start guide for those projects and help you set up ROS.

The following topics are going to be covered in this chapter:

  • Getting started with ROS
  • Fundamentals of ROS
  • ROS client libraries
  • ROS tools
  • ROS simulators
  • Installing ROS
  • Setting up ROS on VirtualBox
  • Introduction to Docker
  • Setting up the ROS workspace
  • Opportunities for ROS in industries and research

So, let's get started with ROS.

Technical requirements

Let's look into the technical requirements for this chapter:

  • ROS Melodic Morenia on Ubuntu 18.04 (Bionic)
  • VMware and Docker
  • Timelines and test platform:
    • Estimated learning time: On average, 65 minutes
    • Project build time (inclusive of compile and run time): On average, 60 minutes
    • Project test platform: HP Pavilion laptop (Intel® Core™ i7-4510U CPU @ 2.00 GHz × 4 with 8 GB Memory and 64-bit OS, GNOME-3.28.2)

Getting started with ROS

ROS is an open source, flexible software framework for programming robots. ROS provides a hardware abstraction layer in which developers can build robotics applications without worrying about the underlying hardware. ROS also provides different software tools to visualize and debug robot data. The core of the ROS framework is a message-passing middleware in which processes can communicate and exchange data with each other, even when they're running from different machines. ROS message passing can be synchronous or asynchronous.

Software in ROS is organized as packages, and it offers good modularity and reusability. Using the ROS message-passing middleware and hardware abstraction layer, developers can create tons of robotic capabilities, such as mapping and navigation (in mobile robots). Almost all the capabilities in ROS will be robot agnostic so that all kinds of robots can use it. New robots can directly use this capability package without modifying any code inside the package.

ROS has widespread collaborations in universities, and lots of developers contribute to it. We can say that ROS is a community-driven project supported by developers worldwide. This active developer ecosystem distinguishes ROS from other robotic frameworks.

In short, ROS is the combination of Plumbing (or communication), Tools, Capabilities, and Ecosystem. These capabilities are demonstrated in the following diagram:

The ROS equation (source: ros.org. licensed under Creative Commons CC-BY-3.0: https://creativecommons.org/licenses/by/3.0/us/legalcode)

The ROS project was started in 2007 at Stanford University under the name Switchyard. Later on, in 2008, the development was undertaken by a robotic research startup called Willow Garage. The major development in ROS happened in Willow Garage. In 2013, the Willow Garage researchers formed the Open Source Robotics Foundation (OSRF). ROS is actively maintained by OSRF now. Now, let's look at a few ROS distributions.

Here are links to their websites: Willow Garage: http://www.willowgarage.com/
OSRF: http://www.osrfoundation.org/.

ROS distributions

The ROS distributions are very similar to Linux distributions, that is, a versioned set of ROS packages. Each distribution maintains a stable set of core packages, up to the End Of Life (EOL) of the distribution.

The ROS distributions are fully compatible with Ubuntu, and most of the ROS distributions are planned according to their respective Ubuntu versions.

The following are some of the latest ROS distributions (at the time of writing) that are recommended for use from the ROS website (http://wiki.ros.org/Distributions):

Latest ROS distributions (source: ros.org. licensed under Creative Commons CC-BY-3.0: https://creativecommons.org/licenses/by/3.0/us/legalcode)

The latest ROS distribution is Melodic Morenia. We will get support for this distribution up until May 2023. One of the problems with this latest ROS distribution is that most of the packages will not be available on it because it will take time to migrate them from the previous distribution. If you are looking for a stable distribution, you can go for ROS Kinetic Kame because the distribution started in 2016, and most of the packages are available on this distribution. The ROS Lunar Loggerhead distribution will stop being supported in May 2019, so I do not recommend that you use it.

Supported OSes

The main OS ROS is tuned for is Ubuntu. ROS distributions are planned according to Ubuntu releases. Other than Ubuntu, it is partially supported by Ubuntu ARM, Debian, Gentoo, macOS, Arch Linux, Android, Windows, and OpenEmbedded.

This table shows new ROS distributions and the specific versions of the supporting OSes:

ROS distribution

Supporting OSes

Melodic Morenia (LTS)

Ubuntu 18.04 (LTS) and 17.10, Debian 8, macOS (Homebrew), Gentoo, and Ubuntu ARM

Kinetic Kame (LTS)

Ubuntu 16.04 (LTS) and 15.10, Debian 8, macOS (Homebrew), Gentoo, and Ubuntu ARM

Jade Turtle

Ubuntu 15.04, 14.10, and 14.04, Ubuntu ARM, macOS (Homebrew), Gentoo, Arch Linux, Android NDK, and Debian 8

Indigo Igloo (LTS)

Ubuntu 14.04 (LTS) and 13.10, Ubuntu ARM, macOS (Homebrew), Gentoo, Arch Linux, Android NDK, and Debian 7

ROS Melodic and Kinetic are Long-Term Support (LTS) distributions that come with the LTS version of Ubuntu. The advantage of using LTS distribution is that we will get maximum lifespan and support.

We will look at a few robots and sensors that are supported by ROS in the next section.

Robots and sensors supported by ROS

The ROS framework is one of the most successful robotics frameworks, and universities around the globe contribute to it. Because of its active ecosystem and open source nature, ROS is being used in a majority of robots and is compatible with major robotic hardware and software. Here are some of the most famous robots completely running on ROS:

Popular robots supported by ROS (Source: ros.org. Licensed under Creative Commons CC-BY-3.0: https://creativecommons.org/licenses/by/3.0/us/legalcode)

The names of the robots listed in preceding images are Pepper (a), REEM-C (b), Turtlebot (c), Robonaut (d), and Universal Robots (e).

The robots supported by ROS are listed at the following link: http://wiki.ros.org/Robots.

The following are the links where you can get the ROS packages of these robots:

Some popular sensors that support ROS are as follows:

Popular robot sensors supported in ROS

The names of the sensors in the preceding image are Velodyne (a), ZED Camera (b), Teraranger (c), Xsens (d), Hokuyo Laser range finder (e), and Intel RealSense (f).

The list of sensors supported by ROS is available at the following link: http://wiki.ros.org/Sensors.

The following are the links to the ROS wiki pages of these sensors:

Now, let's look at the advantages of using ROS.

Why use ROS?

The main intention behind building the ROS framework is to become a generic software framework for robots. Even though there was robotics research happening before ROS, most of the software was exclusive to their own robots. Their software may be open source, but it is very difficult to reuse.

Compared to existing robotic frameworks, ROS is outperforming in the following aspects:

  • Collaborative development: As we've already discussed, ROS is open source and free to use for industries and research. Developers can expand the functionalities of ROS by adding packages. Almost all ROS packages work on a hardware abstraction layer, so it can be reused easily for other robots. So, if one university is good in mobile navigation and another is good in robotic manipulators, they can contribute that to the ROS community and other developers can reuse their packages and build new applications.
  • Language support: The ROS communication framework can be easily implemented in any modern programming language. It already supports popular languages such as C++, Python, and Lisp, and it has experimental libraries for Java and Lua.
  • Library integration: ROS has an interface to many third-party robotics libraries, such as Open Source Computer Vision (OpenCV), Point Cloud Library (PCL), Open-NI, Open-Rave, and Orocos. Developers can work with any of these libraries without much hassle.
  • Simulator integration: ROS also has ties to open source simulators such as Gazebo and has a good interface with proprietary simulators such as Webots and V-REP.
  • Code testing: ROS offers an inbuilt testing framework called rostest to check code quality and bugs.
  • Scalability: The ROS framework is designed to be scalable. We can perform heavy computation tasks with robots using ROS, which can either be placed on the cloud or on heterogeneous clusters.
  • Customizability: As we have already discussed, ROS is completely open source and free, so we can customize this framework as per the robot's requirements. If we only want to work with the ROS messaging platform, we can remove all of the other components and use only that. We can even customize ROS for a specific robot for better performance.
  • Community: ROS is a community-driven project, and it is mainly led by OSRF. The large community support is a great plus for ROS and means we can easily start robotics application development.

The following are the URLs of libraries and simulators that can be integrated with ROS:

Let's go through some of the basic concepts of ROS; these can help you get started with ROS projects.

Fundamentals of ROS

Understanding the basic working of ROS and its terminology can help you understand existing ROS applications and build your own. This section will teach you important concepts that we are going to use in the upcoming chapters. If you find that a topic is missing in this chapter, then rest assured that it will be covered in a corresponding chapter later.

There are three different concepts in ROS. Let's take a look at them.

The filesystem level

The filesystem level explains how ROS files are organized on the hard disk:

The ROS filesystem level

As you can see from the preceding diagram, the filesystem in ROS can be categorized mainly as metapackages, packages, package manifest, messages, services, codes, and miscellaneous files. The following is a short description of each component:

  • Metapackages: Metapackages group a list of packages for a specific application. For example, in ROS, there is a metapackage called navigation for mobile robot navigation. It can hold the information of related packages and helps install those packages during its own installation.
  • Packages: The software in ROS is mainly organized as ROS packages. We can say that ROS packages are the atomic build units of ROS. A package may consist of ROS nodes/processes, datasets, and configuration files, all organized in a single module.
  • Package manifest: Inside every package will be a manifest file called package.xml. This file consists of information such as the name, version, author, license, and dependencies that are required of the package. The package.xml file of a metapackage consists of the names of related packages.
  • Messages (msg): ROS communicates by sending ROS messages. The type of message data can be defined inside a file with the .msg extension. These files are called message files. Here, we are going to follow a convention where we put the message files under our_package/msg/message_files.msg.
  • Service (srv): One of the computation graph level concepts is services. Similar to ROS messages, the convention is to put service definitions under our_package/srv/service_files.srv.

This sums up the ROS filesystem.

The computation graph level

The ROS computation graph is a peer-to-peer based network that processes all the information together. The ROS graph concept constitutes nodes, topics, messages, master, parameter server, services, and bags:

The ROS computational graph concept diagram

The preceding diagram shows the various concepts in the ROS computational graph. Here is a short description of each concept:

  • Nodes: ROS nodes are simply processes that use ROS APIs to communicate with each other. A robot may have many nodes to perform its computations. For example, an autonomous mobile robot may have a node each for hardware interfacing, reading laser scan, and localization and mapping. We can create ROS nodes using ROS client libraries such as roscpp and rospy, which we will be discussing in the upcoming sections.
  • Master: The ROS master works as an intermediate node that aids connections between different ROS nodes. The master has all of the details about all the nodes running in the ROS environment. It will exchange details of one node with another to establish a connection between them. After exchanging this information, communication will start between the two ROS nodes.
  • Parameter server: The parameter server is a pretty useful thing in ROS. A node can store a variable in the parameter server and set its privacy, too. If the parameter has a global scope, it can be accessed by all other nodes. The ROS parameter runs along with the ROS master.
  • Messages: ROS nodes can communicate with each other in many ways. In all the methods, nodes send and receive data in the form of ROS messages. The ROS message is a data structure that's used by ROS nodes to exchange data.
  • Topics: One of the methods to communicate and exchange ROS messages between two ROS nodes is called ROS topics. Topics are named buses in which data is exchanged using ROS messages. Each topic will have a specific name, and one node will publish data to a topic and another node can read from the topic by subscribing to it.
  • Services: Services are another kind of communication method, similar to topics. Topics use publish or subscribe interaction, but in services, a request or reply method is used. One node will act as the service provider, which has a service routine running, and a client node requests a service from the server. The server will execute the service routine and send the result to the client. The client node should wait until the server responds with the results.
  • Bags: Bags are a useful utility in ROS for the recording and playback of ROS topics. While working on robots, there may be some situations where we need to work without actual hardware. Using rosbag, we can record sensor data and copy the bag file to other computers to inspect data by playing it back.

This sums up the computational graph concept.

The ROS community level

The ROS community has grown more now compared to the time it was introduced. You can find at least 2,000+ packages being supported, altered, and used by the community actively. The community level comprises the ROS resources for sharing software and knowledge:

ROS community level diagram

Here is a brief description of each section:

  • Distributions: ROS distributions are versioned collections of ROS packages, such as Linux distributions.
  • Repositories: ROS-related packages and files depend on a Version Control System (VCS) such as Git, SVN, and Mercurial, using which developers around the world can contribute to the packages.
  • ROS Wiki: The ROS community wiki is the knowledge center of ROS, in which anyone can create documentation of their packages. You can find standard documentation and tutorials about ROS on the ROS wiki.
  • Mailing lists: Subscribing to ROS mailing lists enables users to get new updates regarding ROS packages and gives them a place to ask questions about ROS (http://wiki.ros.org/Mailing%20Lists?action=show).
  • ROS Answers: The ROS Answers website is the stack overflow of ROS. Users can ask questions regarding ROS and related areas (http://answers.ros.org/questions/).
  • Blog: The ROS blog provides regular updates about the ROS community with photos and videos (http://www.ros.org/news).

Now, let's learn how communication is carried out in ROS in the next section.

Communication in ROS

Let's learn how two nodes communicate with each other using ROS topics. The following diagram shows how this happens:

Communication between ROS nodes using topics

As you can see, there are two nodes named talker and listener. The talker node publishes a string message called Hello World into a topic called /talker, while the listener node is subscribed to this topic. Let's see what happens at each stage, marked (1), (2), and (3) in the preceding diagram:

  1. Before running any nodes in ROS, we should start the ROS Master. After it has been started, it will wait for nodes. When the talker node (publisher) starts running, it will connect to the ROS Master and exchange the publishing topic details with the master. This includes the topic name, message type, and publishing node URI. The URI of the master is a global value, and all the nodes can connect to it. The master maintains the tables of the publisher connected to it. Whenever a publisher's details change, the table updates automatically.
  1. When we start the listener node (subscriber), it will connect to the master and exchange the details of the node, such as the topic going to be subscribed to, its message type, and the node URI. The master also maintains a table of subscribers, similar to the publisher.
  2. Whenever there is a subscriber and publisher for the same topic, the master node will exchange the publisher URI with the subscriber. This will help both nodes to connect and exchange data. After they've connected, there is no role for the master. The data is not flowing through the master; instead, the nodes are interconnected and exchange messages.

More information on nodes, their namespaces, and usage can be found here: http://wiki.ros.org/Nodes.

Now that we know the fundamentals of ROS, let's look at a few ROS client libraries.

ROS client libraries

ROS client libraries are used to write ROS nodes. All of the ROS concepts are implemented in client libraries. So, we can just use it without implementing everything from scratch. We can implement ROS nodes with a publisher and subscriber, write service callbacks, and so on using client libraries.

The main ROS client libraries are in C++ and Python. Here is a list of popular ROS client libraries:

  • roscpp: This is one of the most recommended and widely used ROS client libraries for building ROS nodes. This client library has most of the ROS concepts implemented and can be used in high-performance applications.
  • rospy: This is a pure implementation of the ROS client library in Python. The advantage of this library is its ease of prototyping, which means that development time isn't as long. It is not recommended for high-performance applications, but it is perfect for non-critical tasks.
  • roslisp: This is the client library for LISP and is commonly used to build robot planning libraries.

Details of all the client ROS libraries can be found at the following link: http://wiki.ros.org/Client%20Libraries. The next section will give us an overview of different ROS tools.

ROS tools

ROS has a variety of GUI and command-line tools to inspect and debug messages. These tools come in handy when you're working in a complex project involving a lot of package integrations. It would help to identify whether the topics and messages are published in the right format and are available to the user as desired. Let's look at some commonly used ones.

ROS Visualizer (RViz)

RViz (http://wiki.ros.org/rviz) is one of the 3D visualizers available in ROS that can visualize 2D and 3D values from ROS topics and parameters. RViz helps to visualize data such as robot models, robot 3D transform data (TF), point cloud, laser and image data, and a variety of different sensor data:

Point cloud data visualized in RViz

The preceding screenshot shows a 3D point cloud scan from a Velodyne sensor placed on an autonomous car.

rqt_plot

The rqt_plot program (http://wiki.ros.org/rqt_plot) is a tool for plotting scalar values that are in the form of ROS topics. We can provide a topic name in the Topic box:

rqt_plot

The preceding screenshot is a plot of a pose from the turtle_sim node.

rqt_graph

The rqt_graph (http://wiki.ros.org/rqt_graph) ROS GUI tool can visualize the graph of interconnection between ROS nodes:

rqt_graph

The complete list of ROS tools is available at the following link: http://wiki.ros.org/Tools.

Since we now have a brief idea of the ROS tools, we can cover different ROS simulators.

ROS simulators

One of the open source robotic simulators tightly integrated with ROS is Gazebo (http://gazebosim.org). Gazebo is a dynamic robotic simulator that has a wide variety of robot models and extensive sensor support. The functionalities of Gazebo can be added via plugins. The sensor values can be accessed by ROS through topics, parameters, and services. Gazebo can be used when your simulation needs full compatibility with ROS. Most of the robotics simulators are proprietary and expensive; if you can't afford it, you can use Gazebo directly without any issues:

Gazebo simulator

The preceding is a PR2 robot model from OSRF. You can find the model at https://github.com/pr2/pr2_common, in the description folder.

The ROS interface of Gazebo is available at the following link: http://wiki.ros.org/gazebo.

Now that we know about the simulators of ROS, we can begin installing ROS Melodic on Ubuntu.

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.

Setting up ROS on VirtualBox

As you know, complete ROS support is only present on Ubuntu. So, what about Windows and macOS users? Can't they use ROS? Yes, they can, using a tool called VirtualBox (https://www.virtualbox.org/). VirtualBox allows us to install a guest OS without affecting the host OS. The virtual OS can work along with the host OS in a given specification of a virtual computer, such as the number of processors and RAM and hard disk size.

You can download VirtualBox for popular OSes from the following link: https://www.virtualbox.org/wiki/Downloads.

The complete installation procedure for Ubuntu on VirtualBox is shown in the following tutorial video on YouTube: https://www.youtube.com/watch?v=QbmRXJJKsvs.

The following is a screenshot of the VirtualBox GUI. You can see the virtual OS list on the left-hand side and the virtual PC configuration on the right-hand side. The buttons for creating a new virtual OS and starting the existing VirtualBox are on the top panel. The optimal virtual PC configuration is shown in the following screenshot:

The VirtualBox configuration

Here are the main specifications of the virtual PC:

  • Number of CPUs: 1
  • RAM: 4 GB
  • Display | Video Memory: 128 MB
  • Acceleration: 3D
  • Storage: 20 GB to 30 GB
  • Network adapter: NAT

In order to have hardware acceleration, you should install drivers from the VirtualBox Guest addons disc. After booting into the Ubuntu desktop, navigate to Devices | Insert Guest Addition CD Image. This will mount the CD image in Ubuntu and ask the user to run the script to install drivers. If we allow it, it will automatically install all of the drivers. After a reboot, you will get full acceleration on the Ubuntu guest.

There is no difference in ROS installation on VirtualBox. If the virtual network adapter is in NAT mode, the internet connection of the host OS will be shared with the guest OS, so the guest can work the same as the real OS. We now have ROS set up on VirtualBox.

The next section is an introduction to Docker.

Introduction to Docker

Docker is a piece of free software and the name of the company that introduced it to open source community. You might have heard of virtual environments in Python, where you can create isolated environments for your projects and install dedicated dependencies that do not cause any trouble with other projects in other environments. Docker is similar, where we can create isolated environments for our projects called containers. Containers work like virtual machines but aren't actually similar to virtual machines. While virtual machines need a separate OS on top of the hardware layer, containers do not and work independently on top of the hardware layer, sharing the resources of the host machine.

This helps us consume less memory and it is often speedier than virtual machines. The best example to show the difference between both is shown here:

Differences between a virtual machine and Docker

Now that we know the difference between a virtual machine and Docker, let's understand why we use Docker.

Why Docker?

In ROS, a project may consist of several metapackages that contain subpackages, and those would need dependencies to work on. It could be quite annoying for a developer to set up packages in ROS as it is quite common that different packages would use different or the same dependencies of different versions and those could lead to compilation issues. The best example would be when we want to use OpenCV3 with ROS Indigo while working with vision algorithms or gazebo_ros_controller packages with different plugin versions, causing the famous gravity error (https://github.com/ros-simulation/gazebo_ros_pkgs/issues/612). By the time the developer tries to rectify them, he/she might end up losing other working projects due to replaced packages or dependency version changes. While there might be different ways to handle this problem, a practical way to go about this problem in ROS would be to use Docker containers. Containers are fast and can start or stop, unlike any process in an OS in a matter of seconds. Any upgrades or updates on the OS, or packages would not affect the containers inside or other containers in place.

Installing Docker

Docker can be installed in two ways: using the Ubuntu repositories or using the official Docker repository:

  • If you would just like to explore and save a couple of minutes with just a single line installation, go ahead and install from the Ubuntu repository.
  • If you would like to explore more options with Docker other than what is intended in this book, I would suggest that you go ahead and install from official Docker repositories as they will have the most stable and bug-fixed packages with added features.
Before going ahead with either of the following installations, ensure you update the apt package index using $ sudo apt-get update.

Installing from the Ubuntu repository

To install Docker from the Ubuntu repository, use the following command:

$ sudo apt-get install docker.io

If you've changed your mind and would like to try out installing from the Docker repository or if you wish to remove the Docker version you installed via the preceding step, move on to the next step.

Removing Docker

If you're not interested in the old Docker version and want to install the latest stable version, remove Docker using the following command and install it from the Docker repository:

$ sudo apt-get remove docker docker-engine docker.io containerd runc 
The preceding is a general command to remove Docker, docker-engine, docker.io (as these are the older version names), and runtime containers, if any were pulled or created.

Installing from the Docker repository

To install Docker from the official repository, follow these steps:

  1. First, we use the following command:
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common 
  1. Then, we add the official GPG key from Docker:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 
  1. Set up the Docker repository using the following command:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" 
There are three types of update channels called the stable, nightly, and test channels. The test channel provides the prereleases that are ready for testing before availability, the nightly channel is the work in progress or beta version, and stable is the finalized bug-fixed channel. The best suggestion from the Docker team is the stable channel; however, you're free to test either channels by replacing the term stable with either nightly or test.
  1. Update the apt package index once again:
$ sudo apt-get update
  1. Now, install the Docker package using the following command:
$ sudo apt install docker-ce
  1. After installing via either method, you could check the versions of Docker for both types of installation using the following command:
$ docker --version

The current version that is available in the Ubuntu repository is 17.12, while the latest release version at the time of writing this book is 18.09 (stable version).

Docker can only be run as a root user by default. Hence, add your username to the Docker group using the following command:

$ sudo usermod -aG docker ${USER}

Ensure you reboot the system for the preceding to take effect; otherwise, you will face a permission denied error, as shown here:

Permission denied error

A quick fix to the preceding error would be to use sudo before any Docker commands.

Working with Docker

Containers are built from Docker images and these images can be pulled from Docker Hub (https://hub.docker.com/). We can pull ROS containers from the ros repository using the following command:

$ sudo docker pull ros:melodic-ros-core

If everything is successful, you see the output shown here:

Successful Docker pull

You can choose the specific version of ROS you want to work with. The best suggestion for any application is to start with melodic-core, where you would continue to work and update the container related to your project goal and not have other unnecessary components installed. You can view Docker images using this command:

$ sudo docker images

By default, all of the containers are saved in /var/lib/docker. Using the preceding command, you can identify the repository name and tag. In my case, for the ros repository name, my tag was melodic-ros-core; hence, you could run the ros container using the following command:

$ sudo docker run -it ros:melodic-ros-core

Other information the $ docker images command gives is the container ID, which is 7c5d1e1e5096 in my case. You will need it when you want to remove the container. Once you're inside Docker, you can check the ROS packages that are available using the following command:

$ rospack list

When you run and exit Docker, you would've created another container, so for beginners, it's quite common to create a list of containers unknowingly. You could use $ docker ps -a or $ docker ps -l to view all active/inactive containers or the latest container and remove containers using $ docker rm <docker_name>. To continue working in the same container, you could use the following command:

$ sudo docker start -a -i silly_volhard

Here, silly_volhard is the default name created by Docker.

Now that you've opened the same container, let's install an ROS package and commit changes to the Docker. Let's install the actionlib_tutorials package using the following command:

$ apt-get update
$ apt-get install ros-melodic-actionlib-tutorials

Now, when you check the ROS packages list once again, you should be able to view a few extra packages. Since you have modified the container, you would need to commit it to experience the modifications while reopening the Docker image. Exit the container and commit using the following command:

$ sudo docker commit 7c5d1e1e5096 ros:melodic-ros-core

Now that we have installed ROS on Ubuntu and VirtualBox, let's learn how to set up the ROS workspace.

Setting up the ROS workspace

After setting up ROS on a real PC, VirtualBox, or Docker, the next step is to create a workspace in ROS. The ROS workspace is a place where we keep ROS packages. In the latest ROS distribution, we use a catkin-based workspace to build and install ROS packages. The catkin system (http://wiki.ros.org/catkin) is the official build system of ROS, which helps us build the source code into a target executable or libraries inside the ROS workspace.

Building an ROS workspace is an easy task; just open a Terminal and follow these instructions:

  1. The first step is to create an empty workspace folder and another folder called src to store the ROS package in. The following command will do this for us. The workspace folder name here is catkin_ws:
$ mkdir -p catkin_ws/src
  1. Switch to the src folder and execute the catkin_init_workspace command. This command will initialize a catkin workspace in the current src folder. We can now start creating packages inside the src folder:
$ cd ~/catkin_ws/src 
$ catkin_init_workspace
  1. After initializing the catkin workspace, we can build the packages inside the workspace using the catkin_make command. We can also build the workspace without any packages:
$ cd ~/catkin_ws/ 
$ catkin_make
  1. This will create additional folders called build and devel inside the ROS workspace:
The catkin workspace folders
  1. Once you've built the workspace, to access packages inside the workspace, we should add the workspace environment to our .bashrc file using the following command:
$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc 
$ source ~/.bashrc
  1. When everything is done, you can verify that everything is correct by executing the following command:
$ echo $ROS_PACKAGE_PATH

This command will print the entire ROS package path. If your workspace path is in the output, you are done:

The ROS package path

You will see that two locations are sourced as ROS_PACKAGE_PATH. The former is the recent edition we made in step 5 and the latter is the actual ROS installed packages folder. With this, we have set up the ROS workspace. We will now look at the different opportunities for ROS in industries and research.

Opportunities for ROS in industries and research

Now that we've installed ROS and set up our ROS workspace, we can discuss the advantages of using it. Why is learning ROS so important for robotics researchers? The reason is that ROS is becoming a generic framework for programming all kinds of robots. So, robots in universities and industries mainly use ROS.

Here are some famous robotics companies using ROS for their robots:

Knowledge of ROS will help you land a robotics application engineering job easily. If you go through the skillset of any job related to robotics, you're bound to find ROS on it.

There are independent courses and workshops in universities and industries to teach ROS development in robots. Knowing ROS will help you to get an internship and MS, Ph.D., and postdoc opportunities from prestigious robotic institutions such as CMU's Robotics Institute (http://www.ri.cmu.edu/) and UPenn's GRAP lab (https://www.grasp.upenn.edu/).

The following chapters will help you build a practical foundation and core skills in ROS.

Summary

This chapter was an introductory chapter to get you started with robotics application development using ROS. The main aim of this chapter was to get you started with ROS by installing and understanding it. This chapter can be used as a kick-start guide for ROS application development and can help you understand the following chapters, which mainly demonstrate ROS-based applications. At the end of this chapter, we saw job and research opportunities related to ROS and saw that a lot of companies and universities are looking for ROS developers for different robotics applications.

From the next chapter onward, we will discuss ROS-2 and its capabilities.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Create and program cool robotic projects using powerful ROS libraries
  • Build industrial robots like mobile manipulators to handle complex tasks
  • Learn how reinforcement learning and deep learning are used with ROS

Description

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.

Who is this book for?

If you’re a student, hobbyist, professional, or anyone with a passion for learning robotics and interested in learning about algorithms, motion control, and perception capabilities from scratch, this book is for you. This book is also ideal for anyone who wants to build a new product and for researchers to make the most of what’s already available to create something new and innovative in the field of robotics.

What you will learn

  • Grasp the basics of ROS and understand ROS applications
  • Uncover how ROS-2 is different from ROS-1
  • Handle complex robot tasks using state machines
  • Communicate with multiple robots and collaborate to build apps with them
  • Explore ROS capabilities with the latest embedded boards such as Tinker Board S and Jetson Nano
  • Discover how machine learning and deep learning techniques are used with ROS
  • Build a self-driving car powered by ROS
  • Teleoperate your robot using Leap Motion and a VR headset

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 18, 2019
Length: 456 pages
Edition : 2nd
Language : English
ISBN-13 : 9781838649326
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 18, 2019
Length: 456 pages
Edition : 2nd
Language : English
ISBN-13 : 9781838649326
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 11,396.97
ROS Robotics Projects,
₹3649.99
Python Machine Learning
₹4096.99
Hands-On ROS for Robotics Programming
₹3649.99
Total 11,396.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Getting Started with ROS Chevron down icon Chevron up icon
Introduction to ROS-2 and Its Capabilities Chevron down icon Chevron up icon
Building an Industrial Mobile Manipulator Chevron down icon Chevron up icon
Handling Complex Robot Tasks Using State Machines Chevron down icon Chevron up icon
Building an Industrial Application Chevron down icon Chevron up icon
Multi-Robot Collaboration Chevron down icon Chevron up icon
ROS on Embedded Platforms and Their Control Chevron down icon Chevron up icon
Reinforcement Learning and Robotics Chevron down icon Chevron up icon
Deep Learning Using ROS and TensorFlow Chevron down icon Chevron up icon
Creating a Self-Driving Car Using ROS Chevron down icon Chevron up icon
Teleoperating Robots Using a VR Headset and Leap Motion Chevron down icon Chevron up icon
Face Detection and Tracking Using ROS, OpenCV, and Dynamixel Servos Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.3
(3 Ratings)
5 star 0%
4 star 33.3%
3 star 0%
2 star 33.3%
1 star 33.3%
NA May 13, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good read but don't have what I was looking for but good info though
Amazon Verified review Amazon
walnut405 Jun 26, 2021
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
目次にROS2があったので期待したけど、ほんのさわりだけだった。残念。基本的に、コンピュータ関連の書籍は、海外の方が内容が新しくて詳しいけど、robot関連は違うようだ。
Amazon Verified review Amazon
Daddy Joe Jan 02, 2022
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Can't get past the installations of ROS1 and ROS2. Soooo many errors and failures, there is no way I could trust the remainder of the book with that much lack of concern with accuracy. I returned the trash.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.