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

You're reading from   Mastering ROS for Robotics Programming Design, build, and simulate complex robots using the Robot Operating System

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788478953
Length 580 pages
Edition 2nd Edition
Languages
Tools
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 (17) Chapters Close

Preface 1. Introduction to ROS FREE CHAPTER 2. Getting Started with ROS Programming 3. Working with 3D Robot Modeling in ROS 4. Simulating Robots Using ROS and Gazebo 5. Simulating Robots Using ROS and V-REP 6. Using the ROS MoveIt! and Navigation Stack 7. Working with pluginlib, Nodelets, and Gazebo Plugins 8. Writing ROS Controllers and Visualization Plugins 9. Interfacing I/O Boards, Sensors, and Actuators to ROS 10. Programming Vision Sensors Using ROS, Open CV, and PCL 11. Building and Interfacing Differential Drive Mobile Robot Hardware in ROS 12. Exploring the Advanced Capabilities of ROS-MoveIt! 13. Using ROS in MATLAB and Simulink 14. ROS for Industrial Robots 15. Troubleshooting and Best Practices in ROS 16. Other Books You May Enjoy

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.

You have been reading a chapter from
Mastering ROS for Robotics Programming - Second Edition
Published in: Feb 2018
Publisher: Packt
ISBN-13: 9781788478953
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 ₹800/month. Cancel anytime