#!/usr/bin/env python3
#coding = 'utf-8'
import rospy
import datetime
import time
from ros_mqtt_communication.msg import data
def velocity_publisher():
# ROS节点初始化
rospy.init_node('data_publisher', anonymous=True)
# 创建一个Publisher,发布名为/data_info的topic,消息类型为learning_topic::data,队列长度10
data_info_pub = rospy.Publisher('/data_info', data, queue_size=10)
#设置循环的频率
rate = rospy.Rate(1)
while not rospy.is_shutdown():
# 初始化learning_topic::data类型的消息
data_msg = data()
data_msg.time= time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
data_msg.location = 1;
data_msg.cage = 1;
data_msg.broiler_state= 1;
data_msg.number = 1;
# 发布消息
data_info_pub.publish(data_msg)
rospy.loginfo("Publsh data message[%s]",
data_msg)
# 按照循环频率延时
rate.sleep()
if __name__ == '__main__':
try:
velocity_publisher()
except rospy.ROSInterruptException:
pass
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42