monitor_dash_widget.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 import rospy
34 from diagnostic_msgs.msg import DiagnosticStatus
35 from python_qt_binding.QtCore import QMutex, QMutexLocker, QSize, QTimer, Signal
36 from rqt_robot_monitor.robot_monitor import RobotMonitorWidget
37 from .icon_tool_button import IconToolButton
38 
39 
41  """
42  A widget which brings up the rqt_robot_monitor.
43 
44  Times out after certain period of time (set as 5 sec as of Apr 2013)
45  without receiving diagnostics msg ('/diagnostics_toplevel_state' of
46  DiagnosticStatus type), status becomes as 'stale'.
47 
48  :param context: The plugin context to create the monitor in.
49  :type context: qt_gui.plugin_context.PluginContext
50  """
51  _msg_trigger = Signal()
52 
53  def __init__(self, context, icon_paths=[]):
54  self._graveyard = []
55  ok_icon = ['bg-green.svg', 'ic-diagnostics.svg']
56  warn_icon = ['bg-yellow.svg', 'ic-diagnostics.svg',
57  'ol-warn-badge.svg']
58  err_icon = ['bg-red.svg', 'ic-diagnostics.svg', 'ol-err-badge.svg']
59  stale_icon = ['bg-grey.svg', 'ic-diagnostics.svg',
60  'ol-stale-badge.svg']
61 
62  icons = [ok_icon, warn_icon, err_icon, stale_icon]
63 
64  super(MonitorDashWidget, self).__init__('MonitorWidget', icons,
65  icon_paths=icon_paths)
66 
67  self.setFixedSize(self._icons[0].actualSize(QSize(50, 30)))
68 
69  self._monitor = None
70  self._close_mutex = QMutex()
71  self._show_mutex = QMutex()
72 
73  self._last_update = rospy.Time.now()
74 
75  self.context = context
76  self.clicked.connect(self._show_monitor)
77 
78  self._monitor_shown = False
79  self.setToolTip('Diagnostics')
80 
81  self._diagnostics_toplevel_state_sub = rospy.Subscriber(
82  'diagnostics_toplevel_state',
83  DiagnosticStatus, self.toplevel_state_callback)
84  self._top_level_state = -1
85  self._stall_timer = QTimer()
86  self._stall_timer.timeout.connect(self._stalled)
87  self._stalled()
88  self._plugin_settings = None
89  self._instance_settings = None
90  self._msg_trigger.connect(self._handle_msg_trigger)
91 
92  def toplevel_state_callback(self, msg):
93  self._is_stale = False
94  self._msg_trigger.emit()
95 
96  if self._top_level_state != msg.level:
97  if (msg.level >= 2):
98  self.update_state(2)
99  self.setToolTip("Diagnostics: Error")
100  elif (msg.level == 1):
101  self.update_state(1)
102  self.setToolTip("Diagnostics: Warning")
103  else:
104  self.update_state(0)
105  self.setToolTip("Diagnostics: OK")
106  self._top_level_state = msg.level
107 
109  self._stall_timer.start(5000)
110 
111  def _stalled(self):
112  self._stall_timer.stop()
113  self._is_stale = True
114  self.update_state(3)
115  self._top_level_state = 3
116  self.setToolTip("Diagnostics: Stale\nNo message received on "
117  "/diagnostics_agg in the last 5 seconds")
118 
119  def _show_monitor(self):
120  with QMutexLocker(self._show_mutex):
121  try:
122  if self._monitor_shown:
123  self.context.remove_widget(self._monitor)
124  self._monitor_close()
125  self._monitor_shown = False
126  else:
127  self._monitor = RobotMonitorWidget(self.context,
128  '/diagnostics_agg')
129  if self._plugin_settings:
131  self._instance_settings)
132  self.context.add_widget(self._monitor)
133  self._monitor_shown = True
134  except Exception:
135  if self._monitor_shown == False:
136  raise
137  #TODO: when closeEvents is available fix this hack
138  # (It ensures the button will toggle correctly)
139  self._monitor_shown = False
140  self._show_monitor()
141 
142  def _monitor_close(self):
143  if self._monitor_shown:
144  with QMutexLocker(self._close_mutex):
145  if self._plugin_settings:
147  self._instance_settings)
148  self._monitor.shutdown()
149  self._monitor.close()
150  self._graveyard.append(self._monitor)
151  self._monitor = None
152 
153  def shutdown_widget(self):
154  self._stall_timer.stop()
155  if self._monitor:
156  self._monitor.shutdown()
157  self._diagnostics_toplevel_state_sub.unregister()
158 
159  def save_settings(self, plugin_settings, instance_settings):
160  if self._monitor_shown:
162  self._instance_settings)
163 
164  def restore_settings(self, plugin_settings, instance_settings):
165  self._plugin_settings = plugin_settings
166  self._instance_settings = instance_settings
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.__init__
def __init__(self, context, icon_paths=[])
Definition: monitor_dash_widget.py:53
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._monitor_shown
_monitor_shown
Definition: monitor_dash_widget.py:78
rqt_robot_monitor::robot_monitor
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._msg_trigger
_msg_trigger
Definition: monitor_dash_widget.py:51
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._last_update
_last_update
Definition: monitor_dash_widget.py:73
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.shutdown_widget
def shutdown_widget(self)
Definition: monitor_dash_widget.py:153
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._diagnostics_toplevel_state_sub
_diagnostics_toplevel_state_sub
Definition: monitor_dash_widget.py:81
rqt_robot_monitor::robot_monitor::RobotMonitorWidget
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._stall_timer
_stall_timer
Definition: monitor_dash_widget.py:85
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._top_level_state
_top_level_state
Definition: monitor_dash_widget.py:84
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._is_stale
_is_stale
Definition: monitor_dash_widget.py:93
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._monitor
_monitor
Definition: monitor_dash_widget.py:69
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._handle_msg_trigger
def _handle_msg_trigger(self)
Definition: monitor_dash_widget.py:108
rqt_robot_dashboard.icon_tool_button.IconToolButton.update_state
def update_state(self, state)
Definition: icon_tool_button.py:92
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._stalled
def _stalled(self)
Definition: monitor_dash_widget.py:111
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._show_mutex
_show_mutex
Definition: monitor_dash_widget.py:71
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.save_settings
def save_settings(self, plugin_settings, instance_settings)
Definition: monitor_dash_widget.py:159
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._monitor_close
def _monitor_close(self)
Definition: monitor_dash_widget.py:142
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._show_monitor
def _show_monitor(self)
Definition: monitor_dash_widget.py:119
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget
Definition: monitor_dash_widget.py:40
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._instance_settings
_instance_settings
Definition: monitor_dash_widget.py:89
rqt_robot_dashboard.icon_tool_button.IconToolButton._icons
_icons
Definition: icon_tool_button.py:84
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._graveyard
_graveyard
Definition: monitor_dash_widget.py:54
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.context
context
Definition: monitor_dash_widget.py:75
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._plugin_settings
_plugin_settings
Definition: monitor_dash_widget.py:88
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget._close_mutex
_close_mutex
Definition: monitor_dash_widget.py:70
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.toplevel_state_callback
def toplevel_state_callback(self, msg)
Definition: monitor_dash_widget.py:92
rqt_robot_dashboard.monitor_dash_widget.MonitorDashWidget.restore_settings
def restore_settings(self, plugin_settings, instance_settings)
Definition: monitor_dash_widget.py:164
rqt_robot_dashboard.icon_tool_button.IconToolButton
Definition: icon_tool_button.py:42


rqt_robot_dashboard
Author(s): Ze'ev Klapow
autogenerated on Wed Mar 2 2022 00:58:48