@@ -26,7 +26,9 @@ def __init__(self):
2626 self .odom_sub = rospy .Subscriber ('base_odometry/odometer' , Odometer , self .odom_cb )
2727
2828 # diagnostics
29- self .pub_diag = rospy .Publisher ('/diagnostics' , DiagnosticArray )
29+ self .pub_diag = rospy .Publisher ('/diagnostics' , DiagnosticArray , queue_size = 1 )
30+
31+ self .diag_timer = rospy .Timer (rospy .Duration (1 ), self .publish_diagnostics )
3032
3133
3234 def imu_cb (self , msg ):
@@ -44,14 +46,16 @@ def odom_cb(self, msg):
4446 self .start_time = rospy .Time .now ()
4547 self .start_angle = self .last_angle
4648 self .dist = dist
47-
49+
4850 # do imu test if possible
4951 if rospy .Time .now () > self .start_time + rospy .Duration (10.0 ):
5052 self .drift = fabs (self .start_angle - self .last_angle )* 180 / (pi * 10 )
5153 self .start_time = rospy .Time .now ()
5254 self .start_angle = self .last_angle
5355 self .last_measured = rospy .Time .now ()
54-
56+
57+ def publish_diagnostics (self , event ):
58+ with self .lock :
5559 # publish diagnostics
5660 d = DiagnosticArray ()
5761 d .header .stamp = rospy .Time .now ()
@@ -77,7 +81,7 @@ def odom_cb(self, msg):
7781 elif age < 3600 :
7882 last_measured = '%f minutes ago' % (age / 60 )
7983 else :
80- last_measured = '%f hours ago' % (age / 3600 )
84+ last_measured = '%f hours ago' % (age / 3600 )
8185 ds .values = [
8286 KeyValue ('Last measured' , last_measured ),
8387 KeyValue ('Drift (deg/sec)' , str (drift )) ]
0 commit comments