fix_timestamp_of_topic.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib
00003 import os
00004 import sys
00005 import rospy
00006 import rosbag
00007 
00008 # Terminal colors for Ubuntu/Linux
00009 SB_='\033[1m' #style bold
00010 CY_='\033[33m' #color yellow
00011 CR_='\033[1;31m' #color red
00012 CLG_='\033[37m' #color light grey
00013 _EC='\033[0m' #end color
00014 
00015 # Get the bag
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   # calcular la diferencia entre t_ok - t_no_ok
00036   diff_stamp = rospy.Duration.from_sec(eldiff)
00037 
00038   # canviar el t_no_ok msg.header.stamp sumant la diferencia
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 


teo_apps
Author(s): Marti
autogenerated on Fri Dec 6 2013 22:19:45