24小时热门版块排行榜    

查看: 1635  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿东华大学化学070300,求调剂 +7 2117205181 2026-03-21 8/400 2026-03-22 22:55 by chixmc
[考研] 305分求调剂(食品工程) +4 Sxy112 2026-03-21 6/300 2026-03-22 15:26 by 无懈可击111
[考研] 269专硕求调剂 +6 金恩贝 2026-03-21 6/300 2026-03-22 14:31 by ColorlessPI
[考研] 303求调剂 +5 安忆灵 2026-03-22 6/300 2026-03-22 12:46 by 素颜倾城1988
[考研] 285求调剂 +6 ytter 2026-03-22 6/300 2026-03-22 12:09 by 星空星月
[基金申请] 山东省面上项目限额评审 +4 石瑞0426 2026-03-19 4/200 2026-03-22 08:50 by Wei_ren
[考研] 297求调剂 +3 喜欢还是不甘心 2026-03-20 3/150 2026-03-21 18:33 by 学员8dgXkO
[考研] 307求调剂 +3 余意卿 2026-03-18 3/150 2026-03-21 17:31 by ColorlessPI
[考研] 302求调剂 +12 呼呼呼。。。。 2026-03-17 12/600 2026-03-21 17:29 by ColorlessPI
[基金申请] 学校已经提交到NSFC,还能修改吗? 40+4 babangida 2026-03-19 9/450 2026-03-21 16:12 by babangida
[考研] 301求调剂 +10 yy要上岸呀 2026-03-17 10/500 2026-03-21 03:14 by JourneyLucky
[考研] 化学求调剂 +4 临泽境llllll 2026-03-17 5/250 2026-03-21 02:23 by JourneyLucky
[考研] 一志愿华中科技大学,080502,354分求调剂 +5 守候夕阳CF 2026-03-18 5/250 2026-03-21 01:06 by JourneyLucky
[考研] 304求调剂 +6 曼殊2266 2026-03-18 6/300 2026-03-21 00:32 by JourneyLucky
[考研] 295求调剂 +4 一志愿京区211 2026-03-18 6/300 2026-03-20 23:41 by JourneyLucky
[考研] 081700化工学硕调剂 +3 【1】 2026-03-16 3/150 2026-03-19 23:40 by edmund7
[考研] 085600材料与化工调剂 324分 +10 llllkkkhh 2026-03-18 12/600 2026-03-19 14:33 by llllkkkhh
[硕博家园] 湖北工业大学 生命科学与健康学院-课题组招收2026级食品/生物方向硕士 +3 1喜春8 2026-03-17 5/250 2026-03-17 17:18 by ber川cool子
[考研] 085601求调剂 +4 Du.11 2026-03-16 4/200 2026-03-17 17:08 by ruiyingmiao
[考研] 考研调剂 +3 淇ya_~ 2026-03-17 5/250 2026-03-17 09:25 by Winj1e
信息提示
请填处理意见