24小时热门版块排行榜    

查看: 1634  |  回复: 0

yadan33

新虫 (初入文坛)

[交流] ROS-topic

重新roscore
$ roscore
run node
$ rosrun turtlesim turtlesim_node
键盘控制乌龟移动,要启动这个terminal乌龟才会动
$ rosrun turtlesim turtle_teleop_key


用rqt-graph查看topic
如果没安装,先安装
$ sudo apt-get install ros-<distro>-rqt
$ sudo apt-get install ros-<distro>-rqt-common-plugins

然后
In a new terminal:
$ rosrun rqt_graph rqt_graph
可以看到类似下面的


$ rostopic -h
rostopic bw     display bandwidth used by topic
rostopic echo   print messages to screen
rostopic hz     display publishing rate of topic   
rostopic list   print information about active topics
rostopic pub    publish data to topic
rostopic type   print topic type

rostopic echo:
rostopic echo [topic]

$ rostopic echo /turtle1/cmd_vel
移动小乌龟,会出现下面的
angular:
  x: 0.0
  y: 0.0
  z: -2.0
---
linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: -2.0
---
linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: -2.0
刷新graph页面,多了一个topic


$ rostopic list -h
Usage: rostopic list [/topic]

Options:
  -h, --help            show this help message and exit
  -b BAGFILE, --bag=BAGFILE
                        list topics in .bag file
  -v, --verbose         list full details about each topic
  -p                    list only publishers
  -s                    list only subscribers
For rostopic list use the verbose option:

$ rostopic list -v
This displays a verbose list of topics to publish to and subscribe to and their type.

Published topics:
* /turtle1/color_sensor [turtlesim/Color] 1 publisher
* /turtle1/command_velocity [turtlesim/Velocity] 1 publisher
* /rosout [roslib/Log] 2 publishers
* /rosout_agg [roslib/Log] 1 publisher
* /turtle1/pose [turtlesim/Pose] 1 publisher

Subscribed topics:
* /turtle1/command_velocity [turtlesim/Velocity] 1 subscriber
* /rosout [roslib/Log] 1 subscriber


4,将消息应用到主题上



I,rostopic pub [topic] [msg_type] [args]
将数据发布到当前主题上,例如小海龟例子:

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
命令诠释:
rostopic
pub ---在给定主题上发布消息
-1
---此选项表示rostopic只发布一个消息,然后退出
/turtle1/cmd_vel
---给定的主题名
geometry_msgs/Twist
---在给定主题上发布的消息类型
--
---双负号,表示词法选择器在此后的参数都不可用。这种情况发生在错误参数比如负数
'[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' --- In this case, '[2.0, 0.0, 0.0]' becomes the linear value with x=2.0, y=0.0, and z=0.0, and '[0.0, 0.0, 1.8]' is the angular value with x=0.0, y=0.0, and z=1.8.
让小乌龟一直移动,加一个-r 1,让其保持1hz频率
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

获得当前的速率
rostopic hz [topic]
Let's see how fast the turtlesim_node is publishing /turtle1/pose:

$ rostopic hz /turtle1/pose

plot显示
$ rosrun rqt_plot rqt_plot

ROS-topic
1111.png


ROS-topic-1
22222.png
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 yadan33 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] (出分啦!!!)26 考研调剂 20w+调剂信息火速更新中!【捡漏】qq 群:1087823172 +3 db58 2026-02-28 79/3950 2026-02-28 17:50 by nbf68
[考研] 085600材料工程一志愿中科大总分312求调剂 +4 吃宵夜1 2026-02-28 6/300 2026-02-28 17:38 by 吃宵夜1
[考研] 高分子化学与物理调剂 +3 好好好1233 2026-02-28 4/200 2026-02-28 17:13 by sandychj
[考研] 化工专硕348,一志愿985求调剂 +3 弗格个 2026-02-28 5/250 2026-02-28 17:04 by sandychj
[高分子] 求环氧树脂研发1名 +3 孙xc 2026-02-25 11/550 2026-02-28 16:57 by ichall
[考研] 0856材料求调剂 +8 hyf hyf hyf 2026-02-28 9/450 2026-02-28 16:27 by etapple
[考研] 285求调剂 +3 满头大汗的学生 2026-02-28 3/150 2026-02-28 16:22 by 无际的草原
[考博] 26申博 +3 想申博! 2026-02-26 3/150 2026-02-28 16:07 by nxgogo
[考研] 295求调剂 +4 19171856320 2026-02-28 4/200 2026-02-28 13:39 by ms629
[考研] 290求调剂 +4 材料专硕调剂; 2026-02-28 5/250 2026-02-28 13:32 by houyaoxu
[考研] 0856调剂 +3 刘梦微 2026-02-28 3/150 2026-02-28 13:22 by houyaoxu
[考研] 寻找调剂 +3 LYidhsjabdj 2026-02-28 3/150 2026-02-28 12:59 by miniwendy
[考研] 304求调剂 +5 曼殊2266 2026-02-28 6/300 2026-02-28 12:44 by 迷糊CCPs
[硕博家园] 博士自荐 +6 科研狗111 2026-02-26 9/450 2026-02-28 12:32 by seaskyy
[考研] 272求调剂 +3 田智友 2026-02-28 3/150 2026-02-28 12:31 by 王加浩to
[考研] 298求调剂 +4 axyz3 2026-02-28 4/200 2026-02-28 11:21 by wang_dand
[基金申请] 什么是人一生最重要的? +10 瞬息宇宙 2026-02-21 10/500 2026-02-27 08:46 by tfang
[基金申请] 面上可以超过30页吧? +12 阿拉贡aragon 2026-02-22 13/650 2026-02-26 22:09 by Hahaxia
[教师之家] 版面费该交吗 +14 苹果在哪里 2026-02-22 17/850 2026-02-26 11:55 by AGI智创机器人
[硕博家园] 【博士招生】太原理工大学2026化工博士 +4 N1ce_try 2026-02-24 8/400 2026-02-26 08:40 by N1ce_try
信息提示
请填处理意见