Home IoT & Hardware Learning ROS for Robotics Programming Second Edition

Learning ROS for Robotics Programming Second Edition

books-svg-icon Book
eBook $43.99 $29.99
Print $54.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $43.99 $29.99
Print $54.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Getting Started with ROS Hydro
About this book
Publication date:
August 2015
Publisher
Packt
Pages
458
ISBN
9781783987580

 

Chapter 1. Getting Started with ROS Hydro

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, based in ROS Fuerte. 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, devices, or add new functionalities such as autonomous navigation, visual perception, and so on to your robot. Thanks to the open source motto and a community that is developing state-of-the-art algorithms and providing new functionalities, ROS is growing every day.

Throughout this book, you will learn the following:

  • Installing ROS Hydro framework on a 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 Hydro 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 12.04 (Precise Pangolin) and you can download it for free from http://releases.ubuntu.com/12.04/.

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

The Robot Operating System (ROS) is a framework that is widely used in Robotics. The philosophy is to make a piece of software that could work in other robots with only little changes to the code. What we get with this idea is the ability to create functionalities that can be shared and used in other robots without effort, so we do not need to reinvent the wheel.

ROS was originally developed in 2007 by the Stanford Artificial Intelligence Laboratory (SAIL) in support of the Stanford AI Robot project. As of 2008, development continues primarily at Willow Garage, a Robotics Research Institute, with more than twenty institutions collaborating within a federated development model.

A lot of research institutions have started to develop in ROS, adding hardware and sharing their code. Also, the 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 which 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 robots are examples of robots with published code and they are humanoids. 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 a lot of such examples at http://wiki.ros.org/Robots.

The sensors and actuators used in robotics have also been adapted for use in ROS. Everyday, more devices are being supported by this framework. Furthermore, thanks to ROS and open hardware, companies are creating cheaper and more powerful sensors. The Arduino board is a good example of this, because using a cheap electronic board you can add a lot of sensors like encoders, light and temperature sensors, and so on.

ROS provides standard operating system facilities such as hardware abstraction, low-level device control, implementation of commonly used functionalities, message passing between processes, and package management.

It is based on graph architecture with a centralized topology, where processing takes place in nodes that may receive, post the multiplex sensor, control, state, planning, actuator, and so on. The library is geared towards a Unix-like system.

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 give a powerful set of tools for working with ROS easily, knowing what is happening every time. Visualization, simulators, and debugging tools are the most important. In the next 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 BSD (Berkeley Software Distribution) 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 do this and more. 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 Hydro because it is a stable version while Indigo is still experimental and may contain bugs.

Now we are going to show you how to install ROS Hydro. Although in this book we use Hydro, you may need to install older versions to use some code that works only with these versions.

As we said 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.

Anyway, if you want to try installing it in an operating system other than Ubuntu, you can find instructions to do so in many other operating systems at http://wiki.ros.org/hydro/Installation.

 

PC installation


We assume that you have a PC with a copy of Ubuntu 12.04. We are using Ubuntu because it comes with a Long-Term Support (LTS). That means the community will maintain this version for five years.

Furthermore, it is necessary to have a basic knowledge of Linux and command tools such as the terminal, vim, creating folders, 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 Hydro – using repositories


Last year, the ROS webpage was updated with a new design and a new organization of contents. You can see a screenshot of the webpage that follows:

In the menu, you can find information about ROS and whether ROS is a good choice for your system, blogs, news, and so on.

Instructions for the 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.

