Mastering ROS for Robotics Programming. - Lentin Joseph - E-Book

Mastering ROS for Robotics Programming. E-Book

Lentin Joseph

0,0
39,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

In this day and age, robotics has been gaining a lot of traction in various industries where consistency and perfection matter. Automation is achieved via robotic applications and various platforms that support robotics. The Robot Operating System (ROS) is a modular software platform to develop generic robotic applications. This book focuses on the most stable release of ROS (Kinetic Kame), discusses advanced concepts, and effectively teaches you programming using ROS.
We begin with aninformative overview of the ROS framework, which will give you a clear idea of how ROS works. During the course of this book, you’ll learn to build models of complex robots, and simulate and interface the robot using the ROS MoveIt! motion planning library and ROS navigation stacks. Learn to leverage several ROS packages to embrace your robot models.
After covering robot manipulation and navigation, you’ll get to grips with the interfacing I/O boards, sensors, and actuators of ROS. Vision sensors are a key component of robots, and an entire chapter is dedicated to the vision sensor and image elaboration, its interface in ROS and programming. You’ll also understand the hardware interface and simulation of complex robots to ROS and ROS Industrial.

At the end of this book, you’ll discover 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:

EPUB
MOBI

Seitenzahl: 509

Veröffentlichungsjahr: 2018

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.



Mastering ROS for Robotics Programming
Second Edition

 

 

 

 

 

 

 

 

Design, build, and simulate complex robots using the Robot Operating System

 

 

 

 

 

 

 

 

 

Lentin Joseph

 

Jonathan Cacace

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Mastering ROS for Robotics Programming Second Edition

 

Copyright © 2018 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 or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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.

Commissioning Editor:Vijin BorichaAcquisition Editor:Divya PoojariContent Development Editor: Eisha DsouzaTechnical Editor: Naveenkumar JainCopy Editor: Safis EditingProject Coordinator:Kinjal BariProofreader: Safis EditingIndexer:Pratik ShirodkarGraphics:Jisha ChirayilProduction Coordinator:Arvindkumar Gupta

First published: December 2015 Second edition: February 2018

Production reference: 1220218

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78847-895-3

www.packtpub.com

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

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.

Contributors

About the authors

Lentin Joseph is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 7 years of experience in the robotics domain especially in Robot Operating System, Open-CV, and PCL.

He has authored three books in ROS, namely, Learning Robotics using Python, Mastering ROS for Robotics Programming, and ROS Robotics Projects.

He is currently pursuing his masters in Robotics from India and is also doing research in Robotics Institute, CMU, USA.

 

 

 

Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received his Master’s degree in computer science, and a Ph.D. degree in Information and Automation Engineering, from the University of Naples Federico II. Currently, he is a postdoc at the PRISMA Lab of the University of Naples Federico II. He is involved in different research projects focused on industrial and service robotics in which he has developed several ROS-based applications integrating robot perception and control.

I would like to express my thanks and gratitude to my friends, my parents and all the people I met during my life who contributed to enrich my life and my knowledge.

About the reviewer

Ruixiang Du is a PhD candidate in Mechanical Engineering at Worcester Polytechnic Institute (WPI). He currently works in the Autonomy, Control and Estimation Laboratory with a research focus on the motion planning and control of autonomous mobile robots. He received a 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 general interests in robotics and in real-time and embedded systems. He has worked on various robotic projects with robot platforms ranging from medical robots, unmanned aerial/ground vehicles, to humanoid robots. He was a member of Team WPI-CMU for the DARPA Robotics Challenge.

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Mastering ROS for Robotics Programming Second Edition

www.PacktPub.com

Why subscribe?

PacktPub.com

Contributors

About the authors

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Introduction to ROS

Why should we learn ROS?

Why we prefer ROS for robots

Why some do not prefer ROS for robots

Understanding the ROS filesystem level

ROS packages

ROS metapackages

ROS messages

The ROS services

Understanding the ROS computation graph level

ROS nodes

ROS messages

ROS topics

ROS services

ROS bags

The ROS Master

Using the ROS parameter

ROS community level

What are the prerequisites for starting with ROS?

Running the ROS Master and the ROS parameter server

Checking the roscore command output

Questions

Summary

Getting Started with ROS Programming

Creating a ROS package

Working with ROS topics

Creating ROS nodes

Building the nodes

Adding custom msg and srv files

Working with ROS services

Working with ROS actionlib

Creating the ROS action server

Creating the ROS action client

Building the ROS action server and client

Creating launch files

Applications of topics, services, and actionlib

Maintaining the ROS package

Releasing your ROS package

Preparing the ROS package for the release

Releasing our package

Creating a Wiki page for your ROS package

Questions

Summary

Working with 3D Robot Modeling in ROS

ROS packages for robot modeling

Understanding robot modeling using URDF

