fake_diagnostics.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import rospy
19 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus
20 
22  def __init__(self, options):
23  self._options = options
25  self._fake_diag_pub = rospy.Publisher('/diagnostics', DiagnosticArray, queue_size=1)
26  rospy.Timer(rospy.Duration(1.0), self.publish_stats)
27 
28  def publish_stats(self, event):
29  msg = DiagnosticArray()
30  msg.header.stamp = rospy.get_rostime()
31  # Add all fake
32  hostname_list = self._options.diag_hostnames.split(", ")
33  for hostname in hostname_list:
34  status = DiagnosticStatus()
35  status.name = hostname
36  status.level = DiagnosticStatus.OK
37  status.message = "fake diagnostics"
38  status.hardware_id = hostname
39  msg.status.append(status)
40 
41  self._fake_diag_pub.publish(msg)
42 
43 if __name__ == '__main__':
44 
45  import optparse
46  parser = optparse.OptionParser(usage="usage: fake_diagnostics.py [--diag-hostnames=hostname1, hostname2, ...]")
47  parser.add_option("--diag-hostnames", dest="diag_hostnames",
48  help="Fake Diagnostics")
49  options, args = parser.parse_args(rospy.myargv())
50 
51  rospy.init_node('fake_diagnostics')
52 
53  fake_diagnostics = FakeDiagnostics(options)
54 
55  rospy.spin()


cob_helper_tools
Author(s): Felix Messmer
autogenerated on Wed Apr 7 2021 03:03:09