So 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 Hydro in your computer. This process has been based on the official installation page, which can be found at http://wiki.ros.org/hydro/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 the 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 next window. Make sure that all the listed options are checked as shown in the following screenshot:

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 Hydro in various versions of the operating system. You can use any of them, but we recommend version 12.04 to follow the chapters of this book. Keep in mind that Hydro works in the Precise Pangolin (12.04), Quantal Quetzal (12.10), and the Raring Ringtail(13.04) versions of Ubuntu.

  • If you're going follow the book with Ubuntu 12.04 (Precise Pangolin), type the following command to add the repositories:

    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list'
    
  • If you're going to follow the book with Ubuntu 12.10 (Quantal Quetzal), type the following command to add the repositories:

    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu quantal main" > /etc/apt/sources.list.d/ros-latest.list'
    
  • To follow the book with Ubuntu 13.04 (Raring Ringtail), type the following command to add the repositories:

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

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can also download these code files from https://github.com/AaronMR/ROS_Book_Hydro.

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 is 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 it's better to make an update to avoid problems with the libraries and software with a version other than what ROS needs. 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, maybe you only need the basic installation for a robot without much space on the hard disc. 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, simulator in 2D (like stage) 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-hydro-desktop-full
    
  • If you do not have enough disk space or you prefer to install only a few packages, install only the desktop install initially, which comes with only 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, using aptitude and looking for ros-hydro-* packages with the following command:.

    $ sudo apt-get install ros-hydro-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-hydro-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-hydro-PACKAGE
    

Initializing rosdep

Before you can use ROS, you will need to initialize rosdep. The rosdep command line too enables you to easily install system dependencies for the source you want to compile and is required to run some core components in ROS. In ROS Fuerte you had to install rosdep after installing ROS, and it was known as a standalone tool. Now rosdep is installed in ROS by default. To initialize rosdep, you have to use 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 so, 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 Hydro, but just replace Hydro with Fuerte or Groovy if you want to try other distros:

$ source /opt/ros/hydro/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.

Notice that if you open another shell and type roscore or other ROS commands, it does not work. This is because it is necessary to execute the script again to configure the global variables, the path where ROS is installed, and so on.

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. So 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/hydro/setup.bash" >> ~/.bashrc 

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

$ source ~/.bashrc

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

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


source /opt/ros/hydro/setup.bash
source /opt/ros/fuerte/setup.bash
source /opt/ros/electric/setup.bash

The ROS Electric version will be executed in this case. So you have to make sure that the version you are running is the last one in the file.

If you want to check the version used in a terminal, you can do so easily using 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 is all! 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 works, and turtlesim.

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

$ roscore
$ rosrun turtlesim turtlesim_node

And 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 to restart 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 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 with ROS Hydro installed. You can download it from http://nootrix.com/2014/04/virtualized-ros-hydro/.

For this version, the Nootrix team are using torrent to download the virtual machine; I tried this way to download the file and it works perfectly.

You can find different virtual machines with Ubuntu and ROS preinstalled, but we are going to use this version because it is referred to in the official pages of ROS.

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 File | Import Appliance. Then click on Open appliance and select the ROSHydro.ova file downloaded earlier:

In the windows that follow, you can configure the parameters of the new virtual machine. Keep the default configuration and change only the name for the virtual system. This name is how you distinguish this virtual machine from others. Our recommendation is to put a descriptive name, in our case the name of this book:

Click on the Import button, and accept the software license agreement in the next window. You will see a progress bar. It means that VirtualBox is copying the file with the virtual image, and it is creating a new copy with the new name.

Notice that this process doesn't modify the original file ROS.ova, and you could create more virtual machines with different copies from the original file.

The process will take a few minutes depending on your computer. When it finishes, 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:

Sometimes, you will get an error as shown in the following screenshot. It is because your computer doesn't have the correct drivers to use the USB 2.0 controller. You can fix this by installing the Oracle VM VirtualBox Extension Pack, but you can also choose to disable the USB support to start using the virtual machine:

To disable the USB support, right-click over the virtual machine and select Settings. In the General tab, click on Ports | USB and uncheck the Enable USB 2.0 (EHCI) Controller, as shown in the following screenshot. Now you can restart the virtual machine and it should start without any problems.

Once the virtual machine starts, you should see the next window as seen in the following screenshot. It is the Ubuntu 12.04 OS with ROS installed:

When you finish these steps, you will have a full copy of ROS Hydro that can be used along 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 Hydro with the examples given in Chapter 4, Using Sensors and Actuators with ROS.

 

