Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering ROS for Robotics Programming, Third edition

You're reading from   Mastering ROS for Robotics Programming, Third edition Best practices and troubleshooting solutions when working with ROS

Arrow left icon
Product type Paperback
Published in Oct 2021
Publisher Packt
ISBN-13 9781801071024
Length 594 pages
Edition 3rd Edition
Languages
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Lentin Joseph Lentin Joseph
Author Profile Icon Lentin Joseph
Lentin Joseph
Jonathan Cacace Jonathan Cacace
Author Profile Icon Jonathan Cacace
Jonathan Cacace
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1 – ROS Programming Essentials
2. Chapter 1: Introduction to ROS FREE CHAPTER 3. Chapter 2: Getting Started with ROS Programming 4. Section 2 – ROS Robot Simulation
5. Chapter 3: Working with ROS for 3D Modeling 6. Chapter 4: Simulating Robots Using ROS and Gazebo 7. Chapter 5: Simulating Robots Using ROS, CoppeliaSim, and Webots 8. Chapter 6: Using the ROS MoveIt! and Navigation Stack 9. Chapter 7: Exploring the Advanced Capabilities of ROS MoveIt! 10. Chapter 8: ROS for Aerial Robots 11. Section 3 – ROS Robot Hardware Prototyping
12. Chapter 9: Interfacing I/O Board Sensors and Actuators to ROS 13. Chapter 10: Programming Vision Sensors Using ROS, OpenCV, and PCL 14. Chapter 11: Building and Interfacing Differential Drive Mobile Robot Hardware in ROS 15. Section 4 – Advanced ROS Programming
16. Chapter 12: Working with pluginlib, nodelets, and Gazebo Plugins 17. Chapter 13: Writing ROS Controllers and Visualization Plugins 18. Chapter 14: Using ROS in MATLAB and Simulink 19. Chapter 15: ROS for Industrial Robots 20. Chapter 16: Troubleshooting and Best Practices in ROS 21. Other Books You May Enjoy

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.

You have been reading a chapter from
Mastering ROS for Robotics Programming, Third edition - Third Edition
Published in: Oct 2021
Publisher: Packt
ISBN-13: 9781801071024
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime