util_robot_monitor.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 # Author: Isaac Saito, Ze'ev Klapow, Austin Hendrix
00034 
00035 from diagnostic_msgs.msg import DiagnosticStatus
00036 from python_qt_binding.QtGui import QColor, QIcon
00037 import rospy
00038 
00039 # TODO: Utils and common configs are mixed in this class.
00040 
00041 # Instantiating icons that show the device status.
00042 _ERR_ICON = QIcon.fromTheme('dialog-error')
00043 _WARN_ICON = QIcon.fromTheme('dialog-warning')
00044 _OK_ICON = QIcon.fromTheme('emblem-default')
00045 # Added following this QA thread http://goo.gl/83tVZ
00046 _STALE_ICON = QIcon.fromTheme('dialog-question')
00047 
00048 _LEVEL_TO_ICON = {0: _OK_ICON, 1: _WARN_ICON, 2: _ERR_ICON, 3: _STALE_ICON}
00049 
00050 _LEVEL_TO_COLOR = {0: QColor(85, 178, 76),  # green
00051                    1: QColor(222, 213, 17), # yellow
00052                    2: QColor(178, 23, 46),  # red
00053                    3: QColor(40, 23, 176)   # blue
00054                    }
00055 
00056 _LEVEL_TO_TEXT = { 0: "OK", 1: "WARNING", 2: "ERROR", 3: "STALE" }
00057 
00058 def level_to_icon(level):
00059     if level in _LEVEL_TO_ICON:
00060         return _LEVEL_TO_ICON[level]
00061     else:
00062         return _ERR_ICON
00063 
00064 def level_to_color(level):
00065     if level in _LEVEL_TO_COLOR:
00066         return _LEVEL_TO_COLOR[level]
00067     else:
00068         return _LEVEL_TO_COLOR[2]
00069 
00070 def level_to_text(level):
00071     if level in _LEVEL_TO_TEXT:
00072         return _LEVEL_TO_TEXT[level]
00073     else:
00074         return "UNKNOWN(%d)" % ( level )
00075 
00076 def get_resource_name(status_name):
00077     """
00078     Get resource name from path
00079 
00080     :param: status_name is a string that may consists of status names that
00081             are delimited by slash.
00082     :rtype: str
00083     """
00084     name = status_name.split('/')[-1]
00085     rospy.logdebug(' get_resource_name name = %s', name)
00086     return name
00087 
00088 def get_color_for_message(msg):
00089     """
00090     Get the overall (worst) color for a DiagnosticArray
00091     :param msg: DiagnosticArray
00092     """
00093     level = 0
00094     min_level = 255
00095 
00096     lookup = {}
00097     for status in msg.status:
00098         if (status.level > level):
00099             level = status.level
00100         if (status.level < min_level):
00101             min_level = status.level
00102 
00103     # Stale items should be reported as errors unless all stale
00104     if (level > 2 and min_level <= 2):
00105         level = 2
00106 
00107     rospy.logdebug(' get_color_for_message color lv=%d', level)
00108     return level_to_color(level)
00109 
00110 def get_status_by_name(msg, name):
00111     for status in msg.status:
00112         if status.name == name:
00113             return status
00114     return None


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