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
00036
00037
00038 import sys
00039 import rospy
00040 from diagnostic_msgs.msg import *
00041
00042
00043 def recurse_tree(element, messages, wiremap):
00044 errors = []
00045 print "Looking at ", element
00046 if element in wiremap:
00047 if "children" in wiremap[element]:
00048 for child in wiremap[element]["children"]:
00049 errors_return = recurse_tree(child, messages, wiremap)
00050 errors.extend(errors_return)
00051
00052 try:
00053 value = float(messages[ wiremap[element]['component']][wiremap[element]['value']])
00054 child_value = float(messages[ wiremap[child]['component']][wiremap[child]['value']])
00055 tolerance = wiremap[element]['tolerance']
00056 if abs(value - child_value) / value > tolerance/100.0:
00057 errors.append("difference between %f (%s) and %f (%s) voltages exceeds tolerance %f percent"%(value, element, child_value, child, tolerance))
00058 else:
00059 rospy.logdebug("%s passed"%child)
00060 except KeyError, e:
00061 errors.append("badly formed parameters for element %s: %s"%(element, e));
00062 else:
00063 print "No children of element: ", element
00064 else:
00065 errors.append("no element %s"% element)
00066
00067 return errors
00068
00069
00070 def test(latest_status, parameters):
00071
00072 results = {}
00073
00074 if "wiring_tree" in parameters:
00075 wiremap = parameters["wiring_tree"]
00076 else:
00077 results['error'] = ["power_wires: no wiring_tree found"]
00078 return results
00079
00080 if 'root' in parameters:
00081 results['error'] = []
00082 for root in parameters["root"]:
00083 results['error'].extend( recurse_tree(root, latest_status, wiremap))
00084
00085 if results['error'] == []:
00086 del results['error']
00087 else:
00088 results['error'] = ["power_wires: no root found"]
00089 return results
00090
00091
00092 return results
00093
00094