$search
00001 #!/usr/bin/python 00002 00003 import roslib; roslib.load_manifest('rosbaglive') 00004 import rospy 00005 import rosbag 00006 import sys 00007 00008 # F#@K IT WE'LL DO IT LIVE 00009 00010 if __name__=='__main__': 00011 rospy.init_node('rosbaglive') 00012 bagfn = None 00013 for arg in sys.argv[1:]: 00014 if ".bag" in arg: 00015 bagfn = arg 00016 break 00017 if bagfn is None: 00018 rospy.logerr("No Bag specified!") 00019 exit(1) 00020 00021 bag = rosbag.Bag(bagfn) 00022 pubs = {} 00023 rospy.loginfo('Start read') 00024 last = None 00025 data = [] 00026 00027 for topic, msg, t in bag.read_messages(): 00028 if topic not in pubs: 00029 pub = rospy.Publisher(topic, type(msg), latch=('map' in topic)) 00030 pubs[topic] = pub 00031 00032 if t!=last: 00033 data.append( (t, []) ) 00034 last = t 00035 data[-1][1].append( (topic, msg) ) 00036 rospy.loginfo('Done read') 00037 start = rospy.Time.now() 00038 sim_start = None 00039 for t, msgs in data: 00040 now = rospy.Time.now() 00041 if sim_start is None: 00042 sim_start = t 00043 else: 00044 real_time = now - start 00045 sim_time = t - sim_start 00046 if sim_time > real_time: 00047 rospy.sleep( sim_time - real_time) 00048 00049 for (topic, msg) in msgs: 00050 if 'header' in dir(msg): 00051 msg.header.stamp = now 00052 elif 'transforms' in dir(msg): 00053 for tf in msg.transforms: 00054 tf.header.stamp = now 00055 pub = pubs[topic] 00056 pub.publish(msg) 00057 if rospy.is_shutdown(): 00058 break 00059 bag.close() 00060