Skip to content

Commit b7037ac

Browse files
committed
Merge pull request #4 from clearpathrobotics/check_drop_plot_vs_time
Plot vs time
2 parents 849cd57 + cfb888c commit b7037ac

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

bag_tools/scripts/check_drop.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,23 @@ def check_drop(inbags, plot_format='png'):
7979
bag_time_diff = {}
8080
seq_diff = {}
8181

82+
min_time = []
8283
for key in msg_time.iterkeys():
8384
msg_time_diff[key] = numpy.diff(msg_time[key])
85+
min_time.append(msg_time[key][0])
8486
bag_time_diff[key] = numpy.diff(bag_time[key])
8587
seq_diff[key] = numpy.diff(seq[key])
8688

89+
min_time = numpy.min(min_time)
90+
8791
# Compute min, max and mean differences:
8892
basename = inbags[0].replace('.bag', '')
8993

9094
max_len = max(len(topic) for topic in msg_time_diff.keys())
9195
topics = msg_time_diff.keys()
9296
topics.sort()
9397

98+
9499
for topic in topics:
95100
msg_time_diff_topic = msg_time_diff[topic]
96101
bag_time_diff_topic = bag_time_diff[topic]
@@ -120,33 +125,33 @@ def check_drop(inbags, plot_format='png'):
120125
rospy.loginfo('%s seq: mean = %s, min = %s, max = %s, median = %s', topic.ljust(max_len + 2), seq_diff_mean, seq_diff_min, seq_diff_max, seq_diff_median)
121126

122127
# Create and save plots:
123-
N = len(msg_time_diff_topic)
124-
x = numpy.array([0, N - 1])
128+
mt = msg_time[topic][1:] - min_time
125129

126130
try:
127131
fig = plt.figure()
128132
fig.set_size_inches(20, 15)
129133

130134
plt.subplot(311)
131135
plt.title(topic + ' - Message time difference [s]')
132-
plt.plot(msg_time_diff_topic, 'b')
133-
plt.plot(x, numpy.array([msg_time_diff_min, msg_time_diff_min]), 'r--')
134-
plt.plot(x, numpy.array([msg_time_diff_max, msg_time_diff_max]), 'r--')
135-
plt.plot(x, numpy.array([msg_time_diff_mean, msg_time_diff_mean]), 'g')
136+
plt.plot(mt, msg_time_diff_topic,'b')
137+
plt.plot([mt[0], mt[-1]], [msg_time_diff_min, msg_time_diff_min], 'r--')
138+
plt.plot([mt[0], mt[-1]], [msg_time_diff_max, msg_time_diff_max], 'r--')
139+
plt.plot([mt[0], mt[-1]], [msg_time_diff_mean, msg_time_diff_mean], 'g')
136140

137141
plt.subplot(312)
138142
plt.title(topic + ' - Bag time difference [s]')
139-
plt.plot(bag_time_diff_topic, 'b')
140-
plt.plot(x, numpy.array([bag_time_diff_min, bag_time_diff_min]), 'r--')
141-
plt.plot(x, numpy.array([bag_time_diff_max, bag_time_diff_max]), 'r--')
142-
plt.plot(x, numpy.array([bag_time_diff_mean, bag_time_diff_mean]), 'g')
143+
plt.plot(mt, bag_time_diff_topic,'b')
144+
plt.plot([mt[0], mt[-1]], [bag_time_diff_min, bag_time_diff_min], 'r--')
145+
plt.plot([mt[0], mt[-1]], [bag_time_diff_max, bag_time_diff_max], 'r--')
146+
plt.plot([mt[0], mt[-1]], [bag_time_diff_mean, bag_time_diff_mean], 'g')
143147

144148
plt.subplot(313)
145149
plt.title(topic + ' - Sequence number difference')
146-
plt.plot(seq_diff_topic, 'b')
147-
plt.plot(x, numpy.array([seq_diff_min, seq_diff_min]), 'r--')
148-
plt.plot(x, numpy.array([seq_diff_max, seq_diff_max]), 'r--')
149-
plt.plot(x, numpy.array([seq_diff_mean, seq_diff_mean]), 'g')
150+
plt.plot(mt, seq_diff_topic, 'b')
151+
plt.plot([mt[0], mt[-1]], [seq_diff_min, seq_diff_min], 'r--')
152+
plt.plot([mt[0], mt[-1]], [seq_diff_max, seq_diff_max], 'r--')
153+
plt.plot([mt[0], mt[-1]], [seq_diff_mean, seq_diff_mean], 'g')
154+
150155

151156
plt.savefig(basename + topic.replace('/', '_').replace(' ', '_').replace(':', '_') + '.' + plot_format)
152157
plt.close(fig)

0 commit comments

Comments
 (0)