24小时热门版块排行榜    

查看: 1682  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +5 s3fFTmArrBt6 2026-09-14 5/250 2026-09-16 19:15 by rRvxEj3zorCy
[博后之家] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +8 QUjhNVAcOSff 2026-09-13 9/450 2026-09-16 18:36 by rRvxEj3zorCy
[找工作] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +5 s3fFTmArrBt6 2026-09-13 6/300 2026-09-16 16:15 by i3KBRD19ERkG
[考研] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +4 s3fFTmArrBt6 2026-09-13 6/300 2026-09-16 16:00 by i3KBRD19ERkG
[找工作] 浙江师范大学是怎么坑我的 +7 recruit123 2026-09-09 7/350 2026-09-16 15:07 by 防腐剂科技部
[考博] 上海工程技术大学激光智能制造课题组|2027级博士研究生招生公告 +7 水士口 2026-09-16 8/400 2026-09-16 13:47 by kkklens
[博后之家] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +3 vZfe6xYu34yj 2026-09-14 3/150 2026-09-16 08:27 by SjQobnC04j06
[考研] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +4 Aj1rhIDL5ixY 2026-09-14 4/200 2026-09-16 07:03 by LH5NkK5Ud4bh
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +3 23jxep3nCNZb 2026-09-14 3/150 2026-09-16 06:24 by LH5NkK5Ud4bh
[考研] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +3 23jxep3nCNZb 2026-09-14 3/150 2026-09-16 06:11 by LH5NkK5Ud4bh
[硕博家园] 售SCI一区文章,我:8O5.5.1.O5.4,科目全,可伽急 +5 s3fFTmArrBt6 2026-09-13 7/350 2026-09-16 03:26 by DgNGHc3h5tPl
[博后之家] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +3 Aj1rhIDL5ixY 2026-09-14 3/150 2026-09-15 20:26 by zNcEhTcH7ihq
[考博] 售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急 +6 s3fFTmArrBt6 2026-09-14 7/350 2026-09-15 16:47 by CgyNCDVNhGVg
[找工作] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +4 s3fFTmArrBt6 2026-09-14 5/250 2026-09-15 16:39 by CgyNCDVNhGVg
[硕博家园] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +4 3n8v2C8RimXI 2026-09-13 4/200 2026-09-15 14:34 by VMDqgnlKimtZ
[教师之家] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +3 6F5UbRU2I5hL 2026-09-14 3/150 2026-09-15 08:14 by C79jjtjAKjEn
[教师之家] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +6 3n8v2C8RimXI 2026-09-13 6/300 2026-09-15 05:38 by 5BDX0d0WFp7t
[教师之家] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +3 LwdutQ8HoqWP 2026-09-13 4/200 2026-09-14 16:13 by Aj1rhIDL5ixY
[基金申请] 求教各位大神:2026教育部人文社科青年基金项目何时公示呀? +5 云宴山人 2026-09-10 7/350 2026-09-14 12:11 by ecnu2013
[考博] 西北工业大学材料学院电化学传感与催化课题组招收2027年推免研究生、博士生、博士后 +3 马方园 2026-09-10 4/200 2026-09-14 09:29 by Chem张zz
信息提示
请填处理意见