imu_timestamp_test.py
Go to the documentation of this file.
00001 '''
00002 
00003 '''
00004 import matplotlib
00005 import matplotlib.pyplot as plt
00006 import numpy as np
00007 
00008 
00009 class ImuTimeStampTester:
00010   def __init__(self, logName):
00011         self.logName = logName
00012  
00013   def run(self):
00014   # try to parse rostopic-echo file and search for timestamps
00015     with open(self.logName, "r") as f:
00016       data = f.readlines()
00017 
00018     state = 0
00019     secVal = 0.000;
00020     nanoVal = 0.0
00021 
00022     timestamps = np.zeros(1)
00023     firstTime = True
00024     for line in data:
00025         words = line.split()
00026         for word in words:
00027             if (state == 1):
00028                 secVal = float(word)
00029                 state = 2
00030             if (state == 3):
00031                 nanoVal = float(word)
00032                 timeStampVal = secVal + 1E-9 * nanoVal
00033                 print("Timestamp: {timestamp}".format(timestamp=timeStampVal))
00034                 if (firstTime):
00035                     firstTime = False
00036                     timestamps[0] = timeStampVal
00037                 else:
00038                     timestamps = np.append(timestamps, timeStampVal)
00039                 state = 0
00040 
00041             if (word == 'secs:'):
00042              state = 1
00043 
00044             if (word == 'nsecs:'):
00045              state = 3
00046         print(words)
00047 
00048     # now we can analyse and plot the result
00049 
00050     deltaT = timestamps[1:] - timestamps[:-1]
00051     X = np.arange(0, timestamps.size, 1)
00052 
00053     ax = plt.gca()
00054     plt.ylabel('Zeitdifferenz t(x)-t(x-1)')
00055     plt.xlabel('relativer Rospaketindex x')
00056     plt.title('Zeitverhalten der IMU Timestamps nach langen Differenzen')
00057     ax.grid(which='major', axis='both', linestyle='--')
00058 
00059     for i in range(0, deltaT.size - 1):
00060       if deltaT[i] > np.mean(deltaT) + 2 * np.std(deltaT):
00061            print('ERROR INDEX:' + str(i) + ' Timestamp[INDEX-1]:' + str(timestamps[i]) + ' Timestamp[INDEX]:' + str(
00062                   timestamps[i + 1]))
00063     plt.plot(deltaT)
00064     plt.show()
00065     plt.savefig('imutimestampsmu+2sigma.png', dpi=300)
00066 
00067 
00068 if __name__ == "__main__":
00069     filename = "/tmp/imu.txt"  # create such a file by running rostopic echo /imu >/tmp/imu.txt for about 10 secs.
00070 
00071     imuTest = ImuTimeStampTester(filename)
00072     imuTest.run()


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 05:05:34