ROS Robotics By Example - Second Edition - Carol Fairchild - E-Book

ROS Robotics By Example - Second Edition E-Book

Carol Fairchild

0,0
45,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Learning how to build and program your own robots with the most popular open source robotics programming framework

About This Book

  • Get to know the fundamentals of ROS and apply its concepts to real examples
  • Learn how to write robotics applications without getting bogged down in hardware problems
  • Learn to implement best practices in ROS development

Who This Book Is For

This book is for robotic enthusiasts, researchers and professional robotics engineers who would like to build robot applications using ROS. It gives the robotics beginner and the ROS newbie an immensely practical introduction to robot building and robotics application coding. Basic knowledge of GNU/Linux and the ability to write simple applications is assumed, but no robotics knowledge, practical or theoretical, is needed.

What You Will Learn

  • Control a robot without requiring a PhD in robotics
  • Simulate and control a robot arm
  • Control a flying robot
  • Send your robot on an independent mission
  • Learning how to control your own robots with external devices
  • Program applications running on your robot
  • Extend ROS itself
  • Extend ROS with the MATLAB Robotics System Toolbox

In Detail

ROS is a robust robotics framework that works regardless of hardware architecture or hardware origin. It standardizes most layers of robotics functionality from device drivers to process control and message passing to software package management.

But apart from just plain functionality, ROS is a great platform to learn about robotics itself and to simulate, as well as actually build, your first robots. This does not mean that ROS is a platform for students and other beginners; on the contrary, ROS is used all over the robotics industry to implement flying, walking and diving robots, yet implementation is always straightforward, and never dependent on the hardware itself.

ROS Robotics has been the standard introduction to ROS for potential professionals and hobbyists alike since the original edition came out; the second edition adds a gradual introduction to all the goodness available with the Kinetic Kame release.

By providing you with step-by-step examples including manipulator arms and flying robots, the authors introduce you to the new features. The book is intensely practical, with space given to theory only when absolutely necessary. By the end of this book, you will have hands-on experience on controlling robots with the best possible framework.

Style and approach

ROS Robotics By Example, Second Edition gives the robotics beginner as well as the ROS newbie an immensely practical introduction to robot building and robotics application coding. ROS translates as "robot operating system"; you will learn how to control a robot via devices and configuration files, but you will also learn how to write robot applications on the foundation of this operating system.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 543

Veröffentlichungsjahr: 2017

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

