Search icon
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Learning Hub
Free Learning
Arrow right icon
Over 7,000 tech titles at $9.99 each with AI-powered learning assistants on new releases
Effective Robotics Programming with ROS - Third Edition
Effective Robotics Programming with ROS - Third Edition

Effective Robotics Programming with ROS: Find out everything you need to know to build powerful robots with the most up-to-date ROS, Third Edition

By Anil Mahtani , Luis Sánchez , Aaron Martinez , Enrique Fernandez Perdomo
$43.99 $9.99
Book Dec 2016 468 pages 3rd Edition
$43.99 $9.99
$15.99 Monthly
$43.99 $9.99
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details

Publication date : Dec 27, 2016
Length 468 pages
Edition : 3rd Edition
Language : English
ISBN-13 : 9781786463654
Category :
Concepts :
Table of content icon View table of contents Preview book icon Preview Book

Effective Robotics Programming with ROS - Third Edition

Chapter 1. Getting Started with ROS

Welcome to the first chapter of this book, where you will learn how to install ROS, the new standard software framework in robotics. This book is an update on Learning ROS for Robotics Programming - Second Edition, based in ROS Hydro/Indigo. With ROS, you will learn how to program and control your robots the easy way, using tons of examples and source code that will show you how to use sensors and devices, or how to add new functionalities, such as autonomous navigation, visual perception, and others, to your robot. Thanks to the open source ethos and a community that is developing state-of-the-art algorithms and providing new functionalities, ROS is growing every day.

This book will cover the following topics:

  • Installing ROS Kinetic framework on a compatible version of Ubuntu

  • The basic operation of ROS

  • Debugging and visualizing data

  • Programming your robot using this framework

  • Connecting sensors, actuators, and devices to create your robot

  • Creating a 3D model to use in the simulator

  • Using the navigation stack to make your robot autonomous

In this chapter, we are going to install a full version of ROS Kinetic in Ubuntu. ROS is fully supported and recommended for Ubuntu, and it is experimental for other operative systems. The version used in this book is the 15.10 (Wily Werewolf), and you can download it for free from Note that you can also use Ubuntu 16.04 (Xenial), following the same steps shown here; indeed, for the BeagleBone Black installation we will use Ubuntu Xenial.

Before starting with the installation, we are going to learn about the origin of ROS and its history.

The Robot Operating System (ROS) is a framework that, nowadays, is widely accepted and used in the robotics community. Its main goal is to make the multiple components of a robotics system easy to develop and share so they can work on other robots with minimal changes. This basically allows for code reuse, and improves the quality of the code by having it tested by a large number of users and platforms. ROS was originally developed in 2007 by the Stanford Artificial Intelligence Laboratory (SAIL) in support of the Stanford AI Robot project. Since 2008, Willow Garage continued the development, and recently Open Source Robotics Foundation (OSRF) began to oversee the maintenance of ROS and partner projects, like Gazebo, including the development of new features.

A lot of research institutions have started to develop in ROS, adding hardware and sharing their code. Also, companies have started to adapt their products to be used in ROS. In the following set of images, you can see some of the platforms that are fully supported. Normally, these platforms are published with a lot of code, examples, and simulators to permit the developers to start work easily. The first three humanoid robots are examples of robots with published code. The last one is an AUV developed by the University of Las Palmas de Gran Canaria, and the code has not been published yet. You can find many other examples at

Most of the sensors and actuators used in robotics are supported by ROS as drivers. Furthermore, some companies benefit from ROS and open hardware to create cheaper and easier to use sensors, as existing software can be used for them at zero cost. The Arduino board is a good example because you can add many different kinds of sensors to this cheap electronic board, such as encoders, light and temperature sensors, and many others, and then expose their measurements to ROS to develop robotic applications.

ROS provides a hardware abstraction, low-level device control with ROS control, implementations of commonly used functionalities and libraries, message passing between processes, and package management with catkin and cmake.

It uses graph architecture with a centralized topology, where processing takes place in nodes that may receive and send messages to communicate with other nodes on the graph net. A node is any process that can read data from a sensor, control an actuator, or run high level, complex robotic or vision algorithms for mapping or navigating autonomously in the environment.

