Skip to content

Commit

Permalink
handle rostime reset
Browse files Browse the repository at this point in the history
due to rosbag loop. Without this patch, the buffer fills up continuously.

This relies on ros/ros_comm#2257 to fix rospy.Timer
with rosbag loops as well.
  • Loading branch information
v4hn authored and pr2admin committed Jul 6, 2022
1 parent 9bdbc84 commit be415fb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions audio_to_spectrogram/scripts/spectrum_to_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ def audio_cb(self, msg):
# Extract spectrogram of last (self.spectrogram_period) seconds
time_now = rospy.Time.now()
for i, stamp in enumerate(self.spectrum_stamp):
if (time_now - stamp).to_sec() < self.spectrogram_period:
diff = (time_now - stamp).to_sec()
if diff > 0.0 and diff < self.spectrogram_period:
self.spectrogram = self.spectrogram[i:]
self.spectrum_stamp = self.spectrum_stamp[i:]
break
return
self.spectrogram = self.spectrogram[self.spectrogram.shape[0]:]
self.spectrum_stamp = []

def timer_cb(self, timer):
if self.spectrogram.shape[0] == 0:
Expand Down

0 comments on commit be415fb

Please sign in to comment.