1. Use of command line tools
Preface
In ROS, the use of command line tools can give us an in-depth understanding of ROS and make it more convenient for us to operate ROS.
We use turtles as an example to learn command line tools.
Steps to run the little turtle:
terminal input
roscore
Then, open another terminal and enter
rosrun turtlesim turtlesim_node
If you want to control the little turtle with the keyboard, open a new terminal based on the above and enter
rosrun turtlesim turtle_teleop_key
一、rostopic
rostopic is a command-line tool for printing information about ROS Topics.
Use ctrl+alt+T to open the terminal, enter rostopic, and press Enter. Tools related to rostopic will appear:
Let’s take the little turtle as an example:
Terminal input
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
Then press the tab key (it is easy to press the enter key out of habit), and the following situation occurs:
use the left and right movement keys on the keyboard to move the cursor, modify the values of linear
and angular
, thereby controlling the movement of the little turtle.
But we can see that after the instruction is issued, the little turtle only moves once and does not move all the time. This is because the instructions received by the little turtle are not continuously issued. If we want the little turtle to keep moving, then we need to keep moving. When the little turtle sends a command, we can add -r and a value to the previous line of code (you need to pay attention to the input format and spaces here). The specific operation method:
After issuing the previous command (in the green box, press ctrl+C to end the command), we use the keyboard arrow keys to press "↑", and then use "←" and "→" to move the cursor and modify the command. Add -r and a value after pub (-r represents frequency rate, the unit of 10 is Hz)
rostopic pub -r 10 /turtle1/ //这里展示部分内容
Finally, the baby turtle will hit the wall.
Here are some explanations:
rostopic pub-r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
turtle1/cmd_vel is the topic name
geometry_msgs/ Twist is the published content, that is, the message structure.
If the terminal enters rostopic pub-r 10 (publish)/ turtle1/cmd_vel geometry_msgs/ Twist,
"-r 10" is added, which means adding a frequency , so that it can continue to issue commands to the terminal.
The number after "-r" means how many times per second.
Enter "ctrl+C to stop" in the terminal.
2. rosnode
rosnode is a command-line tool for printing information about ROS Nodes.
A command to display information related to all nodes in the system
Enter rosnode list in the terminal to list all the nodes in the system.
Enter rosnode info in the terminal to view the specific information of a node. For example, to view the information of the turtlesim node, enter rosnode info /turtlesim in the terminal. After pressing Enter, you can view the subscription topics, Service information
3. rosservice
rossrv is a command-line tool for displaying information about ROS
Service types.
Enter rossrv list at the terminal to view the specific content of rossrv.
Enter rossrv call /spawn at the terminal to request the generation of one more turtle (spwan means spawn). At the same time, enter the coordinate data and name so that the requested thing is named and appears in at designated locationcall是调用、发布、请求的意思
4. rosmsg
rosmsg is a command-line tool for displaying information about ROS
Message types.
5. rosparam
rosparam is a command-line tool for getting, setting, and deleting
parameters from the ROS Parameter Server.
6. rosout
rosout is a default topic in the system, generally you don’t need to care about it