博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ros topic 发布一次可能会接收不到数据
阅读量:4647 次
发布时间:2019-06-09

本文共 1800 字,大约阅读时间需要 6 分钟。

 

rostopic pub -1 /hdw_update hdw_driver/update_file_msg  A B C D 1 1 1 1系统提示:publishing and latching message for 3.0 seconds

可以看到每一个发布都需要大约3s,所以在发布前要等待3s以上。

 

发布

#!/usr/bin/env python2.7# -*- coding: utf-8 -*-  import rospyfrom hdw_driver.msg import update_file_msgimport timedef talker():    pub = rospy.Publisher('hdw_update',update_file_msg, queue_size=1)    rospy.init_node('talker',anonymous=True)    rate = rospy.Rate(10) # 10hz    mi = update_file_msg()    mi.motor_board_file_name="/opt/xx/update_bin/F407.bin"    mi.power_board_file_name="/opt/xx/update_bin/Project.bin"    mi.sensor_board_file_name="/opt/xx/update_bin/F103.bin"    mi.imu_board_file_name="/opt/xx/update_bin/F103.bin"    mi.update_motor_board=True    mi.update_power_board=True    mi.update_sensor_board=True    mi.update_imu_board=True    i=0    while(1):        time.sleep(3.5)        pub.publish(mi)        i+=1        if(i==1):            break    rospy.signal_shutdown("closed!")if __name__ == '__main__':    try:        talker()    except rospy.ROSInterruptException:        pass

 

订阅:

#!/usr/bin/env python2.7# -*- coding: utf-8 -*-  import rospyfrom hdw_driver.msg import update_file_msgdef callback(data):    rospy.loginfo(data)    #回调函数 收到的参数.data是通信的数据 默认通过这样的 def callback(data) 取出data.data数据    def listener():    rospy.init_node('listener', anonymous=True)        #启动节点同时为节点命名, 若anoymous为真则节点会自动补充名字,实际名字以 listener_322345等表示    #若为假,则系统不会补充名字,采用用户命名。但是一次只能有一个同名节点,若后面有一个相同listener    #名字的节点则后面的节点启动会注销前面的相同节点名。    rospy.Subscriber("hdw_update", update_file_msg, callback)        #启动订阅,订阅主题,及标准字符串格式,同时调用回调函数,当有数据时调用函数,取出数据    # spin() simply keeps python from exiting until this node is stopped    #循环程序    rospy.spin()if __name__ == '__main__':    listener()

 

转载于:https://www.cnblogs.com/sea-stream/p/10531463.html

你可能感兴趣的文章
nodejs pm2使用
查看>>
cocos2d-x 3.10 PageView BUG
查看>>
装饰器的基本使用:用户登录
查看>>
CSS选择器总结
查看>>
mysql中sql语句
查看>>
head/tail实现
查看>>
sql语句的各种模糊查询语句
查看>>
vlc 学习网
查看>>
Python20-Day05
查看>>
Real World Haskell 第七章 I/O
查看>>
C#操作OFFICE一(EXCEL)
查看>>
【js操作url参数】获取指定url参数值、取指定url参数并转为json对象
查看>>
移动端单屏解决方案
查看>>
web渗透测试基本步骤
查看>>
使用Struts2标签遍历集合
查看>>
angular.isUndefined()
查看>>
第一次软件工程作业(改进版)
查看>>
网络流24题-飞行员配对方案问题
查看>>
Jenkins 2.16.3默认没有Launch agent via Java Web Start,如何配置使用
查看>>
引入css的四种方式
查看>>