Creating the ROS package for the robot description

Creating our first URDF model

Explaining the URDF file

Visualizing the 3D robot model in RViz

Interacting with pan-and-tilt joints

Adding physical and collision properties to a URDF model

Understanding robot modeling using xacro

Using properties

Using the math expression

Using macros

Converting xacro to URDF

Creating the robot description for a seven DOF robot manipulator

Arm specification

Type of joints

Explaining the xacro model of the seven DOF arm

Using constants

Using macros

Including other xacro files

Using meshes in the link

Working with the robot gripper

Viewing the seven DOF arm in RViz

Understanding joint state publisher

Understanding robot state publisher

Creating a robot model for the differential drive mobile robot

Questions

Summary

Simulating Robots Using ROS and Gazebo

Simulating the robotic arm using Gazebo and ROS

Creating the robotic arm simulation model for Gazebo

Adding colors and textures to the Gazebo robot model

Adding transmission tags to actuate the model

Adding the gazebo_ros_control plugin

Adding a 3D vision sensor to Gazebo

Simulating the robotic arm with Xtion Pro

Visualizing the 3D sensor data

Moving robot joints using ROS controllers in Gazebo

Understanding the ros_control packages

Different types of ROS controllers and hardware interfaces

How the ROS controller interacts with Gazebo

Interfacing joint state controllers and joint position controllers to the arm

Launching the ROS controllers with Gazebo

Moving the robot joints

Simulating a differential wheeled robot in Gazebo

Adding the laser scanner to Gazebo

Moving the mobile robot in Gazebo

Adding joint state publishers in the launch file

Adding the ROS teleop node

Questions

Summary

Simulating Robots Using ROS and V-REP

Setting up V-REP with ROS

Understanding the vrep_plugin

Interacting with V-REP using ROS services

Interacting with V-REP using ROS topics

Simulating the robotic arm using V-REP and ROS

Adding the ROS interface to V-REP joint controllers

Simulating a differential wheeled robot in V-REP

Adding a laser sensor to V-REP

Adding a 3D vision sensor to V-REP

Questions

Summary

Using the ROS MoveIt! and Navigation Stack

Installing MoveIt!

MoveIt! architecture

The move_group node

Motion planning using MoveIt!

Motion planning request adapters

MoveIt! planning scene

MoveIt! kinematics handling

MoveIt! collision checking

Generating MoveIt! configuration package using the Setup Assistant tool

Step 1 – Launching the Setup Assistant tool

Step 2 – Generating the Self-Collision matrix

Step 3 – Adding virtual joints

Step 4 – Adding planning groups

Step 5 – Adding the robot poses

Step 6 – Setting up the robot end effector

Step 7 – Adding passive joints

Step 8 – Author information

Step 9 – Generating configuration files

Motion planning of robot in RViz using MoveIt! configuration package

Using the RViz Motion Planning plugin

Interfacing the MoveIt! configuration package to Gazebo

Step 1 – Writing the controller configuration file for MoveIt!

Step 2 – Creating the controller launch files

Step 3 – Creating the controller configuration file for Gazebo

Step 4 – Creating the launch file for Gazebo trajectory controllers

Step 5 – Debugging the Gazebo- MoveIt! interface

Understanding the ROS Navigation stack

ROS Navigation hardware requirements

Working with Navigation packages

Understanding the move_base node

Working of Navigation stack

Localizing on the map

Sending a goal and path planning

Collision recovery behavior

Sending the command velocity

Installing the ROS Navigation stack

Building a map using SLAM

Creating a launch file for gmapping

Running SLAM on the differential drive robot

Implementing autonomous navigation using amcl and a static map

Creating an amcl launch file

Questions

Summary

Working with pluginlib, Nodelets, and Gazebo Plugins

Understanding pluginlib

Creating plugins for the calculator application using pluginlib

Working with the pluginlib_calculator package

Step 1 - Creating the calculator_base header file

Step 2 - Creating the calculator_plugins header file

Step 3 - Exporting plugins using the calculator_plugins.cpp

Step 4 - Implementing  the plugin loader using the calculator_loader.cpp

Step 5 - Creating the plugin description file: calculator_plugins.xml

Step 6 - Registering the plugin with the ROS package system

Step 7 - Editing the CMakeLists.txt file

Step 8 - Querying the list of plugins in a package

Step 9 - Running the plugin loader

Understanding ROS nodelets

Creating a nodelet

Step 1 - Creating a package for a nodelet

Step 2 - Creating the hello_world.cpp nodelet

Step 3 - Explanation of hello_world.cpp

Step 4 - Creating the plugin description file

Step 5 - Adding the export tag in package.xml

Step 6 - Editing CMakeLists.txt

Step 7 - Building and running nodelets

Step 8 - Creating launch files for nodelets

Understanding the Gazebo plugins

Creating a basic world plugin

