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
00008
00009
00010 def or_to_csv(validgrasps):
00011 meta_info = validgrasps[0]
00012 name = meta_info[0]
00013
00014
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)):
00025 row = []
00026 actual_grasp = validgrasps[i]
00027 row.append(str(actual_grasp[0]))
00028 row.append(name)
00029
00030
00031
00032
00033 joint_values = actual_grasp[1]
00034
00035
00036
00037 if joint_values[0] < 0:
00038 joint_values[0] = 0
00039
00040
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
00046 globApproach = actual_grasp[7]
00047 if globApproach[2] < -0.7:
00048 row.append('TOP')
00049 else:
00050 row.append('SIDE')
00051
00052
00053 trafo4x4 = actual_grasp[2]
00054 m_in_mm = 1000
00055 pose = poseFromMatrix(trafo4x4)
00056 pose[4] = m_in_mm * pose[4]
00057 pose[5] = m_in_mm * pose[5]
00058 pose[6] = m_in_mm * pose[6]
00059 for i in range(0,len(pose)):
00060 row.append(pose[i])
00061
00062
00063 row.append("%.9f" % actual_grasp[3])
00064 row.append("%.9f" % actual_grasp[4])
00065
00066
00067 row.append(actual_grasp[6])
00068
00069
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."