Book Image

ROS Programming: Building Powerful Robots

By : Anil Mahtani, Aaron Martinez, Enrique Fernandez Perdomo, Luis Sánchez, Lentin Joseph
Book Image

ROS Programming: Building Powerful Robots

By: Anil Mahtani, Aaron Martinez, Enrique Fernandez Perdomo, Luis Sánchez, Lentin Joseph

Overview of this book

This learning path is designed to help you program and build your robots using open source ROS libraries and tools. We start with the installation and basic concepts, then continue with the more complex modules available in ROS, such as sensor and actuator integration (drivers), navigation and mapping (so you can create an autonomous mobile robot), manipulation, computer vision, perception in 3D with PCL, and more. We then discuss advanced concepts in robotics and how to program using ROS. You'll get a deep overview of the ROS framework, which will give you a clear idea of how ROS really works. During the course of the book, you will learn how to build models of complex robots, and simulate and interface the robot using the ROS MoveIt motion planning library and ROS navigation stacks. We'll go through great projects such as building a self-driving car, an autonomous mobile robot, and image recognition using deep learning and ROS. You can find beginner, intermediate, and expert ROS robotics applications inside! It includes content from the following Packt products: ? Effective Robotics Programming with ROS - Third Edition ? Mastering ROS for Robotics Programming ? ROS Robotics Projects
Table of Contents (37 chapters)
Title page
Copyright and Credits
Packt Upsell
Preface
Bibliography
Index

Installing ROS in BeagleBone Black


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

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

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

>

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

Now, an ROS version for Ångström distribution is ready to be installed; you can do so following the installation steps given at 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 section 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

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 [email protected]

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
  1. We will look at the partitions of our SD card:
$ fdisk /dev/mmcblk0
  1. On typing p, the two partitions of the SD card will be shown:
$ p
  1. 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
  1. 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
  1. You can write these changes by typing w if everything is right, or eliminate the changes with Ctrl + Z:
$ w
  1. We should reboot the board after finishing:
$ reboot
  1. Once again, become a super user once the reboot is complete:
$ sudosu
  1. 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 TabTab 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.