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
Free Learning
Arrow right icon
Mastering ROS for Robotics Programming, Third edition
Mastering ROS for Robotics Programming, Third edition

Mastering ROS for Robotics Programming, Third edition: Best practices and troubleshooting solutions when working with ROS , Third Edition

Arrow left icon
Profile Icon Lentin Joseph Profile Icon Jonathan Cacace
Arrow right icon
S$82.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (5 Ratings)
Paperback Oct 2021 594 pages 3rd Edition
eBook
S$45.99 S$65.99
Paperback
S$82.99
Subscription
Free Trial
Arrow left icon
Profile Icon Lentin Joseph Profile Icon Jonathan Cacace
Arrow right icon
S$82.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (5 Ratings)
Paperback Oct 2021 594 pages 3rd Edition
eBook
S$45.99 S$65.99
Paperback
S$82.99
Subscription
Free Trial
eBook
S$45.99 S$65.99
Paperback
S$82.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mastering ROS for Robotics Programming, Third edition

Chapter 1: Introduction to ROS

The first two chapters of this book will introduce basic ROS concepts and the ROS package management system in order to approach ROS programming. In this first chapter, we will go through ROS concepts such as the ROS master, the ROS nodes, the ROS parameter server, and ROS messages and services, all while 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?
  • Understanding the ROS filesystem level.
  • Understanding ROS computation graph level.
  • ROS community level.

Technical requirements

To follow this chapter, the only thing you need is a standard computer running Ubuntu 20.04 LTS or a Debian 10 GNU/Linux distribution.

Why should we use ROS?

Robot Operating System (ROS) is a flexible framework that provides various tools and libraries for writing robotic software. It offers several powerful features to help developers in tasks such as message passing, distributed computing, code reusing, and implementing state-of-the-art algorithms for robotic applications. The ROS project was started in 2007 by Morgan Quigley and its development continued at Willow Garage, a robotics research lab for developing hardware and open source software for robots. The goal of ROS was to establish a standard way to program robots while offering off-the-shelf software components that can be easily integrated with custom robotic applications. There are many reasons to choose ROS as a programming framework, and some of them are as follows:

  • High-end capabilities: ROS comes with ready-to-use functionalities. For example, the Simultaneous Localization and Mapping (SLAM) and Adaptive Monte Carlo Localization (AMCL) packages in ROS can be used for having autonomous navigation in mobile robots, while the MoveIt package can be used for motion planning for robot manipulators. These capabilities can directly be used in our robot software without any hassle. In several cases, these packages are enough for having core robotics tasks on different platforms. Also, these capabilities are highly configurable; we can fine-tune each one using various parameters.
  • Tons of tools: The ROS ecosystem is packed with tons of tools for debugging, visualizing, and having a simulation. The tools, such as rqt_gui, RViz, and Gazebo, are some of the strongest open source tools for debugging, visualization, and simulation. A software framework that has this many tools is very rare.
  • Support for high-end sensors and actuators: ROS allows us to use different device drivers and the interface packages of various sensors and actuators in robotics. Such high-end sensors include 3D LIDAR, laser scanners, depth sensors, actuators, and more. We can interface these components with ROS without any hassle.
  • Inter-platform operability: The ROS message-passing middleware allows communication between different programs. In ROS, this middleware is known as nodes. These nodes can be programmed in any language that has ROS client libraries. We can write high-haveance nodes in C++ or C and other nodes in Python or Java.
  • Modularity: One of the issues that can occur in most standalone robotic applications is that if any of the threads of the 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.
  • Concurrent resource handling: Handling a hardware resource via more than two processes is always a headache. Imagine that 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 piece of code for concurrency. If we want to add more than two features to threads, the application behavior will become complex and difficult to debug. But in ROS, we can access 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 have different functionalities. This can reduce the complexity in computation and also increase the debugging ability of the entire system.

The ROS community is growing very fast, and there are many users and developers worldwide. Most 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.

Now that we know why it is convenient to study ROS, we can start introducing its core concepts. There are mainly three levels in ROS: the filesystem level, the computation graph level, and the 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-OS, 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 diagram:

Figure 1.1 – ROS filesystem level

Figure 1.1 – ROS filesystem level

