timeshift_bag.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rosbag
3 import rospy
4 import sys
5 import os
6 
7 from sensor_msgs.msg import Image
8 
9 if len(sys.argv) < 4:
10  print "Usage: {} <bag_name> <topic> <timeshift>".format(os.path.basename(sys.argv[0]))
11  exit()
12 
13 input_bag_name = sys.argv[1]
14 topic_name = sys.argv[2]
15 time_shift = rospy.Duration(float(sys.argv[3]))
16 
17 try:
18  input_bag = rosbag.Bag(input_bag_name)
19  bag_loaded = True
20 except Exception:
21  print "Could not open bag {}".format(input_bag_name)
22  bag_loaded = False
23 
24 if bag_loaded:
25  name, ext = os.path.splitext(input_bag_name)
26  output_bag_name = "{name}_timeshifted{ext}".format(name=name, ext=ext)
27  output_bag = rosbag.Bag(output_bag_name, 'w')
28 
29  for topic, msg, t in input_bag.read_messages():
30  if topic == topic_name:
31  msg.header.stamp += time_shift
32  output_bag.write(topic, msg, t)
33  else:
34  output_bag.write(topic, msg, t)
35 
36  output_bag.close()
37  input_bag.close()


timesync_ros
Author(s): Juraj Oršulić
autogenerated on Mon Jun 10 2019 15:28:33