Last active
July 22, 2016 15:57
-
-
Save dpkoch/f0bb47ddeaf03a939fac1b41500f99ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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