The *-ros-pkg is a community repository for developing high-level libraries easily. Many of the capabilities frequently associated with ROS, such as the navigation library and the rviz visualizer, are developed in this repository. These libraries provide a powerful set of tools for working with ROS easily; visualization, simulators, and debugging tools are among the most important features that they have to offer. In the following image you can see two of these tools, the rviz and rqt_plot. The screenshot in the center is rqt_plot, where you can see the plotted data from some sensors. The other two screenshots are rviz; in the screenshot you can see a 3D representation of a real robot.

ROS is released under the terms of the Berkeley Software Distribution (BSD) license and is an open source software. It is free for commercial and research use. The ros-pkg contributed packages are licensed under a variety of open source licenses.

With ROS, you can take a code from the repositories, improve it, and share it again. This philosophy is the underlying principle of open source software.

ROS has numerous versions, the last one being Indigo. In this book, we are going to use Kinetic because it is the latest version. Now we are going to show you how to install ROS Kinetic. As we mentioned before, the operating system used in the book is Ubuntu, and we are going to use it throughout this book and with all the tutorials. If you use another operating system and you want to follow the book, the best option is to install a virtual machine with a copy of Ubuntu. At the end of this chapter, we will explain how to install a virtual machine to use the ROS inside it, or download a virtual machine with ROS installed.

If you want to try installing it on an operating system other than Ubuntu, you can find instructions on how to do so with many other operating systems at

PC installation

We assume that you have a PC with a copy of Ubuntu 15.10. It will also be necessary to have a basic knowledge of Linux and command tools such as the terminal, Vim, folder creation, and so on. If you need to learn these tools, you can find a lot of relevant resources on the Internet, or you can find books on these topics instead.

Installing ROS Kinetic using repositories

Last year, the ROS web page was updated with a new design and a new organization of contents. The following is a screenshot of the web page:

In the menu, you can find information about ROS and whether ROS is a good choice for your system. You can also find blogs, news, and other features.

Instructions for ROS installation can be found under the Install tab in the Getting Started section.

ROS recommends that you install the system using the repository instead of the source code, unless you are an advanced user and you want to make a customized installation; in that case, you may prefer installing ROS using the source code.

To install ROS using the repositories, we will start by configuring the Ubuntu repository in our system.

Configuring your Ubuntu repositories

In this section, you will learn the steps for installing ROS Kinetic in your computer. This process has been based on the official installation page, which can be found at

We assume that you know what an Ubuntu repository is and how to manage it. If you have any doubts about it, refer to

Before we start the installation, we need to configure our repositories. To do that, the repositories need to allow restricted, universe, and multiverse. To check if your Ubuntu accepts these repositories, click on Ubuntu Software Center in the menu on the left-hand side of your desktop, as shown in the following screenshot:

Click on Edit | Software Sources and you will see the following window. Make sure that all the listed options are checked as shown in the following screenshot (choose the appropriate country for the server from which you download the sources):

Normally these options are marked, so you should not have any problem with this step.

Setting up your source.list file

In this step, you have to select your Ubuntu version. It is possible to install ROS Kinetic in various versions of the operating system. You can use any of them, but we recommend version 15.10 to follow the chapters of this book. Keep in mind that Kinetic works in the Wily Werewolf (15.10) and Xenial Xerus (16.04) versions of Ubuntu. Type the following command to add the repositories:

sudo sh -c 'echo "deb $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros-latest.list'


Downloading the example code

Detailed steps to download the code bundle are mentioned in the Preface of this book. Please have a look.

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!

Once you've added the correct repository, your operating system will know where to download programs to install them into your system.

Setting up your keys

This step is to confirm that the origin of the code is correct and that no one has modified the code or programs without the knowledge of the owner. Normally, when you add a new repository, you have to add the keys of that repository, so it's added to your system's trusted list.

$ wget -O - | sudo apt-key add -

Now we can be sure that the code came from an authorized site and has not been modified.

Installing ROS

We are ready to start the installation now, but before we do that, we'd better make an update to avoid problems with the libraries and versions of software that are not ideal for ROS. This is done with the following command:

$ sudo apt-get update

