00001
00002 """
00003 Copyright (c) 2012,
00004 Systems, Robotics and Vision Group
00005 University of the Balearican Islands
00006 All rights reserved.
00007
00008 Redistribution and use in source and binary forms, with or without
00009 modification, are permitted provided that the following conditions are met:
00010 * Redistributions of source code must retain the above copyright
00011 notice, this list of conditions and the following disclaimer.
00012 * Redistributions in binary form must reproduce the above copyright
00013 notice, this list of conditions and the following disclaimer in the
00014 documentation and/or other materials provided with the distribution.
00015 * Neither the name of Systems, Robotics and Vision Group, University of
00016 the Balearican Islands nor the names of its contributors may be used to
00017 endorse or promote products derived from this software without specific
00018 prior written permission.
00019
00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00024 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 """
00031
00032
00033 PKG = 'bag_tools'
00034
00035 import roslib; roslib.load_manifest(PKG)
00036 import rospy
00037 import rosbag
00038 import os
00039 import sys
00040 import argparse
00041
00042 def check_delay(inbags):
00043 delays = {}
00044 for inbag in inbags:
00045 print ' Processing input bagfile: ', inbag
00046 for topic, msg, t in rosbag.Bag(inbag,'r').read_messages():
00047 if topic == "/tf":
00048 for transform in msg.transforms:
00049 delay = abs((t - transform.header.stamp).to_sec())
00050 key = "/tf: " + transform.header.frame_id + " -> " + transform.child_frame_id
00051 if key not in delays:
00052 delays[key] = []
00053 delays[key].append(delay)
00054 elif msg._has_header:
00055 key = topic
00056 if key not in delays:
00057 delays[key] = []
00058 delay = abs((t - msg.header.stamp).to_sec())
00059 delays[key].append(delay)
00060 max_len = max(len(topic) for topic in delays.keys())
00061 topics = delays.keys()
00062 topics.sort()
00063 for topic in topics:
00064 delay_list = delays[topic]
00065 delay_list.sort()
00066 dmin, dmax, dmean = min(delay_list), max(delay_list), sum(delay_list)/len(delay_list)
00067 dmedian = delay_list[len(delay_list)/2]
00068 print topic.ljust(max_len + 2), ": mean = ", dmean, ", min = ", dmin, ", max = ", dmax, ", median = ", dmedian
00069
00070
00071 if __name__ == "__main__":
00072 parser = argparse.ArgumentParser(
00073 description='Checks the delay in a bagfile between publishing (recording) '
00074 'time and the time stamp in the header (if exists). Prints '
00075 'out min, max and mean delays.')
00076 parser.add_argument('inbag', help='input bagfile(s)', nargs='+')
00077 args = parser.parse_args()
00078 try:
00079 check_delay(args.inbag)
00080 except Exception, e:
00081 import traceback
00082 traceback.print_exc()