Skip to content

Instantly share code, notes, and snippets.

@dpkoch
Last active July 22, 2016 15:57
Show Gist options
  • Save dpkoch/f0bb47ddeaf03a939fac1b41500f99ed to your computer and use it in GitHub Desktop.
Save dpkoch/f0bb47ddeaf03a939fac1b41500f99ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Imu
import numpy as np
import matplotlib.pyplot as plt
class Timing():
def __init__(self):
self.count = 0
self.arrivals = []
self.stamps = []
self.imu_sub = rospy.Subscriber('imu/data', Imu, self.imuCallback, queue_size=1)
while not rospy.is_shutdown():
rospy.spin()
def imuCallback(self, msg):
self.arrivals.append(rospy.Time.now().to_sec())
self.stamps.append(msg.header.stamp.to_sec())
self.count += 1
if self.count >= 1000:
rospy.signal_shutdown("Received IMU measurements")
if __name__ == '__main__':
rospy.init_node('timing')
timing = Timing()
# plot results
plt.figure(1)
plt.subplot(211)
plt.hist(np.diff(timing.arrivals), bins=50)
plt.title('Arrival Times')
plt.subplot(212)
plt.hist(np.diff(timing.stamps), bins=50)
plt.title('Stamp Times')
plt.figure(2)
plt.subplot(211)
plt.plot(timing.arrivals[1:], np.diff(timing.arrivals))
plt.title('Arrival Times')
plt.subplot(212)
plt.plot(timing.stamps[1:], np.diff(timing.stamps))
plt.title('Stamp Times')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment