util_robot_monitor.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 # Author: Isaac Saito, Ze'ev Klapow, Austin Hendrix
34 
35 from diagnostic_msgs.msg import DiagnosticStatus
36 from python_qt_binding.QtGui import QColor, QIcon
37 import rospy
38 
39 # TODO: Utils and common configs are mixed in this class.
40 
41 # Instantiating icons that show the device status.
42 _ERR_ICON = QIcon.fromTheme('dialog-error')
43 _WARN_ICON = QIcon.fromTheme('dialog-warning')
44 _OK_ICON = QIcon.fromTheme('emblem-default')
45 # Added following this QA thread http://goo.gl/83tVZ
46 _STALE_ICON = QIcon.fromTheme('dialog-question')
47 
48 _LEVEL_TO_ICON = {0: _OK_ICON, 1: _WARN_ICON, 2: _ERR_ICON, 3: _STALE_ICON}
49 
50 _LEVEL_TO_COLOR = {0: QColor(85, 178, 76), # green
51  1: QColor(222, 213, 17), # yellow
52  2: QColor(178, 23, 46), # red
53  3: QColor(40, 23, 176) # blue
54  }
55 
56 _LEVEL_TO_TEXT = { 0: "OK", 1: "WARNING", 2: "ERROR", 3: "STALE" }
57 
58 def level_to_icon(level):
59  if level in _LEVEL_TO_ICON:
60  return _LEVEL_TO_ICON[level]
61  else:
62  return _ERR_ICON
63 
64 def level_to_color(level):
65  if level in _LEVEL_TO_COLOR:
66  return _LEVEL_TO_COLOR[level]
67  else:
68  return _LEVEL_TO_COLOR[2]
69 
70 def level_to_text(level):
71  if level in _LEVEL_TO_TEXT:
72  return _LEVEL_TO_TEXT[level]
73  else:
74  return "UNKNOWN(%d)" % ( level )
75 
76 def get_resource_name(status_name):
77  """
78  Get resource name from path
79 
80  :param: status_name is a string that may consists of status names that
81  are delimited by slash.
82  :rtype: str
83  """
84  name = status_name.split('/')[-1]
85  rospy.logdebug(' get_resource_name name = %s', name)
86  return name
87 
89  """
90  Get the overall (worst) color for a DiagnosticArray
91  :param msg: DiagnosticArray
92  """
93  level = 0
94  min_level = 255
95 
96  lookup = {}
97  for status in msg.status:
98  if (status.level > level):
99  level = status.level
100  if (status.level < min_level):
101  min_level = status.level
102 
103  # Stale items should be reported as errors unless all stale
104  if (level > 2 and min_level <= 2):
105  level = 2
106 
107  rospy.logdebug(' get_color_for_message color lv=%d', level)
108  return level_to_color(level)
109 
110 def get_status_by_name(msg, name):
111  for status in msg.status:
112  if status.name == name:
113  return status
114  return None


rqt_robot_monitor
Author(s): Austin Hendrix, Isaac Saito, Ze'ev Klapow, Kevin Watts, Josh Faust
autogenerated on Thu Jun 4 2020 03:46:53