[ROS study notes] (1) Explanation and examples of commonly used commands

1. roscore

roscore is used to start the ros master, which is the first command to run before running the ros system
Insert picture description here

2. rosrun

rosrun is an instruction used to run a node in a function package. It has two parameters. The first parameter is the function package name, and the second parameter is the node name.

Example: emulating a turtle
, type rosrun turtlesim turtlesim_node
in one terminal, type in another terminalrosrun turtlesim turtle_teleop_key
Insert picture description here

3.rosnode

rosnode, an instruction used to display node-related information

  • rosnode list is used to list all nodes in the system
    Insert picture description here
  • rosnode info *, view the specific information of the node, such as which topics are being published, the services provided, and other information
    Insert picture description here
4. rostopic
  • rostopic list, output a list of all topics in the current system
    Insert picture description here
  • rostopic pub [topic name + tab completion], display the published content
    Insert picture description here

Example: Controlling the movement of a turtle by publishing a topic (rostopic pub)
Input code: rostopic pub -r 10 /turtle1/cmd_vel+两次tab补全
By modifying the linear speed and angular angle, the movement of the turtle can be controlled. Among them, -r 10 is the frequency of topic publication, which is published ten times per second.
Insert picture description here

5. rosservice
  • roservice list can display a list of all services in the ros system (all servers are the turtle emulators above)
  • rosservice call [service name + tab completion] release request

Example: Spawn two turtles (/spawn in the service list is a request to spawn a turtle)
Input code: rosservice call /spawn+两次tab补全
where x and y are the coordinates of the new turtle (the lower left corner of the emulator is the origin)
Insert picture description here

6. rosbag

Record all topic data in the current system and reproduce it next time.

Example: Preserving the movement of baby turtles

  1. Input command: rosbag record -a -O cmd_record
    where record means to record, -a means to record all data, -o means to save the data as a compressed package, and finally the name of the saved file
  2. Back to the key terminal, use the keyboard arrow keys to control the little turtle to move
  3. Use ctrl+Cinterrupt rosbag record after exercise
    Insert picture description here

Example: Reproduce the movement of a baby turtle

  1. Close the previously opened terminal, reopen a terminal, and runroscore
  2. Open a new terminal and start the emulation of the little turtle: rosrun turtlesim turtlesim_node(There is no need to start keyboard input here)
  3. Open a new terminal to reproduce the action of the little turtle:rosbag play cmd_record.bag
    Insert picture description here

The learning content in this article comes from the
official forum of Guyueju: https://www.guyuehome.com/
learning video: https://www.bilibili.com/video/BV1zt411G7Vn

Guess you like

Origin blog.csdn.net/weixin_44543463/article/details/113943326