ROS Robotics by Example Second Edition
Total Page:16
File Type:pdf, Size:1020Kb
ROS Robotics By Example Second Edition Learning to control wheeled, limbed, and flying robots using ROS Kinetic Kame Carol Fairchild Dr. Thomas L. Harman BIRMINGHAM - MUMBAI ROS Robotics By Example Second Edition Copyright © 2017 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: June 2016 Second edition: November 2017 Production reference: 1301117 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78847-959-2 www.packtpub.com Credits Authors Copy Editor Carol Fairchild Safis Editing Dr. Thomas L. Harman Proofreader Reviewer Safis Editing Lentin Joseph Indexer Acquisition Editor Aishwarya Gangawane Frank Pohlmann Graphics Project Editor Kirk D'Penha Alish Firasta Production Coordinator Content Development Editor Nilesh Mohite Venugopal Commuri Technical Editor Bhagyashree Rai About the Authors Carol Fairchild is the owner and principal engineer of Fairchild Robotics, a robotics development and integration company. She is a researcher at Baxter's Lab at the University of Houston–Clear Lake (UHCL) and a member of the adjunct faculty. Her research involves the use of Baxter for expanded applications. Ms. Fairchild has been involved in many aspects of robotics from her earliest days of building her first robot, a Heathkit Hero. She has an MS in computer engineering from UHCL and a BS in engineering technology from Texas A&M. Ms. Fairchild has taught middle- school robotics, coached FLL, and volunteered for FIRST Robotics in Houston. Dr. Thomas L. Harman is the chair of the engineering division at UHCL. His research interests are control systems and applications of robotics and microprocessors. Several of his research papers with colleagues involve robotic and laser applications in medicine. In 2005, he was selected as the UHCL Distinguished Professor. He has been a judge and safety advisor for the FIRST robotic contests in Houston. Dr. Harman has authored or coauthored 18 books on subjects including microprocessors, MATLAB and Simulink applications, and the National Electrical Code. His laboratory at UHCL has a Baxter two-armed robot and several TurtleBots as well as other robots. About the Reviewer Lentin Joseph is an author, entrepreneur, electronics engineer, robotics enthusiast, machine vision expert, embedded programmer, and the founder and CEO of Qbotics Labs from India. Lentin 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 could communicate with people and reply intelligently, and it had 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, Lentin worked for 3 years at a start-up company focusing on robotics and image processing. In the meantime, he learned to work with famous robotics software platforms, such as Robot Operating System (ROS), V-REP, and Actin (a robotic simulation tool), and image processing libraries such as OpenCV, OpenNI, and PCL. He also knows about 3D robot design and embedded programming on Arduino and Tiva Launchpad. After 3 years of work experience, Lentin started a new company called Qbotics Labs, which mainly focuses on research into building some great products in domains such as robotics and machine vision. He maintains a personal website and a technology blog called TechnoLabsz. Lentin 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 (learn-robotics. com), Mastering ROS for Robotics Programming (mastering-ros.com), and ROS Robotics Project (http://rosrobots.com)—all books were published by Packt Publishing. The first book was about building an autonomous mobile robot using ROS and OpenCV. This book was launched at ICRA 2015 and was featured on the ROS blog, Robohub, OpenCV, the Python website, and various other such forums. The second book is on mastering Robot Operating System, which was also launched at ICRA 2016, and is one of the bestselling books on ROS. The third book is ROS Robotics Project, which was launched in ICRA 2017 and it is also one of the bestselling books on ROS. Along with writing, he reviewed books such as Effective Robotics Programming using ROS, Raspberry Pi Image Processing Programming, and Raspberry Pi Supercomputing and Scientific Programming. He started a new platform called Robocademy.com exclusively for learning robotics using ROS. Lentin and his team were also winners of the HRATC 2016 challenge conducted as a part of ICRA 2016. He was also a finalist in the ICRA 2015 challenge, HRATC. www.PacktPub.com eBooks, discount offers, and more 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. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1788479599. If you'd like to join our team of regular reviewers, you can email us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface xi Chapter 1: Getting Started with ROS 1 What does ROS do and what are the benefits of learning ROS? 2 Who controls ROS? 3 Which robots are using ROS? 3 Installing and launching ROS 5 Configuring your Ubuntu repositories 6 Setting up your sources.list file 6 Setting up your keys 7 Installing ROS Kinetic 7 Initialize rosdep 7 Environment setup 8 Getting rosinstall 8 Troubleshooting – examining your ROS environment 8 Creating a catkin workspace 9 ROS packages and manifest 10 ROS manifest 11 Exploring the ROS packages 11 rospack find packages 12 rospack list 12 ROS nodes, topics, and messages 13 ROS nodes 14 ROS topics 14 ROS messages 15 ROS Master 15 Invoking the ROS Master using roscore 16 ROS commands to determine the nodes and topics 17 [ i ] Table of Contents Turtlesim – the first ROS robot simulation 19 Starting turtlesim nodes 19 rosrun command 20 Turtlesim nodes 21 Turtlesim topics and messages 23 rostopic list 24 rostopic type 24 rosmsg list 24 rosmsg show 25 rostopic echo 25 Move the turtle by publishing /turtle1/cmd_vel 26 Move the turtle using the keyboard or joystick 28 Parameter Server of Turtlesim 28 rosparam help 28 rosparam list for the /turtlesim node 29 Change parameters for the color of the turtle's background 29 ROS services to move turtle 30 rosservice call 31 ROS commands summary 32 Summary 33 Chapter 2: Creating Your First Two-Wheeled ROS Robot (in Simulation) 35 Introducing rviz 36 Installing and launching rviz 36 Getting familiar with rviz 38 Displays panel 38 Views and Time panels 39 Toolbar 40 Main window menu bar 41 Creating and building a ROS package 41 Building a differential drive robot URDF 42 Creating a robot chassis 43 Using roslaunch 44 Adding wheels 48 Adding a caster 51 Adding color 52 Adding collisions 54 Moving the wheels 55 A word about tf and robot_state_publisher 57 Adding physical properties 57 Trying URDF tools 59 check_urdf 59 urdf_to_graphiz 59 [ ii ] Table of Contents Gazebo 60 Installing and launching Gazebo 61 Using roslaunch with Gazebo 62 Getting familiar with Gazebo 63 Environment toolbar 64 World, Insert and Layers panels 66 Joints panel 67 Main window menu bar 68 Simulation panel 68 Modifications to