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
00039
00040
00041
00042
00043
00044 import rospy
00045 import applanix_msgs.msg
00046 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus, KeyValue
00047
00048
00049 class BitfieldRepublisher(object):
00050 def __init__(self, topic_name, topic_type, fields):
00051 flags = []
00052 attrs = dir(applanix_msgs.msg.GeneralStatus)
00053 for field in fields:
00054 prefix = field.upper() + "_"
00055 field_flags = []
00056 for attr in attrs:
00057 if attr.startswith(prefix):
00058 short_name = attr[len(prefix):len(attr)]
00059 mask = getattr(applanix_msgs.msg.GeneralStatus, attr)
00060 field_flags.append((mask, short_name))
00061 field_flags.sort()
00062 flags.append((field, tuple(field_flags)))
00063 self.flags = tuple(flags)
00064
00065 self.status_msg = DiagnosticArray()
00066 self.status_msg.status.append(DiagnosticStatus(
00067 level = DiagnosticStatus.OK,
00068 name = "Applanix AP10",
00069 message = "OK"))
00070 rospy.Subscriber(topic_name, topic_type, self._cb)
00071 self.pub = rospy.Publisher("/diagnostics", DiagnosticArray, queue_size=5, latch=True)
00072
00073 def _cb(self, msg):
00074 self.status_msg.status[0].values = []
00075 for field, field_flags in self.flags:
00076 field_value = getattr(msg, field)
00077 for mask, flag in field_flags:
00078 value = str(int((field_value & mask) != 0))
00079 self.status_msg.status[0].values.append(KeyValue(flag, value))
00080 self.pub.publish(self.status_msg)
00081
00082
00083 def main():
00084 rospy.init_node('applanix_diagnostics')
00085 BitfieldRepublisher("status/general", applanix_msgs.msg.GeneralStatus, \
00086 ('status_a', 'status_b', 'status_c', 'fdir_1', \
00087 'fdir_2', 'fdir_3', 'fdir_4', 'fdir_5', 'extended'))
00088 rospy.spin()