Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus
00020
00021 class FakeDiagnostics():
00022 def __init__(self, options):
00023 self._options = options
00024 self._last_publish_time = 0
00025 self._fake_diag_pub = rospy.Publisher('/diagnostics', DiagnosticArray, queue_size=1)
00026 rospy.Timer(rospy.Duration(1.0), self.publish_stats)
00027
00028 def publish_stats(self, event):
00029 msg = DiagnosticArray()
00030 msg.header.stamp = rospy.get_rostime()
00031
00032 hostname_list = self._options.diag_hostnames.split(", ")
00033 for hostname in hostname_list:
00034 status = DiagnosticStatus()
00035 status.name = hostname
00036 status.level = DiagnosticStatus.OK
00037 status.message = "fake diagnostics"
00038 status.hardware_id = hostname
00039 msg.status.append(status)
00040
00041 self._fake_diag_pub.publish(msg)
00042
00043 if __name__ == '__main__':
00044
00045 import optparse
00046 parser = optparse.OptionParser(usage="usage: fake_diagnostics.py [--diag-hostnames=hostname1, hostname2, ...]")
00047 parser.add_option("--diag-hostnames", dest="diag_hostnames",
00048 help="Fake Diagnostics")
00049 options, args = parser.parse_args(rospy.myargv())
00050
00051 rospy.init_node('fake_diagnostics')
00052
00053 fake_diagnostics = FakeDiagnostics(options)
00054
00055 rospy.spin()