Common ROS Commands#
Here are some commands that are frequently used during ROS development:
1. Start ROS Core#
Before using ROS, you need to start a core service called roscore
. Enter the following command in a new terminal:
roscore
2. Start a Node#
A ROS node is an executable file that processes and handles data. The following command will start a node named turtlesim
:
rosrun turtlesim turtlesim_node
3. View Node List#
Use the following command to view all currently running nodes:
rosnode list
4. View Topic List#
ROS topics are channels used for communication between nodes. The following command will display all currently available topics:
rostopic list
5. View Service List#
ROS services are a form of synchronous communication between nodes. The following command will list all currently available services:
rosservice list
This note introduces the basic usage of ROS 1 command line. In practical operations, you will also need to learn more advanced features and commands to better master ROS 1 and complete complex robotic projects. Here are some commonly used advanced features and commands:
6. Parameter Server#
The ROS parameter server is a centralized database for storing and managing global parameters. These parameters can be modified at runtime and shared among various nodes.
View Parameter List#
To view all parameters currently stored on the parameter server, use the following command:
rosparam list
Get Parameter Value#
To get the value of a specific parameter, use the following command:
rosparam get <parameter_name>
Set Parameter Value#
To set the value of a specific parameter, use the following command:
rosparam set <parameter_name> <value>
7. ROS Messages#
ROS messages are the basic units of information passed between different nodes in the ROS system. Messages consist of a set of data structures that define different types of data.
View Message Type#
To view the message type on a specific topic, use the following command:
rostopic type <topic_name>
View Message Structure#
To view the detailed structure of a specific message type, use the following command:
rosmsg show <message_type>
8. Use Launch Files to Start Multiple Nodes#
ROS .launch
files allow you to start multiple nodes at once. This is very useful for starting multiple interdependent nodes simultaneously.
Create Launch File#
First, create a directory named launch
in your package and create an XML file named my_launch_file.launch
within it:
mkdir -p ~/my_workspace/src/my_package/launch
touch ~/my_workspace/src/my_package/launch/my_launch_file.launch
Then, edit the my_launch_file.launch
file and add the following content:
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>
</launch>
Start Launch File#
To start the my_launch_file.launch
file, use the following command:
roslaunch my_package my_launch_file.launch
9. Use Rosbag to Record and Playback Data#
rosbag
is a tool for recording and playing back ROS topic data. This is very useful for offline analysis and testing.
Record Data#
To record data from a specific topic, use the following command:
rosbag record -o <output_file> <topic_name>
Playback Data#
To playback recorded data, use the following command:
rosbag play <bag_file>
By learning these advanced features and commands, you will be able to better master ROS 1 and successfully apply it in various complex robotic projects.