Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering ROS for Robotics Programming
Mastering ROS for Robotics Programming

Mastering ROS for Robotics Programming: Design, build, and simulate complex robots using the Robot Operating System , Second Edition

Arrow left icon
Profile Icon Lentin Joseph
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
Paperback Feb 2018 580 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Lentin Joseph
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
Paperback Feb 2018 580 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering ROS for Robotics Programming

Getting Started with ROS Programming

After discussing the basics of the ROS Master, the parameter server, and roscore , we can now start to create and build a ROS package. In this chapter, we will create different ROS nodes implementing the ROS communication system. Working with ROS packages, we will also refresh the concepts of ROS nodes, topics, messages, services, and actionlib.

We will cover the following list of topics:

  • Creating, compiling and running ROS packages.
  • Working with standard and custom ROS messages.
  • Working with ROS services and actionlib.
  • Maintaining and releasing your ROS packages.
  • Creating a wiki page for ROS packages.

Creating a ROS package

The ROS packages are the basic unit of the ROS system. We can create a ROS package, build it, and release it to the public. The current distribution of ROS we are using is kinetic. We are using the catkin build system to build ROS packages. A build system is responsible for generating 'targets' (executable/libraries) from a raw source code that can be used by an end user. In older distributions, such as Electric and Fuerte, rosbuild was the build system. Because of the various flaws of rosbuild, catkin came into existence, which is basically based on Cross Platform Make (CMake). This has a lot of advantages, such as porting the package into another operating system, such as Windows. If an OS supports CMake and Python, catkin -based packages can be easily ported into it.

The first requirement work with ROS packages is to create a...

Adding custom msg and srv files

In this section, we will look at how to create custom messages and services definitions in the current package. The message definitions are stored in a .msg file and the service definitions are stored in a .srv file. These definitions inform ROS about the type of data and name of data to be transmitted from a ROS node. When a custom message is added, ROS will convert the definitions into equivalent C++ codes, which we can include in our nodes.

We can start with message definitions. Message definitions have to be written in the .msg file and have to be kept in the msg folder, which is inside the package. We are going to create a message file called demo_msg.msg with the following definition:

string greeting 
int32 number 

Until now, we have worked only with standard message definitions. Now, we have created our own definitions and can see how to...

Working with ROS services

In this section, we are going to create ROS nodes, which can use the services definition that we defined already. The service nodes we are going to create can send a string message as a request to the server and the server node will send another message as a response.

Navigate to mastering_ros_demo_pkg/src, and find nodes with the names demo_service_server.cpp and demo_service_client.cpp.

The demo_service_server.cpp is the server, and its definition is as follows:

#include "ros/ros.h" 
#include "mastering_ros_demo_pkg/demo_srv.h" 
#include <iostream> 
#include <sstream> 
using namespace std; 
 
