Go to the documentation of this file.00001
00002 import roslib
00003 roslib.load_manifest('jsk_network_tools')
00004 import rospy
00005 from heartbeat.msg import Heartbeat, HeartbeatResponse
00006 from std_msgs.msg import Float32
00007
00008 class Master():
00009 def __init__(self):
00010 rospy.init_node('heartbeat_master')
00011 self.pub_request = rospy.Publisher("heartbeat/request", Heartbeat)
00012 self.pub_round_time = rospy.Publisher("heartbeat/round", Float32)
00013 rospy.Subscriber("heartbeat/response", HeartbeatResponse, self.callback)
00014 self.rate = 1.0
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
00030 rospy.loginfo("upload_time: %f" % (upload_time.to_sec()))
00031 rospy.loginfo("download_time: %f" % (download_time.to_sec()))
00032 rospy.loginfo("round_time: %f" % (round_time.to_sec()))
00033 msg = Float32(round_time.to_sec())
00034 self.pub_round_time.publish(msg)
00035
00036
00037
00038
00039
00040 if __name__ == '__main__':
00041 Master()