Go to the documentation of this file.00001
00002 import roslib
00003 roslib.load_manifest("biotac_log_parser")
00004 import rospy
00005 import rosbag
00006 import numpy
00007 import glob
00008 import sys
00009 import cPickle
00010 from optparse import OptionParser
00011 import itertools
00012 import tables
00013 from biotac_sensors.msg import BioTacHand
00014
00015 from collections import defaultdict
00016
00017
00018
00019 def main():
00020 if len(sys.argv) < 3:
00021 rospy.loginfo("Usage: %s [input_files] [output_files]", sys.argv[0])
00022 return
00023
00024 input_filenames = sys.argv[1:-1]
00025 output_filename = sys.argv[-1]
00026
00027 filters = tables.Filters(complevel=9)
00028 h5file = tables.openFile(output_filename, mode="w", title="Biotach Log",
00029 filters = filters)
00030
00031 for filename in input_filenames:
00032
00033 rospy.loginfo("Opening bag %s"% filename)
00034 bag = rosbag.Bag(filename)
00035
00036 tdc_data = defaultdict(list)
00037 tac_data = defaultdict(list)
00038 pdc_data = defaultdict(list)
00039 pac_data = defaultdict(list)
00040 electrode_data = defaultdict(list)
00041 time_stamp = []
00042
00043 num_entries = 0
00044 for _, msg, stamp in bag.read_messages(topics="/biotac_pub"):
00045 num_entries += 1
00046 isinstance(msg, BioTacHand)
00047
00048 num_fingers = len(msg.bt_data)
00049 for finger_index in xrange(num_fingers):
00050
00051 tdc_data[finger_index].append( msg.bt_data[finger_index].tdc_data)
00052 tac_data[finger_index].append( msg.bt_data[finger_index].tac_data)
00053 pdc_data[finger_index].append( msg.bt_data[finger_index].pdc_data)
00054 pac_data[finger_index].append( msg.bt_data[finger_index].pac_data)
00055 electrode_data[finger_index].append( msg.bt_data[finger_index].electrode_data)
00056
00057 time_stamp.append( stamp.to_sec())
00058
00059
00060
00061 group_name = filename.partition(".")[0]
00062
00063
00064 bag_group = h5file.createGroup("/", group_name)
00065
00066 timestamps_carray = h5file.createCArray(bag_group, "timestamps", tables.Int64Atom(), (num_entries,)
00067 )
00068 timestamps_carray[:] = time_stamp
00069
00070 for finger_index in xrange(num_fingers):
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 finger_group = h5file.createGroup(bag_group, "finger_"+str(finger_index))
00083
00084 electrode_carray = h5file.createCArray(finger_group, "electrodes", tables.Int64Atom(), (num_entries, 19))
00085 electrode_carray[:] = electrode_data[finger_index]
00086
00087 pac_carray = h5file.createCArray(finger_group, "pac", tables.Int64Atom(), (num_entries, 22))
00088 pac_carray[:] = pac_data[finger_index]
00089
00090 tdc_array = h5file.createCArray(finger_group, "tdc", tables.Int64Atom(), (num_entries,))
00091 tdc_array[:] = tdc_data[finger_index]
00092
00093 tac_carray = h5file.createCArray(finger_group, "tac", tables.Int64Atom(), (num_entries,))
00094 tac_carray[:] = tac_data[finger_index]
00095
00096 pdc_carray = h5file.createCArray(finger_group, "pdc", tables.Int64Atom(), (num_entries,))
00097 pdc_carray[:] = pdc_data[finger_index]
00098
00099
00100 h5file.close()
00101
00102
00103 if __name__ == "__main__":
00104 main()