Installing ROS Hydro in BeagleBone Black (BBB)


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 pins GPIO. 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 you use an image of Ubuntu ARM 13.04 raring armhf on the platform to work with ROS.

Now, a ROS version for Ångström distribution is ready to be installed; you can do it following the installation steps given at http://wiki.ros.org/hydro/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, ODROID U3, ODROID X2, or Gumstick.

The 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 have 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 like the Raspberry PI or the Gumstick Overo. Additionally, more powerful boards like Gumstick DuoVero with a Dual Core ARM Cortex A9 or some quad core boards like Odroid U3, Odroid X2 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 entering 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 13.04 Raring armhf using wget with the following command:

$ wget https://rcn-ee.net/deb/flasher/raring/BBB-eMMC-flasher-ubuntu-13.04-2013-10-08.img

Download the Ubuntu 13.04 armhf image and install it on your SD card. You can get more details on how to install Ubuntu on Bealgebone Black on eLinux at http://elinux.org/Beagleboard:Ubuntu_On_BeagleBone_Black#Ubuntu_Raring_On_Micro_SD.

The process described in the preceding webpage works fine, but we have to be careful with the version of Ubuntu used. As the website is periodically updated, they are now using Ubuntu 14.04, which is not compatible with ROS. We will use an Ubuntu 13.04 Raring armhf as mentioned earlier.

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 IP, DNS, and gateway.

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

After setting up the network, we should install the packages, programs, and libraries that ROS will need such as CMake, Python, or Vim using the following commands:

$ sudo apt-get install cmake python-catkin-pkg python-empy python-nose python-setuptools libgtest-dev build-essential

$ sudo apt-get install g++ curl pkg-config libv4l-dev libjpeg-dev build-essential libssl-dev vim

The operating system for Beaglebone Black is set up for micro SD cards with 1-4 GHz. This memory space is very limited if we want to use a great part of the ROS Hydro packages. So in order to solve this situation, we can use SD cards with larger 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.

You can do this by following the commands listed next:

  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:

    $ sudo su
    
  9. And 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 are limited, and only active builds can be found for Ubuntu 13.04 raring armhf, the most popular version of Ubuntu ARM.

  • Ubuntu 13.04 Raring armhf:

    $ sudo sh -c 'echo "deb http://packages.namniart.com/repos/ros raring main" > /etc/apt/sources.list.d/ros-latest.list'
    
  • Ubuntu 12.10 Quantal armhf:

    $ sudo sh -c 'echo "deb http://packages.namniart.com/repos/ros quantal main" > /etc/apt/sources.list.d/ros-latest.list'
    
  • Ubuntu 12.04 Precise armhf:

    $ sudo sh -c 'echo "deb http://packages.namniart.com/repos/ros precise 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:

$ wget http://packages.namniart.com/repos/namniart.key -O - | sudo apt-key add –

Installing the ROS packages

Before the installation of ROS packages, we must update the system to avoid problems of library dependencies.

$ 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 to install 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:

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

We can install specific ROS packages by using the following command:

$ sudo apt-get install ros-hydro-PACKAGE

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

$ apt-cache search ros-hydro

For example, the following packages are the basics that work with ROS and can be installed individually using apt-get install:

$ sudo apt-get install ros-hydro-ros
$ sudo apt-get install ros-hydro-roslaunch
$ sudo apt-get install ros-hydro-rosparam
$ sudo apt-get install ros-hydro-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 we could only not install rviz.

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 solving 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 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/hydro/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/hydro/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 line:

$ sudo apt-get install python-rosinstall
 

Summary


In this chapter, we have installed ROS Hydro on different devices (PC, VirtualBox, and BeagleBone Black) in Ubuntu. With these steps, you have everything necessary installed on your system to start working with ROS 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 repository as installation as it is more common and normally does not give 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, for example, sensors or actuators. Anyway, you can use it for testing the algorithms.

Latest Reviews (7 reviews total)
The book was useful for my studies and contain the basic up to complex operations
Lot's of new things that i still have to learn from it.
Learning ROS for Robotics Programming Second Edition
Unlock this book and the full library FREE for 7 days
Start now