Questions

Summary

Writing ROS Controllers and Visualization Plugins

Understanding ros_control packages

The controller_interface package

Initializating the controller

Starting the ROS controller

Updating the ROS controller

Stopping the controller

The controller_manager

Writing a basic joint controller in ROS

Step 1 - Creating the controller package

Step 2 – Creating the controller header file

Step 3 – Creating the controller source file

Step 4 – Explaining the controller source file

Step 5 – Creating the plugin description file

Step 6 – Updating package.xml

Step 7 – Updating CMakeLists.txt

Step 8 – Building the controller

Step 9 – Writing the controller configuration file

Step 10 – Writing the launch file for the controller

Step 11 – Running the controller along with the seven dof arm in Gazebo

Understanding the ROS visualization tool (RViz) and its plugins

Displays panel

RViz toolbar

Views

Time panel

Dockable panels

Writing an RViz plugin for teleoperation

Methodology of building the RViz plugin

Step 1 – Creating the RViz plugin package

Step 2 – Creating the RViz plugin header file

Step 3 – Creating the RViz plugin definition

Step 4 – Creating the plugin description file

Step 5 – Adding the export tags in package.xml

Step 6 – Editing CMakeLists.txt

Step 7 – Building and loading plugins

Questions

Summary

Interfacing I/O Boards, Sensors, and Actuators to ROS

Understanding the Arduino-ROS interface

What is the Arduino-ROS interface?

Understanding the rosserial package in ROS

Installing rosserial packages on Ubuntu 16.04

Understanding ROS node APIs in Arduino

ROS - Arduino Publisher and Subscriber example

Arduino-ROS, example - blink LED and push button

Arduino-ROS, example - Accelerometer ADXL 335

Arduino-ROS, example - ultrasonic distance sensor

Equations to find distance using the ultrasonic range sensor

Arduino-ROS example - Odometry Publisher

Interfacing non-Arduino boards to ROS

Setting ROS on Odroid-XU4 and Raspberry Pi 2

How to install an OS image to Odroid-XU4 and Raspberry Pi 2

Installation in Windows

Installation in Linux

Connecting to Odroid-XU4 and Raspberry Pi 2 from a PC

Configuring an Ethernet hotspot for Odroid-XU4 and Raspberry Pi 2

Installing Wiring Pi on Odroid-XU4

Installing Wiring Pi on Raspberry Pi 2

Blinking LED using ROS on Raspberry Pi 2

Push button + blink LED using ROS on Raspberry Pi 2

Running examples in Raspberry Pi 2

Interfacing DYNAMIXEL actuators to ROS

Questions

Summary

Programming Vision Sensors Using ROS, Open CV, and PCL

Understanding ROS – OpenCV interfacing packages

Understanding ROS - PCL interfacing packages

Installing ROS perception

Interfacing USB webcams in ROS

Working with ROS camera calibration

Converting images between ROS and OpenCV using cv_bridge

Image processing using ROS and OpenCV

Step 1 – Creating a ROS package for the experiment

Step 2 – Creating source files

Step 3 – Explanation of the code

Publishing and subscribing images using image_transport

Converting OpenCV to ROS images using cv_bridge

Finding edges on the image

Visualizing raw and edge-detected-images

Step 4 – Editing the CMakeLists.txt file

Step 5 – Building and running an example

Interfacing Kinect and Asus Xtion Pro in ROS

Interfacing Intel Real Sense camera with ROS

Working with a point cloud to a laser scan package

Interfacing Hokuyo Laser in ROS

Working with point cloud data

How to publish a point cloud

How to subscribe and process the point cloud

Writing data to a Point Cloud Data (PCD) file

Reading and publishing a point cloud from a PCD file

Working with AR Marker detection for object pose estimation

Using AprilTag with ROS

Questions

Summary

Building and Interfacing Differential Drive Mobile Robot Hardware in ROS

Introducing to Chefbot – a DIY mobile robot and its hardware configuration

Flashing Chefbot firmware using Energia IDE

Serial data sending protocol from LaunchPad to PC

Serial data sending protocol from PC to Launchpad

Discussing Chefbot interface packages on ROS

Computing odometry from encoder ticks

Computing motor velocities from ROS twist message

Running the robot standalone launch file using C++ nodes

Configuring the Navigation stack for Chefbot

Configuring the gmapping node

Configuring the Navigation stack packages

Common configuration local_costmap and global_costmap

Configuring global costmap parameters

Configuring local costmap parameters

Configuring base local planner parameters

Configuring DWA local planner parameters

Configuring move_base node parameters

Understanding AMCL

Understanding RViz for working with the Navigation stack

2D Pose Estimate button

Visualizing the particle cloud

The 2D Nav Goal button

Displaying the static map

Displaying the robot footprint

Displaying the global and local cost map

