tf_stamps_to_csv.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rosbag
3 import rospy
4 import sys
5 import os
6 import PyKDL
7 
8 if len(sys.argv) < 4:
9  print "Usage: {} <bag_name> <parent frame> <child frame>".format(os.path.basename(sys.argv[0]))
10  print "Output file: bag_name.csv - each line: <stamp> <yaw angle>"
11  exit()
12 
13 input_bag_name = sys.argv[1]
14 parent_frame = sys.argv[2]
15 child_frame = sys.argv[3]
16 
17 try:
18  input_bag = rosbag.Bag(input_bag_name)
19  bag_loaded = True
20 except Exception:
21  print "Could not open bag {}".format(input_bag_name)
22  bag_loaded = False
23 
24 if bag_loaded:
25  name, ext = os.path.splitext(input_bag_name)
26 
27  out_file_name = "{name}.csv".format(name=name)
28  print "Writing to {}".format(out_file_name)
29  out_file = open(out_file_name, 'w')
30 
31  counter = 0
32  for topic, msg, t in input_bag.read_messages(topics=['tf']):
33  for t in msg.transforms:
34  if t.header.frame_id == parent_frame and t.child_frame_id == child_frame:
35  counter += 1
36  quat = PyKDL.Rotation.Quaternion(*[ getattr(t.transform.rotation, i) for i in ['x', 'y', 'z', 'w'] ])
37  yaw = quat.GetRPY()[2]
38  out_file.write('{:.12f} {:.12f}\n'.format(t.header.stamp.to_sec(), yaw))
39 
40  out_file.close()
41  input_bag.close()
42  print("Wrote {} entries.".format(counter))


timesync_ros
Author(s): Juraj Oršulić
autogenerated on Mon Jun 10 2019 15:28:33