32 path_in = roslib.packages.get_pkg_dir(
'cob_grasp_generation')+
'/files/database/'+object_name+
'/'+gripper_type+
'_'+object_name+
'.csv' 35 if os.path.exists(path_in):
42 path_in = roslib.packages.get_pkg_dir(
'cob_grasp_generation')+
'/files/database/'+object_name+
'/'+gripper_type+
'_'+object_name+
'.csv' 46 with open(path_in)
as f:
pass 48 rospy.logerr(
"The path or file does not exist: "+path_in)
51 reader = csv.DictReader( open(path_in,
"rb"), delimiter=
',')
55 return sorted(reader, key=
lambda d: float(d[
'eps_l1']), reverse=
True)
57 return sorted(reader, key=
lambda d: float(d[
'id']), reverse=
False)
60 def get_grasps(object_name, gripper_type, gripper_side="", grasp_id=0, num_grasps=0, threshold=0):
66 if grasp_id < len(grasp_list):
68 return [
_fill_grasp_msg(gripper_type, gripper_side, grasp_list[grasp_id])]
70 print(
"Grasp not available")
74 sorted_list = sorted(grasp_list, key=
lambda d: float(d[
'eps_l1']), reverse=
True)
78 max_grasps=min(len(sorted_list),num_grasps)
80 max_grasps=len(sorted_list)
83 selected_grasp_list = []
84 for i
in range(0,max_grasps):
85 if threshold > 0
and float(sorted_list[i][
'eps_l1']) >= threshold:
86 selected_grasp_list.append(
_fill_grasp_msg(gripper_type, gripper_side, sorted_list[i]))
88 selected_grasp_list.append(
_fill_grasp_msg(gripper_type, gripper_side, sorted_list[i]))
93 return selected_grasp_list
99 joint_config = JointTrajectory()
104 if gripper_type ==
"sdh":
105 joint_config.joint_names = [
'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']
106 elif gripper_type ==
"sdhx":
107 joint_config.joint_names = [
'gripper_finger_1_joint',
'gripper_finger_2_joint']
109 rospy.logerr(
"Gripper not supported")
113 point = JointTrajectoryPoint()
114 for joint_name
in joint_config.joint_names:
115 point.positions.append(float(grasp[joint_name]))
116 point.velocities.append(0.0)
117 point.accelerations.append(0.0)
118 point.effort.append(0.0)
119 point.time_from_start = rospy.Duration(3.0)
120 joint_config.points.append(point)
124 if gripper_type ==
"sdh":
125 if gripper_side ==
"left":
126 joint_config.joint_names = [
'sdh_left_knuckle_joint',
'sdh_left_finger_12_joint',
'sdh_left_finger_13_joint',
'sdh_left_finger_22_joint',
'sdh_left_finger_23_joint',
'sdh_left_thumb_2_joint',
'sdh_left_thumb_3_joint']
127 elif gripper_side ==
"right":
128 joint_config.joint_names = [
'sdh_right_knuckle_joint',
'sdh_right_finger_12_joint',
'sdh_right_finger_13_joint',
'sdh_right_finger_22_joint',
'sdh_right_finger_23_joint',
'sdh_right_thumb_2_joint',
'sdh_right_thumb_3_joint']
130 joint_config.joint_names = [
'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']
131 elif gripper_type ==
"sdhx":
132 if gripper_side ==
"left":
133 joint_config.joint_names = [
'gripper_left_finger_1_joint',
'gripper_left_finger_2_joint']
134 elif gripper_side ==
"right":
135 joint_config.joint_names = [
'gripper_right_finger_1_joint',
'gripper_right_finger_2_joint']
137 joint_config.joint_names = [
'gripper_finger_1_joint',
'gripper_finger_2_joint']
139 rospy.logerr(
"Gripper not supported")
145 pre_joint_config = JointTrajectory()
150 if gripper_type ==
"sdh":
151 if gripper_side ==
"left":
152 pre_joint_config.joint_names = [
'sdh_left_knuckle_joint',
'sdh_left_finger_12_joint',
'sdh_left_finger_13_joint',
'sdh_left_finger_22_joint',
'sdh_left_finger_23_joint',
'sdh_left_thumb_2_joint',
'sdh_left_thumb_3_joint']
153 elif gripper_side ==
"right":
154 pre_joint_config.joint_names = [
'sdh_right_knuckle_joint',
'sdh_right_finger_12_joint',
'sdh_right_finger_13_joint',
'sdh_right_finger_22_joint',
'sdh_right_finger_23_joint',
'sdh_right_thumb_2_joint',
'sdh_right_thumb_3_joint']
156 pre_joint_config.joint_names = [
'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']
157 open_config = [0.0, -0.9854, 0.9472, -0.9854, 0.9472, -0.9854, 0.9472]
158 elif gripper_type ==
"sdhx":
159 if gripper_side ==
"left":
160 pre_joint_config.joint_names = [
'gripper_left_finger_1_joint',
'gripper_left_finger_2_joint']
161 elif gripper_side ==
"right":
162 pre_joint_config.joint_names = [
'gripper_right_finger_1_joint',
'gripper_right_finger_2_joint']
164 pre_joint_config.joint_names = [
'gripper_finger_1_joint',
'gripper_finger_2_joint']
165 open_config = [-0.85, -0.5]
168 rospy.logerr(
"Gripper not supported")
171 point = JointTrajectoryPoint()
172 for i
in range(len(pre_joint_config.joint_names)):
173 point.positions.append(open_config[i])
174 point.velocities.append(0.0)
175 point.accelerations.append(0.0)
176 point.effort.append(0.0)
177 point.time_from_start = rospy.Duration(3.0)
178 pre_joint_config.points.append(point)
182 grasp_pose = PoseStamped()
183 grasp_pose.header.stamp = rospy.Time.now()
185 grasp_pose.pose.position.x = float(grasp[
'pos-x'])*0.001
186 grasp_pose.pose.position.y = float(grasp[
'pos-y'])*0.001
187 grasp_pose.pose.position.z = float(grasp[
'pos-z'])*0.001
188 grasp_pose.pose.orientation.x = float(grasp[
'qx'])
189 grasp_pose.pose.orientation.y = float(grasp[
'qy'])
190 grasp_pose.pose.orientation.z = float(grasp[
'qz'])
191 grasp_pose.pose.orientation.w = float(grasp[
'qw'])
195 grasp_out.id = grasp[
'id']
196 grasp_out.pre_grasp_posture = pre_joint_config
197 grasp_out.grasp_posture = joint_config
198 grasp_out.grasp_pose = grasp_pose
199 grasp_out.grasp_quality = float(grasp[
'eps_l1'])
200 grasp_out.max_contact_force = 0
def _fill_grasp_msg(gripper_type, gripper_side, grasp)
def get_grasps(object_name, gripper_type, gripper_side="", grasp_id=0, num_grasps=0, threshold=0)
def get_grasp_list(object_name, gripper_type, sort_by_quality=False)
def check_database(object_name, gripper_type)