bool demo_service_callback(mastering_ros_demo_pkg::demo_srv::Request &req, 
     mastering_ros_demo_pkg::demo_srv::Response &res) { 
 std::stringstream ss; 
 ss << "Received Here"; 
 res.out = ss.str(); 
...

Creating launch files

The launch files in ROS are a very useful feature for launching more than one node. In the preceding examples, we have seen a maximum of two ROS nodes, but imagine a scenario in which we have to launch 10 or 20 nodes for a robot. It will be difficult if we run each node in a terminal one by one. Instead, we can write all nodes inside an XML-based file called launch files and, using a command called roslaunch, we can parse this file and launch the nodes.

The roslaunch command will automatically start the ROS Master and the parameter server. So, in essence, there is no need to start the roscore command and individual node; if we launch the file, all operations will be done in a single command.

Let's start creating launch files. Switch to the package folder and create a new launch file called demo_topic.launch to launch two ROS nodes that are publishing...

Applications of topics, services, and actionlib

Topics, services, and actionlib are used in different scenarios. We know topics are a unidirectional communication method, services are a bidirectional request/reply kind of communication, and actionlib is a modified form of ROS services in which we can cancel the executing process running on the server whenever required.

Here are some of the areas where we use these methods:

  • Topics: Streaming continuous data flow, such as sensor data. For example, stream joypad data to teleoperate a robot, publish robot odometry, publish video stream from a camera.
  • Services: Executing procedures that terminate quickly. For example, save calibration parameter of sensors, save a map generated by the robot during its navigation, or load a parameter file.
  • Actionlib: Execute long and complex actions managing their feedback. For example, navigate towards...

Maintaining the ROS package

Most ROS packages are maintained using a Version Control System (VCS) such as Git, Subversion (svn), Mercurial (hg), and so on. A collection of packages that share a common VCS can be called a repository. The package in the repository can be released using a catkin release automation tool called bloom. Most ROS packages are released as open source with the BSD license. There are active developers around the globe who are contributing to the ROS platform. Maintaining packages is important for all software, especially open source applications. Open source software is maintained and supported by a community of developers. Creating a version control system for our package is essential if we want to maintain and accept a contribution from other developers.
The preceding package is already updated in GitHub, and you can view the source code of the project...

Releasing your ROS package

After creating a ROS package in GitHub, we can officially release our package. ROS provides detailed steps to release the ROS package using a tool called bloom (http://ros-infrastructure.github.io/bloom/). Bloom is a release automation tool, designed to make platform-specific releases from the source projects. Bloom is designed to work best with the catkin project.

The prerequisites for releasing the package are as follows:

  • Install the Bloom tool
  • Create a Git repository for the current package
  • Create an empty Git repository for the release

The following command will install bloom in Ubuntu:

$ sudo apt-get install python-bloom  

Create a Git repository for the current package. The repository that has the package is called the upstream repository. Here, we already created a repository at https://github.com/jocacace/mastering_ros_demo_pkg.

Create an empty...

Creating a ROS package


The ROS packages are the basic unit of the ROS system. We can create a ROS package, build it, and release it to the public. The current distribution of ROS we are using is kinetic. We are using the catkin build system to build ROS packages. A build system is responsible for generating 'targets' (executable/libraries) from a raw source code that can be used by an end user. In older distributions, such as Electric and Fuerte, rosbuild was the build system. Because of the various flaws of rosbuild, catkin came into existence, which is basically based on Cross Platform Make (CMake). This has a lot of advantages, such as porting the package into another operating system, such as Windows. If an OS supports CMake and Python, catkin -based packages can be easily ported into it.

The first requirement work with ROS packages is to create a ROS catkin workspace. After installed ROS, we can create and build a catkin_workspace called catkin_ws:

$ mkdir -p ~/catkin_ws/src

To compile...

Adding custom msg and srv files


In this section, we will look at how to create custom messages and services definitions in the current package. The message definitions are stored in a .msg file and the service definitions are stored in a .srv file. These definitions inform ROS about the type of data and name of data to be transmitted from a ROS node. When a custom message is added, ROS will convert the definitions into equivalent C++ codes, which we can include in our nodes.

We can start with message definitions. Message definitions have to be written in the .msg file and have to be kept in the msg folder, which is inside the package. We are going to create a message file called demo_msg.msg with the following definition:

string greeting 
int32 number 

Until now, we have worked only with standard message definitions. Now, we have created our own definitions and can see how to use them in our code.

The first step is to edit the package.xml file of the current package and uncomment the lines ...

Working with ROS services


In this section, we are going to create ROS nodes, which can use the services definition that we defined already. The service nodes we are going to create can send a string message as a request to the server and the server node will send another message as a response.

Navigate to mastering_ros_demo_pkg/src, and find nodes with the names demo_service_server.cpp and demo_service_client.cpp.

The demo_service_server.cpp is the server, and its definition is as follows:

#include "ros/ros.h" 
#include "mastering_ros_demo_pkg/demo_srv.h" 
#include <iostream> 
#include <sstream> 
using namespace std; 
 
bool demo_service_callback(mastering_ros_demo_pkg::demo_srv::Request &req, 
     mastering_ros_demo_pkg::demo_srv::Response &res) { 
 std::stringstream ss; 
 ss << "Received Here"; 
 res.out = ss.str(); 
 ROS_INFO("From Client [%s], Server says [%s]",req.in.c_str(),res.out.c_str()); 
 return true; 
} 
 
int main(int argc, char **argv) 
{ 
 ros::init...

Creating launch files


The launch files in ROS are a very useful feature for launching more than one node. In the preceding examples, we have seen a maximum of two ROS nodes, but imagine a scenario in which we have to launch 10 or 20 nodes for a robot. It will be difficult if we run each node in a terminal one by one. Instead, we can write all nodes inside an XML-based file called launch files and, using a command called roslaunch, we can parse this file and launch the nodes.

The roslaunch command will automatically start the ROS Master and the parameter server. So, in essence, there is no need to start the roscore command and individual node; if we launch the file, all operations will be done in a single command.

Let's start creating launch files. Switch to the package folder and create a new launch file called demo_topic.launch to launch two ROS nodes that are publishing and subscribing an integer value. We keep the launch files in a launch folder, which is inside the package:

$ roscd mastering_ros_demo_pkg...
Left arrow icon Right arrow icon

Key benefits

  • • Develop complex robotic applications using ROS to interface robot manipulators and mobile robots
  • • Gain insight into autonomous navigation in mobile robots and motion planning in robot manipulators
  • • Discover best practices and troubleshooting solutions

Description

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.

Who is this book for?

If you are a robotics enthusiast or researcher who want to learn more about building robot applications using ROS, this book is for you. In order to learn from this book, you should have a basic knowledge of ROS, GNU/Linux, and C++ programming concepts. The book is also excellent for programmers who want to explore the advanced features of ROS.

What you will learn

  • • Create a robot model with a seven-DOF robotic arm and a differential wheeled mobile robot
  • • Work with Gazebo and V-REP robotic simulator
  • • Implement autonomous navigation in differential drive robots using SLAM and AMCL packages
  • • Explore the ROS Pluginlib, ROS nodelets, and Gazebo plugins
  • • Interface I/O boards such as Arduino, robot sensors, and high-end actuators
  • • Simulate and motion plan an ABB and universal arm using ROS Industrial
  • • Explore the latest version of the ROS framework
  • • Work with the motion planning of a seven-DOF arm using MoveIt!

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 26, 2018
Length: 580 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788478953
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 26, 2018
Length: 580 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788478953
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 209.97
ROS Robotics By Example, Second Edition
$54.99
Mastering ROS for Robotics Programming
$54.99
ROS Programming: Building Powerful Robots
$99.99
Total $ 209.97 Stars icon

Table of Contents

16 Chapters
Introduction to ROS Chevron down icon Chevron up icon
Getting Started with ROS Programming Chevron down icon Chevron up icon
Working with 3D Robot Modeling in ROS Chevron down icon Chevron up icon
Simulating Robots Using ROS and Gazebo Chevron down icon Chevron up icon
Simulating Robots Using ROS and V-REP Chevron down icon Chevron up icon
Using the ROS MoveIt! and Navigation Stack Chevron down icon Chevron up icon
Working with pluginlib, Nodelets, and Gazebo Plugins Chevron down icon Chevron up icon
Writing ROS Controllers and Visualization Plugins Chevron down icon Chevron up icon
Interfacing I/O Boards, Sensors, and Actuators to ROS Chevron down icon Chevron up icon
Programming Vision Sensors Using ROS, Open CV, and PCL Chevron down icon Chevron up icon
Building and Interfacing Differential Drive Mobile Robot Hardware in ROS Chevron down icon Chevron up icon
Exploring the Advanced Capabilities of ROS-MoveIt! Chevron down icon Chevron up icon
Using ROS in MATLAB and Simulink Chevron down icon Chevron up icon
ROS for Industrial Robots Chevron down icon Chevron up icon
Troubleshooting and Best Practices in ROS Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 0%
1 star 50%
Neil John Sep 18, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is an updated version of Mastering ROS book, and this helped me to finish a project. Learning from ROS wiki is time consuming that's why I have looked for books. This was a perfect suit for my project.
Amazon Verified review Amazon
Developer Feb 19, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
I’m hoping this gets better, chapter 1 is deep dive into configuration files and pseudo-bash commands with little focus on the big picture. There is no glue holding this together, and skimming through the upcoming chapters it doesn’t appear to get better. It just feels very clunky, as if each section were written by different people and tossed together in no particular order, lacking any meaningful examples, etc.I’ll update this review if necessary, but as of now, I would not recommend this to anyone.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.