327 字
2 分钟
ros2——Topic 终端命令

Topic 命令#

help 使用帮助文档#

ros2 topic --h
usage: ros2 topic [-h] [--include-hidden-topics]
Call `ros2 topic <command> -h` for more detailed
usage. ...
Various topic related sub-commands
options:
-h, --help show this help message and exit
--include-hidden-topics
Consider hidden topics as well
Commands:
bw Display bandwidth used by topic
delay Display delay of topic from timestamp in header
echo Output messages from a topic
find Output a list of available topics of a given type
hz Print the average receiving rate to screen
info Print information about a topic
list Output a list of available topics
pub Publish a message to a topic
type Print a topic's type

echo 输出主题信息#

ros2 topic echo <topic_name>

示例:

ros2 topic echo /turtle1/pose
---
x: 11.088889122009277
y: 3.7155938148498535
theta: 0.8832588195800781
linear_velocity: 0.0
angular_velocity: 0.0
---

info 打印主题信息#

ros2 topic info <topic_name>

示例:

ros2 topic info /turtle1/pose
Type: turtlesim/msg/Pose
Publisher count: 1
Subscription count: 0

list 列出活动的主题#

ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose

pub 发布消息#

ros2 topic pub --h
usage: ros2 topic pub [-h] [-r N] [-p N] [-1 | -t TIMES]
[-w WAIT_MATCHING_SUBSCRIPTIONS]
[--keep-alive N] [-n NODE_NAME]
[--qos-profile {unknown,system_default,sensor_data,services_default,parameters,parameter_events,action_status_default}]
[--qos-depth N]
[--qos-history {system_default,keep_last,keep_all,unknown}]
[--qos-reliability {system_default,reliable,best_effort,unknown}]
[--qos-durability {system_default,transient_local,volatile,unknown}]
[--spin-time SPIN_TIME] [-s]
topic_name message_type [values]
Publish a message to a topic
positional arguments:
topic_name Name of the ROS topic to publish to (e.g.
'/chatter')
message_type Type of the ROS message (e.g.
'std_msgs/String')
values Values to fill the message with in YAML
format (e.g. 'data: Hello World'), otherwise
the message will be published with default
values. You can use 'now' placeholder to get
the current time and 'auto' placeholder to
get a std_msgs.msg.Header with current time
and empty frame_id.
ros2 topic pub topic_name message_type [values]

示例:

ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 10.0, y: 0.0} , angular: {z: 1.0}}"

type 打印主题的消息类型#

ros2 topic type <topic_name>
ros2——Topic 终端命令
https://blog.wangmasterai.com/posts/ros2系列/话题-topic/terminal/
作者
WangMaster
发布于
2026-09-25
许可协议
CC BY-NC-SA 4.0

分享文章

生成精美分享图或复制链接,与更多人分享本文。

继续阅读

沿着主题读

基于共同的标签与分类

换条路线

从其他文章中稳定抽取