ROS is huge; sometimes you will install libraries and programs that you will never use. Normally it has four different installations, but this depends on the final use. For example, if you are an advanced user, you might only need the basic installation for a robot without much space on the hard disk. For this book, we recommend you use the full installation because it will install everything necessary to practice the examples and tutorials.

It doesn't matter if you don't know what are you installing right now — rviz, simulators, navigation, and so on. You will learn everything in the upcoming chapters:

  • The easiest (and recommended if you have enough hard disk space) installation is known as desktop-full. It comes with ROS, the rqt tools, the rviz visualizer (for 3D), many generic robot libraries, the simulator in 2D (like a stage plan) and 3D (usually Gazebo), the navigation stack (to move, localize, do mapping, and control arms), and also perception libraries using vision, lasers, or RGBD cameras:

    $ sudo apt-get install ros-kinetic-desktop-full
  • If you do not have enough disk space, or if you prefer to install only a few packages, install only the desktop install initially, which only comes with ROS, the rqt tools, rviz, and generic robot libraries. You can install the rest of the packages as and when you need them, for example, by using aptitude and looking for ros-kinetic-* packages with the following command:

    $ sudo apt-get install ros-kinetic-desktop
  • If you only want the bare bones, install ROS-base, which is usually recommended for the robot itself, or for computers without a screen or just a TTY. It will install the ROS package with the build and communication libraries and no GUI tools at all. With BeagleBone Black (BBB), we will install the system with the following option:

    $ sudo apt-get install ros-kinetic-ros-base
  • Finally, whichever of the previous options you choose, you can also install individual/specific ROS packages (for a given package name):

    $ sudo apt-get install ros-kinetic-PACKAGE

Initializing rosdep

Before using ROS we need to initialize rosdep. The rosdep command-line tool helps with the installation of system dependencies for the source code that we are going to compile or install. For this reason, it is required by some of the core components in ROS, so it is installed by default with it. To initialize rosdep, you have to run the following commands:

$ sudo rosdep init
$ rosdep update

Setting up the environment

Congratulations! If you are at this step, you have an installed version of ROS on your system! To start using it, the system needs to know the location of the executable or binary files, as well as the other commands. To do this, normally you need to execute the next script; if you also install another ROS distro, you can work with both just by calling the script of the one you need each time, since this script simply sets your environment. Here, we use the one for ROS Kinetic, but just replace kinetic with indigo or jade, for example, if you want to try other distros:

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

If you type roscore in the shell, you will see something starting up. This is the best test for finding out if you have ROS, and if it is installed correctly.

Note that if you open another terminal you also have to source the setup.bash file to set the environment variables to detect the ROS packages installed on your system. Otherwise, roscore or other ROS commands will not work. This is because the script must be sourced again to configure the environment variables, which include the path where ROS is installed, as well as other packages and additional paths for compiling new code properly.

It is very easy to solve this; you just need to add the script at the end of your .bashrc script file so that when you start a new shell, the script will execute and you will have the environment configured.

The .bashrc file is within the user home (/home/USERNAME/.bashrc). It has the configuration of the shell or terminal, and each time the user opens the terminal, this file is loaded. That way, you can add commands or configuration to make the user's life easy. For this reason, we will add the script at the end of the .bashrc file to avoid keying it in each time we open a terminal. We do this with the following command:

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

To see the results, you have to execute the file using the following command, or close the current terminal and open another:

$ source ~/.bashrc

Some users need more than a single ROS distribution installed in their system, so you'll have several distros living in the same system and may need to switch between them. Your ~/.bashrc file must only source the setup.bash file of the version you are currently using, since the last call will override the environment set by the others.

For example, you might have the following lines in your .bashrc file:

source /opt/ros/indigo/setup.bash
source /opt/ros/jade/setup.bash
source /opt/ros/kinetic/setup.bash

The ROS Kinetic version will be executed in this case. Make sure that the version you are running is the last one in the file. It's also recommended to source a single setup.bash.

If you want to check the version used in a terminal, you can do so easily running the echo $ROS_DISTRO command.

Getting rosinstall

Now the next step is to install a command tool that will help us install other packages with a single command. This tool is based in Python, but don't worry, you don't need to know Python to use it. You will learn how to use this tool in the upcoming chapters:

