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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Robot Operating System Cookbook

You're reading from   Robot Operating System Cookbook Over 70 recipes to help you master advanced ROS concepts

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781783987443
Length 484 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Kumar Bipin Kumar Bipin
Author Profile Icon Kumar Bipin
Kumar Bipin
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with ROS FREE CHAPTER 2. ROS Architecture and Concepts I 3. ROS Architecture and Concepts – II 4. ROS Visualization and Debugging Tools 5. Accessing Sensors and Actuators through ROS 6. ROS Modeling and Simulation 7. Mobile Robot in ROS 8. The Robotic Arm in ROS 9. Micro Aerial Vehicles in ROS 10. ROS-Industrial (ROS-I) 11. Other Books You May Enjoy

Using ROS from a Linux container

As the industry moves beyond the virtual machine consolidation paradigm, several types of containers have come into prominence. Two flavors currently enjoy the lion's share of deployments on the Linux operating system: Docker and LXC.

Getting ready

LXC (Linux Containers) is an OS-level virtualization technology that allows the creation and running of multiple isolated Linux virtual environments (VE) on a single control host. These isolation levels or containers can be used to either sandbox specific applications or emulate an entirely new host. LXC uses the Linux cgroups functionality, which was introduced in version 2.6.24, to allow the host CPU to better partition memory allocation into isolation levels called namespaces (https://linuxcontainers.org/).

Docker, previously called dotCloud, was started as a side project and only open sourced in 2013. It is really an extension of the LXC capabilities. This it achieved using a high-level API that provides a lightweight virtualization solution to run processes in isolation. Docker is developed in the Go language and utilizes LXC, cgroups, and the Linux kernel itself. Since it's based on LXC, a Docker container does not include a separate operating system; instead it relies on the operating system's own functionality, as provided by the underlying infrastructure. So, Docker acts as a portable container engine, packaging the application and all of its dependencies in a virtual container that can run on any Linux server (https://www.docker.com/).

Note that a Linux VE is distinct from a virtual machine (VM).

How to do it...

Since Docker is an open platform that helps to distribute applications and complete systems and is based on LXC, we will discuss working with ROS Docker Images and how to distribute complex applications along with complete systems as a standalone image.

Installing Docker

Before installing Docker, it will require the updated packages:

$ sudo apt-get update

Use the following command to add the GPG key for the official Docker repository to the system:

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Adding the Docker repository to APT sources

For Ubuntu 16.04, add the following:

$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list

For Ubuntu 18.04, add the following:

$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list 

Updating the package database with the Docker packages from the newly added repository is done as follows:

$ sudo apt-get update

Make sure that we are about to install from the Docker repository instead of the default Ubuntu repository:

$ apt-cache policy docker-engine

Notice that docker-engine is not installed yet; to install docker-engine, use the following command:

$ sudo apt-get install -y docker-engine

Check whether Docker is started or not:

$ sudo systemctl status docker

To start the Docker service, use the following command:

$ sudo service docker start
$ docker

We can search for images available on Docker Hub by using the docker command with the search subcommand:

$ sudo docker search Ubuntu

To run the Docker container, use the following command:

$ sudo docker run -it hello-world

Getting and using ROS Docker images

Docker images are akin to packages such as virtual machines or complete systems that are already set up. There are servers that provide the images, and users only have to download them. The main server is Docker Hub, which is located at https://hub.docker.com. Here, it is possible to search for Docker images for different systems and configurations.

Well! All ROS Docker images are listed in the official ROS repository on the web at https://hub.docker.com/_/ros/. We will use ROS Kinetic images, which are already available here:

$ sudo docker pull ros
$ sudo docker pull kinetic-ros-core 
$ sudo docker pull kinetic-ros-base
$ sudo docker pull kinetic-robot
$ sudo docker pull kinetic-perception

Similarly, we could pull ROS Melodic images, which are also already available there:

$ sudo docker pull ros
$ sudo docker pull melodic-ros-core
$ sudo docker pull melodic-ros-base
$ sudo docker pull melodic-robot
$ sudo docker pull melodic-perception

After 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. The preceding command will create a new container from the main image wherein we have a full Ubuntu system with ROS Kinetic already installed. We will be able to work as in a regular system, install additional packages, and run the ROS nodes.

We can list all the Docker containers available and the origin of their images:

$ sudo docker ps

Congratulations! We have completed the Docker installation. To set up the ROS environment inside the container in order to start using ROS, we have to run the following command (ros_version: kinetic/melodic):

$ source /opt/ros/<ros_version>/setup.bash

However, in principle, running docker should be enough, but we could even SSH into a running Docker container as a regular machine, using name or ID.

$ sudo docker attach 665b4a1e17b6 #by ID ...OR
$ sudo docker attach loving_heisenberg #by Name

If we use attach, we can use only one instance of the shell. So, if we want to open a new terminal with a new instance of a container's shell, we just need to run the following:

$ sudo docker exec -i -t 665b4a1e17b6 /bin/bash #by ID ...OR 
$ sudo docker exec -i -t loving_heisenberg /bin/bash #by Name

Moreover, Docker containers can be stopped from other terminals using docker stop, and they can also be removed with docker rm.

See also

This book comes with a working Docker Image, which is basically an extension of ROS Kinetic with the code for the examples. The instructions to download and install it will be on the GitHub repository with the rest of the code.

You have been reading a chapter from
Robot Operating System Cookbook
Published in: Jun 2018
Publisher: Packt
ISBN-13: 9781783987443
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image