29,99 €
If you have ever tried building a robot, then you know how cumbersome programming everything from scratch can be. This is where ROS comes into the picture. It is a collection of tools, libraries, and conventions that simplifies the robot building process. What’s more, ROS encourages collaborative robotics software development, allowing you to connect with experts in various fields to collaborate and build upon each other's work.
Packed full of examples, this book will help you understand the ROS framework to help you build your own robot applications in a simulated environment and share your knowledge with the large community supporting ROS.
Starting at an introductory level, this book is a comprehensive guide to the fascinating world of robotics, covering sensor integration, modeling, simulation, computer vision, navigation algorithms, and more. You will then go on to explore concepts like topics, messages, and nodes. Next, you will learn how to make your robot see with HD cameras, or navigate obstacles with range sensors. Furthermore, thanks to the contributions of the vast ROS community, your robot will be able to navigate autonomously, and even recognize and interact with you in a matter of minutes.
What’s new in this updated edition? First and foremost, we are going to work with ROS Hydro this time around. You will learn how to create, visualize, and process Point Cloud information from different sensors. This edition will also show you how to control and plan motion of robotic arms with multiple joints using MoveIt!
By the end of this book, you will have all the background you need to build your own robot and get started with ROS.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 458
Veröffentlichungsjahr: 2015
Copyright © 2015 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
Production reference: 1120815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-758-0
www.packtpub.com
Authors
Enrique Fernández
Luis Sánchez Crespo
Anil Mahtani
Aaron Martinez
Reviewers
Piotr Gródek
Akihiko HONDA
Matthieu Keller
Aridane J. Sarrionandia de León
Commissioning Editor
Usha Iyer
Acquisition Editor
Richard Brookes-Bland
Content Development Editor
Adrian Raposo
Technical Editor
Parag Topre
Copy Editors
Sarang Chari
Sonia Mathur
Project Coordinator
Sanchita Mandal
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Graphics
Sheetal Aute
Jason Monteiro
Abhinash Sahu
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Enrique Fernández has a PhD in computer engineering from the University of Las Palmas de Gran Canaria and is a senior robotics engineer currently working at Clearpath Robotics, Inc. He did his MSc master's thesis in 2009 on SLAM. Enrique addresses the problem of path planning for autonomous underwater gliders (AUGs) in his PhD thesis, which was presented in 2013. During that period, he also worked on Computer Vision, AI, and other robotics topics, such as inertial navigation systems and Visual SLAM at the CIRS/ViCOROB Research Lab of the University of Girona for AUVs. He also participated in the Student Autonomous Underwater Challenge, Europe (SAUC-E) in 2012 and collaborated in the 2013 edition; in the 2012 edition, he was awarded a prize.
After his PhD, Enrique joined PAL Robotics in June 2013 as a senior robotics engineer in the Autonomous Navigation department. There, he developed software for REEM, REEM-C, and mobile-based robots and also for corresponding projects, such as Stockbot, using the ROS framework intensively. He worked on motion planning (path planning and control for mobile robots), robot localization, and SLAM. Recently, in 2015, he joined Clearpath Robotics, Inc. to work as a senior autonomy developer on SLAM, within the Autonomy department.
From an academic perspective, Enrique has published several conference papers and publications, two of them on the International Conference of Robotics and Automation (ICRA), in 2011. He is also an author of chapters of a few books and a previous book about ROS, Learning ROS for Robotics Programming by Packt Publishing. His MSc master's thesis was about the FastSLAM algorithm for indoor robots using a SICK laser scanner and the wheel odometry of a Pioneer differential platform. His PhD thesis contributed path planning algorithms and tools for AUGs. He also has experience with electronics and embedded systems such as PC104 and Arduino. His background covers SLAM, Computer Vision, path planning, optimization, and robotics and artificial intelligence in general.
I would like to thank the coauthors of this book for the effort put into writing and developing the code for the countless examples provided. I also want to say thanks to the members of the research groups where I did my PhD thesis: the University Institute of Intelligent Systems and Computational Engineering (SIANI) and the Center of Underwater Robotics Research (CIRS/ViCOROB). Also, a big thanks goes to my ex-colleagues at PAL Robotics, where I learned a lot about ROS, robotics for mobile, and humanoid biped robots—not only software, but also electronics and hardware design. Finally, I would like to thank my family and friends for their help and support.
Luis Sánchez Crespo completed his dual master's degree in electronics and telecommunication engineering from the University of Las Palmas de Gran Canaria. He has collaborated with different research groups at 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 the imaging of super-resolution algorithms.
His professional interests lie in computer vision, signal processing, and electronic design applied to 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 (AUVs) from scratch. In this project, Luis has started developing acoustic and computer vision systems, extracting information from different sensors, such as hydrophones, sonar, and cameras.
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 was demonstrated at the SAUC-E competition, where he directed the AVORA team. 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 for the previous version of Learning ROS for Robotics Programming by Packt Publishing.
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 have grown together during these years. I have to mention LPA Fabrika: Gran Canaria Maker Space for their enthusiasm in preparing and teaching educational robotics and technological projects; sharing a workspace with kids can be really motivating.
Finally, I have to thank my family and my girlfriend for their big support and encouragement in every project I'm involved in. I want to dedicate my contribution in this book to them.
Anil Mahtani is a computer scientist who has been working for the past 5 years on underwater robotics. He first started working in the field with his master's 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, he completed his thesis and his MSc in computer science at the University of Las Palmas de Gran Canaria, and shortly thereafter, he became a software engineer at SeeByte Ltd, a world leader in smart software solutions for underwater systems.
During his tenure at SeeByte Ltd, Anil was key to the development of several semi-autonomous and autonomous underwater systems for the military and the oil and gas industries. In those projects, he was heavily involved in the development of autonomous systems, the design of distributed software architectures, and low-level software development and has also contributed to providing computer vision solutions for front-looking sonar imagery. At SeeByte Ltd., he has 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, 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, and control problems. Anil is interested in DIY and electronics, and he has developed several Arduino libraries that 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've needed them. I would also like to thank David Rubio Vidal, Emilio Migueláñez Martín, and John Brydon for being the most supportive colleagues and friends, who have taught me so much personally and professionally. I would also like to thank my colleagues at SeeByte and the AVORA team from whom I've learned and experienced so much over the years. Finally, a special thank you to Jorge Cabrera Gámez, whose guidance and advice shaped my career in a way I could have never imagined.
Aaron Martinez is a computer engineer, entrepreneur, and expert in digital fabrication. He did his master's thesis in 2010 at Instituto Universitario de Ciencias y Tecnologias Ciberneticas (IUCTC) from 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 at 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 projects related to robotics; one of them is the AVORA project at the University of Las Palmas de Gran Canaria. In this project, he worked on the creation of an autonomous underwater vehicle (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 adapt the navigation stack and other algorithms from ROS to the robotic platform.
Recently, Aaron cofounded a company called SubSeaMechatronics, SL. This company works on projects related to underwater robotics and telecontrol systems; it also designs and manufactures subsea sensors. The main purpose of the company is to develop custom solutions for R&D prototypes and heavy-duty robots.
Aaron has experience in many fields, such as programming, robotics, mechatronics, and digital fabrication, and devices such as Arduino, BeagleBone, servers, and LIDAR. Nowadays, he is designing robotics platforms for underwater and aerial environments at SubSeaMechatronics SL.
I would like to thank my girlfriend, who supported me while writing this book and gave me the motivation to continue growing professionally. I also want to thank Donato Monopoli, head of the Biomedical Engineering department at the Canary Islands Institute of Technology (ITC), and all the staff there. Thanks for teaching me all that I know about digital fabrication, machinery, and tissue engineering. I spent the best years of my life in your workshop.
Thanks to my colleagues from 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.
Piotr Gródek is a C++ programmer interested in computer vision and image processing. He has worked as an embedded programmer and now works in banking. He is a developer of open source gaming and a self-driving car. In his free time, he enjoys running, playing squash, and reading.
Akihiko HONDA is an engineer of space robotics. He did his master's thesis in 2012 at the Tokyo Institute of Technology (Tokyo Tech). He is currently a PhD course student at Tokyo Tech.
His research interests include the teleoperation and automation of space robots that interact with flexible or deformable materials. He has a goal to improve the performance and stability of spacecraft in space by developing a much better operation and automation system. In his previous research, he worked for an earth observation satellite with a large solar array paddle and a space robotic arm used to capture the ISS supplier. Currently, he is planning to apply his research results to Space Solar Power System, planetary exploration rovers, and so on. He got an award for the best entry and an award from the Astronomical Society of Japan in JSF's Satellite Design Contest by proposing a new exploration spacecraft using his research.
Through his research at university, he has also participated in several projects conducted by Japan Aerospace Exploration Agency (JAXA). In the Robot Experiment on JEM (REX-J) project, he played a role in supporting operations for the experiment facility in orbit and got inspiration for his research. He also joined a project to develop a wearable manipulator for astronauts and developed systems for human control. He is currently working on two exploration robot projects. In one of them, a transformable rover named "KENAGE" is being developed to overcome the extra-rough terrain on the moon and Mars. The rover is now being examined for the possibility of using a GAZEBO simulator prepared by him. In another other project, he is developing an environment recognition system for Jumping Scouter.
In 2013, he participated in the SMART rover project at the University of Surrey and contributed to develop an environment protection and recognition system. Also, he played a role in a field test to check the practical utility of the rover in a real environment.
I would like to thank Hiroki KATO from JAXA for opening the door to ROS for me and giving precious suggestions for my research. I would also like to thank Professor Mitsushige ODA, Professor Hiroki NAKANISHI, and my colleagues in the Space Robotics Lab at Tokyo Tech. They share wonderful future visions about cool robots working in space with me, give suggestions, and support my research to realize them using ROS. I would also like to thank my professors and colleagues at STAR Lab at the University of Surrey for providing me with important advice about how to use ROS in a real environment. I would especially like to thank my friends from Gran Canaria who introduced me to this exciting work.
Finally, big thanks go to my family, Yoshihiko, Nobuko, and Ayaka, who have supported my life and my dream, and my girlfriend, who understands me.
Matthieu Keller is a French engineer who loves technology and computer science. His education walked him through computing and robotics, which have now become a hobby. He has reviewed the first version of this book.
Aridane J. Sarrionandia de León studied computer sciences and has always had a great interest in robotics and autonomous vehicles. His degree project is about underwater mapping using sonar, for which he has worked with an autonomous underwater vehicle with ROS. He has experience with autonomous systems and ROS. He is familiar with OpenCV and PCL and is currently working on the development of the control system of an autonomous surface vehicle.
I would like to thank Luis and Aaron for giving me the opportunity to review this book. Also, I would like to thank the AVORA team from the University of Las Palmas de Gran Canaria, especially Aaron, Luis, and Enrique, for introducing me to the wonders of ROS and helping me discover the world of autonomous vehicles, and my tutor, Jorge Cabrera Gámez, who gave me the opportunity to be a part of the AVORA team.
Finally, I would like to thank my family and friends, who supported me through the bugs in my life. Special thanks to Eva for dealing with all my gibberish.
For support files and downloads related to your book, please visit www.PacktPub.com.
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://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Learning ROS for Robotics Programming, Second Edition gives you a comprehensive review of ROS tools. ROS is the Robot Operating System framework, which is used nowadays by hundreds of research groups and companies in the robotics industry. But it is also the painless entry point to robotics for nonprofessional people. You will see how to install ROS, you will start playing with its basic tools, and you will end up working with state-of-the-art computer vision and navigation tools.
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 in 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 simulated environment. You will learn how to create your own robot and integrate it with the powerful navigation stack. Moreover, you will be able to run everything in simulation by using the Gazebo simulator. We will end the book by providing an example of how to use the Move it! package to perform manipulation tasks with robotic arms. At the end of the book, you will see that you can work directly with a ROS robot and understand what is going on under the hood.
Chapter 1, Getting Started with ROS Hydro, 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 Hydro 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 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 Debug 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, 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, GPS, and much more. Moreover, we explain how to use embedded systems with microcontrollers, similar to the widely known Arduino boards.
Chapter 5, 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 6, Point Clouds, in this chapter, we show 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.
Chapter 7, 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 by 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 8, 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 9, 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 by 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 10, 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, pick and place, or simple motion planning with inverse kinematics.
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 12.04 LTS. Then, you will use ROS Hydro, which is installed according to the instructions given in Chapter 1, Getting Started with ROS Hydro.
For this distribution of ROS, you will need a version of Ubuntu prior to 14.04 because, since this version, Hydro is no longer supported.
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/AaronMR/ROS_Book_Hydro.
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 http://www.packtpub.com/sites/default/files/downloads/7580OS_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, based in ROS Fuerte. 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, devices, or add new functionalities such as autonomous navigation, visual perception, and so on to your robot. Thanks to the open source motto and a community that is developing state-of-the-art algorithms and providing new functionalities, ROS is growing every day.
Throughout this book, you will learn the following:
In this chapter, we are going to install a full version of ROS Hydro 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 12.04 (Precise Pangolin) and you can download it for free from http://releases.ubuntu.com/12.04/.
Before starting with the installation, we are going to learn about the origin of the ROS and its history.
The Robot Operating System (ROS) is a framework that is widely used in Robotics. The philosophy is to make a piece of software that could work in other robots with only little changes to the code. What we get with this idea is the ability to create functionalities that can be shared and used in other robots without effort, so we do not need to reinvent the wheel.
ROS was originally developed in 2007 by the Stanford Artificial Intelligence Laboratory (SAIL) in support of the Stanford AI Robot project. As of 2008, development continues primarily at Willow Garage, a Robotics Research Institute, with more than twenty institutions collaborating within a federated development model.
A lot of research institutions have started to develop in ROS, adding hardware and sharing their code. Also, the 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 which 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 robots are examples of robots with published code and they are humanoids. 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 a lot of such examples at http://wiki.ros.org/Robots.
The sensors and actuators used in robotics have also been adapted for use in ROS. Everyday, more devices are being supported by this framework. Furthermore, thanks to ROS and open hardware, companies are creating cheaper and more powerful sensors. The Arduino board is a good example of this, because using a cheap electronic board you can add a lot of sensors like encoders, light and temperature sensors, and so on.
ROS provides standard operating system facilities such as hardware abstraction, low-level device control, implementation of commonly used functionalities, message passing between processes, and package management.
It is based on graph architecture with a centralized topology, where processing takes place in nodes that may receive, post the multiplex sensor, control, state, planning, actuator, and so on. The library is geared towards a Unix-like system.
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 give a powerful set of tools for working with ROS easily, knowing what is happening every time. Visualization, simulators, and debugging tools are the most important. In the next 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 BSD (Berkeley Software Distribution) 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 do this and more. 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 Hydro because it is a stable version while Indigo is still experimental and may contain bugs.
Now we are going to show you how to install ROS Hydro. Although in this book we use Hydro, you may need to install older versions to use some code that works only with these versions.
As we said 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.
Anyway, if you want to try installing it in an operating system other than Ubuntu, you can find instructions to do so in many other operating systems at http://wiki.ros.org/hydro/Installation.
We assume that you have a PC with a copy of Ubuntu 12.04. We are using Ubuntu because it comes with aLong-Term Support (LTS). That means the community will maintain this version for five years.
Furthermore, it is necessary to have a basic knowledge of Linux and command tools such as the terminal, vim, creating folders, 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 webpage was updated with a new design and a new organization of contents. You can see a screenshot of the webpage that follows:
In the menu, you can find information about ROS and whether ROS is a good choice for your system, blogs, news, and so on.
Instructions for the 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.
So 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 Hydro in your computer. This process has been based on the official installation page, which can be found at http://wiki.ros.org/hydro/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 the 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 next window. Make sure that all the listed options are checked as shown in the following screenshot:
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 Hydro in various versions of the operating system. You can use any of them, but we recommend version 12.04 to follow the chapters of this book. Keep in mind that Hydro works in the Precise Pangolin (12.04), Quantal Quetzal (12.10), and the Raring Ringtail(13.04) versions of Ubuntu.
Downloading the example code
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/AaronMR/ROS_Book_Hydro.
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 is 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 it's better to make an update to avoid problems with the libraries and software with a version other than what ROS needs. 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, maybe you only need the basic installation for a robot without much space on the hard disc. 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 you can use ROS, you will need to initialize rosdep. The rosdep command line too enables you to easily install system dependencies for the source you want to compile and is required to run some core components in ROS. In ROS Fuerte you had to install rosdep after installing ROS, and it was known as a standalone tool. Now rosdep is installed in ROS by default. To initialize rosdep, you have to use 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 so, 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 Hydro, but just replace Hydro with Fuerte or Groovy 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.
Notice that if you open another shell and type roscore or other ROS commands, it does not work. This is because it is necessary to execute the script again to configure the global variables, the path where ROS is installed, and so on.
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. So 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 next command, or close the current terminal and open another.
Some users need more than a single ROS distribution installed in their system. Your ~/.bashrc must only source the setup.bash of the version you are currently using, since the last call will override the environment set of the others. So you have several distros living in the same system and need to switch between them.
For example, you might have the following lines in your .bashrc file:
The ROS Electric version will be executed in this case. So you have to make sure that the version you are running is the last one in the file.
If you want to check the version used in a terminal, you can do so easily using 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 is all! 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 works, and turtlesim.
If you want to do the same,, type the following commands in different shells:
And 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 to restart 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 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 with ROS Hydro installed. You can download it from http://nootrix.com/2014/04/virtualized-ros-hydro/.
For this version, the Nootrix team are using torrent to download the virtual machine; I tried this way to download the file and it works perfectly.
You can find different virtual machines with Ubuntu and ROS preinstalled, but we are going to use this version because it is referred to in the official pages of ROS.
Creating a new virtual machine with the downloaded file is very easy; just proceed with the following steps. Open VirtualBox and click on File | Import Appliance. Then click on Open appliance and select the ROSHydro.ova file downloaded earlier:
In the windows that follow, you can configure the parameters of the new virtual machine. Keep the default configuration and change only the name for the virtual system. This name is how you distinguish this virtual machine from others. Our recommendation is to put a descriptive name, in our case the name of this book: