_publisher.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 # -*- coding: utf-8 -*-
34 
35 """ diagnostic_updater for Python.
36 @author Brice Rebsamen <brice [dot] rebsamen [gmail]>
37 """
38 
39 import rospy
40 import threading
41 from ._update_functions import *
42 
43 
45  """A class to facilitate making diagnostics for a topic using a
46  FrequencyStatus.
47 
48  The word "headerless" in the class name refers to the fact that it is
49  mainly designed for use with messages that do not have a header, and
50  that cannot therefore be checked using a TimeStampStatus.
51  """
52 
53  def __init__(self, name, diag, freq):
54  """Constructs a HeaderlessTopicDiagnostic.
55 
56  @param name The name of the topic that is being diagnosed.
57 
58  @param diag The diagnostic_updater that the CompositeDiagnosticTask
59  should add itself to.
60 
61  @param freq The parameters for the FrequencyStatus class that will be
62  computing statistics.
63  """
64  CompositeDiagnosticTask.__init__(self, name + " topic status")
65  self.diag = diag
66  self.freq = FrequencyStatus(freq)
67  self.addTask(self.freq)
68  self.diag.add(self)
69 
70  def tick(self):
71  """Signals that a publication has occurred."""
72  self.freq.tick()
73 
74  def clear_window(self):
75  """Clears the frequency statistics."""
76  self.freq.clear()
77 
78 
80  """A class to facilitate making diagnostics for a topic using a
81  FrequencyStatus and TimeStampStatus.
82  """
83 
84  def __init__(self, name, diag, freq, stamp):
85  """Constructs a TopicDiagnostic.
86 
87  @param name The name of the topic that is being diagnosed.
88 
89  @param diag The diagnostic_updater that the CompositeDiagnosticTask
90  should add itself to.
91 
92  @param freq The parameters for the FrequencyStatus class that will be
93  computing statistics.
94 
95  @param stamp The parameters for the TimeStampStatus class that will be
96  computing statistics.
97  """
98 
99  HeaderlessTopicDiagnostic.__init__(self, name, diag, freq)
100  self.stamp = TimeStampStatus(stamp)
101  self.addTask(self.stamp)
102 
103  def tick(self, stamp):
104  """Collects statistics and publishes the message.
105 
106  @param stamp Timestamp to use for interval computation by the
107  TimeStampStatus class.
108  """
109  self.stamp.tick(stamp)
110  HeaderlessTopicDiagnostic.tick(self)
111 
112 
114  """A TopicDiagnostic combined with a ros::Publisher.
115 
116  For a standard ros::Publisher, this class allows the ros::Publisher and
117  the TopicDiagnostic to be combined for added convenience.
118  """
119 
120  def __init__(self, pub, diag, freq, stamp):
121  """Constructs a DiagnosedPublisher.
122 
123  @param pub The publisher on which statistics are being collected.
124 
125  @param diag The diagnostic_updater that the CompositeDiagnosticTask
126  should add itself to.
127 
128  @param freq The parameters for the FrequencyStatus class that will be
129  computing statistics.
130 
131  @param stamp The parameters for the TimeStampStatus class that will be
132  computing statistics.
133  """
134  TopicDiagnostic.__init__(self, pub.name, diag, freq, stamp)
135  self.publisher = pub
136 
137  def publish(self, message):
138  """Collects statistics and publishes the message.
139 
140  The timestamp to be used by the TimeStampStatus class will be
141  extracted from message.header.stamp.
142  """
143  self.tick(message.header.stamp)
144  self.publisher.publish(message)
def __init__(self, pub, diag, freq, stamp)
Definition: _publisher.py:120
def __init__(self, name, diag, freq, stamp)
Definition: _publisher.py:84


diagnostic_updater
Author(s): Kevin Watts, Brice Rebsamen , Jeremy Leibs, Blaise Gassend
autogenerated on Mon Feb 28 2022 22:18:16