Displaying the global plan, the local plan, and the planner plan

The current goal

Obstacle avoidance using the Navigation stack

Working with Chefbot simulation

Building a room in Gazebo

Adding model files to the Gazebo model folder

Sending a goal to the Navigation stack from a ROS node

Questions

Summary

Exploring the Advanced Capabilities of ROS-MoveIt!

Motion planning using the move_group C++ interface

Motion planning a random path using MoveIt! C++ APIs

Motion planning a custom path using MoveIt! C++ APIs

Collision checking with a robot arm using MoveIt!

Adding a collision object to MoveIt!

Removing a collision object from the planning scene

Attaching a collision object to a robot link

Checking self-collisions using MoveIt! APIs

Working with perception using MoveIt! and Gazebo

Manipulating objects with MoveIt!

Working with a robot pick-and-place task using MoveIt!

Calculating grasp poses with GPD

Pick and place action in Gazebo and real robot

Understanding DYNAMIXEL ROS Servo controllers for robot hardware interfacing

The DYNAMIXEL servos

DYNAMIXEL-ROS interface

Interfacing 7 DOF DYNAMIXEL-based robotic arm to ROS MoveIt!

Creating a controller package for a COOL arm robot

MoveIt! configuration of the COOL Arm

Questions

Summary

Using ROS in MATLAB and Simulink

Getting started with MATLAB and MATLAB-ROS

Getting started with the Robotic System Toolbox and ROS-MATLAB interface

Starting with ROS topics and MATLAB callback functions

Implementing an obstacle avoidance system for a Turtlebot robot

Getting started with ROS and Simulink

Creating a wave signal integrator in Simulink

Working with ROS messages in Simulink

Publishing a ROS message in Simulink

Subscribing to a ROS topic in Simulink

Developing a simple control system in Simulink

Configuring the Simulink model

Questions

Summary

ROS for Industrial Robots

Understanding ROS-Industrial packages

Goals of ROS-Industrial

ROS-Industrial – a brief history

Benefits of ROS-Industrial

Installing ROS-Industrial packages

Block diagram of ROS-Industrial packages

Creating a URDF for an industrial robot

Creating the MoveIt! configuration for an industrial robot

Updating the MoveIt! configuration files

Testing the MoveIt! configuration

Installing ROS-Industrial packages of  Universal robotic arms

Installing the ROS interface of Universal Robots

Understanding the Moveit! configuration of a Universal Robot arm

Getting started with real Universal Robots hardware and ROS-I

Working with MoveIt! configuration of ABB robots

Understanding the ROS-Industrial robot support packages

Visualizing the ABB robot model in RViz

ROS-Industrial robot client package

Designing industrial robot client nodes

ROS-Industrial robot driver package

Understanding the MoveIt! IKFast plugin

Creating the MoveIt! IKFast plugin for the ABB IRB 6640 robot

Prerequisites for developing the MoveIt! IKFast plugin

OpenRave and IK Fast modules

MoveIt! IKFast

Installing the MoveIt! IKFast package

Installing OpenRave on Ubuntu 16.04

Creating the COLLADA file of a robot to work with OpenRave

Generating the IKFast CPP file for the IRB 6640 robot

Creating the MoveIt! IKFast plugin

Questions

Summary

Troubleshooting and Best Practices in ROS

Setting up RoboWare Studio in Ubuntu

Installing/uninstalling RoboWare Studio

Getting started with RoboWare Studio

Create ROS packages in RoboWare Studio

Building ROS workspace in RoboWare Studio

Executing ROS nodes in RoboWare Studio

Starting ROS tools from the RoboWare interface

Handling active ROS topics, nodes, and services

Creating ROS nodes and classes with RoboWare tools

ROS package manager in RoboWare Studio

Best practices in ROS

ROS C++ coding style guide

Standard naming conventions used in ROS

Code license agreement

ROS code formatting

Console output

Best practices in the ROS package

Important troubleshooting tips in ROS

Using roswtf

Questions

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Robot Operating System is robotic middleware that helps developers to program robotic applications, and is widely used in robotics companies, research centers, and universities. Mastering ROS for Robotics Programming, Second Edition presents advanced concepts of the ROS framework and is particularly suitable for users who are already familiar with the basic concepts of ROS. However, a brief introduction of the basic ROS concepts is proposed in the first chapter in order to help new developers start with the examples in the book. Readers will be guided through the creation, the modeling model and design, new robots, as well as simulating and interfacing them with the ROS framework. They will use advanced simulation software to use ROS tools that allow robot navigation, manipulation, and sensor elaboration. Finally, the reader will learn how to handle important concepts such as ROS low-level controllers, nodelets, and plugins. The readers can work with almost all of the examples of the book using only a standard computer without any special hardware requirements. However, additional hardware components will be used in some chapters of the book to discuss how to use ROS with external sensors, actuators, and I/O boards.

