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.
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 therosmaster
and the ROS parameter server. Theroslaunch
command is a Python script, which can startrosmaster
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
androsversion
displayed on the Terminal. These parameters are displayed when it executesroscore.xml
. We look atroscore.xml
and its details further in the next section. - In section 4, we can see the
rosmaster
node is started usingROS_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 rosversion
roslaunch
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.
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.