_publisher.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 # -*- coding: utf-8 -*-
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)


diagnostic_updater
Author(s): Kevin Watts, Brice Rebsamen , Jeremy Leibs, Blaise Gassend
autogenerated on Tue Mar 26 2019 03:09:44