ROS Robotics By Example Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with ROS
What does ROS do and what are the benefits of learning ROS?
Who controls ROS?
Which robots are using ROS?
Installing and launching ROS
Configuring your Ubuntu repositories
Setting up your sources.list file
Setting up your keys
Installing ROS Kinetic
Initialize rosdep
Environment setup
Getting rosinstall
Troubleshooting – examining your ROS environment
Creating a catkin workspace
ROS packages and manifest
ROS manifest
Exploring the ROS packages
rospack find packages
rospack list
ROS nodes, topics, and messages
ROS nodes
ROS topics
ROS messages
ROS Master
Invoking the ROS Master using roscore
Parameter Server
ROS commands to determine the nodes and topics
Turtlesim – the first ROS robot simulation
Starting turtlesim nodes
rosrun command
Turtlesim nodes
Turtlesim topics and messages
rostopic list
rostopic type
rosmsg list
rosmsg show
rostopic echo
Move the turtle by publishing /turtle1/cmd_vel
Move the turtle using the keyboard or joystick
Parameter Server of Turtlesim
rosparam help
rosparam list for the /turtlesim node
Change parameters for the color of the turtle's background
rosparam get
rosparam set
ROS services to move turtle
rosservice call
ROS commands summary
Summary
2. Creating Your First Two-Wheeled ROS Robot (in Simulation)
Introducing rviz
Installing and launching rviz
Getting familiar with rviz
Displays panel
Views and Time panels
Mouse control
Toolbar
Main window menu bar
Creating and building a ROS package
Building a differential drive robot URDF
Creating a robot chassis
Using roslaunch
Adding wheels
Adding a caster
Adding color
Adding collisions
Moving the wheels
A word about tf and robot_state_publisher
Adding physical properties
Trying URDF tools
check_urdf
urdf_to_graphiz
Gazebo
Installing and launching Gazebo
Using roslaunch with Gazebo
Getting familiar with Gazebo
Environment toolbar
World, Insert and Layers panels
Joints panel
Main window menu bar
Simulation panel
Modifications to the robot URDF
Adding the Gazebo tag
Specifying color in Gazebo
A word about the <visual> and <collision> elements in Gazebo
Verifying a Gazebo model
Viewing the URDF in Gazebo
Tweaking your model
Moving your model around
Other ROS simulation environments
Summary
3. Driving Around with TurtleBot
Introducing TurtleBot 2
Loading TurtleBot 2 simulator software
Launching TurtleBot 2 simulator in Gazebo
Problems and troubleshooting
ROS commands and Gazebo
Keyboard teleoperation of TurtleBot 2 in simulation
Setting up to control a real TurtleBot 2
TurtleBot 2 standalone test
Networking the netbook and remote computer
Types of networks
Network addresses
Remote computer network setup
Netbook network setup
Secure Shell (SSH) connection
Summary of network setup
Troubleshooting your network connection
Testing the TurtleBot 2 system
TurtleBot 2 hardware specifications
TurtleBot 2 dashboard
Moving the real TurtleBot 2
Using keyboard teleoperation to move TurtleBot 2
Using ROS commands to move TurtleBot 2 around
Writing your first Python script to control TurtleBot 2
Introducing rqt tools
rqt_graph
rqt message publisher and topic monitor
TurtleBot's odometry
Odom for the simulated TurtleBot 2
Real TurtleBot 2's odometry display in rviz
TurtleBot 2 automatic docking
Introducing TurtleBot 3
Loading TurtleBot 3 simulation software
Launching TurtleBot 3 simulation in rviz
Launching TurtleBot 3 simulation in Gazebo
Hardware assembly and testing
Loading TurtleBot 3 software
Installing remote computer software
Installing SBC software
Loading Ubuntu MATE
Loading ROS packages
Loading TurtleBot 3 packages
Setting up udev rules for TurtleBot 3
Networking TurtleBot 3 and the remote computer
Remote computer network setup
TurtleBot 3 network setup
SSH connection
Testing the SSH communication
Troubleshooting your network connection
Moving the real TurtleBot 3
Using keyboard teleoperation to move TurtleBot 3
Summary
4. Navigating the World with TurtleBot
3D vision systems for TurtleBot
How these 3D vision sensors work
Comparison of 3D sensors
Microsoft Kinect
ASUS
PrimeSense Carmine
Intel RealSense
Hitachi-LG LDS
Obstacle avoidance drawbacks
Configuring TurtleBot and installing the 3D sensor software
Kinect
ASUS and PrimeSense
Intel RealSense
Camera software structure
Defining terms
Testing the 3D sensor in standalone mode
Running ROS nodes for visualization
Visual data using Image Viewer
Visual data using rviz
Navigating with TurtleBot
Mapping a room with TurtleBot 2
Defining terms
Building a map
How does TurtleBot accomplish this mapping task?
Autonomous navigation with TurtleBot 2
Defining terms
Driving without steering TurtleBot 2
rviz control
How does TurtleBot accomplish this navigation task?
Navigating to a designated location
Navigating to waypoints with a Python script using a map
Defining TurtleBot's position on a map
Defining waypoints on a map
Using Python code to move TurtleBot
TurtleBot at final goal point
SLAM for TurtleBot 3
Autonomous navigation with TurtleBot 3
rqt_reconfigure
Exploring ROS navigation further
Summary
5. Creating Your First Robot Arm (in Simulation)
Features of Xacro
Building an articulated robot arm URDF using Xacro
Specifying a namespace
Using the Xacro property tag
Expanding Xacro
Using roslaunch for rrbot
Using the Xacro include and macro tags
Adding mesh to the robot arm
Controlling an articulated robot arm in Gazebo
Adding Gazebo-specific elements
Fixing the robot arm to the world
Viewing the robot arm in Gazebo
Adding controls to Xacro
Defining transmission elements for joints
Adding a Gazebo ROS control plugin
Creating a YAML configuration file
Creating a control launch file
Controlling your robot arm with the ROS command line
Controlling your robot arm with rqt
Trying more things in rqt
Summary
6. Wobbling Robot Arms Using Joint Control
Introducing Baxter
Baxter, the research robot
Baxter Simulator
Baxter's arms
Baxter's bend joints
Baxter's twist joints
Baxter's coordinate frame
Control modes for Baxter's arms
Baxter's grippers
Baxter's arm sensors
Loading Baxter software
Installing Baxter SDK software
Installing Baxter Simulator
Configuring the Baxter shell
Installing MoveIt!
Launching Baxter Simulator in Gazebo
Bringing Baxter Simulator to life
Warm-up exercises
Flexing Baxter's arms
Untucking Baxter's arms
Wobbling arms
Controlling arms and grippers with a keyboard
Controlling arms and grippers with a joystick
Controlling arms with a Python script
Recording and replaying arm movements
Baxter's arms and forward kinematics
Joints and joint state publisher
Understanding tf
A program to move Baxter's arms to a zero angle position
Commanding the joint angles directly
rviz tf frames
Viewing a tf tree of robot elements
Introducing MoveIt!
Planning a move of Baxter's arms with MoveIt!
Adding objects to a scene
Position of objects
Planning a move to avoid obstacles with MoveIt!
Configuring a real Baxter setup
Controlling a real Baxter
Commanding joint position waypoints
Commanding joint torque springs
Demonstrating joint velocity
Additional examples
Visual servoing and grasping
Inverse kinematics
Moving Baxter's arms with IK
Using a state machine to perform YMCA
Summary
7. Making a Robot Fly
Introducing quadrotors
Why are quadrotors so popular?
Defining roll, pitch, and yaw
How do quadrotors fly?
Components of a quadrotor
Adding sensors
Quadrotor communications
Understanding quadrotor sensors
Inertial measurement unit
Quadrotor condition sensors
Preparing to fly your quadrotor
Testing your quadrotor
Pre-flight checklist
Precautions when flying your quadrotor
Following the rules and regulations
Using ROS with UAVs
Introducing Hector Quadrotor
Loading Hector Quadrotor
Launching Hector Quadrotor in Gazebo
Flying Hector outdoors
Flying Hector indoors
Introducing Crazyflie 2.0
Controlling Crazyflie without ROS
Communicating using Crazyradio PA
Loading Crazyflie ROS software
Setting up udev rules for Crazyradio
Pre-flight check
Flying Crazyflie with teleop
Details of teleop_xbox360.launch
Flying with a motion capture system
Flying multiple Crazyflies
Introducing Bebop
Loading bebop_autonomy software
Testing Bebop communications
Flying Bebop using commands
Take off
Landing
Summary
8. Controlling Your Robots with External Devices
Creating a custom ROS game controller interface
Testing a game controller
Alternative test of a game controller
Using the ROS joy package
Controlling Turtlesim with a custom game controller interface
Creating a custom ROS Android device interface
Installing Android Studio and tools
Installing a ROS–Android development environment
Defining terms
Introducing ROS–Android development
Creating ROS nodes on Arduino or Raspberry Pi
Using Arduino
Installing Arduino IDE software
Installing ROS–Arduino software
Ultrasonic sensor control using ROS and Arduino
Connecting the Arduino to the HC-SR04 ultrasonic sensor
Programming the Arduino to sense distance
Executing the ultrasonic sensor program
Other applications using ROS and Arduino
Using Raspberry Pi
Installing ROS on the Raspberry Pi
Summary
9. Flying a Mission with Crazyflie
Mission components
Kinect for Windows v2
Crazyflie operation
Mission software structure
OpenCV and ROS
Loading software for the mission
Installing libfreenect2
Installing iai_kinect2
Using the iai_kinect2 metapackage
kinect2_bridge and kinect2_viewer
kinect2_calibration
Calibrating your Kinect
Setting up the mission
Detecting Crazyflie and a target
Identifying markers in a color image
Problems with target detection
Detecting and viewing markers with OpenCV
Using Kinect and OpenCV
How to track Crazyflie
How to control Crazyflie
Crazyflie control states
Using ROS services to control takeoff and land
Activating takeoff and land
What makes takeoff and land work?
Using PID control for hover and flight
Using an observer node
Flying Crazyflie
Hovering in place
What makes hover work?
Flying to a stationary target
What makes target detection work?
Learned lessons
Logging messages with rosout and rospy
Summary
10. Controlling Baxter with MATLAB©
Installing the MATLAB Robotics System Toolbox
Check the MATLAB and Robotics System Toolbox versions
View the Robotics System Toolbox commands for ROS
Using MATLAB Robotics System Toolbox and Baxter Simulator
Installing Baxter messages in MATLAB
Running Baxter Simulator and MATLAB
Making Baxter move
Summary
Index

