analyze.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import roslib
00004 roslib.load_manifest('tf')
00005 roslib.load_manifest('hrl_lib')
00006 import math, time, optparse
00007 import numpy as np
00008 import tf.transformations as tr
00009 import cPickle as pkl
00010 import scipy.stats as st
00011 import matplotlib.pyplot as plt
00012 from mpl_toolkits.mplot3d import Axes3D
00013 
00014 import scipy.optimize as so
00015 import hrl_lib.util as ut
00016 import hrl_lib.transforms as hrl_tr
00017 
00018 def parse():
00019         parser = optparse.OptionParser('Input the Pose node name and the ft sensor node name')
00020         parser.add_option("-n", "--name", action="store", type="string",\
00021                 dest="file_name", default="test")
00022         (options, args) = parser.parse_args()
00023         print 'Opening file name: ',options.file_name
00024 
00025         return options.file_name
00026 
00027 def compare(file1,file2):
00028         f1=ut.load_pickle(file1+'.pkl')
00029         f2=ut.load_pickle(file2+'.pkl')
00030         force1 = f1['force']
00031         force2 = f2['force']
00032         fmag1 = []
00033         fmag2 = []
00034 
00035         for i in range(len(force1)):
00036                 fmag1.append(np.linalg.norm(force1[i]))
00037         for i in range(len(force2)):
00038                 fmag2.append(np.linalg.norm(force2[i]))
00039         res = st.ttest_ind(fmag1,fmag2)
00040         print res
00041 
00042 
00043 if __name__ == '__main__':
00044         file_name = parse()
00045         d = ut.load_pickle(file_name+'.pkl')
00046         log = open('result_'+file_name+'.log','w')
00047         force = d['force']
00048         force_raw = d['force_raw']
00049         rot = d['rot_data']
00050         quat = d['quat']
00051         pos = d['pos']
00052         ptime = np.array(d['ptime'])-d['init_time']
00053         ftime = np.array(d['ftime'])-d['init_time']
00054         init_time = d['init_time']
00055         ptime2 = []
00056         force_mag = []
00057         length = []
00058         accel = []
00059         accel_mag = []
00060         v = []
00061         fx = []
00062         fy = []
00063         fz = []
00064         x = []
00065         y = []
00066         z = []
00067         vx = []
00068         vy = []
00069         vz = []
00070         rotx = []
00071         roty = []
00072         rotz = []
00073         time_diff = []
00074         vel = np.matrix([0.,0.,0.]).T
00075 
00076         for i in range(len(pos)):
00077                 if i < len(pos)-1:
00078                         if ptime[i+1]-ptime[i] > .02:
00079                                 vel=(pos[i+1]-pos[i])/(ptime[i+1]-ptime[i])
00080                                 length.append(np.linalg.norm(vel)*(ptime[i+1]-ptime[i]))
00081                                 ptime2.append(ptime[i])
00082                                 v.append(np.linalg.norm(vel))
00083                                 vx.append(vel[0,0])
00084                                 vy.append(vel[1,0])
00085                                 vz.append(vel[2,0])
00086                 
00087                 x.append(pos[i][0,0])
00088                 y.append(pos[i][1,0])
00089                 z.append(pos[i][2,0])
00090                 
00091                 rotx.append(math.degrees(rot[i][0,0]))
00092                 roty.append(math.degrees(rot[i][1,0]))
00093                 rotz.append(math.degrees(rot[i][2,0]))
00094 
00095         for i in range(len(force)):
00096                 force_mag.append(np.linalg.norm(force[i]))
00097                 fx.append(force[i][0,0])
00098                 fy.append(force[i][1,0])
00099                 fz.append(force[i][2,0])
00100 
00101                 
00102                 
00103 #       for i in range(len(v)-1):
00104 #               a = (v[i+1]-v[i])/.01
00105 #               accel.append(a)
00106 #               accel_mag.append(np.linalg.norm(a))
00107         
00108         print 'time: ', max(ptime)
00109         print 'max speed: ', max(v)
00110         print 'min speed: ', min(v)
00111                 
00112         path_length = sum(length)
00113         print 'Path Length: ', path_length
00114 
00115         print 'max vel: ', max(vx),max(vy),max(vz)
00116         print 'min vel: ', min(vx),min(vy),min(vz)
00117         print 'ave vel: ', np.mean(vx),np.mean(vx),np.mean(vz)
00118 
00119         print 'max force: ', max(fx), max(fy), max(fz)
00120         print 'min force: ', min(fx), min(fy), min(fz)
00121         print 'ave force: ', np.mean(fx),np.mean(fx),np.mean(fz)
00122 
00123         print 'max force_mag: ', max(force_mag)
00124         print 'min force_mag: ', min(force_mag)
00125         print 'ave force_mag: ', np.mean(force_mag)
00126         print 'std_force_mag: ', np.std(force_mag)
00127         print 'integration of force (N*s): ',sum(np.array(force_mag)*.01)
00128 
00129         print >> log, 'Categories x-axis y-axis z-axis'
00130         print >> log, 'max_vel', max(vx),max(vy),max(vz)
00131         print >> log, 'min_vel', min(vx),min(vy),min(vz)
00132         print >> log, 'ave_vel', np.mean(vx),np.mean(vx),np.mean(vz)
00133 
00134         print >> log, 'max_force', max(fx), max(fy), max(fz)
00135         print >> log, 'min_force', min(fx), min(fy), min(fz)
00136         print >> log, 'ave_force', np.mean(fx),np.mean(fx),np.mean(fz)
00137 
00138 
00139         print >> log, 'time', max(ptime)
00140         print >> log, 'path_length', sum(length)
00141         print >> log, 'max_force_mag', max(force_mag)
00142         print >> log, 'min_force_mag', min(force_mag)
00143         print >> log, 'ave_force_mag', np.mean(force_mag)
00144         print >> log, 'std_force_mag', np.std(force_mag)
00145         print >> log, 'int_force_mag',sum(np.array(force_mag)*.01)
00146 
00147 
00148         fig = plt.figure()
00149 #       ax = Axes3D(fig)
00150 #       ax.scatter(x,y,z,zdir = 'z')
00151         fig.suptitle(file_name+'_Position')
00152         ax = fig.add_subplot(3,1,1)
00153         ax.plot(ptime,x)
00154         ax.grid(True)
00155         ax.set_ylabel('x (m)')
00156         ax = fig.add_subplot(3,1,2)
00157         ax.plot(ptime,y)
00158         ax.grid(True)
00159         ax.set_ylabel('y (m)')
00160         ax = fig.add_subplot(3,1,3)
00161         ax.plot(ptime,z)
00162         ax.grid(True)
00163         ax.set_ylabel('z (m)')
00164 
00165         fig2 = plt.figure()
00166         fig2.suptitle(file_name+'_Force')
00167         ax = fig2.add_subplot(3,1,1)
00168         ax.plot(ftime,fx)
00169         ax.grid(True)
00170         ax.set_ylabel('Fx (N)')
00171         ax = fig2.add_subplot(3,1,2)
00172         ax.plot(ftime,fy)
00173         ax.grid(True)
00174         ax.set_ylabel('Fy (N)')
00175         ax = fig2.add_subplot(3,1,3)
00176         ax.plot(ftime,fz)
00177         ax.grid(True)
00178         ax.set_ylabel('Fz (N)')
00179 
00180 
00181         fig2b = plt.figure()
00182         fig2b.suptitle(file_name+' 3D Tra')
00183         ax = Axes3D(fig2b)
00184         ax.plot3D(x,y,z)
00185         ax.set_xlabel('x')
00186         ax.set_ylabel('y')
00187         ax.set_zlabel('z')
00188         
00189 
00190         fig2c = plt.figure()
00191         fig2c.suptitle(file_name+' Force Magnitute')
00192         ax = fig2c.gca()
00193         ax.plot(ftime,force_mag)
00194         ax.set_ylabel('Force (N)')
00195         ax.set_xlabel('Time (s)')
00196 
00197         fig3 = plt.figure()
00198         fig3.suptitle(file_name+'_Velocity')
00199         ax = fig3.add_subplot(3,1,1)
00200         ax.plot(ptime2,vx)
00201         ax.grid(True)
00202         ax.set_ylabel('Vx (m/s)')
00203         ax = fig3.add_subplot(3,1,2)
00204         ax.plot(ptime2,vy)
00205         ax.grid(True)
00206         ax.set_ylabel('Vy (m/s)')
00207         ax = fig3.add_subplot(3,1,3)
00208         ax.plot(ptime2,vz)
00209         ax.grid(True)
00210         ax.set_ylabel('Vz (m/s)')
00211 
00212         fig3a = plt.figure()
00213         fig3a.suptitle(file_name+' Speed')
00214         ax = fig3a.gca()
00215         ax.plot(ptime2,v)
00216         ax.set_ylabel('Speed (m/s)')
00217         ax.set_xlabel('Time (s)')
00218 
00219 
00220         fig4 = plt.figure()
00221         fig4.suptitle(file_name+'_rotation')
00222         ax = fig4.add_subplot(3,1,1)
00223         ax.plot(ptime,rotx)
00224         ax.grid(True)
00225         ax.set_ylabel('angle (deg)')
00226         ax = fig4.add_subplot(3,1,2)
00227         ax.plot(ptime,roty)
00228         ax.grid(True)
00229         ax.set_ylabel('angle (deg)')
00230         ax = fig4.add_subplot(3,1,3)
00231         ax.plot(ptime,rotz)
00232         ax.grid(True)
00233         ax.set_ylabel('angle (deg)')
00234 
00235 
00236         plt.show()
00237         log.close()
00238 
00239 #       compare('aa_scratch_arm','aa_scratch_face')


adl_pr2_log
Author(s): Aaron King
autogenerated on Wed Nov 27 2013 12:19:09