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.