ROS Robotics By Example Second Edition

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

Carol Fairchild

Dr. Thomas L. Harman

Reviewer

Lentin Joseph

Acquisition Editor

Frank Pohlmann

Project Editor

Alish Firasta

Content Development Editor

Venugopal Commuri

Technical Editor

Bhagyashree Rai

Copy Editor

Safis Editing

Proofreader

Safis Editing

Indexer

Aishwarya Gangawane

Graphics

Kirk D'Penha

Production Coordinator

Nilesh Mohite

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 PacktCopy and paste, print, and bookmark contentOn 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.

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!

Preface

Being excited about learning ROS and working with ROS robots such as Baxter and TurtleBot is the beginning of a big adventure. The features and benefits of ROS are substantial, but the learning curve is steep. Through trial and error, we have foraged a path through many of the ROS applications trying everything. In this book, we hope to present to you the best of our knowledge of ROS and provide you with detailed step-by-step instructions for your journey. Our approach centers on using the ROS robots that are featured, namely TurtleBot, Baxter, Crazyflie, and Bebop, as well as simulated robots—Turtlesim and Hector.

This book provides introductory information as well as advanced applications featuring these ROS robots. The chapters begin with the basics of setting up your computer and loading ROS and the packages for ROS robots and tools. Straightforward instructions are provided with troubleshooting steps for when the desired results are not achieved. The building blocks of ROS are described first in the simulation Turtlesim, then on each of the featured robots. Starting with basic ROS commands, the ROS packages, nodes, topics, and messages are explored to gain an overall knowledge of these ROS robotic systems. Technical information on these example robots is provided to describe the robot's full capabilities.

ROS encompasses a full spectrum of software concepts, implementation, and tools that attempt to provide a homogeneous view of the complex systems and software integration required in robotics. Extensive libraries of sensor and actuator drivers and interfaces are already in place, as well as the latest and most efficient algorithms. What ROS doesn't provide directly is imported from other prevailing open source projects such as OpenCV. ROS also possesses a spectrum of time-saving tools to control, monitor, and debug robot applications: rqt, rviz, Gazebo, dynamic reconfigure, and MoveIt, to name a few.

In the pages that follow, each of these areas will be incrementally introduced to the reader as part of the robot examples. With TurtleBot, the subjects of navigation and mapping are explored. Using Baxter, joint control and path planning are described for your understanding. Simple Python scripts are included to provide examples of implementing ROS elements for many of these robots. These robots are all available in simulation to accomplish the exercises in this book. Furthermore, instructions are provided for you to build and control your own robot models in simulation.

The power of ROS, the variety of robots using ROS, and the diversity and support of the widespread ROS community make this adventure worthwhile. Extensive online tutorials, wiki instructions, forums, and tips and tricks are available for ROS. So dive into the pages of this book to begin your adventure with ROS robotics!

What this book covers

Chapter 1, Getting Started with ROS, explains to you the advantages of learning ROS and highlights the spectrum of robots currently using ROS. Instructions for installing and launching ROS on a computer running an Ubuntu operating system are provided. An overview of the ROS architecture is given and its components are described. The Turtlesim simulation is introduced, and used to provide a deeper understanding of how the components of ROS work and a familiarity with ROS commands.

