gps_to_std_gt.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('stereo_slam')
00003 import pylab
00004 import numpy as np
00005 from matplotlib import pyplot
00006 from mpl_toolkits.mplot3d import Axes3D
00007 
00008 class Error(Exception):
00009   """ Base class for exceptions in this module. """
00010   pass
00011 
00012 def get_xyz(gps_point):
00013   lat = gps_point[3]*np.pi/180 #converting to radians.
00014   lon = gps_point[4]*np.pi/180 #converting to radians.
00015   alt = gps_point[5]*np.pi/180 #converting to radians.  
00016   a = 6378137.0 # earth semimajor axis in meters.   
00017   f = 1/298.257223563 # reciprocal flattening. 
00018   e2 = 2*f - np.power(f,2) # eccentricity squared. 
00019 
00020   chi = np.sqrt(1-e2 * np.power(np.sin(lat),2)); 
00021   x = (a/chi +alt) * np.cos(lat) * np.cos(lon);   
00022   y = (a/chi +alt) * np.cos(lat) * np.sin(lon);   
00023   z = (a*(1-e2)/chi + alt) * np.sin(lat); 
00024   return x, y, z
00025 
00026 if __name__ == "__main__":
00027   import argparse
00028   parser = argparse.ArgumentParser(
00029           description='Convert gps/fix topic to standard ground truth file',
00030           formatter_class=argparse.ArgumentDefaultsHelpFormatter)
00031   parser.add_argument('gps_topic_file', 
00032           help='file with the gps/fix topic. Saved with "rostopic echo -p /gps/fix > data/anselm_turmeda/gt_gps.txt"')
00033   parser.add_argument('output_file', 
00034           help='output file where the standard ground truth values will be saved.')
00035   args = parser.parse_args()
00036 
00037   # Read the 
00038   gps_topic = pylab.loadtxt(args.gps_topic_file, delimiter=',', skiprows=1, usecols=(0,1,2,6,7,8))
00039 
00040   # Write the x, y, z data to the output file
00041   with open(args.output_file, 'w') as outfile:
00042     outfile.write("%time,field.header.seq,field.header.stamp,field.header.frame_id,field.child_frame_id,x,y,z,qx,qy,qz,qw\n")
00043     x0, y0, z0 = get_xyz(gps_topic[0])
00044     gt = []
00045     gt.append([0.0, 0.0, 0.0])
00046     for i in range(len(gps_topic)-1):
00047       x, y, z = get_xyz(gps_topic[i+1])
00048       x = x-x0
00049       y = y-y0
00050       z = z-z0
00051       gt.append([x, y, z])
00052       outfile.write("%.9F," % gps_topic[i+1, 0])
00053       outfile.write(str(gps_topic[i+1, 1]) + "," + str(gps_topic[i+1, 2]) + ",/gps,,")
00054       outfile.write("%.9F," % x)
00055       outfile.write("%.9F," % y)
00056       outfile.write("%.9F," % z)
00057       outfile.write("0.0,0.0,0.0,0.0")
00058       outfile.write("\n")
00059   gt = np.array(gt)
00060 
00061   # Init figure
00062   fig = pylab.figure(1)
00063   ax = Axes3D(fig)
00064   ax.grid(True)
00065   ax.set_title("GT Viewer")
00066   ax.set_xlabel("X")
00067   ax.set_ylabel("Y")
00068   ax.set_zlabel("Z")
00069 
00070   ax.plot(gt[:,0], gt[:,1], gt[:,2], 'g', label='Ground Truth')
00071   ax.legend()
00072 
00073   pyplot.draw()
00074   pylab.show()
00075     


bag_tools
Author(s): Stephan Wirth , Miquel Massot
autogenerated on Fri Aug 28 2015 13:15:13