To install this tool on Ubuntu, run the following command:

$ sudo apt-get install python-rosinstall

And that's it! You have a complete ROS system installed in your system. When I finish a new installation of ROS, I personally like to test two things: that roscore and turtlesim both work.

If you want to do the same, type the following commands in different shells:

$ roscore
$ rosrun turtlesim turtlesim_node

If everything is okay, you will see the following screenshot:

How to install VirtualBox and Ubuntu

VirtualBox is a general-purpose, full virtualizer for x86 hardware, targeted at server, desktop, and embedded use. VirtualBox is free and supports all the major operating systems and pretty much every Linux flavor out there.

If you don't want to change the operating system of your computer to Ubuntu, tools such as VirtualBox help us virtualize a new operating system in our computers without making any changes.

In the following section, we are going to show you how to install VirtualBox and a new installation of Ubuntu. After this virtual installation, you should have a clean installation for restarting your development machine if you have any problems, or to save all the setups necessary for your robot in the machine.

Downloading VirtualBox

The first step is to download the VirtualBox installation file. The latest version at the time of writing this book is 4.3.12; you can download the Linux version of it from If you're using Windows, you can download it from

Once installed, you need to download the image of Ubuntu; for this tutorial we will use a copy of Ubuntu 15.10 from OSBOXES found at; then we will simply install ROS Kinetic following the same instructions described in the previous section. In particular, the Ubuntu 15.10 image can be downloaded from

This would download a .7z file. In Linux, it can be uncompressed with the following:

$ 7z x Ubuntu_15.10-64bit.7z

If the .7z command is not installed, it can be installed with the following:

$ sudo apt-get install p7zip-full

The virtual machine file will go into the 64-bit folder with the name: Ubuntu 15.10 Wily (64bit).vdi

Creating the virtual machine

Creating a new virtual machine with the downloaded file is very easy; just proceed with the following steps. Open VirtualBox and click on New. We are going to create a new virtual machine that will use the Ubuntu 15.10 Wily (64bit).vdi file downloaded before, which is a hard disk image with Ubuntu 15.10 already installed. Set the name, type, and version of the virtual machine as shown in the following screenshot:

You can configure the parameters of the new virtual machine in the windows that follow. Keep the default configuration and change only the name for the virtual system. This name is how you distinguish this virtual machine from others. For the RAM, we advise that you use as much as possible, but 8 GB should be enough.

For the hard drive, use the existing virtual hard drive file Ubuntu 15.10 Wily (64bit).vdi downloaded before, as shown in the following screenshot:

After this, you can start your virtual machine by clicking on the Start button. Remember to select the right machine before you start it. In our case, we only have one, but you could have more:

Once the virtual machine starts, you should see another window, as seen in the following screenshot. It is the Ubuntu 15.10 OS with ROS installed (use as the password to log in):

When you finish these steps, install ROS Kinetic as you would on a regular computer following the steps of the previous sections, and you will have a full copy of ROS Kinetic that can be used with this book. You can run all the examples and stacks that we are going to work with. Unfortunately, VirtualBox has problems when working with real hardware, and it's possible that you may not be able to use this copy of ROS Kinetic with the examples given in Chapter 4, 3D Modeling and Simulation.

Using ROS from a Docker image

Docker is an open platform that helps to distribute applications and complete systems. In some ways, it is similar to a virtual machine, but it is much faster and more flexible; see or for more information.

Installing Docker

In order to install it in Ubuntu, you only have to run the following:

$ sudo apt-get install

Getting and using ROS Docker images and containers

Docker images are like virtual machines or systems already set up. There are servers that provide images like this, so the users only have to download them. The main server is Docker hub, found at There, it is possible to search for Docker images for different systems and configurations. In our case, we are going to use ROS Kinetic images already available. All ROS Docker images are listed in the official ROS repo images on the web at The ROS container image is pulled down with the following command:

$ docker pull ros

There's a possibility that you may see this error:

You should either update your system or try adding your user to the docker group to resolve this:

$ sudo usermod -a -G docker $(whoami)