The book is organized as follows. After an introduction to the basic concepts of ROS, how to model and simulate a robot is discussed. Gazebo and the V-REP software simulator will be used to control and interact with the modeled robot. These simulators will be used to connect the robots with MoveIt! and navigation ROS package. ROS plugins, controllers, and nodelets are then discussed. Finally, the book discusses how to connect Matlab and Simulink software with ROS.

Who this book is for

This book is meant to be used by passionate robotics developers or researchers who want to fully exploit the features of ROS. The book is also good for all the users who already are familiar with typical robotics applications or who want to start learning how to develop the world of ROS in an advanced manner, learning how to model, build, and control their own robots. A basic knowledge of GNU/Linux and C++ programming is strongly recommended if you want to easily comprehend the contents of the book.

What this book covers

Chapter 1, Introduction to ROS, gives you an understanding of the core underlying concepts of ROS. 

Chapter 2, Getting Started with ROS Programming, explains how to work with ROS packages.

Chapter 3, Working with 3D Robot Modeling in ROS, discusses the design of two robots; one is a seven Degree of Freedom (DOF) manipulator and the other is a differential drive robot.

Chapter 4, Simulating Robots Using ROS and Gazebo, discusses the simulation of a seven DOF arm, differential wheeled robots, and ROS controllers that help control robot joints in Gazebo.

Chapter 5, Simulating Robots Using ROS and V-REP, introduces using the V-REP simulator and vrep_plugin to connect ROS with the simulation scene. Then the control of a seven DOF arm and a differential mobile robot is discussed.

Chapter 6, Using the ROS MoveiIt! and Navigation Stack, interfaces out-of-the-box functionalities such as robot manipulation and autonomous navigation using ROS MoveIt! and Navigation stack.

Chapter 7, 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 8, 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 will also see how to create plugin for RViz.

Chapter 9, Interfacing I/O Boards, Sensor, 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-XU4, with ROS.

Chapter 10, 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 (OpenCV) and Point Cloud Library (PCL), and working with AR Markers.

Chapter 11, 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 to give you an idea of building a custom mobile robot and interfacing it with ROS.

Chapter 12, 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 how to interface of a robotic manipulator hardware with MoveIt!

Chapter 13, Using ROS in Matlab and Simulink, discusses how to connect Matlab and Simulink software with ROS.

Chapter 14, 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 15, 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.

To get the most out of this book

In order to run the examples in this book, you need a standard PC running Linux OS. Ubuntu 16.04 is the suggested Linux distribution, but Debian 8 is supported as well. The suggested PC configuration requires at least 4 GB of RAM and a modern processor (Intel i-family) to execute Gazebo simulations and image processing algorithms.

Readers can even work in a virtual environment setup installing Linux OS on a virtual machine, using Virtual box or VMware software hosted on a Windows system. The disadvantage of this choice is that more computational power is needed to work with the examples and the reader could face issues when interfacing ROS with real hardware.

The software needed to follow the book is ROS and Kinetic Kame. Additional software required is V-REP simulator, Git, Matlab, and Simulink.

Finally, some chapters help readers to interface ROS with commercial hardware such as I/O boards (Arduino, Odroid, and Raspberry Pi computers), vison sensors (Kinect/Asus Xition Pro), and actuators. These are special hardware components that must be bought to run some examples of the book but are not strictly required to learn ROS.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit 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 at

www.packtpub.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

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

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/Mastering-ROS-for-Robotics-Programming-Second-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/MasteringROSforRoboticsProgrammingSecondEdition_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

<launch> <group ns="/"> <param name="rosversion" command="rosversion roslaunch" /> <param name="rosdistro" command="rosversion -d" /> <node pkg="rosout" type="rosout" name="rosout" respawn="true"/> </group> </launch>

Any command-line input or output is written as follows:

$ rostopic list

$ cd

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "On the main toolbar, select File | Open Workspace, and choose the directory representing the ROS workspace."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Introduction to ROS

The first two chapters of this book introduce basic ROS concepts and its package management system in order to refresh your memory about concepts you should already know. In this first chapter, we will go through ROS concepts such as the ROS Master, the ROS nodes, the ROS parameter server, ROS  messages and services discussing what we need to install ROS and how to get started with the ROS master.

In this chapter, we will cover the following topics:

Why should we learn ROS?

Why should we prefer or should not prefer ROS for robots?

Getting started with the ROS filesystem level and its computation graph level.

Understanding ROS framework elements.

Getting started with the ROS master.

Why should we learn ROS?

Robot Operating System (ROS) is a flexible framework, providing various tools and libraries to write robotic software. It offers several powerful features to help developers in such tasks as message passing, distributing computing, code reusing, and implementation of state-of-the-art algorithms for robotic applications.

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 applications 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, a knowledge of ROS will be an essential requirement for a robotics engineer.