Here are the explanations for each block in the filesystem:

  • Packages: The ROS packages are a central element 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 and release items in the ROS software.
  • Package manifest: The package manifest file is inside a package and 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 that can be loosely grouped. 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, with the difference being that it might include packages inside it as runtime dependencies and declare an export tag.
  • Messages (.msg): 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 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), or Mercurial (hg). A set of files placed on a VCS represents a repository.

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 1.2 – List of files inside the exercise package

Figure 1.2 – List of files inside the exercise package

The goal of all the files and directories included in a ROS package will be discussed next.

ROS packages

The typical structure of a ROS package is shown here:

Figure 1.3 – Structure of a typical C++ ROS package

Figure 1.3 – Structure of a typical C++ ROS package

Let's discuss the use of each folder:

  • 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 as this is where we keep the configuration files.
  • include/package_name: This folder consists of headers and libraries that we need to use inside the package.
  • script: This folder contains executable Python scripts. In the block diagram, we can see two example scripts.
  • src: This folder stores the C++ source codes.
  • launch: This folder contains 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 learn more about these kinds of files in the next chapter.
  • package.xml: This is the package manifest file of this package.
  • CMakeLists.txt: This file contains the directives to compile the package.

We need to know some commands for creating, modifying, and working with ROS packages. Here are some of the commands we can use 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 in a typical package is shown in the following screenshot:

Figure 1.4 – Structure of package.xml


Figure 1.4 – Structure of package.xml

The package.xml file also contains information about the compilation. The <build_depend></build_depend> tag includes the packages that are necessary for building the source code of the package. The packages inside the <run_depend></run_depend> tags are necessary for running the package node at runtime.

ROS metapackages

Metapackages are specialized packages that require only one file; that is, a package.xml file.

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 that are grouped inside the metapackage.

The ROS navigation stack is a good example of somewhere that contains metapackages. If ROS and its navigation package are installed, we can try using 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 1.5 – Structure of the package.xml metapackage

Figure 1.5 – Structure of the package.xml metapackage

This file contains several pieces of information about the package, such as a brief description, its dependencies, and the package version.

ROS messages

ROS nodes can write or read data of various types. These different types of data are described using a simplified message description language, also called ROS messages. These data type descriptions can be used to generate source code for the appropriate message type in different target languages.

Even though the ROS framework provides a large set of robotic-specific messages that have already been 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, while the field name is the name of it.

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 to access 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:

ROS provides a set of complex and more structured message files that are designed to cover a specific application's necessity, such as exchanging common geometrical (geometry_msgs) or sensor (sensor_msgs) information. These messages are composed of different primitive types. A special type of ROS message is called a message header. This header can carry information, such as time, frame of reference or frame_id, and sequence number. Using the header, we will get numbered messages and more clarity about which component is sending the current message. The header information is mainly used to send data such as robot joint transforms. Here is the definition of the 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 view the message header of a particular message:

rosmsg show std_msgs/Header  

This will give you an output like the preceding example's message header. We will look at the rosmsg command and how to work with custom message definitions later in this chapter.

The ROS services

The ROS services are a type of request/response communication between ROS nodes. One node will send a request and wait until it gets a response from the other.

Similar to the message definitions when using the .msg file, we must define the service definition in another file called .srv, which must be kept inside the srv subdirectory of the package.

An example service description format is as follows:

#Request message type 
string req
--- 
#Response message type 
string res

The first section is the message type of the request, which is separated by ---, while the next section contains 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

Computation in ROS is done using a network of ROS nodes. This computation network is 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 1.6 – Structure of the ROS graph layer

Figure 1.6 – Structure of the ROS graph layer

Some new elements of the ROS graph are as follows:

  • Nodes: Nodes are the processes that have 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 the different nodes of our robot must exchange information between them. One of the aims of ROS nodes is to build simple processes rather than a large process with all the desired functionalities. Being simple structures, ROS nodes are easy to debug.
  • Master: The ROS master provides the name registration and lookup processes for 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; then, the other remote nodes can find each other by communicating with this master.
  • Parameter server: The parameter server allows you to store data in a central location. All the nodes can access and modify these values. The parameter server is part of the ROS master.
  • 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 to a topic that might not have any publisher. In short, the production of information and its consumption are decoupled. Each topic has a unique name, and any node can access this topic and send data through it so long as they have the right message type.
  • 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. These are known as bagfiles. Bagfiles are very useful features when we're working with complex robot mechanisms.

The following graph shows how the nodes communicate with each other using topics:

