Book Image

Effective Robotics Programming with ROS - Third Edition

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

Effective Robotics Programming with ROS - Third Edition

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

Overview of this book

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.
Table of Contents (18 chapters)
Effective Robotics Programming with ROS Third Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
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 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.