Why we prefer ROS for robots

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:

High-end capabilities

: ROS comes with ready-to-use capabilities. For example,

Simultaneous Localization and Mapping

(

SLAM

) and

Adaptive Monte Carlo Localization

(

AMCL

) packages in ROS can be used for performing autonomous navigation in mobile robots, and the

MoveIt

package can be used for motion planning of robot manipulators. These capabilities can directly be used in our robot software without any hassle. These capabilities are its best form of implementation, so writing new code for existing capabilities is like reinventing the wheel. Also, these capabilities are highly configurable; we can fine-tune each capability using various parameters.

Tons of tools

: ROS is packed with tons of tools for debugging, visualizing, and performing a simulation. The tools, such as rqt_gui, RViz, and Gazebo, are some of the strong open source tools for debugging, visualization, and simulation. A software framework that has these many tools is very rare.

Support for high-end sensors and actuators

: ROS is packed with device drivers and interface packages of various sensors and actuators in robotics. The high-end sensors include Velodyne-LIDAR, Laser scanners, Kinect, and so on, and actuators such as

DYNAMIXEL

servos. We can interface these components to ROS without any hassle.

Inter-platform operability

: The ROS message-passing middleware allows communication between different nodes. These nodes can be programmed in any language that has ROS client libraries. We can write high-performance nodes in C++ or C and other nodes in Python or Java. This kind of flexibility is not available in other frameworks.

Modularity

: One of the issues that can occur in most of the standalone robotic applications is that if any of the threads of main code crash, the entire robot application can stop. In ROS, the situation is different; we are writing different nodes for each process, and if one node crashes, the system can still work. Also, ROS provides robust methods to resume operations even if any sensors or motors are dead.

Concurrent resource handling

: Handling a hardware resource via more than two processes is always a headache. Imagine we want to process an image from a camera for face detection and motion detection; we can either write the code as a single entity that can do both, or we can write a single-threaded code for concurrency. If we want to add more than two features in threads, the application behavior will get complex and will be difficult to debug. But in ROS, we can access the devices using ROS topics from the ROS drivers. Any number of ROS nodes can subscribe to the image message from the ROS camera driver, and each node can perform different functionalities. It can reduce the complexity in computation and also increase the debug ability of the entire system.

Active community

: When we choose a library or software framework, especially from an open source community, one of the main factors that needs to be checked before using it is its software support and developer community. There is no guarantee of support from an open source tool. Some tools provide good support and some tools don't. In ROS, the support community is active. There is a web portal to handle the support queries from users too (

http://answers.ros.org

). It seems that the ROS community has a steady growth in developers worldwide.

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.

Why some do not prefer ROS for robots

Here are some of the reasons why some people do not prefer ROS for their robotic projects:

Difficulty in learning

: ROS can be difficult to learn. It has a steep learning curve and developers should become familiar with many new concepts to get benefits from the ROS framework. 

Difficulties in starting with simulation

: The main simulator in ROS is Gazebo. Even though Gazebo works well, to get started with Gazebo is not an easy task. The simulator has no inbuilt features to program. Complete simulation is done only through coding in ROS. When we compare Gazebo with other simulators, such as V-REP and Webots, they have inbuilt functionalities to prototype and program the robot. They also have a rich GUI toolset support a wide variety of robots and have ROS interfaces too. These tools are proprietary but can deliver a decent job. The toughness of learning simulation using Gazebo and ROS is a reason for not using it in projects.

Difficulties in robot modeling

: The robot modeling in ROS is performed using URDF, which is an XML-based robot description. In short, we need to write the robot model as a description using URDF tags. In V-REP, we can directly build the 3D robot model in the GUI itself, or we can import the mesh. In ROS, we should write the robot model definitions using URDF tags. There is a SolidWorks plugin to convert a 3D model from SolidWorks to URDF, but if we use other 3D CAD tools, there are no options at all. Learning to model a robot in ROS will take a lot of time, and building using URDF tags is also time-consuming compared to other simulators.

Potential limitations

: Current ROS versions have some limitations. For example, there is a lack of a native real-time application development support or the complexity to implement robust multi-robot distributed applications.

ROS in commercial robot products

: When we deploy ROS on a commercial product, a lot of things need to be taken care of. One thing is the code quality. ROS code follows a standard coding style and keeps best practices for maintaining the code too. We have to check whether it satisfies the quality level required for our product. We might have to do additional work to improve the quality of the code. Most of the code in ROS is contributed by researchers from universities, so if we are not satisfied with the ROS code quality, it is better to write our own code, which is specific to the robot and only use the ROS core functionalities if required.

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: the filesystem level, computation graph level, and community level. We will briefly have a look at each level.

Understanding the ROS filesystem level

