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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 """ diagnostic_updater for Python.
00036 @author Brice Rebsamen <brice [dot] rebsamen [gmail]>
00037 """
00038
00039 import rospy
00040 import threading
00041 from ._update_functions import *
00042
00043
00044 class HeaderlessTopicDiagnostic(CompositeDiagnosticTask):
00045 """A class to facilitate making diagnostics for a topic using a
00046 FrequencyStatus.
00047
00048 The word "headerless" in the class name refers to the fact that it is
00049 mainly designed for use with messages that do not have a header, and
00050 that cannot therefore be checked using a TimeStampStatus.
00051 """
00052
00053 def __init__(self, name, diag, freq):
00054 """Constructs a HeaderlessTopicDiagnostic.
00055
00056 @param name The name of the topic that is being diagnosed.
00057
00058 @param diag The diagnostic_updater that the CompositeDiagnosticTask
00059 should add itself to.
00060
00061 @param freq The parameters for the FrequencyStatus class that will be
00062 computing statistics.
00063 """
00064 CompositeDiagnosticTask.__init__(self, name + " topic status")
00065 self.diag = diag
00066 self.freq = FrequencyStatus(freq)
00067 self.addTask(self.freq)
00068 self.diag.add(self)
00069
00070 def tick(self):
00071 """Signals that a publication has occurred."""
00072 self.freq.tick()
00073
00074 def clear_window(self):
00075 """Clears the frequency statistics."""
00076 self.freq.clear()
00077
00078
00079 class TopicDiagnostic(HeaderlessTopicDiagnostic):
00080 """A class to facilitate making diagnostics for a topic using a
00081 FrequencyStatus and TimeStampStatus.
00082 """
00083
00084 def __init__(self, name, diag, freq, stamp):
00085 """Constructs a TopicDiagnostic.
00086
00087 @param name The name of the topic that is being diagnosed.
00088
00089 @param diag The diagnostic_updater that the CompositeDiagnosticTask
00090 should add itself to.
00091
00092 @param freq The parameters for the FrequencyStatus class that will be
00093 computing statistics.
00094
00095 @param stamp The parameters for the TimeStampStatus class that will be
00096 computing statistics.
00097 """
00098
00099 HeaderlessTopicDiagnostic.__init__(self, name, diag, freq)
00100 self.stamp = TimeStampStatus(stamp)
00101 self.addTask(self.stamp)
00102
00103 def tick(self, stamp):
00104 """Collects statistics and publishes the message.
00105
00106 @param stamp Timestamp to use for interval computation by the
00107 TimeStampStatus class.
00108 """
00109 self.stamp.tick(stamp)
00110 HeaderlessTopicDiagnostic.tick(self)
00111
00112
00113 class DiagnosedPublisher(TopicDiagnostic):
00114 """A TopicDiagnostic combined with a ros::Publisher.
00115
00116 For a standard ros::Publisher, this class allows the ros::Publisher and
00117 the TopicDiagnostic to be combined for added convenience.
00118 """
00119
00120 def __init__(self, pub, diag, freq, stamp):
00121 """Constructs a DiagnosedPublisher.
00122
00123 @param pub The publisher on which statistics are being collected.
00124
00125 @param diag The diagnostic_updater that the CompositeDiagnosticTask
00126 should add itself to.
00127
00128 @param freq The parameters for the FrequencyStatus class that will be
00129 computing statistics.
00130
00131 @param stamp The parameters for the TimeStampStatus class that will be
00132 computing statistics.
00133 """
00134 TopicDiagnostic.__init__(self, pub.name, diag, freq, stamp)
00135 self.publisher = pub
00136
00137 def publish(self, message):
00138 """Collects statistics and publishes the message.
00139
00140 The timestamp to be used by the TimeStampStatus class will be
00141 extracted from message.header.stamp.
00142 """
00143 self.tick(message.header.stamp)
00144 self.publisher.publish(message)