analyzegrasp3d.py
Go to the documentation of this file.
00001 """Analyze Grasp 3D - own module: a collection of several function for analyzing the grasps
00002 """
00003 from openravepy import *
00004 import numpy, time, scipy, csv, os
00005 import roslib.packages
00006 
00007 #converts all openrave grasps to csv format for scripting
00008 #input-first-line (meta-info): name, time (@todo: add planner infos)
00009 #input-struct: number, jointconf, trafo, epsilon, volume, forceclosure, validindicees, direction
00010 def or_to_csv(validgrasps):
00011         meta_info = validgrasps[0]
00012         name = meta_info[0]
00013 
00014         #create directories
00015         directory = roslib.packages.get_pkg_dir('cob_grasp_generation')+'/files/database/'+name
00016         if not os.path.exists(directory):
00017                 os.makedirs(directory)
00018         pathname_out = directory+'/'+name+'.csv'
00019         f_out = open(pathname_out, 'w+')
00020 
00021         wr = csv.writer(f_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) 
00022         wr.writerow(['id', 'object', 'sdh_knuckle_joint', 'sdh_finger_12_joint', 'sdh_finger_13_joint', 'sdh_finger_22_joint', 'sdh_finger_23_joint', 'sdh_thumb_2_joint', 'sdh_thumb_3_joint', 'direction', 'qw', 'qx', 'qy', 'qz','pos-x', 'pos-y', 'pos-z', 'eps_l1', 'vol_l1'])
00023 
00024         for i in range (1,len(validgrasps)): #because line 0 is meta-info
00025                 row = [] #create/empty row for new grasp
00026                 actual_grasp = validgrasps[i]
00027                 row.append(str(actual_grasp[0])) #ID
00028                 row.append(name) #Object-name
00029                 
00030                 ##SOLL
00031                 #SDH Joint Values - Beginnend mit Daumen(1) und die Zwei Finger GUZS nummeriert(2)(3)
00032                 #[Fingerwinkel(2)(3), Fingerwinkel(2), Fingerknick(2), Fingerwinkel(3), Fingerknick(3), Fingerwinkel(1), Fingerknick(1)]
00033                 joint_values = actual_grasp[1]
00034 
00035                 #Check Knuckle_joint of SDH for values < 0
00036                 #Reason: Openrave generates some zero values that are slighlty below zero
00037                 if joint_values[0] < 0:
00038                         joint_values[0] = 0
00039 
00040                 #assign joint values in the right order 
00041                 joint_values_sorted = [joint_values[0], joint_values[3], joint_values[4], joint_values[1], joint_values[2], joint_values[5], joint_values[6]]
00042                 for i in range(0,len(joint_values)):
00043                         row.append(joint_values_sorted[i])
00044                 
00045                 #grasp-direction
00046                 globApproach = actual_grasp[7] #globalApproachDir
00047                 if globApproach[2] < -0.7: #if hand approaches > 63 degrees
00048                         row.append('TOP')
00049                 else:
00050                         row.append('SIDE')
00051 
00052                 #convert 4x4 matrix to pose
00053                 trafo4x4 = actual_grasp[2]
00054                 m_in_mm = 1000
00055                 pose = poseFromMatrix(trafo4x4) #returns [w, q0, q1, q2, x, y, z]
00056                 pose[4] = m_in_mm * pose[4] #x-koord
00057                 pose[5] = m_in_mm * pose[5] #y-koord
00058                 pose[6] = m_in_mm * pose[6] #z-koord
00059                 for i in range(0,len(pose)):
00060                         row.append(pose[i])
00061 
00062                 #quality
00063                 row.append("%.9f" % actual_grasp[3]) #epsilon with precision
00064                 row.append("%.9f" % actual_grasp[4]) #volume with precision
00065 
00066                 #misc
00067                 row.append(actual_grasp[6]) #validindicees
00068 
00069                 #write this grasp as row to file
00070                 if (not actual_grasp[3] == 0.0) and (not actual_grasp[4] == 0.0):
00071                         wr.writerow(row)
00072         
00073         f_out.close()
00074         print "Finished."


cob_grasp_generation
Author(s): Witalij Siebert, Felix Messmer
autogenerated on Wed Aug 26 2015 11:01:25