44,39 €
The area of robotics is gaining huge momentum among corporate people, researchers, hobbyists, and students. The major challenge in robotics is its controlling software. The Robot Operating System (ROS) is a modular software platform to develop generic robotic applications.
This book discusses the advanced concepts in robotics and how to program using ROS. It starts with deep overview of the ROS framework, which will give you a clear idea of how ROS really works. During the course of the book, you will learn how to build models of complex robots, and simulate and interface the robot using the ROS MoveIt motion planning library and ROS navigation stacks.
After discussing robot manipulation and navigation in robots, you will get to grips with the interfacing I/O boards, sensors, and actuators of ROS. One of the essential ingredients of robots are vision sensors, and an entire chapter is dedicated to the vision sensor, its interfacing in ROS, and its programming.
You will discuss the hardware interfacing and simulation of complex robot to ROS and ROS Industrial (Package used for interfacing industrial robots).
Finally, you will get to know the best practices to follow when programming using ROS.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 470
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 author, 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: December 2015
Production reference: 1141215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-179-8
www.packtpub.com
Author
Lentin Joseph
Reviewers
Jonathan Cacace
Ruixiang Du
Acquisition Editor
Vivek Anantharaman
Content Development Editor
Athira Laji
Technical Editor
Ryan Kochery
Copy Editor
Merilyn Pereira
Alpha Singh
Project Coordinator
Harshal Ved
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa
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) from 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. 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 in 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 robot 3D designing and embedded programming on Arduino and Tiva Launchpad.
After 3 years of work experience, he started a new company called 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 called 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 book Learning Robotics Using Python (refer to http://learn-robotics.com to know more) by Packt Publishing. The book was about building an autonomous mobile robot using ROS and OpenCV. The book was launched in ICRA 2015 and was featured in the ROS blog, Robohub, OpenCV, the Python website, and various other such forums.
Lentin was a finalist in the ICRA 2015 challenge, HRATC (http://www2.isr.uc.pt/~embedded/events/HRATC2015/Welcome.html).
I dedicate this book to my parents because they gave me the inspiration to write this book. I also convey my regards to my friends who helped and inspired me to write this book.
Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received has a bachelor's and master's degree in computer science from the University of Naples Federico II. Currently, he is attending a PhD Scholar Course in Information and Automation Engineering at the Department of Electrical Engineering and Information Technology (DIETI) in the same institution. His research is focused on autonomous action planning and execution by mobile robots, high-level and low-level control of UAV platforms, and human-robot interaction with humanoid robots in service task execution. He is the author and coauthor of several scientific publications in the robotics field, published at international conferences and scientific journals.
Jonathan is a member of the PRISMA Laboratory (http://prisma.dieti.unina.it/) of the University of Naples Federico II. With his research group, he is involved in different EU-funded collaborative research projects focused on several topics, such as the use of unmanned aerial vehicles for search and rescue operations or service task execution (http://www.sherpa-project.eu/sherpa/ and http://www.arcas-project.eu/) and the dynamic manipulation of elastic objects using humanoid robotic platforms (http://www.rodyman.eu/).
Ruixiang Du is currently a PhD student studying Robotics at Worcester Polytechnic Institute (WPI). He received his bachelor's degree in Automation from North China Electric Power University in 2011 and a master's degree in Robotics Engineering from WPI in 2013.
Ruixiang has worked on various robotic projects with robot platforms ranging from medical robots, UAV/UGV, to humanoid robots. He was an active member of Team WPI-CMU for the DARPA Robotics Challenge.
Ruixiang has general interests in robotics and in real-time and embedded systems. His research focus is on the control and motion planning of mobile robots in cluttered and dynamic environments.
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.
Mastering ROS for Robotics Programming is an advanced guide of ROS that is very suitable for readers who already have a basic knowledge in ROS. ROS is widely used in robotics companies, universities, and robotics research institutes for designing, building, and simulating a robot model and interfacing it into real hardware. ROS is now an essential requirement for Robotic engineers; this guide can help you acquire knowledge of ROS and can also help you polish your skills in ROS using interactive examples. Even though it is an advanced guide, you can see the basics of ROS in the first chapter to refresh the concepts. It also helps ROS beginners. The book mainly focuses on the advanced concepts of ROS, such as ROS Navigation stack, ROS MoveIt!, ROS plugins, nodelets, controllers, ROS Industrial, and so on.
You can work with the examples in the book without any special hardware; however, in some sections you can see the interfacing of I/O boards, vision sensors, and actuators to ROS. To work with this hardware, you will need to buy it.
The book starts with an introduction to ROS and then discusses how to build a robot model in ROS for simulating and visualizing. After the simulation of robots using Gazebo, we can see how to connect the robot to Navigation stack and MoveIt!. In addition to this, we can see ROS plugins, controllers, nodelets, and interfacing of I/O boards and vision sensors. Finally, we can see more about ROS Industrial and troubleshooting and best practices in ROS.
Chapter 1, Introduction to ROS and Its Package Management, gives you an understanding of the core underlying concepts of ROS and how to work with ROS packages.
Chapter 2, Working with 3D Robot Modeling in ROS, discusses the design of two robots; one is a seven-DOF (Degree of Freedom) manipulator and the other is a differential drive robot.
Chapter 3, Simulating Robots Using ROS and Gazebo, discusses the simulation of seven-DOF arms, differential wheeled robots, and ROS controllers that help control robot joints in Gazebo.
Chapter 4, Using the ROS MoveIt! and Navigation Stack, interfaces out-of-the-box functionalities such as robot manipulation and autonomous navigation using ROS MoveIt! and Navigation stack.
Chapter 5, Working with Pluginlib, Nodelets, and Gazebo Plugins, shows some of the advanced concepts in ROS, such as ROS pluginlib, nodelets, and Gazebo plugins. We will discuss the functionalities and application of each concept and can practice one example to demonstrate its working.
Chapter 6, Writing ROS Controllers and Visualization Plugins, shows how to write a basic ROS controller for PR2 robots and robots similar to PR2. After creating the controller, we will run the controller using the PR2 simulation in Gazebo. We can also see how to create plugin for RViz.
Chapter 7, Interfacing I/O Boards, Sensors, and Actuators to ROS, discusses interfacing some hardware components, such as sensors and actuators, with ROS. We will see the interfacing of sensors using I/O boards, such as Arduino, Raspberry Pi, and Odroid-C1, with ROS.
Chapter 8, Programming Vision Sensors using ROS, Open-CV, and PCL, discusses how to interface various vision sensors with ROS and program it using libraries such as Open Source Computer Vision (Open-CV) and Point Cloud Library (PCL).
Chapter 9, Building and Interfacing Differential Drive Mobile Robot Hardware in ROS, helps you to build autonomous mobile robot hardware with differential drive configuration and interface it with ROS. This chapter aims at giving you an idea of building a custom mobile robot and interfacing it with ROS.
Chapter 10, Exploring the Advanced Capabilities of ROS-MoveIt!, discusses the capabilities of MoveIt! such as collision avoidance, perception using 3D sensors, grasping, picking, and placing. After that, we can see the interfacing of a robotic manipulator hardware with MoveIt!
Chapter 11, ROS for Industrial Robots, helps you understand and install ROS-Industrial packages in ROS. We can see how to develop an MoveIt! IKFast plugin for an industrial robot.
Chapter 12, Troubleshooting and Best Practices in ROS, discusses how to set the ROS development environment in Eclipse IDE, best practices in ROS, and troubleshooting tips in ROS.
You should have a good PC running Linux distribution, preferably Ubuntu 14.04.3 or Ubuntu 15.04.
Readers can use a laptop or PC with a graphics card, and a RAM of 4 GB to 8 GB is preferred. This is actually for running high-end simulation in Gazebo and also for processing Point cloud and for computer vision.
The readers should have sensors, actuators, and the I/O board mentioned in the book and should have the provision to connect them all to their PC.
The readers also need a Git tool installed to clone the packages files.
If you are a Windows user, then it will be good to download Virtual box and set up Ubuntu in that. Working with Virtual box can have issues when we try to interface real hardware with ROS, so it would be good if you could work with the real system itself.
If you are a robotics enthusiast or a researcher who wants to learn more about building robot applications using ROS, this book is for you. In order to learn from this book, you should have a basic knowledge of ROS, GNU/Linux, and C++ programming concepts. The book will also be good for programmers who want to explore the advanced features of ROS.
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]> or <[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 chapter codes from https://github.com/qboticslabs/mastering_ros.git.
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/B04782_ColoredImages.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.
This is an introductory chapter that gives you an understanding of the core underlying concepts of ROS and how to work with ROS packages. We will also go through the ROS concepts such as ROS master, nodes, parameter server, topic, message, service, and actionlib to refresh your memory of the concepts you already know.
The basic building blocks of the ROS software framework are ROS packages. We will see how to create, build, and maintain a ROS package. We will also see how to create a wiki page for our package on the ROS website to contribute to the ROS community.
In this chapter, we will cover the following topics:
Robot Operating System (ROS) is a trending robot application development platform that provides various features such as message passing, distributed computing, code reusing, and so on.
The ROS project was started in 2007 with the name Switchyard by Morgan Quigley (http://wiki.osrfoundation.org/morgan) as part of the Stanford STAIR robot project. The main development of ROS happened at Willow Garage (https://www.willowgarage.com/).
The ROS community is growing very fast and there are many users and developers worldwide. Most of the high-end robotics companies are now porting their software to ROS. This trend is also visible in industrial robotics, in which companies are switching from proprietary robotic application to ROS.
The ROS industrial movement has gained momentum in the past few years owing to the large amount of research done in that field. ROS Industrial can extend the advanced capabilities of ROS to manufacturing. The increasing applications of ROS can generate a lot of job opportunities in this field. So after some years, knowledge in ROS will be an essential requirement for a robotics engineer.
Imagine that we are going to build an autonomous mobile robot. Here are some of the reasons why people choose ROS over other robotic platforms such as Player, YARP, Orocos, MRPT, and so on:
There are many reasons to choose ROS other than the preceding points.
Next, we can check the various reasons why people don't use ROS. Here are some of the existing reasons.
Here are some of the reasons why people do not prefer ROS for their robotic projects:
We now know where we have to use ROS and where we do not. If ROS is really required for your robot, let's start discussing ROS in more detail. First, we can see the underlying core concepts of ROS. There are mainly three levels in ROS: file system level, computation graph level, and community level. We can have a look at each level in short.
Similar to an operating system, ROS files are also organized on the hard disk in a particular fashion. In this level, we can see how these files are organized on the disk. The following graph shows how ROS files and folder are organized on the disk:
Figure 1 : ROS File system level
Here are the explanations of each block in the file system
The following screenshot gives you an idea of files and folders of a package that we are going to make in the upcoming sections:
Figure 2 : List of files inside the exercise package
A typical structure of a ROS package is shown here:
Figure 3 : Structure of a typical ROS package
We can discuss the use of each folder as follows:
We need to know some commands to create, modify, and work with the ROS packages. Here are some of the commands used to work with ROS packages:
To work with packages, ROS provides a bash-like command called rosbash (http://wiki.ros.org/rosbash), which can be used to navigate and manipulate the ROS package. Here are some of the rosbash commands:
The definition of package.xml of a typical package is shown as follows:
Figure 4 : Structure of package.xml
The package.xml file consists of the package name, version of the package, the package description, author details, package build dependencies, and runtime dependencies. The <build_depend></build_depend> tag includes the packages that are necessary to build the source code of the package. The packages inside the <run_depend></run_depend> tag are necessary during runtime of the package node.
Meta packages are specialized packages in ROS that only contain one file, that is, a package.xml file. It doesn't contain folders and files similar to a normal package.
Meta packages simply group a set of multiple packages as a single logical package. In the package.xml file, the meta package contains an export tag, as shown here:
Also, in meta packages, there are no <buildtool_depend> dependencies for catkin, there are only <run_depend> dependencies, which are the packages grouped in the meta package.
The ROS navigation stack is a good example of meta packages. If ROS is installed, we can try the following command, by switching to the navigation meta package folder:
Open package.xml using gedit text editor
This is a lengthy file; here is a stripped down version of it:
Figure 5 : Structure of meta-package package.xml
The ROS nodes can publish data having a particular type. The types of data are described using a simplified message description language, also called ROS messages. These datatype descriptions can be used to generate source code for the appropriate message type in different target languages.
The data type description of ROS messages are stored in .msg files in the msg subdirectory of a ROS package.
The message definition can consist of two types: fields and constants. The field is split into field types and field name. Field types is the data type of the transmitting message and field name is the name of it. The constants define a constant value in the message file.
Here is an example of message definitions:
Here, the first part is the field type and second is the field name. The field type is the data type and the field name can be used to access the value from the message. For example, we can use msg.number for accessing the value of the number from the message.
Here is a table to show some of the built-in field types that we can use in our message:
Primitive type
Serialization
C++
Python
bool(1)
unsigned 8-bit int
uint8_t(2)
bool
int8
signed 8-bit int
int8_t
int
uint8
unsigned 8-bit int
uint8_t
int (3)
int16
signed 16-bit int
int16_t
int
uint16
unsigned 16-bit int
uint16_t
int
int32
signed 32-bit int
int32_t
int
uint32
unsigned 32-bit int
uint32_t
int
int64
signed 64-bit int
int64_t
long
uint64
unsigned 64-bit int
uint64_t
long
float32
32-bit IEEE float
float
float
float64
64-bit IEEE float
double
float
string
ascii string(4)
std::string
string
time
secs/nsecs unsigned 32-bit ints
ros::Time
rospy.Time
duration
secs/nsecs signed 32-bit ints
ros::Duration
rospy.Duration
A special type of ROS message is called message headers. Headers can carry information such as time, frame of reference or frame_id, and sequence number. Using headers, we will get numbered messages and more clarity in who is sending the current message. The header information is mainly used to send data such as robot joint transforms (TF). Here is an example of the message header:
The rosmsg command tool can be used to inspect the message header and the field types. The following command helps to view the message header of a particular message:
This will give you an output like the preceding example message header. We can see more about the rosmsg command and how to work with custom message definitions in the upcoming sections.
The ROS services are a type request/response communication between ROS nodes. One node will send a request and wait until it gets a response from the other. The request/response communication is also using the ROS message description.
Similar to the message definitions using the .msg file, we have to define the service definition in another file called .srv, which has to be kept inside the srv sub directory of the package. Similar to the message definition, a service description language is used to define the ROS service types.
An example service description format is as follows:
The first section is the message type of request that is separated by --- and in the next section is the message type of response. In these examples, both Request and Response are strings.
In the upcoming sections, we can see how to work with ROS services.
The computation in ROS is done using a network of process called ROS nodes. This computation network can be called the computation graph. The main concepts in the computation graph are ROS Nodes, Master, Parameterserver, Messages, Topics, Services, and Bags. Each concept in the graph is contributed to this graph in different ways.
The ROS communication related packages including core client libraries such as roscpp and rospython and the implementation of concepts such as topics, nodes, parameters, and services are included in a stack called ros_comm (http://wiki.ros.org/ros_comm).
This stack also consists of tools such as rostopic, rosparam, rosservice, and rosnode to introspect the preceding concepts.
The ros_comm stack contains the ROS communication middleware packages and these packages are collectively called ROS Graph layer.
Figure 6 : Structure of the ROS Graph layer
The following are abstracts of each graph's concepts:
The following graph shows how the nodes communicate with each other using topics. The topics are mentioned in a rectangle and nodes are represented in ellipses. The messages and parameters are not included in this graph. These kinds of graphs can be generated using a tool called rqt_graph (http://wiki.ros.org/rqt_graph).
Figure 7 : Graph of communication between nodes using topics
ROS nodes are a process that perform computation using ROS client libraries such as roscpp and rospy. One node can communicate with other nodes using ROS Topics, Services, and Parameters.
A robot might contain many nodes, for example, one node processes camera images, one node handles serial data from the robot, one node can be used to compute odometry, and so on.
Using nodes can make the system fault tolerant. Even if a node crashes, an entire robot system can still work. Nodes also reduce the complexity and increase debug-ability compared to monolithic codes because each node is handling only a single function.
All running nodes should have a name assigned to identify them from the rest of the system. For example, /camera_node could be a name of a node that is broadcasting camera images.
There is a rosbash tool to introspect ROS nodes. The rosnode command can be used to get information about a ROS node. Here are the usages of rosnode:
We will see example nodes using the roscpp client and will discuss the working of ROS nodes that use functionalities such ROS Topics, Service, Messages, and actionlib.
ROS nodes communicate with each other by publishing messages to a topic. As we discussed earlier, messages are a simple data structure containing field types. The ROS message supports standard primitive datatypes and arrays of primitive types.
Nodes can also exchange information using service calls. Services are also messages, the service message definitions are defined inside the srv file.
We can access the message definition using the following method. For example, to access std_msgs/msg/String.msg, we can use std_msgs/String. If we are using the roscpp client, we have to include std_msgs/String.h for the string message definition.
In addition to message data type, ROS uses an MD5 checksum comparison to confirm whether the publisher and subscriber exchange the same message data types.
ROS has inbuilt tools called rosmsg to get information about ROS messages. Here are some parameters used along with rosmsg:
ROS topics are named buses in which ROS nodes exchange messages. Topics can anonymously publish and subscribe, which means that the production of messages is decoupled from the consumption. The ROS nodes are not interested to know which node is publishing the topic or subscribing topics, it only looks for the topic name and whether the message types of publisher and subscriber are matching.
The communication using topics are unidirectional, if we want to implement request/response such as communication, we have to switch to ROS services.
The ROS nodes communicate with topics using TCP/IP-based transport known as TCPROS. This method is the default transport method used in ROS. Another type of communication is UDPROS, which has low-latency, loose transport, and is only suited for teleoperation.
The ROS topic tool can be used to get information about ROS topics. Here is the syntax of this command:
