heartbeat_master.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import rospy
00003 from jsk_network_tools.msg import Heartbeat, HeartbeatResponse
00004 from std_msgs.msg import Float32
00005 
00006 class Master():
00007     def __init__(self):
00008         rospy.init_node('heartbeat_master')
00009         self.rate = rospy.get_param("~rate", 1.0)
00010         self.pub_request = rospy.Publisher("heartbeat/request", Heartbeat)
00011         self.pub_upload_time = rospy.Publisher("heartbeat/upload_time", Float32)
00012         self.pub_download_time = rospy.Publisher("heartbeat/download_time", Float32)
00013         self.pub_round_time = rospy.Publisher("heartbeat/round_time", Float32)
00014         rospy.Subscriber("heartbeat/response", HeartbeatResponse, self.callback)
00015 
00016         while not rospy.is_shutdown():
00017             msg = Heartbeat()
00018             msg.rate = self.rate
00019             msg.header.stamp = rospy.Time.now()
00020             self.pub_request.publish(msg)
00021             rospy.sleep(1.0/self.rate)
00022 
00023     def callback(self, data):
00024         now = rospy.Time.now()
00025         upload_time = data.header.stamp - data.heartbeat.header.stamp
00026         download_time = now - data.header.stamp
00027         round_time = now - data.heartbeat.header.stamp
00028 
00029         rospy.loginfo("upload_time: %f" % (upload_time.to_sec()))
00030         rospy.loginfo("download_time: %f" % (download_time.to_sec()))
00031         rospy.loginfo("round_time: %f" % (round_time.to_sec()))
00032 
00033         #publish time
00034         upload_time_msg = Float32(upload_time.to_sec())
00035         download_time_msg = Float32(download_time.to_sec())
00036         round_time_msg = Float32(round_time.to_sec())
00037 
00038         self.pub_upload_time.publish(upload_time_msg)
00039         self.pub_download_time.publish(download_time_msg)
00040         self.pub_round_time.publish(round_time_msg)
00041 
00042 if __name__ == '__main__':
00043     Master()


jsk_network_tools
Author(s): Yusuke Furuta
autogenerated on Sun Jan 25 2015 00:30:33