ROS is more than a development framework. We can refer to ROS as a meta-operating system, since it offers not only tools and libraries but even OS-like functions, such as hardware abstraction, package management, and a developer toolchain. Like a real operating system, ROS files are organized on the hard disk in a particular manner, as depicted in the following figure:

Figure 1: ROS filesystem level

Here are the explanations for each block in the filesystem:

Packages

: The ROS packages are the most basic unit of the ROS software. They contain one or more ROS programs (nodes), libraries, configuration files, and so on, which are organized together as a single unit. Packages are the atomic build item and release item in the ROS software.

Package manifest

: The package manifest file is inside a package that contains information about the package, author, license, dependencies, compilation flags, and so on. The

package.xml

file inside the ROS package is the manifest file of that package.

Metapackages

: The term metapackage refers to one or more related packages which can be loosely grouped together. In principle, metapackages are virtual packages that don't contain any source code or typical files usually found in packages.

Metapackages manifest

: The metapackage manifest is similar to the package manifest, the difference being that it might include packages inside it as runtime dependencies and declare an

export

tag.

Messages

(

.msg

): The ROS messages are a type of information that is sent from one ROS process to the other. We can define a custom message inside the

msg

folder inside a package (

my_package/msg/MyMessageType.msg

). The extension of the message file is

.msg

.

Services

(

.srv

): The ROS service is a kind of request/reply interaction between processes. The reply and request data types can be defined inside the

srv

folder inside the package (

my_package/srv/MyServiceType.srv

).

Repositories

: Most of the ROS packages are maintained using a

Version Control System

(

VCS

), such as Git, Subversion (svn), Mercurial (hg), and so on. The collection of packages that share a common VCS can be called repositories. The package in the repositories can be released using a catkin release automation tool called

bloom

.

The following screenshot gives you an idea of the files and folders of a package that we are going to create in the upcoming sections:

Figure 2: List of files inside the exercise package

ROS packages

A typical structure of an ROS package is shown here:

Figure 3: Structure of a typical C++ ROS package

We can discuss the use of each folder as follows:

config

: All configuration files that are used in this ROS package are kept in this folder. This folder is created by the user and it is a common practice to name the folder

config

to keep the configuration files in it.

include/package_name

: This folder consists of headers and libraries that we need to use inside the package.

script

: This folder keeps executable Python scripts. In the block diagram, we can see two example scripts.

src

: This folder stores the C++ source codes.

launch

: This folder keeps the launch files that are used to launch one or more ROS nodes.

msg

: This folder contains custom message definitions.

srv

: This folder contains the services definitions.

action

: This folder contains the action files. We will see more about these kind of files in the next chapter.

package.xml

: This is the package manifest file of this package.

CMakeLists.txt

: This files contains the directives to compile the package.

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:

catkin_create_pkg

: This command is used to create a new package

rospack

: This command is used to get information about the package in the filesystem

catkin_make

: This command is used to build the packages in the workspace

rosdep

: This command will install the system dependencies required for this package

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:

roscd

: This command is used to change the current directory using a package name, stack name, or a special location. If we give the argument a package name, it will switch to that package folder.

roscp

: This command is used to copy a file from a package.

rosed

: This command is used to edit a file using the 

vim

editor.

rosrun

: This command is used to run an executable inside a package.

The definition of package.xml of a typical package is shown in the following screenshot:

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> tags are necessary during runtime of the package node.

ROS metapackages

Metapackages are specialized packages in ROS that only contain one file, that is, a package.xml file. They don't contain folders and files like a normal package.

Metapackages simply group a set of multiple packages as a single logical package. In the package.xml file, the metapackage contains an export tag, as shown here:

<export> <metapackage/> </export>

Also, in metapackages, there are no <buildtool_depend> dependencies for catkin; there are only <run_depend> dependencies, which are the packages grouped in the metapackage.

The ROS navigation stack is a good example of metapackages. If ROS and its navigation package are installed, we can try the following command, by switching to the navigation metapackage folder:

$ roscd navigation

Open package.xml using your favorite text editor (gedit in the following case):

$ gedit package.xml

This is a lengthy file; here is a stripped-down version of it:

Figure 5: Structure of meta-package package.xml

ROS messages

The ROS nodes can write or read data that has a different 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 is stored in .msg files in the msg subdirectory of a ROS package. Even though the ROS framework provides a large set of robotic-specific messages already implemented, developers can define their own message type inside their nodes.

The message definition can consist of two types: fields and constants. The field is split into field types and field names. The field type 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:

int32 number string name float32 speed

Here, the first part is the field type and the 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 showing 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

Other kinds of messages are designed to cover a specific application necessity, such as exchanging common geometrical (geometry_msgs) or sensor (sensor_msgs) information. A special type of ROS message is called a message header. 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:

uint32 seq time stamp string frame_id

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:

$ rosmsg show std_msgs/Header

