39,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 463
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2013
Second edition: August 2015
Third edition: December 2016
Production reference: 1231216
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78646-365-4
www.packtpub.com
Authors
Anil Mahtani
Luis Sánchez
Enrique Fernández
Aaron Martinez
Reviewer
Lentin Joseph
Commissioning Editor
Kartikey Pandey
Acquisition Editor
Narsimha Pai
Content Development Editor
Abhishek Jadhav
Technical Editor
Gaurav Suri
Copy Editors
Safis Editing
Dipti Mankame
Project Coordinator
Judie Jose
Proofreader
Safis Editing
Indexer
Pratik Shirodkar
Graphics
Kirk D'Penha
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
Anil Mahtani is a computer scientist who has dedicated an important part of his career to underwater robotics. He first started working in the field with his master thesis, where he developed a software architecture for a low-cost ROV. During the development of his thesis, he also became the team leader and lead developer of AVORA, a team of university students that designed and developed an autonomous underwater vehicle for the Students Autonomous Underwater Challenge – Europe (SAUC-E) in 2012. That same year, Anil Mahtani completed his thesis and his MSc in Computer Science at the University of Las Palmas de Gran Canaria and then became a Software Engineer at SeeByte Ltd, a world leader in smart software solutions for underwater systems. In 2015, he joined Dell Secureworks as a Software Engineer, where he applies his knowledge and skills toward developing intrusion detection and prevention systems.
During his time at SeeByte Ltd, Anil Mahtani played a key role in the development of several semi-autonomous and autonomous underwater systems for the military and oil and gas industries. In those projects, he was heavily involved in the development of autonomy systems, the design of distributed software architectures, and low-level software development and also contributed in providing Computer Vision solutions for front-looking sonar imagery. At SeeByte Ltd, he also achieved the position of project manager, managing a team of engineers developing and maintaining the internal core C++ libraries.
His professional interests lie mainly in software engineering, algorithms, data structures, distributed systems, networks, and operating systems. Anil's main role in robotics is to provide efficient and robust software solutions, addressing not only the current problems at hand but also foreseeing future problems or possible enhancements. Given his experience, he is also an asset when dealing with Computer Vision, machine learning, or control problems. Anil has also interests in DIY and electronics, and he has developed several Arduino libraries, which he has contributed back to the community.
First of all, I would like to thank my family and friends for their support and for always being there when I needed them. I would also like to thank my girlfriend Alex for her support and patience, and for being a constant source of inspiration. Finally, I would like to thank my colleagues Ihor Bilyy and Dan Good, who have taught me a lot, both personally and professionally, during these new steps in my career as a software engineer.
Luis Sánchez has completed his dual master's degree in electronics and telecommunication engineering at the University of Las Palmas de Gran Canaria.
He has collaborated with different research groups as the Institute for Technological Development and Innovation (IDETIC), the Oceanic Platform of Canary Islands (PLOCAN), and the Institute of Applied Microelectronics (IUMA) where he actually researches on imaging super-resolution algorithms.
His professional interests lie in Computer Vision, signal processing, and electronic design applied on robotics systems. For this reason, he joined the AVORA team, a group of young engineers and students working on the development of Underwater Autonomous Vehicles (AUV) from scratch. Inside this project, Luis has started developing acoustic and Computer Vision systems, extracting information from different sensors such as hydrophones, sonar, or camera.
With a strong background gained in marine technology, Luis cofounded Subsea Mechatronics, a young start-up, where he works on developing remotely operated and autonomous vehicles for underwater environments.
Here's what Dario Sosa Cabrera, a marine technologies engineer and entrepreneur (and the cofounder and maker of LPA Fabrika: Gran Canaria Maker Space) has to say about Luis:
"He is very enthusiastic and an engineer in multiple disciplines. He is responsible for his work. He can manage himself and can take up responsibilities as a team leader, as demonstrated at the euRathlon competition. His background in electronics and telecommunications allows him to cover a wide range of expertise from signal processing and software, to electronic design and fabrication."
Luis has participated as a technical reviewer of the previous version of Learning ROS for Robotics Programming and as a cowriter of the second edition.
First, I have to acknowledge Aaron, Anil, and Enrique for inviting me to participate in this book. It has been a pleasure to return to work with them. Also, I want to thank the Subsea Mechatronics team for the great experience working with heavy underwater robots, we grew together during these years. I have to mention LPA Fabrika – Gran Canaria Maker Space for the enthusiasm preparing and teaching educational robotics and technological projects; sharing a workspace with kids can be really motivating.
Finally, I will have to thank my family and my girlfriend for the big support and encouragement in every project where I'm involved. I want to dedicate my contribution in this book to them.
Enrique Fernández has a PhD in computer engineering and an extensive background in robotics. His PhD thesis addressed the problem of Path Planning for Autonomous Underwater Gliders, but he also worked on other robotics projects, including SLAM, perception, vision, and control. During his doctorate, he joined the Center of Underwater Robotics Research in the University of Girona, where he developed Visual SLAM and INS modules in ROS for Autonomous Underwater Vehicles (AUVs), and participated in the Student Autonomous Underwater Challenge, Europe (SAUC-E) in 2012, and collaborated in the 2013 edition; in 2012, he was awarded a prize.
During his PhD, Enrique published several conference papers and publications to top robotics conferences, such as the International Conference of Robotics and Automation (ICRA). He has also authored some book chapters and ROS books.
Later, Enrique joined PAL Robotics as a SLAM engineer in June 2013. There he worked with the REEM and REEM-C humanoid robots using ROS software and also contributed to the open source community, mainly to ROS Control repository, being one of the maintainers nowadays. In 2015, he joined Clearpath Robotics to work on the Autonomy team, developing perception algorithms. He has worked on the software that runs on the industrial mobile robots OTTO 1500 and OTTO 100, which has been deployed into the facilities of multiple large industry companies, such as General Electric and John Deere.
I would like to thank the coauthors of the book for their dedication. I also want to say thanks to the members of my research group in Las Palmas de Gran Canaria and the Center of Underwater Robotics Research in Girona. I learned a lot about robotics then, and I started to work with ROS. Thanks also to the ex-colleagues from PAL Robotics, who received me with open hands, and have given me the opportunity to learn even more from ROS and (humanoid) robots. Last by not least, to my current colleagues at Clearpath Robotics, where I have mastered ROS and contributed to the software that runs 24/7 in the self-driving robots we have sold for the Industry 4.0. Finally, thanks to my family and friends for their help and support, especially Eva.
Aaron Martinez is a computer engineer, entrepreneur, and expert in digital fabrication. He did his master's thesis in 2010 at the IUCTC (Instituto Universitario de Ciencias y Tecnologias Ciberneticas) in the University of Las Palmas de Gran Canaria. He prepared his master's thesis in the field of telepresence using immersive devices and robotic platforms. After completing his academic career, he attended an internship program at The Institute for Robotics in the Johannes Kepler University in Linz, Austria. During his internship program, he worked as part of a development team of a mobile platform using ROS and the navigation stack. After that, he was involved in some projects related to robotics; one of them is the AVORA project in the University of Las Palmas de Gran Canaria. In this project, he worked on the creation of an AUV to participate in the Student Autonomous Underwater Challenge-Europe (SAUC-E) in Italy. In 2012, he was responsible for manufacturing this project; in 2013, he helped to adapt the navigation stack and other algorithms from ROS to the robotic platform.
Recently, Aaron created his own company named SubSeaMechatronics, SL. This company works with projects related with underwater robotics and telecontrol systems. They are also designing and manufacturing subsea sensors. The company manufactures devices for other companies and research and development institutes.
Aaron has experience in many fields, such as programming, robotics, mechatronics, and digital fabrication as well as many devices, such as Arduino, BeagleBone, Servers, and LIDAR, and nowadays he is designing in SubSeaMechatronics SL some robotics platforms for underwater and aerial environments.
I would like to thank my girlfriend who has supported me while writing this book and gave me motivation to continue growing professionally. I also want to thank Donato Monopoli, Head of Biomedical Engineering Department at ITC (Canary-Islands Institute of Technology), and all the staff there. Thanks for teaching me all I know about digital fabrication, machinery, and engineering tissue. I spent the best years of my life in your workshop.
Thanks to my colleagues in the university, especially Alexis Quesada, who gave me the opportunity to create my first robot in my master's thesis. I have learned a lot about robotics working with them.
Finally, thanks to my family and friends for their help and support.
Lentin Joseph is an author, entrepreneur, electronics engineer, robotics enthusiast, machine vision expert, embedded programmer, and the founder and CEO of Qbotics Labs (http://www.qboticslabs.com) in India.
He completed his bachelor's degree in electronics and communication engineering at the Federal Institute of Science and Technology (FISAT), Kerala. For his final year engineering project, he made a social robot that can interact with people (http://www.technolabsz.com/2012/07/social-robot-my-final-year.html). The project was a huge success and was mentioned in many forms of visual and print media. The main features of this robot were that it can communicate with people and reply intelligently and has some image processing capabilities, such as face, motion, and color detection. The entire project was implemented using the Python programming language. His interest in robotics, image processing, and Python started with that project.
After his graduation, for 3 years he worked at a start-up company focusing on robotics and image processing. In the meantime, he learned famous robotic software platforms, such as Robot Operating System (ROS), V-REP, Actin (a robotic simulation tool), and image processing libraries, such as OpenCV, OpenNI, and PCL. He also knows about robot 3D designing and embedded programming on Arduino and Tiva Launchpad.
After 3 years of work experience, he started a new company named Qbotics Labs, which mainly focuses on research to build up some great products in domains, such as robotics and machine vision. He maintains a personal website (http://www.lentinjoseph.com) and a technology blog named technolabsz (http://www.technolabsz.com). He publishes his works on his tech blog. He was also a speaker at PyCon2013, India, on the topic Learning Robotics using Python.
Lentin is the author of the books Learning Robotics using Python (refer to http://learn-robotics.com to find out more) and Mastering ROS for Robotics Programming (refer to http://mastering-ros.com to find out more) by Packt Publishing. The first book was about building an autonomous mobile robot using ROS and OpenCV. This book was launched in ICRA 2015 and was featured in the ROS blog, Robohub, OpenCV, the Python website, and various other such forums. The second book is for mastering robot operating system; this was also launched ICRA 2016, and it is one of the best seller book in ROS.
Lentin and his team was a winner of HRATC 2016 challenge conducted as a part of ICRA 2016, and he was Also a finalist in the ICRA 2015 challenge, HRATC (http://www.icra2016.org/conference/challenges/).
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Thank you for purchasing this Packt book. We take our commitment to improving our content and products to meet your needs seriously—that's why your feedback is so valuable. Whatever your feelings about your purchase, please consider leaving a review on this book's Amazon page. Not only will this help us, more importantly it will also help others in the community to make an informed decision about the resources that they invest in to learn.
You can also review for us on a regular basis by joining our reviewers' club. If you're interested in joining, or would like to learn more about the benefits we offer, please contact us: <[email protected]>.
Effective Robotics Programming with ROS, Third Edition gives you a comprehensive review of ROS, the Robot Operating System framework, which is used nowadays by hundreds of research groups and companies in the robotics industry. More importantly, ROS is also the painless entry point to robotics for nonprofessionals and students. This book will guide you through the installation process of ROS, and soon enough, you will be playing with the basic tools and understanding the different elements of the framework.
The content of the book can be followed without any special devices, and each chapter comes with a series of source code examples and tutorials that you can run on your own computer. This is the only thing you need to follow the book.
However, we also show you how to work with hardware so that you can connect your algorithms with the real world. Special care has been taken in choosing devices that are affordable for amateur users, but at the same time, the most typical sensors or actuators in robotics research are covered.
Finally, the potential of ROS is illustrated with the ability to work with whole robots in a real or simulated environment. You will learn how to create your own robot and integrate it with a simulation by using the Gazebo simulator. From here, you will have the chance to explore the different aspects of creating a robot, such as perceiving the world using computer vision or point cloud analysis, navigating through the environment using the powerful navigation stack, and even being able to control robotic arms to interact with your surroundings using the MoveIt! package. By the end of the book, it is our hope that you will have a thorough understanding of the endless possibilities that ROS gives you when developing robotic systems.
Chapter 1, Getting Started with ROS, shows the easiest way you must follow in order to have a working installation of ROS. You will see how to install ROS on different platforms, and you will use ROS Kinetic throughout the rest of the book. This chapter describes how to make an installation from Debian packages, compile the sources, and make installations in virtual machines, Docker, and ARM CPU.
Chapter 2, ROS Architecture and Concepts, is concerned with the concepts and tools provided by the ROS framework. We will introduce you to nodes, topics, and services, and you will also learn how to use them. Through a series of examples, we will illustrate how to debug a node and visualize the messages published through a topic.
Chapter 3, Visualization and Debugging Tools, goes a step further in order to show you powerful tools to debug your nodes and visualize the information that goes through the node's graph along with the topics. ROS provides a logging API that allows you to diagnose node problems easily. In fact, we will see some powerful graphical tools, such as rqt_console and rqt_graph, as well as visualization interfaces, such as rqt_plot and rviz. Finally, this chapter explains how to record and play back messages using rosbag and rqt_bag.
Chapter 4, 3D Modeling and Simulation, constitutes one of the first steps in order to implement your own robot in ROS. It shows you how to model a robot from scratch and run it in simulation using the Gazebo simulator. You will simulate sensors, such as cameras and laser range sensors. This will later allow you to use the whole navigation stack provided by ROS and other tools.
Chapter 5, The Navigation Stack – Robot Setups, is the first of two chapters concerned with the ROS navigation stack. This chapter describes how to configure your robot so that it can be used with the navigation stack. In the same way, the stack is explained, along with several examples.
Chapter 6, The Navigation Stack – Beyond Setups, continues the discussion of the previous chapter by showing how we can effectively make our robot navigate autonomously. It will use the navigation stack intensively for that. This chapter shows the great potential of ROS using the Gazebo simulator and RViz to create a virtual environment in which we can build a map, localize our robot, and do path planning with obstacle avoidance.
Chapter 7, Manipulation with MoveIt!, is a set of tools for mobile manipulation in ROS. This chapter contains the documentation that you need to install this package. The chapter also contains example demonstrations with robotic arms that use MoveIt! for manipulation tasks, such as grasping, picking and placing, or simple motion planning with inverse kinematics.
Chapter 8, Using Sensors and Actuators with ROS, literally connects ROS with the real world. This chapter goes through a number of common sensors and actuators that are supported in ROS, such as range lasers, servo motors, cameras, RGB-D sensors, and GPS. Moreover, we explain how to use embedded systems with microcontrollers, similar to the widely known Arduino boards.
Chapter 9, Computer Vision, shows the support for cameras and computer vision tasks in ROS. This chapter starts with drivers available for FireWire and USB cameras so that you can connect them to your computer and capture images. You will then be able to calibrate your camera using the ROS calibration tools. Later, you will be able to use the image pipeline, which is explained in detail. Then, you will see how to use several APIs for vision and integrate OpenCV. Finally, the installation and usage of a visual odometry software is described.
Chapter 10, Point Clouds, shows how to use Point Cloud Library in your ROS nodes. This chapter starts with the basics utilities, such as read or write a PCL snippet and the conversions needed to publish or subscribe to these messages. Then, you will create a pipeline with different nodes to process 3D data, and you will downsample, filter, and search for features using PCL.
This book was written with the intention that almost everybody can follow it and run the source code examples provided with it. Basically, you need a computer with a Linux distribution. Although any Linux distribution should be fine, it is recommended that you use a version of Ubuntu 16.04 LTS. Then, you will use ROS Kinetic, which is installed according to the instructions given in Chapter 1, Getting Started with ROS.
As regards the hardware requirements of your computer, in general, any computer or laptop is enough. However, it is advisable to use a dedicated graphics card in order to run the Gazebo simulator. Also, it will be good to have a good number of peripherals so that you can connect several sensors and actuators, including cameras and Arduino boards.
You will also need Git (the git-core Debian package) in order to clone the repository with the source code provided with this book. Similarly, you are expected to have a basic knowledge of the Bash command line, GNU/Linux tools, and some C/C++ programming skills.
This book is targeted at all robotics developers, from amateurs to professionals. It covers all the aspects involved in a whole robotic system and shows how ROS helps with the task of making a robot really autonomous. Anyone who is learning robotics and has heard about ROS but has never tried it will benefit from this book. Also, ROS beginners will learn advanced concepts and tools of this framework. Indeed, even regular users may learn something new from some particular chapters. Certainly, only the first three chapters are intended for new users; so those who already use ROS can skip these ones and go directly to the rest.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
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/rosbook/effective_robotics_programming_with_ros. The same code files are also available at https://github.com/PacktPublishing/Effective-Robotics-Programming-with-ROS.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/EffectiveRoboticsProgrammingwithROSThirdEdition_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
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 - Second Edition, based in ROS Hydro/Indigo. 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 and devices, or how to add new functionalities, such as autonomous navigation, visual perception, and others, to your robot. Thanks to the open source ethos and a community that is developing state-of-the-art algorithms and providing new functionalities, ROS is growing every day.
This book will cover the following topics:
In this chapter, we are going to install a full version of ROS Kinetic 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 15.10 (Wily Werewolf), and you can download it for free from http://releases.ubuntu.com/15.10. Note that you can also use Ubuntu 16.04 (Xenial), following the same steps shown here; indeed, for the BeagleBone Black installation we will use Ubuntu Xenial.
Before starting with the installation, we are going to learn about the origin of ROS and its history.
The Robot Operating System (ROS) is a framework that, nowadays, is widely accepted and used in the robotics community. Its main goal is to make the multiple components of a robotics system easy to develop and share so they can work on other robots with minimal changes. This basically allows for code reuse, and improves the quality of the code by having it tested by a large number of users and platforms. ROS was originally developed in 2007 by the Stanford Artificial Intelligence Laboratory (SAIL) in support of the Stanford AI Robot project. Since 2008, Willow Garage continued the development, and recently Open Source Robotics Foundation (OSRF) began to oversee the maintenance of ROS and partner projects, like Gazebo, including the development of new features.
A lot of research institutions have started to develop in ROS, adding hardware and sharing their code. Also, 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 that 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 humanoid robots are examples of robots with published code. 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 many other examples at http://wiki.ros.org/Robots.
Most of the sensors and actuators used in robotics are supported by ROS as drivers. Furthermore, some companies benefit from ROS and open hardware to create cheaper and easier to use sensors, as existing software can be used for them at zero cost. The Arduino board is a good example because you can add many different kinds of sensors to this cheap electronic board, such as encoders, light and temperature sensors, and many others, and then expose their measurements to ROS to develop robotic applications.
ROS provides a hardware abstraction, low-level device control with ROS control, implementations of commonly used functionalities and libraries, message passing between processes, and package management with catkin and cmake.
It uses graph architecture with a centralized topology, where processing takes place in nodes that may receive and send messages to communicate with other nodes on the graph net. A node is any process that can read data from a sensor, control an actuator, or run high level, complex robotic or vision algorithms for mapping or navigating autonomously in the environment.
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 provide a powerful set of tools for working with ROS easily; visualization, simulators, and debugging tools are among the most important features that they have to offer. In the following 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 Berkeley Software Distribution (BSD) 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 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 Kinetic because it is the latest version. Now we are going to show you how to install ROS Kinetic. As we mentioned 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.
If you want to try installing it on an operating system other than Ubuntu, you can find instructions on how to do so with many other operating systems at http://wiki.ros.org/kinetic/Installation.
We assume that you have a PC with a copy of Ubuntu 15.10. It will also be necessary to have a basic knowledge of Linux and command tools such as the terminal, Vim, folder creation, 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.
Last year, the ROS web page was updated with a new design and a new organization of contents. The following is a screenshot of the web page:
In the menu, you can find information about ROS and whether ROS is a good choice for your system. You can also find blogs, news, and other features.
Instructions for 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.
To install ROS using the repositories, we will start by configuring the Ubuntu repository in our system.
In this section, you will learn the steps for installing ROS Kinetic in your computer. This process has been based on the official installation page, which can be found at http://wiki.ros.org/kinetic/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 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 following window. Make sure that all the listed options are checked as shown in the following screenshot (choose the appropriate country for the server from which you download the sources):
Normally these options are marked, so you should not have any problem with this step.
In this step, you have to select your Ubuntu version. It is possible to install ROS Kinetic in various versions of the operating system. You can use any of them, but we recommend version 15.10 to follow the chapters of this book. Keep in mind that Kinetic works in the Wily Werewolf (15.10) and Xenial Xerus (16.04) versions of Ubuntu. Type the following command to add the repositories:
Downloading the example code
Detailed steps to download the code bundle are mentioned in the Preface of this book. Please have a look.
The code bundle for the book is also hosted on GitHub at https://github.com/rosbook/effective_robotics_programming_with_ros. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Once you've added the correct repository, your operating system will know where to download programs to install them into your system.
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's added to your system's trusted list.
Now we can be sure that the code came from an authorized site and has not been modified.
We are ready to start the installation now, but before we do that, we'd better make an update to avoid problems with the libraries and versions of software that are not ideal for ROS. This is done with the following command:
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, you might only need the basic installation for a robot without much space on the hard disk. 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:
Before using ROS we need to initialize rosdep. The rosdep command-line tool helps with the installation of system dependencies for the source code that we are going to compile or install. For this reason, it is required by some of the core components in ROS, so it is installed by default with it. To initialize rosdep, you have to run the following commands:
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 this, 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 Kinetic, but just replace kinetic with indigo or jade, for example, if you want to try other distros:
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.
Note that if you open another terminal you also have to source the setup.bash file to set the environment variables to detect the ROS packages installed on your system. Otherwise, roscore or other ROS commands will not work. This is because the script must be sourced again to configure the environment variables, which include the path where ROS is installed, as well as other packages and additional paths for compiling new code properly.
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. That way, 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:
To see the results, you have to execute the file using the following command, or close the current terminal and open another:
Some users need more than a single ROS distribution installed in their system, so you'll have several distros living in the same system and may need to switch between them. Your ~/.bashrc file must only source the setup.bash file of the version you are currently using, since the last call will override the environment set by the others.
For example, you might have the following lines in your .bashrc file:
The ROS Kinetic version will be executed in this case. Make sure that the version you are running is the last one in the file. It's also recommended to source a single setup.bash.
If you want to check the version used in a terminal, you can do so easily running the echo $ROS_DISTRO command.
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:
And that's it! 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 and turtlesim both work.
If you want to do the same, type the following commands in different shells:
If everything is okay, you will see the following screenshot:
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 for restarting your development machine if you have any problems, or to save all the setups necessary for your robot in the machine.
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 the Linux version of 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 15.10 from OSBOXES found at http://www.osboxes.org/ubuntu/; then we will simply install ROS Kinetic following the same instructions described in the previous section. In particular, the Ubuntu 15.10 image can be downloaded from http://sourceforge.net/projects/osboxes/files/vms/vbox/Ubuntu/15.10/Ubuntu_15.10-64bit.7z/download.
This would download a .7z file. In Linux, it can be uncompressed with the following:
If the .7z command is not installed, it can be installed with the following:
The virtual machine file will go into the 64-bit folder with the name: Ubuntu 15.10 Wily (64bit).vdi
Creating a new virtual machine with the downloaded file is very easy; just proceed with the following steps. Open VirtualBox and click on New. We are going to create a new virtual machine that will use the Ubuntu 15.10 Wily (64bit).vdi file downloaded before, which is a hard disk image with Ubuntu 15.10 already installed. Set the name, type, and version of the virtual machine as shown in the following screenshot:
You can configure the parameters of the new virtual machine in the windows that follow. Keep the default configuration and change only the name for the virtual system. This name is how you distinguish this virtual machine from others. For the RAM, we advise that you use as much as possible, but 8 GB should be enough.
For the hard drive, use the existing virtual hard drive file Ubuntu 15.10 Wily (64bit).vdi downloaded before, as shown in the following screenshot:
After this, 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:
Once the virtual machine starts, you should see another window, as seen in the following screenshot. It is the Ubuntu 15.10 OS with ROS installed (use osboxes.org as the password to log in):
When you finish these steps, install ROS Kinetic as you would on a regular computer following the steps of the previous sections, and you will have a full copy of ROS Kinetic that can be used 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 Kinetic with the examples given in Chapter 4, 3D Modeling and Simulation.
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.
In order to install it in Ubuntu, you only have to run the following:
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:
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:
