首页 技术 正文
技术 2022年11月18日
0 收藏 744 点赞 2,848 浏览 1508 个字

发布者

#!/usr/bin/env python2.
# -*- coding: utf- -*-
import rospy
from hdw_driver.msg import update_file_msgdef talker():
pub = rospy.Publisher('hdw_update',update_file_msg, queue_size=)
rospy.init_node('talker',anonymous=True)
#rate = rospy.Rate() # 10hz mi = update_file_msg()
mi.motor_board_file_name="/opt/xx/motor_board_file_name.rb"
mi.power_board_file_name="/opt/xx/power_board_file_name.rb"
mi.sensor_board_file_name="/opt/xx/sensor_board_file_name.rb"
mi.imu_board_file_name="/opt/xx/imu_board_file_name.rb" mi.update_motor_board=True
mi.update_power_board=True
mi.update_sensor_board=True
mi.update_imu_board=True
pub.publish(mi)
rospy.signal_shutdown("closed!")if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass

订阅者:

#!/usr/bin/env python2.
# -*- coding: utf- -*- import rospy
from hdw_driver.msg import update_file_msgdef callback(data):
rospy.loginfo(data)
#回调函数 收到的参数.data是通信的数据 默认通过这样的 def callback(data) 取出data.data数据def listener(): # In ROS, nodes are uniquely named. If two nodes with the same
# node are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
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()
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781