analyzegrasp3d.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 """Analyze Grasp 3D - own module: a collection of several function for analyzing the grasps
19 """
20 
21 from openravepy import poseFromMatrix # pylint: disable=import-error
22 import numpy, time, scipy, csv, os
23 import roslib.packages
24 
25 #converts all openrave grasps to csv format for scripting
26 #input-first-line (meta-info): object_name, gripper_type, time (@todo: add planner infos)
27 #input-struct: number, jointconf, trafo, epsilon, volume, forceclosure, validindicees, direction
28 def or_to_csv(validgrasps):
29  meta_info = validgrasps[0]
30  object_name = meta_info[0]
31  gripper_type = meta_info[1]
32 
33  #create directories
34  directory = roslib.packages.get_pkg_dir('cob_grasp_generation')+'/files/database/'+object_name
35  if not os.path.exists(directory):
36  os.makedirs(directory)
37  pathname_out = directory+'/'+gripper_type+'_'+object_name+'.csv'
38  f_out = open(pathname_out, 'w+')
39 
40  wr = csv.writer(f_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
41  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'])
42  # ToDo: This will not work for grippers other than SDH
43 
44  for i in range (1,len(validgrasps)): #because line 0 is meta-info
45  row = [] #create/empty row for new grasp
46  actual_grasp = validgrasps[i]
47  row.append(str(actual_grasp[0])) #ID
48  row.append(object_name)
49 
50  ##SOLL
51  #SDH Joint Values - Beginnend mit Daumen(1) und die Zwei Finger GUZS nummeriert(2)(3)
52  #[Fingerwinkel(2)(3), Fingerwinkel(2), Fingerknick(2), Fingerwinkel(3), Fingerknick(3), Fingerwinkel(1), Fingerknick(1)]
53  joint_values = actual_grasp[1]
54 
55  #Check Knuckle_joint of SDH for values < 0
56  #Reason: Openrave generates some zero values that are slighlty below zero
57  if joint_values[0] < 0:
58  joint_values[0] = 0
59 
60  #assign joint values in the right order
61  joint_values_sorted = [joint_values[0], joint_values[3], joint_values[4], joint_values[1], joint_values[2], joint_values[5], joint_values[6]]
62  for i in range(0,len(joint_values)):
63  row.append(joint_values_sorted[i])
64 
65  #grasp-direction
66  globApproach = actual_grasp[7] #globalApproachDir
67  if globApproach[2] < -0.7: #if hand approaches > 63 degrees
68  row.append('TOP')
69  else:
70  row.append('SIDE')
71 
72  #convert 4x4 matrix to pose
73  trafo4x4 = actual_grasp[2]
74  m_in_mm = 1000
75  pose = poseFromMatrix(trafo4x4) #returns [w, q0, q1, q2, x, y, z]
76  pose[4] = m_in_mm * pose[4] #x-koord
77  pose[5] = m_in_mm * pose[5] #y-koord
78  pose[6] = m_in_mm * pose[6] #z-koord
79  for i in range(0,len(pose)):
80  row.append(pose[i])
81 
82  #quality
83  row.append("%.9f" % actual_grasp[3]) #epsilon with precision
84  row.append("%.9f" % actual_grasp[4]) #volume with precision
85 
86  #misc
87  row.append(actual_grasp[6]) #validindicees
88 
89  #write this grasp as row to file
90  if (not actual_grasp[3] == 0.0) and (not actual_grasp[4] == 0.0):
91  wr.writerow(row)
92 
93  f_out.close()
94  print("Finished.")


cob_grasp_generation
Author(s): Witalij Siebert, Felix Messmer
autogenerated on Sun Dec 6 2020 03:25:46