• +4917626969472
  • info@ur-techpartner.de

Important ROS Commands (01/09) – Basics + ROS Node

Important ROS Commands Robot Operating System(ROS1/ROS2)

Important ROS Commands

In this article, we will get through some essential ROS commands, which are very important to get familiarize with. In order to use ROS properly, it is necessary to know not only the basic Linux commands but also the ROS specific commands. With the passage of time and with practice, you will be proficient and at more ease to use these commands.

Here, we will describe the function of important commands along with examples.

ROS Change Directory command “roscd”

The “roscd” command is used to directly move to a specific ROS package. It is a combination of (ros+cd).

Type following command on terminal

roscd turtlesim

you will move to the corresponding package folder as shown in first figure.

Similarly, if you have created your own package , you can move to that package. Currently, the package “my_example_package” is created in the workspace “catkin_ws”

Run the command in terminal

roscd my_example_package

It will move to the specified package folder.

Since I have installed ROS kinetic which has a package of turtlesim, therefore it is moved to that folder. However, if you have installed some other version such as melodic or noetic. You will get the result accordingly. If you don’t have the package “turtlesim” installed. You can install it as with the following command

sudo apt-get install ros-kinetic-turtlesim

In case of ROS noetic, you can replace kinetic with noetic, like below

sudo apt-get install ros-noetic-turtlesim

ROS File List command “rosls”

As we have seen in the blog of basic Linux commands that “ls” command is used to see the contents of the folder. However, in that case we have to move into that folder or package to see the file list (contents) of the folder.

But if we want to see the contents (file list) of any ROS package without moving to the package folder. We can use “rosls” command. This command is a combination of (ros+ls).

Write following on terminal

rosls my_example_package

You will see the list of files inside the package.

Similarly to see what is inside “turtlesim”, write

rosls turtlesim

Command “roscore”

As we have already seen in ROS Terminologies blog that “roscore” is a command which is used to run the master. The master manages the connection information for communication among nodes. The master is an essential element and it should be the first element to run, which is launched by the command “roscore”. When executing “roscore” command, “rosout” and parameter server are also executed. “rosout” is used to record ROS standard output logs, while parameter server is used to manage parameters.

You can run this command in your terminal as follows

roscore

The command to Run ROS Node “rosrun”

The command “rosrun” runs only one node in a specified package. The structure of running this command is as follows

rosrun [Package_Name] [Node_Name]

Here, we run the “turtlesim_node” which is inside the package “turtlesim”.

rosrun turtlesim turtlesim_node

oh, it fails to connect the master. This might be because the master is not running. Therefore first we execute the command “roscore”

roscore

Now we run the turtlesim_node again using “rosrun” command.

rosrun turtlesim turtlesim_node

Yes! it worked now. Following screen will be opened after execution of turtlesim_node.

The command to launch multiple nodes “roslaunch”

The command “roslaunch” has the same structure as rosrun, however it is used to launch multiple nodes. The extension of launch file which is executed by “roslaunch” command is “.launch”. We will see the creation of launch file in later blogs.

The structure is as follows

roslaunch [Package_Name] [ Launch_File_name]

For example

roslaunch openni_launch openni.launch

This will launch multiple nodes. If the openni_launch package is not already installed, you can install it using following command.

sudo apt-get install ros-kinetic-openni_launch

or for noetic run

sudo apt-get install ros-noetic-openni_launch

“.launch” is usually placed in “launch” folder of the package. Hence, which ever package we want to execute, we can execute its relevant launch file using “roslaunch” command. Unlike the “rosrun”, command which first requires “roscore” command to run. The “roslaunch” command will be executed successfully, even if we have not executed “roscore” command.

ROS Information Commands

These are the commands which are used to check information about topics, nodes, services, parameters etc. These commands include “rostopic”, “rosnode”, “rosservice”, “rosparam”, “rosbag” etc. We will see what are their functions.

We will first run turtlesim_node, so that we can execute ROS Information commands to see their functions.

For this, close all terminals so that previously running programs may not conflict with the new ones.

Open a new terminal and run following commands

roscore

Open a new terminal and run the turtlesim_node with rosrun command, that we have run previously.

rosrun turtlesim turtlesim_node

Open a new terminal and run “turtle_teleop_key” node. With this node, we will be able to control the turtle in simulation environment with our keyboard.

rosrun turtlesim turtle_teleop_key

By using arrow keys on keyboard, we can move turtle to any direction, let’s do it

wow, It is interesting! isn’t it? 🙂

“rosnode” command

Now open a new terminal and run the following command

rosnode list

you will see following nodes are running

/rosout

/teleop_turtle

/turtlesim

Similarly you can use “rosnode” command to get the information about a specific node as follows

rosnode info turtlesim

This command will displays the information related to the specified node as shown in figure below.

We can see, so far we have used, “list” and “info” arguments along with the command “rosnode”. To further explore which more arguments we can use with “rosnode” command.

Run following command.

rosnode --help

or

rosnode -h

Both commands will do the same thing, and we will get following output as shown in figure below.

You can try yourself the remaining arguments with “rosnode” command.

No comments