You should see multiple Docker images getting downloaded simultaneously. Each image has a different hash name. This will take some time, especially on slow networks. You will see something like the following once it is done:

The ROS Kinetic distribution can be pulled down using the corresponding tag, using the following command:

$ docker pull ros:kinetic-robot

Although you do not need to know it, the images and containers are stored by Docker in /var/lib/docker by default.

Once the container is downloaded, we can run it interactively with the following command:

$ docker run -it ros

This will be like entering a session inside the Docker container. This command will create a new container from the main image. Inside it we have a full Ubuntu system with ROS Kinetic already installed. We can install additional packages and run ROS nodes, as in a regular system. With docker ps -a, you can check all the containers available and the image they come from.

We have to set up the ROS environment inside the container in order to start using ROS. That is, we have to run the following command:

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

Docker containers can be stopped from other terminals using docker stop, and they can also be removed with docker rm. Docker also allows you to configure the container to expose the network, as well as mounting a host folder as volumes into it. In addition to this, it also supports a Python API, and has many other features. All this can be found in the official documentation at However, in principle, docker run should be enough, and we can even SSH into a running Docker container, as a regular machine, using its name. We can also open another terminal for a running container with the following command (where NAME is the name of the Docker container, that you can fine using docker ps -a):

$ docker exec -it NAME bash

You can also create your own Docker images using docker build and specify what should be installed in them in Dockerfile. You can even publish them online with docker push, contributing them to the community or simply sharing your working setup. This book comes with a working Docker image and Dockerfile to build it, and you can find this by running docker build from the same folder where Dockerfile is. This Docker image is basically an extension of the ROS Kinetic one with the code of the book. The instructions to download and install it would be on the GitHub repository with the rest of the code.

Installing ROS in BeagleBone Black

BeagleBone Black is a low-cost development platform based on an ARM Cortex A8 processor. This board is fabricated with a Linux distribution called Ångström. Ångström was developed by a small group who wanted to unify Linux distribution for embedded systems. They wanted an operating system that was stable and user-friendly.

Texas Instruments designed BeagleBone Black thinking that the community of developers needed an on-board computer with some general purpose input/output (GPIO) pins. The BeagleBone Black platform is an evolution of the original BeagleBone. The main features of the board are an ARM Cortex A8 processor at 1 GHz with 512 MB RAM, and with Ethernet, USB, and HDMI connections and two headers of 46 GPIO pins.

This GPIO can be set up as digital I/O, ADC, PWM, or for communication protocol like I2C, SPI, or UART. The GPIO is an easy way to communicate with sensors and actuators directly from the BeagleBone without intermediaries. The following is a labeled image of BeagleBone:

When the BeagleBone board came out, it was not possible to install ROS on the Ångström distribution. For this reason, it was common to install an operating system based on Ubuntu on the BeagleBone. There are different versions of Ubuntu ARM compatible with the BeagleBone Black and ROS; we recommend that you use an image of Ubuntu ARM 16.04 Xenial armhf on the platform to work with ROS.

Now, an ROS version for Ångström distribution is ready to be installed; you can do so following the installation steps given at Despite this possibility, we have chosen to install ROS on Ubuntu ARM because these distributions are more common and can be used on other ARM-based boards such as UDOO, ODROIDU3, ODROIDX2, or Gumstick.

ARM technology is booming with the use of mobile devices such as smartphones and tablets. Apart from the increasing computer power of the ARM cortex, the great level of integration and low consumption has made this technology suitable for autonomous robotic systems. In the last few years, multiple ARM platforms for developers have been launched in the market. Some of them have features similar to the BeagleBone Black, such as the Raspberry PI or the Gumstick Overo. Additionally, more powerful boards like GumstickDuoVero with a Dual Core ARM Cortex A9 or some quad core boards like OdroidU3, OdroidX2 or UDOO are now available.


Before installing ROS on BeagleBone Black, we have to achieve some prerequisites. As this book is focused on ROS, we will list them without going into detail. There is a lot of information about BeagleBone Black and Ubuntu ARM available on websites, forums, and books that you can check out.

First, we have to install an Ubuntu ARM distribution compatible with ROS, so an image of Ubuntu ARM is needed. You can obtain an Ubuntu 16.04 Xenial armhf using wget with the following command:

