3 from jsk_network_tools.msg
import Heartbeat, HeartbeatResponse
4 from std_msgs.msg
import Float32
8 rospy.init_node(
'heartbeat_master')
9 self.
rate = rospy.get_param(
"~rate", 1.0)
10 self.
pub_request = rospy.Publisher(
"heartbeat/request", Heartbeat)
14 rospy.Subscriber(
"heartbeat/response", HeartbeatResponse, self.
callback)
16 while not rospy.is_shutdown():
19 msg.header.stamp = rospy.Time.now()
20 self.pub_request.publish(msg)
21 rospy.sleep(1.0/self.
rate)
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
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()))
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())
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)
42 if __name__ ==
'__main__':