_diagnostic_status_wrapper.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 """ diagnostic_updater for Python.
00004 @author Brice Rebsamen <brice [dot] rebsamen [gmail]>
00005 """
00006 
00007 import roslib
00008 roslib.load_manifest('diagnostic_updater')
00009 import rospy
00010 from diagnostic_msgs.msg import DiagnosticStatus, KeyValue
00011 
00012 
00013 
00014 class DiagnosticStatusWrapper(DiagnosticStatus):
00015     """ Wrapper for the diagnostic_msgs::DiagnosticStatus message that makes it
00016     easier to update.
00017 
00018     This class handles common string formatting and vector handling issues
00019     for filling the diagnostic_msgs::DiagnosticStatus message. It is a subclass of
00020     diagnostic_msgs::DiagnosticStatus, so it can be passed directly to
00021     diagnostic publish calls.
00022     """
00023 
00024     def __init__(self, *args, **kwds):
00025         """
00026         Constructor. Any message fields that are implicitly/explicitly
00027         set to None will be assigned a default value. The recommend
00028         use is keyword arguments as this is more robust to future message
00029         changes.  You cannot mix in-order arguments and keyword arguments.
00030 
00031         The available fields are:
00032         level,name,message,hardware_id,values
00033 
00034         @param args: complete set of field values, in .msg order
00035         @param kwds: use keyword arguments corresponding to message field names
00036         to set specific fields.
00037         """
00038         DiagnosticStatus.__init__(self, *args, **kwds)
00039 
00040 
00041     def summary(self, *args):
00042         """ Fills out the level and message fields of the DiagnosticStatus.
00043 
00044         Usage:
00045         summary(diagnostic_status): Copies the summary from a DiagnosticStatus message
00046         summary(lvl,msg): sets from lvl and messages
00047         """
00048         if len(args)==1:
00049             self.level = args[0].level
00050             self.message = args[0].message
00051         elif len(args)==2:
00052             self.level = args[0]
00053             self.message = str(args[1])
00054 
00055 
00056     def clearSummary(self):
00057         """ Clears the summary, setting the level to zero and the message to "".
00058         """
00059         self.summary(0, "")
00060 
00061 
00062     def mergeSummary(self, *args):
00063         """ Merges a level and message with the existing ones.
00064 
00065         It is sometimes useful to merge two DiagnosticStatus messages. In that case,
00066         the key value pairs can be unioned, but the level and summary message
00067         have to be merged more intelligently. This function does the merge in
00068         an intelligent manner, combining the summary in *this, with the one
00069         that is passed in.
00070 
00071         The combined level is the greater of the two levels to be merged.
00072         If both levels are non-zero (not OK), the messages are combined with a
00073         semicolon separator. If only one level is zero, and the other is
00074         non-zero, the message for the zero level is discarded. If both are
00075         zero, the new message is ignored.
00076 
00077         Usage:
00078         mergeSummary(diagnostic_status): merge from a DiagnosticStatus message
00079         mergeSummary(lvl,msg): sets from lvl and msg
00080         """
00081         if len(args)==1:
00082             lvl = args[0].level
00083             msg = args[0].message
00084         elif len(args)==2:
00085             lvl = args[0]
00086             msg = args[1]
00087 
00088         if (lvl>0) == (self.level>0):
00089             if len(self.message)>0:
00090                 self.message += "; "
00091             self.message += msg
00092         elif lvl > self.level:
00093             self.message = msg
00094 
00095         if lvl > self.level:
00096             self.level = lvl
00097 
00098 
00099     def add(self, key, val):
00100         """ Add a key-value pair.
00101 
00102         This method adds a key-value pair. Any type that has a << stream
00103         operator can be passed as the second argument.  Formatting is done
00104         using a std::stringstream.
00105 
00106         @type key string
00107         @param key Key to be added.
00108         @type value string
00109         @param value Value to be added.
00110         """
00111         self.values.append(KeyValue(key,str(val)))


diagnostic_updater
Author(s): Jeremy Leibs, Blaise Gassend, Brice Rebsamen
autogenerated on Fri Jan 3 2014 11:18:57