5 from sensor_msgs.msg
import Imu
6 from pr2_mechanism_controllers.msg
import Odometer
7 from threading
import Lock
8 from math
import fabs, pi
9 from diagnostic_msgs.msg
import DiagnosticArray, DiagnosticStatus, KeyValue
25 self.
imu_sub = rospy.Subscriber(
'torso_lift_imu/data', Imu, self.
imu_cb)
26 self.
odom_sub = rospy.Subscriber(
'base_odometry/odometer', Odometer, self.
odom_cb)
29 self.
pub_diag = rospy.Publisher(
'/diagnostics', DiagnosticArray)
34 rot = PyKDL.Rotation.Quaternion(msg.orientation.x, msg.orientation.y,
35 msg.orientation.z, msg.orientation.w)
40 dist = msg.distance + (msg.angle * 0.25)
43 if dist > self.
dist + EPS:
49 if rospy.Time.now() > self.
start_time + rospy.Duration(10.0):
57 d.header.stamp = rospy.Time.now()
58 ds = DiagnosticStatus()
59 ds.name =
"imu_node: Imu Drift Monitor" 61 ds.level = DiagnosticStatus.OK
63 elif self.
drift < 1.0:
64 ds.level = DiagnosticStatus.WARN
65 ds.message =
'Drifting' 67 ds.level = DiagnosticStatus.ERROR
68 ds.message =
'Drifting' 71 last_measured =
'No measurements yet, waiting for base to stop moving before measuring' 76 last_measured =
'%f seconds ago'%age
78 last_measured =
'%f minutes ago'%(age/60)
80 last_measured =
'%f hours ago'%(age/3600)
82 KeyValue(
'Last measured', last_measured),
83 KeyValue(
'Drift (deg/sec)', str(drift)) ]
85 self.pub_diag.publish(d)
88 rospy.init_node(
'imu_monitor')
96 if __name__ ==
'__main__':