Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Make diagnostics more reasonable #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions nodes/mtnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
FluidPressure, Temperature, TimeReference
from geometry_msgs.msg import TwistStamped, PointStamped
from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus
from diagnostic_updater import Updater, TopicDiagnostic,\
FrequencyStatusParam, TimeStampStatusParam

import time
import datetime
import calendar
Expand Down Expand Up @@ -51,7 +54,6 @@ def matrix_from_diagonal(diagonal):


class XSensDriver(object):

def __init__(self):
device = get_param('~device', 'auto')
baudrate = get_param('~baudrate', 0)
Expand Down Expand Up @@ -90,7 +92,6 @@ def __init__(self):
self.mt.SetNoRotation(no_rotation_duration)

self.frame_id = get_param('~frame_id', '/base_imu')

self.frame_local = get_param('~frame_local', 'ENU')

self.angular_velocity_covariance = matrix_from_diagonal(
Expand All @@ -103,17 +104,36 @@ def __init__(self):
get_param_list("~orientation_covariance_diagonal", [radians(1.), radians(1.), radians(9.)])
)

fcolas marked this conversation as resolved.
Show resolved Hide resolved
self.diag_msg = DiagnosticArray()
self.stest_stat = DiagnosticStatus(name='mtnode: Self Test', level=1,
message='No status information')
self.xkf_stat = DiagnosticStatus(name='mtnode: XKF Valid', level=1,
message='No status information')
self.gps_stat = DiagnosticStatus(name='mtnode: GPS Fix', level=1,
message='No status information')
self.diag_msg.status = [self.stest_stat, self.xkf_stat, self.gps_stat]

self.device_info = {
'product_code': self.mt.GetProductCode(),
'device_id': self.mt.GetDeviceID(),
'firmware_rev': self.mt.GetFirmwareRev()
}

self.device_info.update(self.mt.GetConfiguration())
self.updater = Updater()
self.updater.setHardwareID(str(self.mt.GetDeviceID()))
fcolas marked this conversation as resolved.
Show resolved Hide resolved

self.updater.add("Self Test", self.diagnostic_self_test)
self.updater.add("XKF", self.diagnostic_xkf)
self.updater.add("GPS Fix", self.diagnostic_gps)
self.updater.add("Device Info", self.diagnostic_device)

self.imu_freq = TopicDiagnostic("imu/data", self.updater,
FrequencyStatusParam({'min': 0, 'max': 100}, 0.1, 10),
TimeStampStatusParam())
self.mag_freq = TopicDiagnostic("imu/mag", self.updater,
FrequencyStatusParam({'min': 0, 'max': 100}, 0.1, 10),
TimeStampStatusParam())

# publishers created at first use to reduce topic clutter
self.diag_pub = None
self.imu_pub = None
self.raw_gps_pub = None
self.vel_pub = None
Expand Down Expand Up @@ -172,6 +192,20 @@ def spin(self):
except (select.error, OSError, serial.serialutil.SerialException):
pass

def diagnostic_self_test(self, stat):
stat.summary(self.stest_stat.level, self.stest_stat.message)

def diagnostic_xkf(self, stat):
stat.summary(self.xkf_stat.level, self.xkf_stat.message)

def diagnostic_gps(self, stat):
stat.summary(self.gps_stat.level, self.gps_stat.message)

def diagnostic_device(self, stat):
stat.summary(DiagnosticStatus.OK, "Device Ok")
for (key, value) in self.device_info.iteritems():
stat.add(key, value)

fcolas marked this conversation as resolved.
Show resolved Hide resolved
def spin_once(self):
'''Read data from device and publishes ROS messages.'''
def convert_coords(x, y, z, source, dest=self.frame_local):
Expand Down Expand Up @@ -563,7 +597,7 @@ def fill_from_Angular_Velocity(o):
block.'''
try:
dqw, dqx, dqy, dqz = (o['Delta q0'], o['Delta q1'],
o['Delta q2'], o['Delta q3'])
o['Delta q2'], o['Delta q3'])
now = rospy.Time.now()
if self.last_delta_q_time is None:
self.last_delta_q_time = now
Expand Down Expand Up @@ -723,6 +757,7 @@ def find_handler_name(name):
self.imu_msg.header = self.h
if self.imu_pub is None:
self.imu_pub = rospy.Publisher('imu/data', Imu, queue_size=10)
self.imu_freq.tick(self.h.stamp)
self.imu_pub.publish(self.imu_msg)
if self.pub_raw_gps:
self.raw_gps_msg.header = self.h
Expand All @@ -745,6 +780,7 @@ def find_handler_name(name):
if self.mag_pub is None:
self.mag_pub = rospy.Publisher('imu/mag', MagneticField,
queue_size=10)
self.mag_freq.tick(self.h.stamp)
self.mag_pub.publish(self.mag_msg)
if self.pub_temp:
self.temp_msg.header = self.h
Expand Down Expand Up @@ -774,14 +810,10 @@ def find_handler_name(name):
self.ecef_pub = rospy.Publisher('ecef', PointStamped,
queue_size=10)
self.ecef_pub.publish(self.ecef_msg)
if self.pub_diag:
self.diag_msg.header = self.h
if self.diag_pub is None:
self.diag_pub = rospy.Publisher('/diagnostics', DiagnosticArray,
queue_size=10)
self.diag_pub.publish(self.diag_msg)

# publish string representation
self.str_pub.publish(str(data))
self.updater.update()


def main():
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<build_depend>sensor_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>diagnostic_msgs</build_depend>
<build_depend>diagnostic_updater</build_depend>

<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
Expand All @@ -23,6 +24,7 @@
<run_depend>geometry_msgs</run_depend>
<run_depend>diagnostic_msgs</run_depend>
<run_depend>python-serial</run_depend>
<run_depend>diagnostic_updater</run_depend>
</package>