Chapter 2, Creating Your First Two-Wheeled ROS Robot (in Simulation), introduces you to the ROS simulation environment of Gazebo. We will lead you through the steps to create your first robot simulation (a two-wheeled differential-drive base) and teach the structure of the Universal Robotic Description Format. The use of the ROS tool rviz and Gazebo are detailed to enable you to display your robot and interact with it.

Chapter 3, Driving Around with TurtleBot, introduces you to real ROS robots, TurtleBot2 and the recently available TurtleBot 3. These mobile base robots can be used in the simulation environment of Gazebo if you do not own one. ROS commands and Python scripts are used to control TurtleBot through a variety of methods. The ROS tool rqt is introduced, and subsets of its plugins are used to control TurtleBot and monitor its sensor data.

Chapter 4, Navigating the World with TurtleBot, explores visual sensors and the ability for a robot to map its environment. The 3D sensor options for TurtleBot's vision system are described and their setup and operation using ROS enables TurtleBot to navigate autonomously. The knowledge of the Simultaneous Localization and Mapping techniques is applied in combination with TurtleBot's navigation stack to move about in the mapped environment.

Chapter 5, Creating Your First Robot Arm (in Simulation), provides a gentle introduction into the complexity of robotic arms. A simulated robot arm is designed and built using the macro language of Xacro. Controllers for the arm are created to operate the arm in Gazebo. Through developing the controllers for this arm, an insight into the mechanics and physics of a simple robot arm is offered.

Chapter 6, Wobbling Robot Arms Using Joint Control, takes a deeper look at the intricacies of controlling robotic arms. Baxter has two 7 degree-of-freedom arms and a number of other sensors. Baxter Simulator is available as open source software to use for the instructions in this chapter. Examples are provided for control of Baxter's arms using position, velocity, and torque modes with control for both forward and inverse kinematics. The ROS tool MoveIt is introduced for motion planning in simulation and execution on either a real or simulated Baxter.

Chapter 7, Making a Robot Fly, describes a growing area of ROS robotics—unmanned air vehicles. This chapter focuses on quadrotors, and an understanding of quadrotor hardware and flight control is provided. Instructions for downloading and controlling the simulated quadrotor Hector are supplied. With skills from flying a simulated quadrotor, you can move on to control a real Bitcraze Crazyflie or Parrot Bebop. Quadrotor control is via teleoperation or ROS topic/message commands.

Chapter 8, Controlling Your Robots with External Devices, presents a number of peripheral devices you can use for controlling a ROS robot. Joystick controllers, controller boards (Arduino and Raspberry Pi), and mobile devices have ROS interfaces that can be integrated with your robot to provide external control.

Chapter 9, Flying a Mission with Crazyflie, incorporates many of the ROS components and concepts presented in this book into a challenging mission of autonomous flight. The mission involves the Crazyflie quadrotor flying to a "remote" target all mapped through a Kinect 3D sensor. This mission uses ROS message communication and co-ordinate transforms to employ the Kinect's view of the quadrotor and target to orchestrate the flight. Flight control software for Crazyflie using PID control is described and provided as part of the mission software.

Chapter 10, Controlling Baxter with MATLAB©, delves into a new realm of communicating with and controlling ROS robots through MATLAB and its Robotics System Toolbox. Baxter, the two-armed robot introduced in Chapter 6, Wobbling Robot Arms Using Joint Control, will be used to show how to set up a ROS robot in MATLAB by adding custom messages into the Robotics System Toolbox. Communication and control of Baxter and his arms will be accomplished using MATLAB scripts and ROS commands.

What you need for this book