This will give you an output like the preceding example message header. We will look at the rosmsg command and how to work with custom message definitions further in the upcoming sections.

The ROS services

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 subdirectory 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:

#Request message type string str --- #Response message type string str

The first section is the message type of the request that is separated by --- and in the next section is the message type of the response. In these examples, both Request and Response are strings.

In the upcoming sections, we will look at how to work with ROS services.

Understanding the ROS computation graph level

The computation in ROS is done using a network of a process called ROS nodes. This computation network can be called the computation graph. The main concepts in the computation graph are ROS Nodes, Master, Parameter server, 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 the ROS Graph layer:

Figure 6: Structure of the ROS Graph layer

The following are abstracts of each graph's concepts:

Nodes

: Nodes are the process that perform computation. Each ROS node is written using ROS client libraries. Using client library APIs, we can implement different ROS functionalities, such as the communication methods between nodes, which is particularly useful when different nodes of our robot must exchange information between them. Using the ROS communication methods, they can communicate with each other and exchange data. One of the aims of ROS nodes is to build simple processes rather than a large process with all the functionality. Being a simple structure, ROS nodes are easy to debug.

Master

: The ROS Master provides the name registration and lookup to the rest of the nodes. Nodes will not be able to find each other, exchange messages, or invoke services without a ROS Master. In a distributed system, we should run the master on one computer, and other remote nodes can find each other by communicating with this master.

Parameter server

: The parameter server allows you to keep the data to be stored in a central location. All nodes can access and modify these values. The parameter server is a part of the ROS Master.

Messages

: Nodes communicate with each other using messages. Messages are simply a data structure containing the typed field, which can hold a set of data, and that can be sent to another node. There are standard primitive types (integer, floating point, Boolean, and so on) and these are supported by ROS messages. We can also build our own message types using these standard types.

Topics

: Each message in ROS is transported using named buses called topics. When a node sends a message through a topic, then we can say the node is publishing a topic. When a node receives a message through a topic, then we can say that the node is subscribing to a topic. The publishing node and subscribing node are not aware of each other's existence. We can even subscribe a topic that might not have any publisher. In short, the production of information and consumption of it are decoupled. Each topic has a unique name, and any node can access this topic and send data through it as long as they have the right message type.

Services

: In some robot applications, the publish/subscribe communication model may not be suitable. For example, in some cases, we need a kind of request/response interaction, in which one node can ask for the execution of a fast  procedure to another node; for example, asking for some quick calculation. The ROS service interaction is like a remote procedure call.

Logging

: ROS provides a logging system for storing data, such as sensor data, which can be difficult to collect but is necessary for developing and testing robot algorithms: the bagfiles. Bagfiles are very useful features when we work with complex robot mechanisms.

The following graph shows how the nodes communicate with each other using topics. The topics are mentioned in a rectangle and the 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

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 code 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:

$ rosnode info [node_name]

: This will print the information about the node

$ rosnode kill [node_name]

: This will kill a running node

$ rosnode list

: This will list the running nodes

$ rosnode machine [machine_name]

: This will list the nodes running on a particular machine or a list of machines

$ rosnode ping

: This will check the connectivity of a node

$ rosnode cleanup

: This will purge the registration of unreachable nodes

We will look at 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 messages

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:

$ rosmsg show [message]

: This shows the message description

$ rosmsg list

: This lists all messages

$ rosmsg md5 [message]

: This displays

md5sum

of a message

$ rosmsg package [package_name]

: This lists messages in a package

$ rosmsg packages [package_1] [package_2]

: This lists packages that contain messages

ROS topics

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 in knowing which node is publishing the topic or subscribing topics; they only look for the topic name and whether the message types of the publisher and subscriber are matching.

The communication using topics are unidirectional. If we want to implement a 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 teleoperations.

The ROS topic tool can be used to get information about ROS topics. Here is the syntax of this command:

$ rostopic bw /topic

: This command will display the bandwidth used by the given topic.

$ rostopic echo /topic

: This command will print the content of the given topic in a human readable format. Users can use the "-p" option to print data in a csv format.

$ rostopic find /message_type

: This command will find topics using the given message type.

$ rostopic hz /topic

: This command will display the publishing rate of the given topic.

$ rostopic info /topic

: This command will print information about an active topic.

$ rostopic list

: This command will list all active topics in the ROS system.

$ rostopic pub /topic message_type args

: This command can be used to publish a value to a topic with a message type.

$ rostopic type /topic

: This will display the message type of the given topic.

ROS services

When we need a request/response kind of communication in ROS, we have to use the ROS services. ROS topics can't implement natively such kind of communication because it is unidirectional. The ROS services are mainly used in a distributed system.

The ROS services are defined using a pair of messages. We have to define a request datatype and a response datatype in a srv file. The srv files are kept in a srv folder inside a package.