Figure 1.7 – Graph of communication between nodes using topics

Figure 1.7 – Graph of communication between nodes using topics

As you can see, the topics are represented by rectangles, while the nodes are represented by 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).

ROS nodes

ROS nodes have computations using ROS client libraries such as roscpp and rospy.

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 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 help us identify them. For example, /camera_node could be the name of a node that is broadcasting camera images.

There is a rosbash tool for introspecting ROS nodes. The rosnode command can be used to gather information about an ROS node. Here are the usages of rosnode:

  • rosnode info [node_name]: This will print out 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 that are 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.

Next, we will look at some example nodes that use the roscpp client and discuss how ROS nodes that use functionalities such ROS topics, service, messages, and actionlib work.

ROS messages

As we discussed earlier, messages are simple data structures that contain field types. ROS messages support standard primitive data types and arrays of primitive types.

We can access a message definition using the following method. For example, to access std_msgs/msg/String.msg when we are using the roscpp client, we must include std_msgs/String.h for the string message definition.

In addition to the message data type, ROS uses an MD5 checksum comparison to confirm whether the publisher and subscriber exchange the same message data types.

ROS has a built-in tool called rosmsg for gathering information about ROS messages. Here are some parameters that are used along with rosmsg:

  • rosmsg show [message_type]: This shows the message's description.
  • rosmsg list: This lists all messages.
  • rosmsg md5 [message_type]: This displays md5sum of a message.
  • rosmsg package [package_name]: This lists messages in a package.
  • rosmsg packages [package_1] [package_2]: This lists all packages that contain messages.

Now, let's take a look at ROS topics.

ROS topics

Using topics, the ROS communication is unidirectional. Differently, if we want a direct request/response communication, we need to implement ROS services.

The ROS nodes communicate with topics using a 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 and loose transport and is only suited for teleoperations.

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

  • rostopic bw /topic: This command will display the bandwidth being 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 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 the 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.

Now, let's take a look at ROS services.

ROS services

In ROS services, one node acts as a ROS server in which the service client can request the service from the server. If the server completes the service routine, it will send the results to the service client. For example, consider a node that can provide the sum of two numbers that has been received as input while implementing this functionality through an ROS service. The other nodes of our system might request the sum of two numbers via this service. In this situation, topics are used to stream continuous data flows.

The ROS service definition can be accessed by the following method. For example, my_package/srv/Image.srv can be accessed by my_package/Image.

In ROS services, there is an MD5 checksum that checks in the nodes. If the sum is equal, then only the server responds to the client.

There are two ROS tools for gathering information about the ROS service. The first tool is rossrv, which is similar to rosmsg, and is used to get information about service types. The next command is rosservice, which is used to list and query the running ROS services.

Let's explain how to use the rosservice tool to gather information about the running services:

  • rosservice call /service args: This tool will call the service using the given arguments.
  • rosservice find service_type: This command will find the services of the given service type.
  • rosservice info /services: This will print information about the given service.
  • rosservice list: This command will list the active services running on the system.
  • rosservice type /service: This command will print the service type of a given service.
  • rosservice uri /service: This tool will print the service's ROSRPC URI.

Now, let's take a look at ROS bagfiles.

ROS bagfiles

The rosbag command is used to work with rosbag files. A bag file in ROS is used for storing ROS message data that's streamed by topics. The .bag extension is used to represent a bag file.

Bag files are created using the rosbag record command, which will subscribe to one or more topics and store the message's data in a file as it's received. This file can play the same topics that they are recorded from, and it can remap the existing topics too.

Here are the commands for recording and playing back a bag file:

  • rosbag record [topic_1] [topic_2] -o [bag_name]: This command will record the given topics into the bag file provided in the command. We can also record all topics using the -a argument.
  • rosbag play [bag_name]: This will play back the existing bag file.

The full, detailed list of commands can be found by using the following command in a Terminal:

rosbag play -h

There is a GUI tool that we can use to handle how bag files are recorded and played back called rqt_bag. To learn more about rqt_bag, go to https://wiki.ros.org/rqt_bag.

The ROS master

The ROS master is much like a DNS server, in that it associates unique names and IDs to the ROS elements that are active in our system. When any node starts in the ROS system, it will start looking for the ROS master and register the name of the node in it. So, the ROS master has the details of all the nodes currently running on the ROS system. When any of the node's details change, it will generate a callback and update the node with the latest details. These node details are useful for connecting each node.

