ROS2常用的命令

只记录ROS2 和 ROS1 不同的命令

pkg

1
2
3
4
5
6
7
8
9
10
# 列出某个包的所有可执行文件
ros2 pkg executables pkg_name
# 列出所有的包
ros2 pkg list

# 某个包所在路径的前缀
ros2 pkg prefix pkg_name

# 查看包对应的 package.xml 文件
ros2 pkg xml pkg_name

topic

  • ros2 topic info topic_name

现在必须加/

1
2
3
4
5
6
7
user@robot:~$ ros2 topic info imu
Unknown topic 'imu'

user@robot:~$ ros2 topic info /imu
Type: sensor_msgs/msg/Imu
Publisher count: 1
Subscription count: 1

  • 输出话题的详细信息,包括发布订阅者: ros2 topic info /odom -v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Type: nav_msgs/msg/Odometry

Publisher count: 1

Node name: turtlebot3_diff_drive
Node namespace: /
Topic type: nav_msgs/msg/Odometry
Endpoint type: PUBLISHER
GID: 01.0f.ea.0f.41.6a.0c.34.01.00.00.00.00.00.a5.03.00.00.00.00.00.00.00.00
QoS profile:
Reliability: RMW_QOS_POLICY_RELIABILITY_RELIABLE
Durability: RMW_QOS_POLICY_DURABILITY_VOLATILE
Lifespan: 2147483651294967295 nanoseconds
Deadline: 2147483651294967295 nanoseconds
Liveliness: RMW_QOS_POLICY_LIVELINESS_AUTOMATIC
Liveliness lease duration: 2147483651294967295 nanoseconds

Subscription count: 1

Node name: my_node
Node namespace: /
Topic type: nav_msgs/msg/Odometry
Endpoint type: SUBSCRIPTION
GID: 01.0f.ea.0f.0d.6a.5d.f0.01.00.00.00.00.00.13.04.00.00.00.00.00.00.00.00
QoS profile:
Reliability: RMW_QOS_POLICY_RELIABILITY_RELIABLE
Durability: RMW_QOS_POLICY_DURABILITY_VOLATILE
Lifespan: 2147483651294967295 nanoseconds
Deadline: 2147483651294967295 nanoseconds
Liveliness: RMW_QOS_POLICY_LIVELINESS_AUTOMATIC
Liveliness lease duration: 2147483651294967295 nanoseconds
  • ros2 interface show msg_name

显示 Topic 发送的消息定义 ros2 interface show sensor_msgs/msg/Imu

  • ros2 topic find msg_name

获知某个消息类型是谁在用

1
2
user@robot:~$ ros2 topic find sensor_msgs/msg/Imu
/imu

  • 手动发消息到话题
1
ros2 topic pub /chatter std_msgs/msg/String 'data:"123"

interface

  • ros2 interface list

分类显示消息、动作、服务的所有类型

  • ros2 interface package pkg_name
1
2
3
4
5
user@robot:~$ ros2 interface package action_msgs
action_msgs/srv/CancelGoal
action_msgs/msg/GoalInfo
action_msgs/msg/GoalStatus
action_msgs/msg/GoalStatusArray

获知某个消息类型是谁在用,可以这样查

1
2
3
4
5
6
7
8
user@robot:~$ ros2 interface packages | grep pendulum_msgs
pendulum_msgs
user@robot:~$ ros2 interface package pendulum_msgs
pendulum_msgs/msg/RttestResults
pendulum_msgs/msg/JointState
pendulum_msgs/msg/JointCommand

user@robot:~$ ros2 topic find pendulum_msgs/msg/RttestResults

  • 显示消息的成员
1
2
user@robot:~$ ros2 interface proto std_msgs/msg/String
"data: ''"

service

  • ros2 service type

可以看到服务的定义。

  • ros2 service find

找出指定类型的所有服务

  • ros2 service find std_srvs/srv/Empty

  • ros2 interface show

显示服务的定义

param

  • ros2 param list
  • ros2 param describe
1
2
3
4
5
6
7
8
ros2 param describe /turtlesim background_r
Parameter name: background_r
Type: integer
Description: Red channel of the background color
Constraints:
Min value: 0
Max value: 255
Step: 1
  • ros2 param get
1
2
ros2 param get /turtlesim background_r
Integer value is: 69
  • ros2 param set (省略)

  • ros2 run + param

  • ros2 run —ros-args —params-file

rqt_graph 能够可视化节点和主题之间的连接。这个命令和ROS1一样,也是ROS2为数不多的GUI可视界面

tf

  • 可视化ROS2的tf树

ros2 run tf2_tools view_frames.py

  • ros2 run tf2_ros static_transform_publisher 1 2 3 0.5 0.1 -1.0 foo bar

  • ros2 run tf2_ros tf2_echo foo bar

运行结果:

1
2
3
4
5
6
7
8
9
10
At time 197.27000000
- Translation: [0.008, -0.000, 0.064]
- Rotation: in Quaternion [-0.000, -0.001, -0.010, 1.000]
- Rotation: in RPY (radian) [-0.000, -0.002, -0.020]
- Rotation: in RPY (degree) [-0.001, -0.092, -1.160]
- Matrix:
1.000 0.020 -0.002 0.008
-0.020 1.000 0.000 -0.000
0.002 -0.000 1.000 0.064
0.000 0.000 0.000 1.000