Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 """Analyze Grasp 3D - own module: a collection of several function for analyzing the grasps
00019 """
00020 from openravepy import *
00021 import numpy, time, scipy, csv, os
00022 import roslib.packages
00023
00024
00025
00026
00027 def or_to_csv(validgrasps):
00028 meta_info = validgrasps[0]
00029 object_name = meta_info[0]
00030 gripper_type = meta_info[1]
00031
00032
00033 directory = roslib.packages.get_pkg_dir('cob_grasp_generation')+'/files/database/'+object_name
00034 if not os.path.exists(directory):
00035 os.makedirs(directory)
00036 pathname_out = directory+'/'+gripper_type+'_'+object_name+'.csv'
00037 f_out = open(pathname_out, 'w+')
00038
00039 wr = csv.writer(f_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
00040 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'])
00041
00042
00043 for i in range (1,len(validgrasps)):
00044 row = []
00045 actual_grasp = validgrasps[i]
00046 row.append(str(actual_grasp[0]))
00047 row.append(object_name)
00048
00049
00050
00051
00052 joint_values = actual_grasp[1]
00053
00054
00055
00056 if joint_values[0] < 0:
00057 joint_values[0] = 0
00058
00059
00060 joint_values_sorted = [joint_values[0], joint_values[3], joint_values[4], joint_values[1], joint_values[2], joint_values[5], joint_values[6]]
00061 for i in range(0,len(joint_values)):
00062 row.append(joint_values_sorted[i])
00063
00064
00065 globApproach = actual_grasp[7]
00066 if globApproach[2] < -0.7:
00067 row.append('TOP')
00068 else:
00069 row.append('SIDE')
00070
00071
00072 trafo4x4 = actual_grasp[2]
00073 m_in_mm = 1000
00074 pose = poseFromMatrix(trafo4x4)
00075 pose[4] = m_in_mm * pose[4]
00076 pose[5] = m_in_mm * pose[5]
00077 pose[6] = m_in_mm * pose[6]
00078 for i in range(0,len(pose)):
00079 row.append(pose[i])
00080
00081
00082 row.append("%.9f" % actual_grasp[3])
00083 row.append("%.9f" % actual_grasp[4])
00084
00085
00086 row.append(actual_grasp[6])
00087
00088
00089 if (not actual_grasp[3] == 0.0) and (not actual_grasp[4] == 0.0):
00090 wr.writerow(row)
00091
00092 f_out.close()
00093 print "Finished."