When a node starts publishing to a topic, the node will give the details of the topic, such as its name and data type, to the ROS master. The ROS master will check whether any other nodes are subscribed to the same topic. If any nodes are subscribed to the same topic, the ROS master will share the node details of the publisher to the subscriber node. After getting the node details, these two nodes will be connected. After connecting to the two nodes, the ROS master has no role in controlling them. We might be able to stop either the publisher node or the subscriber node according to our requirements. If we stop any nodes, they will check in with the ROS master once again. This same method is used for the ROS services.

As we've already stated, the nodes are written using ROS client libraries, such as roscpp and rospy. These clients interact with the ROS master using XML Remote Procedure Call (XMLRPC)-based APIs, which act as the backend of the ROS system APIs.

The ROS_MASTER_URI environment variable contains the IP and port of the ROS master. Using this variable, ROS nodes can locate the ROS master. If this variable is wrong, communication between the nodes will not take place. When we use ROS in a single system, we can use the IP of a localhost or the name localhost itself. But in a distributed network, in which computation is done on different physical computers, we should define ROS_MASTER_URI properly; only then will the remote nodes be able to find each other and communicate with each other. We only need one master in a distributed system, and it should run on a computer in which all the other computers can ping it properly to ensure that remote ROS nodes can access the master.

The following diagram shows how the ROS master interacts with publishing and subscribing nodes, with the publisher node publishing a string type topic with a Hello World message and the subscriber node subscribing to this topic:

Figure 1.8 – Communication between the ROS master and Hello World publisher and subscriber

Figure 1.8 – Communication between the ROS master and Hello World publisher and subscriber

When the publisher node starts advertising the Hello World message in a particular topic, the ROS master gets the details of the topic and the node. It will check whether any node is subscribing to the same topic. If no nodes are subscribing to the same topic at that time, both nodes will remain unconnected. If the publisher and subscriber nodes run at the same time, the ROS master will exchange the details of the publisher to the subscriber, and they will connect and exchange data through ROS topics.

Using the ROS parameter

When programming a robot, we might have to define robot parameters to tune our control algorithm, such as the robot controller gains P, I, and D of a standard proportional–integral–derivative controller. When the number of parameters increases, we might need to store them as files. In some situations, these parameters must be shared between two or more programs. In this case, ROS provides a parameter server, which is a shared server in which all the ROS nodes can access parameters from this server. A node can read, write, modify, and delete parameter values from the parameter server.

We can store these parameters in a file and load them into the server. The server can store a wide variety of data types and even dictionaries. The programmer can also set the scope of the parameter; that is, whether it can be accessed by only this node or all the nodes.

The parameter server supports the following XMLRPC data types:

  • 32-bit integers
  • Booleans
  • Strings
  • Doubles
  • ISO8601 dates
  • Lists
  • Base64-encoded binary data

We can also store dictionaries on the parameter server. If the number of parameters is high, we can use a YAML file to save them. Here is an example of the YAML file parameter definitions:

/camera/name : 'nikon'  #string type 
/camera/fps : 30     #integer   
/camera/exposure : 1.2  #float  
/camera/active : true  #boolean 

The rosparam tool is used to get and set the ROS parameter from the command line. The following are the commands for working with ROS parameters:

  • rosparam set [parameter_name] [value]: This command will set a value in the given parameter.
  • rosparam get [parameter_name]: This command will retrieve a value from the given parameter.
  • rosparam load [YAML file]: The ROS parameters can be saved into a YAML file. It can load them into the parameter server using this command.
  • rosparam dump [YAML file]: This command will dump the existing ROS parameters into a YAML file.
  • rosparam delete [parameter_name]: This command will delete the given parameter.
  • rosparam list: This command will list existing parameter names.

These parameters can be changed dynamically when you're executing a node that uses these parameters by using the dyamic_reconfigure package (http://wiki.ros.org/dynamic_reconfigure).

ROS community level

