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

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:

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

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

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

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

$ docker pull ros:kinetic-robot

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

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

$ docker run -it ros

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

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

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

Docker containers can be stopped from other terminals using docker stop, and they can also be removed with docker rm. Docker also allows you to configure the container to expose the network, as well as mounting a host folder as volumes into it. In addition to this, it also supports a Python API, and has many other features. All this can be found in the official documentation at 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 section 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 section. The instructions to download and install it would be on the GitHub repository with the rest of the code.