$ wget

From the URL you can look for newer versions too. This version is the one mentioned in the official documentation at

Once the image is downloaded, the next step is installing it on a microSD card. First, unpack the image with the following commands:

$ tar xf ubuntu-16.04.1-console-armhf-2016-10-06.tar.xz
$ cd ubuntu-16.04.1-console-armhf-2016-10-06

Insert a microSD of 2 GB or more on the card reader of your computer and install the Ubuntu image on it with the following setup script:

$ sudo ./ --mmc DEVICE --dtb BOARD

In the preceding script, DEVICE is the device where the microSD appears on the system, for example /dev/sdb, and BOARD is the board name. For the BeagleBone Black it would be beaglebone. So, assuming the microSD is in /dev/mmcblk0, and you are using a BeagleBone Black, the command would be as follows:

$ sudo ./ --mmc /dev/mmcblk0 --dtb beaglebone

If you do not know the device assigned to the microSD, you can use the following command:

$ sudo ./ --probe-mmc

Once we have Ubuntu ARM on our platform, the BeagleBone Black network interfaces must be configured to provide access to the network, so you will have to configure the network settings, such as the IP, DNS, and gateway.

Remember that the easiest way could be mounting the SD card in another computer and editing /etc/network/interfaces.

Another easy way consists on using an Ethernet cable and running the DHCP client to obtain an IP address.

$ sudo dhclient eth0

For this, you need to boot up the BeagleBone Black with the microSD. For that, you need to keep the S2 button press before you power on the board, either with the DC or USB connector. After some minutes the system will show the login prompt. Log in with the user ubuntu and password temppwd (default ones) and then run the DHCP client command shown above with the Ethernet cable connected. Then, you can check the IP address assigned using (look at the inet addr: value):

$ ifconfig eth0

In our setup, we have connected to the BeagleBone Black the following devices (as shown in the image below):

  • HDMI (with microHDMI adapter) cable to see terminal prompt on the screen during the network setup; after that we can SSH into the board

  • Keyboard connected through USB

  • Power supplied through the microUSB connector

  • Ethernet cable to access the Internet, as explained so far

