fake_diagnostics.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
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         # Add all fake
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()


cob_helper_tools
Author(s): Felix Messmer
autogenerated on Sun Jun 9 2019 20:20:17