These are ROS resources that enable a new community in ROS to exchange software and knowledge. The various resources in these communities are as follows:

  • Distributions: Similar to the Linux distribution, ROS distributions are a collection of versioned metapackages that we can install. The ROS distributions allow us to easily install and collect ROS software. They also maintain consistent versions across a set of software.
  • Repositories: ROS relies on a federated network of code repositories, where different institutions can develop and release their own robot software components.
  • The ROS Wiki: The ROS community Wiki is the main forum for documenting information about ROS. Anyone can sign up for an account and contribute their own documentation, provide corrections or updates, write tutorials, and more.
  • Bug ticket system: If we find a bug in the existing software or need to add a new feature, we can use this resource.
  • Mailing lists: We can use the ROS-users mailing list to ask questions about ROS software and share program problems with the community.
  • ROS Answers: This website resource helps us ask questions related to ROS. If we post our doubts on this site, other ROS users can see them and provide solutions.
  • Blog: The ROS blog updates with news, photos, and videos related to the ROS community (http://www.ros.org/news).

Now, let's take a look at prerequisites for starting with ROS.

Prerequisites for starting with ROS

Before getting started with ROS and trying the code in this book, the following prerequisites should be met:

  • Ubuntu 20.04 LTS/Debian 10: ROS is officially supported by the Ubuntu and Debian operating systems. We prefer to stick with the LTS version of Ubuntu; that is, Ubuntu 20.04.
  • ROS noetic desktop full installation: Install the full desktop installation of ROS. The version we prefer is ROS Noetic, which is the latest stable version. The following link provides the installation instructions for the latest ROS distribution: http://wiki.ros.org/noetic/Installation/Ubuntu. Choose the ros-noetic-desktop-full package from the repository list.

Let's see the different versions of ROS framework.

ROS distributions

ROS updates are released with new ROS distributions. A new distribution of ROS is composed of an updated version of its core software and a set of new/updated ROS packages. ROS follows the same release cycle as the Ubuntu Linux distribution: a new version of ROS is released every 6 months. Typically, for each Ubuntu LTS version, an LTS version of ROS is released. Long Term Support (LTS) and means that the released software will be maintained for a long time (5 years in the case of ROS and Ubuntu):

Figure 1.9 – List of recent ROS releases

Figure 1.9 – List of recent ROS releases

The tutorials in this book are based on the latest LTS version of ROS, known as ROS Noetic Ninjemys. It represents the thirteenth ROS distribution release. The list of recent ROS distributions is shown in the preceding image.

Running the ROS master and the ROS parameter server

Before running any ROS nodes, we should start the ROS master and the ROS parameter server. We can start the ROS master and the ROS parameter server by using a single command called roscore, which will start the following programs:

  • ROS master
  • ROS parameter server
  • rosout logging nodes

The rosout node will collect log messages from other ROS nodes and store them in a log file, and will also re-broadcast the collected log message to another topic. The /rosout topic is published by ROS nodes using ROS client libraries such as roscpp and rospy, and this topic is subscribed by the rosout node, which rebroadcasts the message in another topic called /rosout_agg. This topic contains an aggregate stream of log messages. The roscore command should be run as a prerequisite to running any ROS nodes. The following screenshot shows the messages that are printed when we run the roscore command in a Terminal.

Use the following command to run roscore on a Linux Terminal:

roscore   

After running this command, we will see the following text in the Linux Terminal:

Figure 1.10 – Terminal messages while running the roscore command

Figure 1.10 – Terminal messages while running the roscore command

The following are explanations of each section when executing roscore in a Terminal:

  • In section 1, we can see that a log file is created inside the ~/.ros/log folder for collecting logs from ROS nodes. This file can be used for debugging purposes.
  • In section 2, the command starts a ROS launch file called roscore.xml. When a launch file starts, it automatically starts rosmaster and the ROS parameter server. The roslaunch command is a Python script, which can start rosmaster and the ROS parameter server whenever it tries to execute a launch file. This section shows the address of the ROS parameter server within the port.
  • In section 3, we can see parameters such as rosdistro and rosversion being displayed in the Terminal. These parameters are displayed when it executes roscore.xml. We will look at roscore.xml in more detail in the next section.
  • In section 4, we can see that the rosmaster node is being started with ROS_MASTER_URI, which we defined earlier as an environment variable.
  • In section 5, we can see that the rosout node is being started, which will start subscribing to the /rosout topic and rebroadcasting it to /rosout_agg.

The following is the content of roscore.xml:

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

When the roscore command is executed, initially, the command checks the command-line argument for a new port number for rosmaster. If it gets the port number, it will start listening to the new port number; otherwise, it will use the default port. This port number and the roscore.xml launch file will be passed to the roslaunch system. The roslaunch system is implemented in a Python module; it will parse the port number and launch the roscore.xml file.

In the roscore.xml file, we can see that the ROS parameters and nodes are encapsulated in a group XML tag with a / namespace. The group XML tag indicates that all the nodes inside this tag have the same settings.

The rosversion and rosdistro parameters store the output of the rosversionroslaunch and rosversion-d commands using the command tag, which is a part of the ROS param tag. The command tag will execute the command mentioned in it and store the output of the command in these two parameters.

rosmaster and the parameter server are executed inside roslaunch modules via the ROS_MASTER_URI address. This happens inside the roslaunch Python module. ROS_MASTER_URI is a combination of the IP address and port that rosmaster is going to listen to. The port number can be changed according to the given port number in the roscore command.

Checking the roscore command's output

Let's check out the ROS topics and ROS parameters that are created after running roscore. The following command will list the active topics in the Terminal:

rostopic list  

The list of topics is as follows, as per our discussion of the rosout node's subscribe /rosout topic. This contains all the log messages from the ROS nodes. /rosout_agg will rebroadcast the log messages:

/rosout
/rosout_agg  

The following command lists the parameters that are available when running roscore. The following command is used to list the active ROS parameter:

rosparam list  

These parameters are mentioned here; they provide the ROS distribution name, version, the address of the roslaunch server, and run_id, where run_id is a unique ID associated with a particular run of roscore:

/rosdistro
/roslaunch/uris/host_robot_virtualbox__51189
/rosversion
/run_id

The list of ROS services that's generated when running roscore can be checked by using the following command:

rosservice list  

The list of services that are running is as follows:

/rosout/get_loggers
/rosout/set_logger_level  

These ROS services are generated for each ROS node, and they are used to set the logging levels.

Summary

ROS is now a trending software framework among roboticists. Gaining knowledge of ROS will be essential in the upcoming years if you are planning to build your career as a robotics engineer. In this chapter, we have gone through the basics of ROS, mainly to refresh you on the concepts if you have already learned about ROS. We discussed the necessity of learning ROS and how it excels among the current robotics software platforms. We went through the basic concepts, such as the ROS master and the parameter server, and provided an explanation of the working of roscore. In the next chapter, we will introduce ROS package management and discuss some practical examples of the ROS communication system.

Here are some questions based on what we covered in this chapter.

Questions

  • Why should we use ROS?
  • What are the basic elements of the ROS framework?
  • What are the prerequisites for programming with ROS?
  • What is the internal working of roscore?
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Become proficient in ROS programming using C++ with this comprehensive guide
  • Build complex robot applications using the ROS Noetic Ninjemys release to interface robot manipulators with mobile robots
  • Learn to interact with aerial robots using ROS

Description

The Robot Operating System (ROS) is a software framework used for programming complex robots. ROS enables you to develop software for building complex robots without writing code from scratch, saving valuable development time. Mastering ROS for Robotics Programming provides complete coverage of the advanced concepts using easy-to-understand, practical examples and step-by-step explanations of essential concepts that you can apply to your ROS robotics projects. The book begins by helping you get to grips with the basic concepts necessary for programming robots with ROS. You'll then discover how to develop a robot simulation, as well as an actual robot, and understand how to apply high-level capabilities such as navigation and manipulation from scratch. As you advance, you'll learn how to create ROS controllers and plugins and explore ROS's industrial applications and how it interacts with aerial robots. Finally, you'll discover best practices and methods for working with ROS efficiently. By the end of this ROS book, you'll have learned how to create various applications in ROS and build your first ROS robot.

Who is this book for?

If you are a robotics graduate, robotics researcher, or robotics software professional looking to work with ROS, this book is for you. Programmers who want to explore the advanced features of ROS will also find this book useful. Basic knowledge of ROS, GNU/Linux, and C++ programming concepts is necessary to get started with this book.

What you will learn

  • Create a robot model with a 7-DOF robotic arm and a differential wheeled mobile robot
  • Work with Gazebo, CoppeliaSim, and Webots robotic simulators
  • Implement autonomous navigation in differential drive robots using SLAM and AMCL packages
  • Interact with and simulate aerial robots using ROS
  • Explore ROS pluginlib, ROS nodelets, and Gazebo plugins
  • Interface I/O boards such as Arduino, robot sensors, and high-end actuators
  • Simulate and perform motion planning for an ABB robot and a universal arm using ROS-Industrial
  • Work with the motion planning features of a 7-DOF arm using MoveIt
Estimated delivery fee Deliver to Singapore

Standard delivery 10 - 13 business days

S$11.95

Premium delivery 5 - 8 business days

S$54.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 28, 2021
Length: 594 pages
Edition : 3rd
Language : English
ISBN-13 : 9781801071024
Vendor :
Google
Category :
Languages :
Concepts :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Singapore

Standard delivery 10 - 13 business days

S$11.95

Premium delivery 5 - 8 business days

S$54.95
(Includes tracking information)

Product Details

Publication date : Oct 28, 2021
Length: 594 pages
Edition : 3rd
Language : English
ISBN-13 : 9781801071024
Vendor :
Google
Category :
Languages :
Concepts :

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 S$6 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 S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 213.97 225.97 12.00 saved
Mastering ROS for Robotics Programming, Third edition
S$82.99
Mastering Embedded Linux Programming
S$62.99 S$74.99
Learn Robotics Programming
S$67.99
Total S$ 213.97 225.97 12.00 saved Stars icon
Banner background image

Table of Contents

21 Chapters
Section 1 – ROS Programming Essentials Chevron down icon Chevron up icon
Chapter 1: Introduction to ROS Chevron down icon Chevron up icon
Chapter 2: Getting Started with ROS Programming Chevron down icon Chevron up icon
Section 2 – ROS Robot Simulation Chevron down icon Chevron up icon
Chapter 3: Working with ROS for 3D Modeling Chevron down icon Chevron up icon
Chapter 4: Simulating Robots Using ROS and Gazebo Chevron down icon Chevron up icon
Chapter 5: Simulating Robots Using ROS, CoppeliaSim, and Webots Chevron down icon Chevron up icon
Chapter 6: Using the ROS MoveIt! and Navigation Stack Chevron down icon Chevron up icon
Chapter 7: Exploring the Advanced Capabilities of ROS MoveIt! Chevron down icon Chevron up icon
Chapter 8: ROS for Aerial Robots Chevron down icon Chevron up icon
Section 3 – ROS Robot Hardware Prototyping Chevron down icon Chevron up icon
Chapter 9: Interfacing I/O Board Sensors and Actuators to ROS Chevron down icon Chevron up icon
Chapter 10: Programming Vision Sensors Using ROS, OpenCV, and PCL Chevron down icon Chevron up icon
Chapter 11: Building and Interfacing Differential Drive Mobile Robot Hardware in ROS Chevron down icon Chevron up icon
Section 4 – Advanced ROS Programming Chevron down icon Chevron up icon
Chapter 12: Working with pluginlib, nodelets, and Gazebo Plugins Chevron down icon Chevron up icon
Chapter 13: Writing ROS Controllers and Visualization Plugins Chevron down icon Chevron up icon
Chapter 14: Using ROS in MATLAB and Simulink Chevron down icon Chevron up icon
Chapter 15: ROS for Industrial Robots Chevron down icon Chevron up icon
Chapter 16: 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 Full star icon Full star icon 5
(5 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Abhishek Chothani Jul 27, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's really good book for starting with ros
Feefo Verified review Feefo
GOLAK M Jan 29, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written book to work with robotics as the authors provided various practical examples starting from scratch
Amazon Verified review Amazon
katrina Feb 14, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is quite thorough, and gives the ROS beginner an excellent introduction in the first 2 chapters. Then it goes on to 3D modeling and simulations with various programs that work with ROS. It covers how to use ROS for navigation, and even advanced topics like servo controllers. There are chapters on interfacing with I/O sensors and board activators, actuators, vision sensors, differential drives...and THEN it gets into the advanced stuff. In this advanced section are many things like creating plugins, controllers and nodelets; working with Matlab, industrial robots, and so much more. If you want a book to cover almost anything you could want to use a robot for, this is the book for you.
Amazon Verified review Amazon
JIE JIN Feb 08, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is quite practical. As a beginner of ROS, I feel very comfortable getting started with the examples this book provided. You have to be patient to finish this book since it has 500+ pages :). Overall, it is an awesome book worth reading! Thanks, authors!
Amazon Verified review Amazon
James C. May 30, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book goes over concepts well. I haven't had a lot of time to go over it in depth, but from what I have read I can recommend it.
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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela