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 import rospy
00036
00037 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus, KeyValue
00038
00039 class WheeledRobinDiagnostics():
00040 def __init__(self):
00041 self.digital_outputs = {0:"OFF",
00042 1:"ON"}
00043 self.mode = {1:"Passive",
00044 2:"Safe",
00045 3:"Full"}
00046 self.diag_pub = rospy.Publisher('/diagnostics', DiagnosticArray)
00047 self.last_diagnostics_time = rospy.get_rostime()
00048
00049 def node_status(self, msg, status):
00050 curr_time = rospy.Time.now()
00051 diag = DiagnosticArray()
00052 diag.header.stamp = curr_time
00053 stat = DiagnosticStatus()
00054 if status == "error":
00055 stat = DiagnosticStatus(name="WheeledRobin Node", level=DiagnosticStatus.ERROR, message=msg)
00056 if status == "warn":
00057 stat = DiagnosticStatus(name="WheeledRobin Node", level=DiagnosticStatus.WARN, message=msg)
00058 diag.status.append(stat)
00059 self.diag_pub.publish(diag)
00060
00061 def publish(self, sensor_state, gyro):
00062 curr_time = sensor_state.header.stamp
00063
00064 if (curr_time - self.last_diagnostics_time).to_sec() < 0.2:
00065 return
00066 self.last_diagnostics_time = curr_time
00067
00068 diag = DiagnosticArray()
00069 diag.header.stamp = curr_time
00070 stat = DiagnosticStatus()
00071
00072
00073 stat = DiagnosticStatus(name="WheeledRobin Node", level=DiagnosticStatus.OK, message="RUNNING")
00074 diag.status.append(stat)
00075
00076
00077 """
00078 stat = DiagnosticStatus(name="Operating Mode", level=DiagnosticStatus.OK)
00079 try:
00080 stat.message = self.mode[sensor_state.mode]
00081 except KeyError as ex:
00082 stat.level=DiagnosticStatus.ERROR
00083 stat.message = "Invalid Mode Reported %s"%ex
00084 rospy.logwarn(stat.message)
00085 diag.status.append(stat)
00086 """
00087
00088
00089 """
00090 stat = DiagnosticStatus(name="Cliff Sensor", level=DiagnosticStatus.OK, message="OK")
00091 if sensor_state.cliff_left or sensor_state.cliff_front_left or sensor_state.cliff_right or sensor_state.cliff_front_right:
00092 stat.level = DiagnosticStatus.WARN
00093 if (sensor_state.current/1000.0)>0:
00094 stat.message = "Near Cliff: While the irobot create is charging, the create thinks it's near a cliff."
00095 stat.level = DiagnosticStatus.OK # We're OK here
00096 else:
00097 stat.message = "Near Cliff"
00098 stat.values = [KeyValue("Left", str(sensor_state.cliff_left)),
00099 KeyValue("Left Signal", str(sensor_state.cliff_left_signal)),
00100 KeyValue("Front Left", str(sensor_state.cliff_front_left)),
00101 KeyValue("Front Left Signal", str(sensor_state.cliff_front_left_signal)),
00102 KeyValue("Front Right", str(sensor_state.cliff_right)),
00103 KeyValue("Front Right Signal", str(sensor_state.cliff_right_signal)),
00104 KeyValue("Right", str(sensor_state.cliff_front_right)),
00105 KeyValue("Right Signal", str(sensor_state.cliff_front_right_signal))]
00106 diag.status.append(stat)
00107
00108 #Wall sensors
00109 stat = DiagnosticStatus(name="Wall Sensor", level=DiagnosticStatus.OK, message="OK")
00110 #wall always seems to be false???
00111 if sensor_state.wall:
00112 stat.level = DiagnosticStatus.ERROR
00113 stat.message = "Near Wall"
00114 stat.values = [KeyValue("Wall", str(sensor_state.wall)),
00115 KeyValue("Wall Signal", str(sensor_state.wall_signal)),
00116 KeyValue("Virtual Wall", str(sensor_state.virtual_wall))]
00117 diag.status.append(stat)
00118
00119 #Gyro
00120 stat = DiagnosticStatus(name="Gyro Sensor", level = DiagnosticStatus.OK, message = "OK")
00121 if gyro is None:
00122 stat.level = DiagnosticStatus.WARN
00123 stat.message = "Gyro Not Enabled: To enable the gyro set the has_gyro param in the wheeled_robin_node."
00124 elif gyro.cal_offset < 100:
00125 stat.level = DiagnosticStatus.ERROR
00126 stat.message = "Gyro Power Problem: For more information visit http://answers.ros.org/question/2091/turtlebot-bad-gyro-calibration-also."
00127 elif gyro.cal_offset > 575.0 or gyro.cal_offset < 425.0:
00128 stat.level = DiagnosticStatus.ERROR
00129 stat.message = "Bad Gyro Calibration Offset: The gyro average is outside the standard deviation."
00130
00131 if gyro is not None:
00132 stat.values = [KeyValue("Gyro Enabled", str(gyro is not None)),
00133 KeyValue("Raw Gyro Rate", str(sensor_state.user_analog_input)),
00134 KeyValue("Calibration Offset", str(gyro.cal_offset)),
00135 KeyValue("Calibration Buffer", str(gyro.cal_buffer))]
00136 diag.status.append(stat)
00137 """
00138
00139 stat = DiagnosticStatus(name="Digital Outputs", level = DiagnosticStatus.OK, message = "OK")
00140 out_byte = sensor_state.digital_outputs
00141 stat.values = [KeyValue("Raw Byte", str(out_byte)),
00142 KeyValue("Digital Out 0", self.digital_outputs[(out_byte >>0)%2]),
00143 KeyValue("Digital Out 1", self.digital_outputs[(out_byte >>1)%2]),
00144 KeyValue("Digital Out 2", self.digital_outputs[(out_byte >>2)%2]),
00145 KeyValue("Digital Out 3", self.digital_outputs[(out_byte >>3)%2]),
00146 KeyValue("Digital Out 4", self.digital_outputs[(out_byte >>4)%2]),
00147 KeyValue("Digital Out 5", self.digital_outputs[(out_byte >>5)%2]),
00148 KeyValue("Digital Out 6", self.digital_outputs[(out_byte >>6)%2]),
00149 KeyValue("Digital Out 7", self.digital_outputs[(out_byte >>7)%2])]
00150 diag.status.append(stat)
00151
00152
00153 stat = DiagnosticStatus(name="Digital Inputs", level = DiagnosticStatus.OK, message = "OK")
00154 in_byte = sensor_state.digital_inputs
00155 stat.values = [KeyValue("Raw Byte", str(in_byte)),
00156 KeyValue("Digital Input 0", self.digital_outputs[(in_byte >>0)%2]),
00157 KeyValue("Digital Input 1", self.digital_outputs[(in_byte >>1)%2]),
00158 KeyValue("Digital Input 2", self.digital_outputs[(in_byte >>2)%2]),
00159 KeyValue("Digital Input 3", self.digital_outputs[(in_byte >>3)%2]),
00160 KeyValue("Digital Input 4", self.digital_outputs[(in_byte >>4)%2]),
00161 KeyValue("Digital Input 5", self.digital_outputs[(in_byte >>5)%2]),
00162 KeyValue("Digital Input 6", self.digital_outputs[(in_byte >>6)%2]),
00163 KeyValue("Digital Input 7", self.digital_outputs[(in_byte >>7)%2])]
00164 diag.status.append(stat)
00165
00166
00167 self.diag_pub.publish(diag)
00168