Go to the documentation of this file.00001
00002 import roslib
00003 import os
00004 import sys
00005 import rospy
00006 import rosbag
00007
00008
00009 SB_='\033[1m'
00010 CY_='\033[33m'
00011 CR_='\033[1;31m'
00012 CLG_='\033[37m'
00013 _EC='\033[0m'
00014
00015
00016 if len(sys.argv) < 4:
00017 print " "
00018 print CR_+"-------------------------------------------------------------------------------------------------"+_EC
00019 print CR_+"Error! "+_EC+SB_+" fix_timestamp_of_topic.py BAG_FILE TOPIC TIME_DIFF(in s)"+_EC
00020 print CR_+"-------------------------------------------------------------------------------------------------"+_EC
00021 exit()
00022 else:
00023 elbagin = str(sys.argv[1])
00024 elbagout = elbagin[:-4]+"_ts_fixed.bag"
00025 eltopic = str(sys.argv[2])
00026 eldiff = float(sys.argv[3])
00027
00028 print ""
00029 print CY_+"-------------------------------------------------------------------------------------------------"+_EC
00030 print SB_+" Fix topic timestamp from Bag"+_EC
00031 print CY_+"-------------------------------------------------------------------------------------------------"+_EC
00032
00033 with rosbag.Bag(elbagout, 'w') as outbag:
00034
00035
00036 diff_stamp = rospy.Duration.from_sec(eldiff)
00037
00038
00039 for topic, msg, t in rosbag.Bag(elbagin).read_messages():
00040 if topic == eltopic:
00041 print " before",msg.header.stamp.to_sec()
00042 msg.header.stamp = msg.header.stamp + diff_stamp
00043 print " fixed ",msg.header.stamp.to_sec()
00044 outbag.write(topic, msg,t)
00045 print CY_+"-------------------------"+_EC
00046 else:
00047 outbag.write(topic, msg,t)
00048
00049 print SB_+" End! the bag has been written"+_EC
00050 print " "+CY_+elbagout
00051 print CY_+"-------------------------------------------------------------------------------------------------"+_EC
00052