The format of this book is intended for the reader to follow along and perform the instructions as the information is provided. The reader will need a computer ideally with Ubuntu 16.04 (Xenial Xerus) installed. Other Ubuntu versions and Linux distributions may work, as well as macOS, Android, and Windows, but documentation for those versions will need to reference the ROS wiki (http://wiki.ros.org/kinetic/Installation).

The version of ROS that this book was written around is Kinetic Kame, which is the current release recommended for stability. Its end of life is targeted for April 2021.

All software used in this book is open source and freely available for download and use. Instructions for downloading the software are found in the chapter where the software is introduced. In Chapter 1, Getting Started with ROS, instructions are given for downloading and setting up the ROS software environment.

Our preferred method to download software is the use of Debian packages. Where no Debian packages exist, we refer to downloading the software from repositories such as GitHub.

Gazebo simulation performs intensive graphics processing, and the use of a dedicated graphics card is advised but not required.

Peripheral devices, such as 3D sensors, Xbox or PS3 controllers, Arduino or Raspberry Pi controller boards, and Android mobile devices are optional equipment.

Who this book is for

If you are a robotics developer, whether a hobbyist, researcher, or professional, and are interested in learning about ROS through a hands-on approach, then this book is for you. You are encouraged to have a working knowledge of GNU/Linux systems and Python.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, directory names, filenames, file extensions, and pathnames are shown as follows: "The Terminal commands rostopic and rosnode have a number of options…"

A block of code is set as follows:

<?xml version='1.0'?> <robot name="dd_robot"> <!-- Base Link --> <link name="base_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <box size="0.5 0.5 0.25"/> </geometry> </visual> </link> </robot>

To avoid repeating previous code blocks, but provide with placement of new code blocks, previous code left for reference is abbreviated and grayed-out as follows:

<?xml version='1.0'?> <robot name="dd_robot"> <!-- Base Link --> <link name="base_link"> … </link> <!-- Right Wheel --> <link name="right_wheel">

Any command-line input is written as follows:

$ rosrun rqt_reconfigure rqt_reconfigure

Output from command is written as:

[ INFO] [1427212356.117628994]: Starting turtlesim with node name /turtlesim

New terms and key words are shown in bold.

Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "By clicking on the Add button on the Displays panel..."

URL references are shown as: http://www.ros.org/about-ros/

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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 find useful and enjoyable.

To send us general feedback, simply email <[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.

Customer support

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.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/ROS-Robotics-By-Example-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

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/ROSRoboticsByExampleSecondEdition_ColorImages.pdf.

Errata

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

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.

Questions

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.

Chapter 1. Getting Started with ROS

In this chapter, we will introduce the Robot Operating System (ROS), which is a collection of software packages to aid researchers and developers using robotic systems. After we discuss the instructions to install ROS on your computer system using the Ubuntu operating system, the ROS architecture and many of its components are discussed. This will aid you in understanding the use of ROS to develop software for robotic applications.

ROS will be introduced in terms of its elements and their functions. An understanding of the ROS vocabulary is necessary to become proficient in using ROS to create programs for the control of real or simulated robots as well as devices, such as cameras.

To make the discussion more concrete, the turtlesim simulator will be presented with various examples of the ROS command usage. This simulator is part of ROS and it provides an excellent introduction to the capabilities of ROS.

In this chapter, we will cover the following topics:

What ROS is and which robots use ROSHow to install and launch ROS on your computerHow to navigate the ROS directoriesAn introduction to ROS packages, nodes, and topicsExamples of useful ROS commandsHow to use ROS commands with the turtlesim simulator

What does ROS do and what are the benefits of learning ROS?

ROS is sometimes called a meta operating system because it performs many functions of an operating system, but it requires a computer's operating system such as Linux. One of its main purposes is to provide communication between the user, the computer's operating system, and equipment external to the computer. This equipment can include sensors, cameras, as well as robots. As with any operating system, the benefit of ROS is the hardware abstraction and its ability to control a robot without the user having to know all of the details of the robot.

For example, to move a robot's arms, a ROS command is issued or scripts in Python or C++ written by the robot designers cause the robot to respond as commanded. The scripts can, in turn, call various control programs that cause the actual motion of the robot's arms. It is also possible to design and simulate your own robot using ROS. These subjects and many others will be considered in this book.

In this book, you will learn a set of concepts, software, and tools that apply to an ever-increasing and diverse army of robots. For example, the navigation software of one mobile robot can be used, with a few changes, to work in another mobile robot. The flight navigation of an aerial robot is similar to that of the ground robot and so on. All across the broad spectrum of robotics, system interfaces are standardized or upgraded to support increased complexity. There are readily available libraries for commonly used robotics functions. ROS not only applies to the central processing of robotics but also to sensors and other subsystems. ROS hardware abstraction combined with low-level device control speeds the upgrade toward the latest technology.

ROS is an open source robotic software system that can be used without licensing fees by universities, government agencies, and commercial companies. The advantages of open source software are that the source code for the system is available and can be modified according to a user's needs. More importantly for some users, the software can be used in a commercial product as long as the appropriate licenses are cited. The software can be improved and modules can be added by users and companies.

ROS is used by many thousands of users worldwide and knowledge can be shared between users. The users range from hobbyists to professional developers of commercial robots. In addition to the large group of ROS researchers, there is a ROS-Industrial group dedicated to applying ROS software to robots for manufacturing. Other versions of ROS currently under development include:

ROS-M for military robotic systemsH-ROS is Hardware ROS for interoperable robot componentsROS 2.0 to upgrade ROS with the latest technology and software

Who controls ROS?

A ROS distribution is a set of ROS software packages that can be downloaded to your computer. These packages are supported by the Open Source Robotics Foundation (OSRF), a nonprofit organization. The distributions are updated periodically and given different names by the ROS organization. More details about the ROS organization are available at: http://www.ros.org/about-ros/

Which robots are using ROS?

There is a long list of robots on the ROS wiki website, http://wiki.ros.org/Robots, which use ROS. For example, we are using four different robots in this book to provide you with an experience of a wide range of ROS capabilities. These robots are as follows:

TurtleBot, a mobile robotBaxter, a friendly two-armed robotCrazyflie and Bebop, flying robots

The images of these robots are in the following figures:

TurtleBot 2 and 3

Of course, not everyone has the opportunity to use real robots such as Baxter (shown in the following image):

Baxter in the authors' laboratory

However, there is good news! Using the ROS Gazebo software, you can simulate Baxter as well as many other robots whose models are provided for Gazebo. We will simulate TurtleBot using Gazebo and actually design our own mobile robot in the upcoming chapters of this book.

Bebop and Crazyflie

Installing and launching ROS

For this book, we assume the reader has a computer with Ubuntu Wily 15.10 or Xenial 16.04 installed. The examples in this book have been developed using ROS Kinetic and this version of ROS is only supported by these two versions of Ubuntu. The instructions for ROS installation provided in this section are for installing Debian (binary) packages. This is the most efficient and preferred way to install ROS.

If you wish to install the ROS Kinetic source code and build the software, refer to the instructions at http://wiki.ros.org/kinetic/Installation/Source. The instructions presented here to install ROS Kinetic with Debian packages can also be found at http://wiki.ros.org/kinetic/Installation/Ubuntu.

If you have any problems while installing ROS, refer to this site and the ROS forum at http://answers.ros.org.

Note

Refer to the Gazebo tutorial at http://gazebosim.org/tutorials/?tut=ros_urdf for a list of these elements and their usage (Elements for Links and Elements for Joints).

Configuring your Ubuntu repositories

To configure your Ubuntu repositories to allow restricted, universe and multiverse, perform the following steps:

Click on the Ubuntu System Settings icon in the menu on the left side of your desktop.Click on the Software & Updates icon. On the Software & Updates screen, select the appropriate checkboxes to match the following screenshot:

Ubuntu Software & Updates screen

Setting up your sources.list file

Open a terminal window to set up the sources.list file on your computer to accept software from the ROS software repository at http://packages.ros.org which is the authorized site for the ROS software.

At the $ command prompt, type the following command as one long command:

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu$(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Tip

In copying such two line commands from the electronic version of this book, be sure to delete the Carriage Return at the end of the first line.

This step allows the operating system to know where to download programs that need to be installed on your system. When updates are made to ROS Kinetic, your operating system will be made aware of these updates.

Setting up your keys

Keys confirm the origin of the code and verify that unauthorized modifications to the code have not been made without the knowledge of the owner. A repository and the keys of that repository are added to the operating system's trusted software list. Type the following command:

$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

Installing ROS Kinetic

Before you begin with the installation, the current system software must be up to date to avoid problems with libraries and wrong versions of software. To make sure your Debian package index is up-to-date, type the following command:

$ sudo apt-get update

Install the desktop-full configuration of ROS. Desktop-full includes ROS, rqt, rviz, robot-generic libraries, 2D/3D simulators, navigation, and 2D/3D perception. In this book, we will be using rqt and rviz for visualization and also the Gazebo 3D simulator, as well as the ROS navigation and perception packages. To install, type the following command:

$ sudo apt-get install ros-kinetic-desktop-full

ROS Kinetic is installed on your computer system when the installation process is complete!

Initialize rosdep

The ROS system may depend on software packages that are not loaded initially. These software packages external to ROS are provided by the operating system. The ROS environment command rosdep is used to download and install these external packages. Type the following commands:

$ sudo rosdep init$ rosdep update

Environment setup

Your terminal session must now be made aware of these ROS files so that it knows what to do when you attempt to execute ROS command-line commands. Running this script will set up the ROS environment variables:

$ source /opt/ros/kinetic/setup.bash

Alternatively, it is convenient if the ROS environment variables are automatically added to your terminal session every time a new shell is launched. If you are using bash for your terminal shell, do this by typing the following commands:

$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc$ source ~/.bashrc

Now when a new terminal session is launched, the bash shell is automatically aware of the ROS environment variables.

Getting rosinstall

The rosinstall command is a command-line tool in ROS that allows you to download ROS packages with one command.

To install this tool on Ubuntu, type the following command:

$ sudo apt-get install python-rosinstall

Troubleshooting – examining your ROS environment

The ROS environment is set up through a number of variables that tell the system where to find ROS packages. Two main variables are ROS_ROOT and ROS_PACKAGE_PATH that enable ROS to locate packages in the filesystem.

To check whether the ROS environment variables are set correctly, use the env command in the following form that lists the ROS environment variables:

$ env | grep ROS

The output of the preceding command is as follows:

ROS_ROOT=/opt/ros/kinetic/share/rosROS_PACKAGE_PATH=/opt/ros/kinetic/shareROS_MASTER_URI=http://localhost:11311ROSLISP_PACKAGE_DIRECTORIES=ROS_DISTRO=kineticROS_ETC_DIR=/opt/ros/kinetic/etc/ros

If the variables are not set correctly, you will need to source your setup.bash file, as described in the Environment setup section of this chapter. Check whether the ROS_DISTRO= "kinetic" and ROS_PACKAGE_PATH variables are correct, as shown previously.

The tutorial that discusses the ROS environment can be found at: http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment

Creating a catkin workspace

The next step is to create a catkin workspace. A catkin workspace is a directory (folder) in which you can create or modify existing catkin packages. The catkin structure simplifies the build and installation process for your ROS packages. The ROS wiki website is http://wiki.ros.org/catkin/Tutorials/create_a_workspace.

A catkin workspace can contain up to three or more different subdirectories (/build, /devel, and /src), each of which serve a different role in the software development process.

We will label our catkin workspace catkin_ws. To create the catkin workspace, type the following commands:

$ mkdir -p ~/catkin_ws/src$ cd ~/catkin_ws/src$ catkin_init_workspace

Even though the workspace is empty (there are no packages in the src folder, just a single CMakeLists.txt link), you can still build the workspace by typing the following commands:

$ cd ~/catkin_ws/$ catkin_make

The catkin_make command creates the catkin workspace. If you view your current directory contents, you should now have the build and devel folders. Inside the devel folder there are now several setup.*sh files. We will source the setup.bash file to overlay this workspace on top of your ROS environment:

$ source ~/catkin_ws/devel/setup.bash

Remember to add this source command to your .bashrc file by typing the following command:

$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

To make sure your workspace is properly overlaid by the setup script, make sure the ROS_PACKAGE_PATH environment variable includes the directory you're in by typing the following command:

$ echo $ROS_PACKAGE_PATH

The output of the preceding command should be as follows:

/home/<username>/catkin_ws/src:/opt/ros/kinetic/share

Here, <username> is the name you chose for the user when Ubuntu was installed.

ROS packages and manifest

The ROS software is divided into packages that can contain various types of programs, images, data, and even tutorials. The specific contents depend on the application for the package. The site http://wiki.ros.org/Packages discusses ROS packages.

A package can contain programs written in Python or C++ to control a robot or another device. For the turtlesim simulator package, for example, the package contains the executable code used to change the background color or move a turtle around on the screen. This package also contains images of a turtle for display and files used to create the simulator.

There is another class of packages in ROS called metapackages that are specialized packages that only contain a package.xml manifest. Their purpose is to reference one or more related packages, which are loosely grouped together.

ROS manifest

Each package contains a manifest named package.xml that describes the package in the Extensible Markup Language (XML) format. In addition to providing a minimal specification describing the package, the manifest defines properties about the package such as the package name, version numbers, authors, maintainers, and any dependencies on other packages.

Exploring the ROS packages

Occasionally, we would like to find packages that we wish to use and display the files involved. This section introduces several useful ROS commands:

rospack used for information about a packageroscd used to navigate the ROS directoriesrosls used to list directories and files in a package directory

The rospack command can be used to list ROS packages, locate packages by name, and determine if a package depends on another package, among other uses. For more information use the following command with the help or -h option in the form:

$ rospack help | less

We will use the turtlesim package for the examples here. To change directories to the location of turtlesim, use the following command:

$ roscd turtlesim

This changes the location on one of the author's workstations as follows:

linux@D158-45929:/opt/ros/kinetic/share/turtlesim$

On your computer, the $ command prompt will be preceded by the information about your computer. Generally, that information for our computers will be deleted in our examples using ROS commands. Once you are in the turtlesim directory, the standard Linux commands can be used with the subdirectories or files, or the ROS commands can be used. To determine the directories and files in the turtlesim directory but without changing to the turtlesim directory, use the following command:

$ rosls turtlesim

Here is the result from the home directory of the author's workstation with ROS installed:

cmake images msg package.xml srv

To see the filenames of the images loaded with turtlesim, specify the images directory in the package as follows:

$ rosls turtlesim/images

The output of the preceding command is as follows:

box-turtle.png groovy.png indigo.svg palette.pngdiamondback.png hydro.png jade.png robot-turtle.pngelectric.png hydro.svg kinetic.png sea-turtle.pngfuerte.png indigo.png kinetic.svg turtle.png

There are various turtle images that can be used. The rosls turtlesim command will also work to show the contents of the turtlesim subdirectories: /msg for messages and /srv for services. These files will be discussed later. To see the manifest, type the following commands:

$ roscd turtlesim$ cat package.xml

This will also show the dependencies, such as roscpp for C++ programs.

rospack find packages

The rospack find <package name> command returns the path to the package named <package name>. For example, type the following command:

$ rospack find turtlesim

The preceding command displays the path to the turtlesim directory.

rospack list

Execute the following command:

$ rospack list

This lists the ROS package names and their directories on the computer. In the case of the workstation mentioned earlier, there are 195 ROS packages listed!

Tip

If you really want to see all the ROS packages and their locations, use the following command form:

$ rospack list | less

This form allows paging of the long list of names and directories for the packages. Press Q to quit.

Alternatively, this is the form of the rospack command:

$ rospack list-names

This lists only the names of the packages without the directories. After such a long list, it is a good idea to open a new terminal window or clear the window with the clear command.

This is the form of the rospack command:

$ rospack list-names | grep turtle

This lists the packages with turtle in the name.

More information on commands that are useful to navigate the ROS filesystem is available at the ROS website http://wiki.ros.org/ROS/Tutorials/NavigatingTheFilesystem

ROS nodes, topics, and messages

Here we will explore some of the main components of ROS. One of the primary purposes of ROS is to facilitate communication between the ROS nodes. These nodes represent the executable code. The code can reside entirely on one computer, or nodes can be distributed between computers or between computers and robots. The advantage of this distributed structure is that each node can control one aspect of a system.

For example, one node can capture the images from a camera and send the images to another node for processing. After processing the image, the second node can send a control signal to a third node for controlling a robotic manipulator in response to the camera view.

The main mechanism used by ROS nodes to communicate is by sending and receiving messages. The messages are organized into specific categories called topics. Nodes may publish messages on a particular topic or subscribe to a topic to receive information.

ROS nodes

Basically, nodes are processes that perform some computation or task. The nodes themselves are really software processes but with the capability to register with the ROS Master node and communicate with other nodes in the system. The ROS design idea is that each node is independent and interacts with other nodes using the ROS communication capability. The Master node is described in the ROS Master section to follow.

One of the strengths of ROS is that a particular task, such as controlling a wheeled mobile robot, can be separated into a series of simpler tasks. The tasks can include the perception of the environment using a camera or laser scanner, map making, planning a route, monitoring the battery level of the robot's battery, and controlling the motors driving the wheels of the robot. Each of these actions might consist of a ROS node or a series of nodes to accomplish the specific tasks.

A node can independently execute code to perform its task but can also communicate with other nodes by sending or receiving messages. The messages can consist of data, commands, or other information necessary for the application.

ROS topics

Some nodes provide information for other nodes, as a camera feed would do, for example. Such a node is said to publish information that can be received by other nodes. The information in ROS is called a topic. A topic defines the types of messages that will be sent concerning that topic.

The nodes that transmit data publish the topic name and the type of message to be sent. The actual data is published by the node. A node can subscribe to a topic and transmitted messages on that topic are received by the node subscribing.

Continuing with the camera example, the camera node can publish the image on the camera/image_raw topic.

Image data from the camera/image_raw topic can be used by a node that shows the image on the computer screen. The node that receives the information is said to subscribe to the topic being published, in this case camera/image_raw.

In some cases, a node can both publish and subscribe to one or more topics.

ROS messages

ROS messages are defined by the type of message and the data format. The ROS package named std_msgs, for example, has messages of type String which consist of a string of characters. Other message packages for ROS have messages used for robot navigation or robotic sensors. The turtlesim package has its own set of messages that pertain to the simulation.

We will see in the section, Turtlesim – the first ROS robot simulation that the turtlesim simulator has two nodes that are created when turtlesim is executed. Turtlesim has relatively few topics and messages so it is ideal for the initial study of ROS.

The ROS site http://www.ros.org/core-components/ describes the communication and robot-specific features of ROS. Here, we will explore some of the main components of a ROS system including ROS nodes and the ROS Master. It is important for you to understand the ROS nodes, topics, and messages as they are involved in almost every ROS activity.

ROS Master

The ROS nodes are typically independent programs that can run concurrently on several systems. The ROS Master provides naming and registration services to the nodes in the ROS system. It tracks publishers and subscribers to the topics. Communication is established between the nodes by the ROS Master.

The role of the Master is to enable individual ROS nodes to locate one another. The most often used protocol for connection is the standard Transmission Control Protocol/Internet Protocol (TCP/IP) or Internet Protocol called TCPROS in ROS. Once these nodes are able to locate one another, they can communicate with each other peer-to-peer.

One responsibility of the Master is to keep track of nodes when new nodes are executed and come into the system. Thus, the Master provides a dynamic allocation of connections. The nodes cannot communicate however until the Master notifies the nodes of each other's existence. A simple example is shown at http://wiki.ros.org/Master.

Invoking the ROS Master using roscore

roscore starts processes that you must have running in order for ROS nodes to communicate. When it executes, roscore will start the following:

A ROS MasterA ROS Parameter ServerA rosout logging node

The roscore command creates the Master so that nodes can register with the Master. You can view the ROS tutorial for roscore at http://wiki.ros.org/roscore.

Issue the following command to start the Master in a new terminal window and observe the output:

$ roscore

The output of the preceding command is as follows:

... logging to /home/linux/.ros/log/9c3776b4-09cd-11e7-bb39-1866da2351d7/roslaunch-D158-45929-29790.logChecking log directory for disk usage. This may take a while.Press Ctrl-C to interruptDone checking log file disk usage. Usage is <1GB.started roslaunch server http://D158-45929:34807/ros_comm version 1.12.7SUMMARYPARAMETERS * /rosdistro: kinetic * /rosversion: 1.12.7NODESauto-starting new masterprocess[master]: started with pid [29802]ROS_MASTER_URI=http://D158-45929:11311/setting /run_id to 9c3776b4-09cd-11e7-bb39-1866da2351d7process[rosout-1]: started with pid [29815]started core service [/rosout]

In the preceding screen output, you will see information about the computer, parameters that list the name (kinetic) and version number of the ROS distribution, and other information. The Master is defined by its Uniform Resource Identifier (URI). This identifies the location of the Master; in this case, it is running on the workstation used to execute the roscore command.

Parameter Server

The Parameter Server is a shared dictionary of parameters that nodes store and retrieve at runtime. The Parameter Server runs inside the Master and parameters are globally viewable so that nodes can access the parameters.

In the preceding screen output from the roscore command, the parameters associated with the Master are as follows:

* /rosdistro: kinetic* /rosversion: 1.12.7

Kinetic is the ROS distribution release that we are using. As Kinetic is changed or packages are added, numbered versions such as 1.12.7 are released. Issuing the roscore command is a way to determining the version of ROS running on your computer.

Whenever ROS is executing, it is possible to list the nodes that are active and the topics that are used for communication. We will explore the information in the roscore output in more detail by invoking useful ROS terminal commands.

ROS commands to determine the nodes and topics

Three commands used extensively in ROS are as follows:

roscore to start the Master and allow nodes to communicaterosnode listto list the active nodesrostopic list to list the topics associated with active ROS nodes

After the roscore command is executed, the terminal window used to execute roscore must remain active, but it can be minimized. In another terminal window, the rosnode list command will cause a list of the ROS nodes that are active to be displayed on the screen. After the command for roscore is executed, only one node rosout will be listed as an active node if you type the following command:

$ rosnode list

The output of the preceding command is as follows:

/rosout

In the second terminal window, list the active topics by typing:

$ rostopic list

The output of the preceding command is as follows:

/rosout/rosout_agg

Notice that the /rosout node and the /rosout topic have the same designation. In ROS terms, the rosout node subscribes to the /rosout topic. All the active nodes publish their debug messages to the /rosout topic. We will not be concerned with these messages here; however, they can be useful to debug a program. For an explanation refer to the ROS wiki at http://wiki.ros.org/rosout.

The rosout node is connected to every other active node in the system. The /rosout_agg topic receives messages also, but just from the rosout node so it does not have to connect to all of the nodes and thus saves time at system startup.

The rostopic and rosnode terminal commands have a number of options that will be demonstrated by various examples in this book.

Tip

Most of the ROS commands have help screens that are usually helpful. Type the following command for the command options:

$ rosnode -h

For more detailed usage, use the subcommand name, for example:

$ rosnode list –h

This will list the subcommands and the options for the rosnode command.

There are a number of other important ROS terminal commands that you should know. They are introduced and explained using the turtlesim simulator in the upcoming section.