Book Image

Mastering ROS for Robotics Programming - Second Edition

By : Jonathan Cacace, Lentin Joseph
Book Image

Mastering ROS for Robotics Programming - Second Edition

By: Jonathan Cacace, Lentin Joseph

Overview of this book

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.
Table of Contents (22 chapters)
Title Page
Copyright and Credits
www.PacktPub.com
Contributors
Preface
Index

What are the prerequisites for starting with ROS?


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

  • Ubuntu 16.04 LTS / Ubuntu 15.10 / Debian 8: ROS is officially supported by Ubuntu and Debian operating systems. We prefer to stick with the LTS version of Ubuntu, that is, Ubuntu 16.04.
  • ROS kinetic desktop full installation: Install the full desktop installation of ROS. The version we prefer is ROS kinetic, the latest stable version. The following link gives you the installation instruction of the latest ROS distribution: http://wiki.ros.org/kinetic/Installation/Ubuntu. Choose the ros-kinetic-desktop-full package from the repository list.

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 by 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 has an aggregate stream of log messages. The roscore command is a prerequisite before running any ROS node. The following screenshot shows the messages printing when we run the roscore command in a Terminal.

The following is a command to run roscore on a Linux Terminal:

$ roscore

Figure 9: Terminal messages while running the roscore command

The following are explanations of each section when executing roscore on the Terminal:

  • In section 1, we can see 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 the 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 the parameters such as rosdistro and rosversion displayed on the Terminal. These parameters are displayed when it executes roscore.xml. We look at roscore.xml and its details further in the next section.
  • In section 4, we can see the rosmaster node is started using ROS_MASTER_URI, which we defined earlier as an environment variable.
  • In section 5, we can see the rosout node is started, which will start subscribing the /rosout topic and rebroadcasting into /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 the 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 pass 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 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 two parameters called rosversion and rosdistro 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 on it and store the output of the command in these two parameters.

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

Checking the roscore command output

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

$ rostopic list

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

/rosout/rosout_agg

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

$ rosparam list

The parameters are mentioned here; they have the ROS distribution name, version, 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 the ROS service generated during the running roscore can be checked using the following command:

$ rosservice list

The list of services running is as follows:

/rosout/get_loggers/rosout/set_logger_level

These ROS services are generated for each ROS node for setting the logging levels.