After setting up the network, we should install the packages, programs, and libraries that ROS will need. Now that the network is up, we can also SSH into the board with (assuming the IP address assigned to it is

$ ssh ubuntu@

We are going to follow the instructions in, but with the changes required so they work for ROS kinetic (note they are still for indigo on the web). The first step consists on setting up the repository sources so we can install ROS.

$ sudo vi /etc/apt/sources.list

And add restricted to the sources, so you have something like this:

deb xenial main restricted universe multiverse
#deb-src xenial main restricted universe multiverse
deb xenial-updates main restricted universe multiverse
#deb-src xenial-updates main restricted universe multiverse
#Kernel source ( :
#git clone
#cd ./linux-stable-rcn-ee
#git checkout `uname -r` -b tmp
deb [arch=armhf] xenial main
#deb-src [arch=armhf] xenial main

Then, update the sources running:

$ sudo apt-get update

The operating system for BeagleBone Black is set up for micro SD cards with 1-4 GB. This memory space is very limited if we want to use a large part of the ROS Kinetic packages. In order to solve this problem, we can use SD cards with more space and expand the file system to occupy all the space available with re-partitioning.

So if we want to work with a bigger memory space, it is recommended to expand the BeagleBone Black memory file system. This process is further explained at

Although the following steps are not needed in general, they are here in case you need them in your particular case. You can Proceed by following these commands:

  1. We need to become a super user, so we will type the following command and our password:

    $ sudo su
  2. We will look at the partitions of our SD card:

    $ fdisk /dev/mmcblk0
  3. On typing p, the two partitions of the SD card will be shown:

    $ p
  4. After this, we will delete one partition by typing d and then we will type 2 to indicate that we want to delete /dev/mmcblk0p2:

    $ d
    $ 2
  5. On typing n, a new partition will be created; if we type p it will be a primary partition. We will indicate that we want to number it as the second partition by typing 2:

    $ n
    $ p
    $ 2
  6. You can write these changes by typing w if everything is right, or eliminate the changes with Ctrl + Z:

    $ w
  7. We should reboot the board after finishing:

    $ reboot
  8. Once again, become a super user once the reboot is complete:

    $ sudosu
  9. Finally, run the following command to execute the expansion of the memory file system of the operating system:

    $ resize2fs /dev/mmcblk0p2

Now we should be ready to install ROS. At this point, the process of installation is pretty similar to the PC installation previously explained in this chapter, so we should be familiar with it. We will see that the main difference when installing ROS on BeagleBone Black is that we can't install the ROS full-desktop; we must install it package by package.

Setting up the local machine and source.list file

Now you will start setting up your local machine:


After this, we will configure the source lists depending on the Ubuntu version that we have installed in BeagleBone Black. The number of Ubuntu versions compatible with BeagleBone Black is limited, and only active builds can be found for Ubuntu 16.40 Xenial armhf, the most popular version of Ubuntu ARM. Run the following to install the Ubuntu armhf repositories:

$ sudo sh -c 'echo "deb $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros-latest.list'

Setting up your keys

As explained previously, this step is needed to confirm that the origin of the code is correct and that no one has modified the code or programs without the knowledge of the owner:

$ sudo apt-key adv --keyserver hkp:// --recv-key 0xB01FA116

Installing the ROS packages

Before the installation of ROS packages, we must update the system to see all the packages on the ROS repository just added:

$ sudo apt-get update

This part of the installation is slightly different for the BeagleBone Black. There are a lot of libraries and packages in ROS, and not all of them compile fully on an ARM, so it is not possible to make a full desktop installation. It is recommended that you install them package by package to ensure that they will work on an ARM platform.

You can try to install ROS-base, known as ROS Bare Bones. ROS-base installs the ROS package along with the build and communications libraries but does not include the GUI tools (press ENTER (Y) when prompted):

$ sudo apt-get install ros-kinetic-ros-base

We can install specific ROS packages with the following command:

$ sudo apt-get install ros-kinetic-PACKAGE

If you need to find the ROS packages available for BeagleBone Black, you can run the following command:

$ apt-cache search ros-kinetic

For example, the following packages are the basics (already installed as ros-base dependencies) that work with ROS and can be installed individually using apt-get install:

$ sudo apt-get install ros-kinetic-ros
$ sudo apt-get install ros-kinetic-roslaunch
$ sudo apt-get install ros-kinetic-rosparam
$ sudo apt-get install ros-kinetic-rosservice

Although, theoretically, not all the packages of ROS are supported by BeagleBone Black, in practice, we have been able to migrate entire projects developed on PC to BeagleBone Black. We tried a lot of packages, and the only one that we could not install was rviz, which is indeed not recommended to run on it.

Initializing rosdep for ROS

The rosdep command-line tool must be installed and initialized before you can use ROS. This allows you to easily install libraries and solve system dependencies for the source you want to compile, and is required to run some core components in ROS. You can use the following commands to install and initialize rosdep:

$ sudo apt-get install python-rosdep
$ sudo rosdep init
$ rosdep update

Setting up the environment in the BeagleBone Black

If you have arrived at this step, congratulations, because you have installed ROS in your BeagleBone Black. The ROS environment variables can be added to your bash, so they will be added every time a shell is launched:

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

We have to be careful if we have more than one version of ROS in our system. The bashrc setup must use the variables of the version being used only.

If we want to set up the environment in the current shell, we will run the following command:

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

Getting rosinstall for BeagleBone Black

Rosinstall is a common command-line tool in ROS that helps us to install packages easily. It can be installed on Ubuntu with the following command:

$ sudo apt-get install python-rosinstall

Basic ROS example on the BeagleBone Black

As a basic example, you can run a ROS core on one terminal on the BeagleBone Black:

$ roscore

And from another terminal publish a pose message (note you can press Tab Tab after geometry_msgs/Pose and it'd autocomplete the message fields, that then you need to change since it'd have the default values):

$ rostopic pub /dummy geometry_msgs/Pose
x: 1.0
y: 2.0
z: 3.0
x: 0.0
y: 0.0
z: 0.0
w: 1.0 -r 10

Now, from your laptop (in the same network), you can set ROS_MASTER_URI to point to the BeagleBone Black (IP in our case):

$ export ROS_MASTER_URI=

And now you should be able to see the pose published from the BeagleBone Black on your laptop doing:

$ rostopic echo -n1 /dummy
x: 1.0
y: 2.0
z: 3.0
x: 0.0
y: 0.0
z: 0.0
w: 1.0

If you use a PoseStamped, you can even visualize it on rviz.

From this point, you can check multiple projects at, as well as another installation option, which uses the Angstrom OS instead of Ubuntu, but it does not support ROS Kinetic at the moment.


In this chapter, we have installed ROS Kinetic on different physical and virtual devices (PC, VirtualBox, and BeagleBone Black) in Ubuntu. With these steps, you should have everything needed to start working with ROS installed on your system, and you can also practice the examples in this book. You also have the option of installing ROS using the source code. This option is for advanced users and we recommend you use only the installation from the apt repositories as it is more common and normally does not give any errors or problems.

It is a good idea to play around with ROS and its installation on a virtual machine. That way, if you have problems with the installation or with something else, you can reinstall a new copy of your operating system and start again.

Normally, with virtual machines, you will not have access to real hardware, such as sensors or actuators. In any case, you can use it for testing the algorithms.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • This comprehensive, yet easy-to-follow guide will help you find your way through the ROS framework
  • Successfully design and simulate your 3D robot model and use powerful robotics algorithms and tools to program and set up your robots with an unparalleled experience by using the exciting new features from Robot Kinetic
  • Use the latest version of gazebo simulator, OpenCV 3.0, and C++11 standard for your own algorithms


Building and programming a robot can be cumbersome and time-consuming, but not when you have the right collection of tools, libraries, and more importantly expert collaboration. ROS enables collaborative software development and offers an unmatched simulated environment that simplifies the entire robot building process. This book is packed with hands-on examples that will help you program your robot and give you complete solutions using open source ROS libraries and tools. It also shows you how to use virtual machines and Docker containers to simplify the installation of Ubuntu and the ROS framework, so you can start working in an isolated and control environment without changing your regular computer setup. It starts with the installation and basic concepts, then continues with more complex modules available in ROS such as sensors and actuators integration (drivers), navigation and mapping (so you can create an autonomous mobile robot), manipulation, Computer Vision, perception in 3D with PCL, and more. By the end of the book, you’ll be able to leverage all the ROS Kinetic features to build a fully fledged robot for all your needs.

What you will learn

• Understand the concepts of ROS, the command-line tools, visualization GUIs, and how to debug ROS • Connect robot sensors and actuators to ROS • Obtain and analyze data from cameras and 3D sensors • Use Gazebo for robot/sensor and environment simulation • Design a robot and see how to make it map the environment, navigate autonomously, and manipulate objects in the environment using MoveIt! • Add vision capabilities to the robot using OpenCV 3.0 • Add 3D perception capabilities to the robot using the latest version of PCL

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details

Publication date : Dec 27, 2016
Length 468 pages
Edition : 3rd Edition
Language : English
ISBN-13 : 9781786463654
Category :
Concepts :

Table of Contents

18 Chapters
Effective Robotics Programming with ROS Third Edition Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Authors Chevron down icon Chevron up icon
About the Reviewer Chevron down icon Chevron up icon Chevron down icon Chevron up icon
Customer Feedback Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Getting Started with ROS Chevron down icon Chevron up icon
2. ROS Architecture and Concepts Chevron down icon Chevron up icon
3. Visualization and Debugging Tools Chevron down icon Chevron up icon
4. 3D Modeling and Simulation Chevron down icon Chevron up icon
5. The Navigation Stack – Robot Setups Chevron down icon Chevron up icon
6. The Navigation Stack – Beyond Setups Chevron down icon Chevron up icon
7. Manipulation with MoveIt! Chevron down icon Chevron up icon
8. Using Sensors and Actuators with ROS Chevron down icon Chevron up icon
9. Computer Vision Chevron down icon Chevron up icon
10. Point Clouds Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by

No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial


How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to
  • To contact us directly if a problem is not resolved, use
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.