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
Effective Robotics Programming with ROS
Effective Robotics Programming with ROS

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

Arrow left icon
Profile Icon Mahtani Profile Icon Fernandez Perdomo Profile Icon Sánchez
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6 (5 Ratings)
Paperback Dec 2016 468 pages 3rd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Mahtani Profile Icon Fernandez Perdomo Profile Icon Sánchez
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6 (5 Ratings)
Paperback Dec 2016 468 pages 3rd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 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

Effective Robotics Programming with ROS

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 http://releases.ubuntu.com/15.10. 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 http://wiki.ros.org/Robots.

Getting Started with ROS

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.

Getting Started with ROS

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 http://wiki.ros.org/kinetic/Installation.

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:

Installing ROS Kinetic using repositories

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 http://wiki.ros.org/kinetic/Installation/Ubuntu.

We assume that you know what an Ubuntu repository is and how to manage it. If you have any doubts about it, refer to https://help.ubuntu.com/community/Repositories/Ubuntu.

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:

Configuring your Ubuntu repositories

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):

Configuring your Ubuntu repositories

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 http://packages.ros.org/ros/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros-latest.list'

Tip

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 https://github.com/rosbook/effective_robotics_programming_with_ros. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. 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 http://packages.ros.org/ros.key -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:

Getting rosinstall

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 http://download.virtualbox.org/virtualbox/4.3.12/. If you're using Windows, you can download it from http://download.virtualbox.org/virtualbox/4.3.12/VirtualBox-4.3.12-93733-Win.exe.

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 http://www.osboxes.org/ubuntu/; 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 http://sourceforge.net/projects/osboxes/files/vms/vbox/Ubuntu/15.10/Ubuntu_15.10-64bit.7z/download.

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:

Creating the virtual machine

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:

Creating the virtual machine

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:

Creating the virtual machine

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 osboxes.org as the password to log in):

Creating the virtual machine

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 https://www.docker.com or https://dockerproject.org for more information.

Installing Docker

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

$ sudo apt-get install docker.io

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 https://hub.docker.com. 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 https://hub.docker.com/_/ros/. The ROS container image is pulled down with the following command:

$ docker pull ros

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

Getting and using ROS Docker images and containers

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:

Getting and using ROS Docker images and containers

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 https://docs.docker.com. 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:

Installing ROS in BeagleBone Black

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 http://wiki.ros.org/kinetic/Installation/Angstrom. 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.

Prerequisites

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 https://rcn-ee.com/rootfs/2016-10-06/elinux/ubuntu-16.04.1-console-armhf-2016-10-06.tar.xz

From the URL https://rcn-ee.com/rootfs you can look for newer versions too. This version is the one mentioned in the official documentation at http://elinux.org/BeagleBoardUbuntu.

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 ./setup_sdcard.sh --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 ./setup_sdcard.sh --mmc /dev/mmcblk0 --dtb beaglebone

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

$ sudo ./setup_sdcard.sh --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
    Prerequisites

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 192.168.1.6):

$ ssh ubuntu@192.168.1.6

We are going to follow the instructions in http://wiki.ros.org/indigo/Installation/UbuntuARM, 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 http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
#Kernel source (repos.rcn-ee.com) : https://github.com/RobertCNelson/linux-stable-rcn-ee
#
#git clone https://github.com/RobertCNelson/linux-stable-rcn-ee
#cd ./linux-stable-rcn-ee
#git checkout `uname -r` -b tmp
#
deb [arch=armhf] http://repos.rcn-ee.com/ubuntu/ xenial main
#deb-src [arch=armhf] http://repos.rcn-ee.com/ubuntu/ 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 http://elinux.org/Beagleboard:Expanding_File_System_Partition_On_A_microSD.

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:

$ sudo update-locale LANG=C LANGUAGE=C LC_ALL=C LC_MESSAGES=POSIX

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 http://packages.ros.org/ros/ubuntu $(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://ha.pool.sks-keyservers.net --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
Position:
x: 1.0
y: 2.0
z: 3.0
Orientation:
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 192.168.1.6 in our case):

$ export ROS_MASTER_URI=http://192.168.1.6:11311

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

$ rostopic echo -n1 /dummy
Position:
x: 1.0
y: 2.0
z: 3.0
Orientation:
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 http://wiki.ros.org/BeagleBone, as well as another installation option, which uses the Angstrom OS instead of Ubuntu, but it does not support ROS Kinetic at the moment.

Summary

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

Description

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.

Who is this book for?

This book is suitable for an ROS beginner as well as an experienced ROS roboticist or ROS user or developer who is curious to learn ROS Kinetic and its features to make an autonomous Robot. The book is also suitable for those who want to integrate sensors and embedded systems with other software and tools using ROS as a framework.

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

Product Details

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

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 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 27, 2016
Length: 468 pages
Edition : 3rd
Language : English
ISBN-13 : 9781786463654
Category :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 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
€189.99 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 €5 each
Feature tick icon Exclusive print discounts
€264.99 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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 125.97
ROS Robotics Projects
€41.99
Effective Robotics Programming with ROS
€41.99
ROS Robotics By Example, Second Edition
€41.99
Total 125.97 Stars icon
Banner background image

Table of Contents

11 Chapters
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

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(5 Ratings)
5 star 40%
4 star 20%
3 star 20%
2 star 0%
1 star 20%
Christopher Adamson Aug 04, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
For a beginner ROS developer, this is a good book for an intro, and has helpful documentation on general ROS concepts and specific ROS technologies such as the Navigation stack.
Amazon Verified review Amazon
Neil John Jan 27, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Hi EveryoneI am Lentin Joseph, Technical reviewer of this book and author of few books in ROS .Actually, this book is the continuation of a book called Learning ROS for Robotics Programming which is pretty popular in ROS community. I can recommend you guys, this will be very useful to people who are wanted to work with ROS.This book mainly discussing ROS concepts using the latest version of ROS called ROS Kinetic and teaches you to create interactive project using ROS. Also, book is written in a simple language so that everyone can understand :)
Amazon Verified review Amazon
Amazon Customer Jun 02, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book has better structure and formatting than the ROS wiki tutorials. The examples are well executed but, I recommend following along with the ROS wiki page tutorials. Sometimes the ROS wiki gives extra information.My school's online edition of this book has a typo. When creating the config.cfg file for example4.cpp pay close attention to the name given in the last line of the file.>> exit(gen.generate(PACKAGE, "chapter2_tutorials", "chapter2_"))There is an underscore in the last parameter name "chapter2_".This will generate the file chapter2_Config.hThe example4.cpp file is looking for chapter2Config.h (no underscore).You will need to remove the underscore or add an underscore to the example4.cpp file.Not sure if this is the appropriate forum a typo mistake,The book has been a great help! Raub Camaioni
Amazon Verified review Amazon
Cade Carvell Dec 13, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I bought this book, only to find out it doesn't cover ROS 2.0, jsut ROS 1.0. If you are using ROS 1.0, then this book looks really good. The diagrams and text were great, just dated.
Amazon Verified review Amazon
uce-techcom Nov 20, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
The book looks like covering lot of topics and lot examples. But when you follow it to do project, you will find the reference code for this book will miss lot of piece file, such as launch file, parameter configuration file etc. When send email to Author and ask if he can send the missing files to me, no answer. I hate it !!!
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.