heartbeat_master.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 from jsk_network_tools.msg import Heartbeat, HeartbeatResponse
4 from std_msgs.msg import Float32
5 
6 class Master():
7  def __init__(self):
8  rospy.init_node('heartbeat_master')
9  self.rate = rospy.get_param("~rate", 1.0)
10  self.pub_request = rospy.Publisher("heartbeat/request", Heartbeat)
11  self.pub_upload_time = rospy.Publisher("heartbeat/upload_time", Float32)
12  self.pub_download_time = rospy.Publisher("heartbeat/download_time", Float32)
13  self.pub_round_time = rospy.Publisher("heartbeat/round_time", Float32)
14  rospy.Subscriber("heartbeat/response", HeartbeatResponse, self.callback)
15 
16  while not rospy.is_shutdown():
17  msg = Heartbeat()
18  msg.rate = self.rate
19  msg.header.stamp = rospy.Time.now()
20  self.pub_request.publish(msg)
21  rospy.sleep(1.0/self.rate)
22 
23  def callback(self, data):
24  now = rospy.Time.now()
25  upload_time = data.header.stamp - data.heartbeat.header.stamp
26  download_time = now - data.header.stamp
27  round_time = now - data.heartbeat.header.stamp
28 
29  rospy.loginfo("upload_time: %f" % (upload_time.to_sec()))
30  rospy.loginfo("download_time: %f" % (download_time.to_sec()))
31  rospy.loginfo("round_time: %f" % (round_time.to_sec()))
32 
33  #publish time
34  upload_time_msg = Float32(upload_time.to_sec())
35  download_time_msg = Float32(download_time.to_sec())
36  round_time_msg = Float32(round_time.to_sec())
37 
38  self.pub_upload_time.publish(upload_time_msg)
39  self.pub_download_time.publish(download_time_msg)
40  self.pub_round_time.publish(round_time_msg)
41 
42 if __name__ == '__main__':
43  Master()
def callback(self, data)


jsk_network_tools
Author(s): Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:07