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 import copy
00036 from collections import deque
00037 from python_qt_binding.QtCore import Signal, Slot, QObject
00038
00039 import rospy
00040
00041 from diagnostic_msgs.msg import DiagnosticArray
00042
00043 class Timeline(QObject):
00044 """
00045 A class which represents the status history of diagnostics
00046 It can be queried for a past history of diagnostics, and paused
00047 """
00048 message_updated = Signal(DiagnosticArray)
00049 queue_updated = Signal(deque)
00050 pause_changed = Signal(bool)
00051
00052 def __init__(self, topic, topic_type, count=30):
00053 super(Timeline, self).__init__()
00054 self._queue = deque(maxlen=count)
00055 self._queue_copy = deque(maxlen=count)
00056 self._count = count
00057 self._current_index = -1
00058
00059
00060
00061
00062 self._paused_queue = None
00063
00064 self._have_messages = False
00065 self._last_message_time = 0
00066
00067 self._subscriber = rospy.Subscriber(topic, topic_type, self.callback,
00068 queue_size=10)
00069
00070 def shutdown(self):
00071 """
00072 Turn off this Timeline
00073 Internally, this just shuts down the subscriber
00074 """
00075 self._subscriber.unregister()
00076
00077 @Slot(bool)
00078 def set_paused(self, pause):
00079 """
00080 Slot, to be called to change the pause status of the timeline
00081
00082 This is generally intended to be connected to the status signal
00083 from a button or checkbox
00084 """
00085 if pause != self.paused:
00086 if pause:
00087 self._paused_queue = deque(self._queue, self._queue.maxlen)
00088 else:
00089 self._queue = self._paused_queue
00090 self._queue_copy = copy.deepcopy(self._paused_queue)
00091 self._paused_queue = None
00092
00093
00094 self._current_index = -1
00095 self.message_updated.emit(self._queue[self._current_index])
00096 self.pause_changed.emit(pause)
00097
00098 @property
00099 def paused(self):
00100 """ True if this timeline is paused """
00101 return self._paused_queue is not None
00102
00103 def callback(self, msg):
00104 """
00105 ROS Callback for new diagnostic messages
00106
00107 Puts new msg into the queue, and emits a signal to let listeners know
00108 that the timeline has been updated
00109
00110 If the timeline is paused, new messages are placed into a separate
00111 queue and swapped back in when the timeline is unpaused
00112
00113 :type msg: Either DiagnosticArray or DiagnosticsStatus. Can be
00114 determined by __init__'s arg "msg_callback".
00115 """
00116 self._have_messages = True
00117 self._last_message_time = rospy.get_time()
00118 if self.paused:
00119 self._paused_queue.append(msg)
00120 else:
00121 self._queue.append(msg)
00122 self._queue_copy = copy.deepcopy(self._queue)
00123 self.queue_updated.emit(self._queue_copy)
00124 self.message_updated.emit(msg)
00125
00126 @property
00127 def queue(self):
00128 return self._queue_copy
00129
00130 @property
00131 def has_messages(self):
00132 """
00133 True if this timeline has received any messages.
00134 False if no messages have been received yet
00135 """
00136 return self._have_messages
00137
00138 def data_age(self):
00139 """ Get the age (in seconds) of the most recent diagnostic message """
00140 current_time = rospy.get_time()
00141 time_diff = current_time - self._last_message_time
00142 return time_diff
00143
00144 @property
00145 def is_stale(self):
00146 """ True is this timeline is stale. """
00147 return self.data_age() > 10.0
00148
00149 def set_position(self, index):
00150 max_index = len(self._queue) - 1
00151 min_index = -len(self._queue)
00152 index = min(index, max_index)
00153 index = max(index, min_index)
00154 if index != self._current_index:
00155 self._current_index = index
00156 self.message_updated.emit(self._queue[index])
00157
00158 def get_position(self):
00159 index = self._current_index
00160 if index < 0:
00161 index = len(self._queue) + index
00162 return index
00163
00164 def __len__(self):
00165 return len(self._queue)
00166
00167 def __iter__(self):
00168 for msg in self._queue:
00169 yield msg
rqt_robot_monitor
Author(s): Austin Hendrix, Isaac Saito, Ze'ev Klapow, Kevin Watts, Josh Faust
autogenerated on Tue Sep 26 2017 02:44:21