fake_diagnostics.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import rospy
00005 from diagnostic_msgs.msg import DiagnosticArray,DiagnosticStatus
00006 
00007 global last_received_
00008 
00009 def callback(msg):
00010         global last_received_
00011         last_received_ = rospy.Time.now()
00012 
00013 if __name__ == "__main__":
00014         rospy.init_node('fake_diagnostics')
00015 
00016         if not rospy.has_param("~diagnostics_name"):
00017                 rospy.logerr("parameter diagnostics_name not found, shutting down " + rospy.get_name())
00018                 sys.exit()
00019         diagnostics_name = rospy.get_param("~diagnostics_name")
00020 
00021         if not rospy.has_param("~topic_name"):
00022                 rospy.logwarn("parameter topic_name not found. Not listening to any topic for " + rospy.get_name())
00023         topic_name = rospy.get_param("~topic_name",None)
00024 
00025         global last_received_
00026         last_received_ = rospy.Time.now()
00027 
00028         # subscribe to topics
00029         if topic_name != None:
00030                 rospy.Subscriber(topic_name, rospy.AnyMsg, callback)
00031 
00032         pub_diagnostics = rospy.Publisher('/diagnostics', DiagnosticArray, queue_size=1)
00033 
00034         rospy.loginfo("fake diagnostics for %s running listening to %s",diagnostics_name, topic_name)
00035         rate = rospy.Rate(1)
00036         while not rospy.is_shutdown():
00037                 # if no topic_name is set, we assume that we received a
00038                 if topic_name == None:
00039                         last_received_ = rospy.Time.now()
00040 
00041                 # only publish ok if message received recently
00042                 if rospy.Time.now() - last_received_ <= rospy.Duration(10.0):
00043                         status = DiagnosticStatus()
00044                         status.level = 0
00045                         status.name = diagnostics_name
00046                         status.message = diagnostics_name + " running"
00047                         diagnostics = DiagnosticArray()
00048                         diagnostics.header.stamp = rospy.Time.now()
00049                         diagnostics.status.append(status)
00050                 else:
00051                         status = DiagnosticStatus()
00052                         status.level = 2
00053                         status.name = diagnostics_name
00054                         status.message = "no message received on " + topic_name
00055                         diagnostics = DiagnosticArray()
00056                         diagnostics.header.stamp = rospy.Time.now()
00057                         diagnostics.status.append(status)
00058                 pub_diagnostics.publish(diagnostics)
00059                 try:
00060                         rate.sleep()
00061                 except rospy.ROSInterruptException as e:
00062                         #print "ROSInterruptException"
00063                         pass
00064 


cob_controller_configuration_gazebo
Author(s): Florian Weisshardt
autogenerated on Wed Dec 14 2016 04:18:43