23 import sensor_msgs.msg
24 import visualization_msgs.msg
25 import cob_grasp_generation.msg
26 from cob_grasp_generation
import grasp_query_utils
30 from urdf_parser_py.urdf
import URDF
38 for joint
in URDF.from_parameter_server().joints:
40 self.joint_mimic.append(joint)
41 elif joint.type ==
'revolute':
42 self.joint_names.append(joint.name)
43 if joint.limit.lower < 0.0
and 0.0 < joint.limit.upper:
44 self.joint_positions.append(0.0)
46 self.joint_positions.append((joint.limit.upper + joint.limit.lower)/2.0)
48 self.
js = sensor_msgs.msg.JointState()
52 self.
t = geometry_msgs.msg.TransformStamped()
53 self.t.header.frame_id =
"object_link" 54 self.t.child_frame_id =
"grasp_link" 55 self.t.transform.translation.x = 0.0
56 self.t.transform.translation.y = 0.0
57 self.t.transform.translation.z = 0.0
58 q = tf.transformations.quaternion_from_euler(0, 0, 0)
59 self.t.transform.rotation.x = q[0]
60 self.t.transform.rotation.y = q[1]
61 self.t.transform.rotation.z = q[2]
62 self.t.transform.rotation.w = q[3]
64 self.
marker = visualization_msgs.msg.Marker()
65 self.marker.header.frame_id =
"object_link" 66 self.marker.type = visualization_msgs.msg.Marker.MESH_RESOURCE
67 self.marker.pose.orientation.w = 1.0
68 self.marker.scale = geometry_msgs.msg.Vector3(1,1,1)
69 self.marker.color = std_msgs.msg.ColorRGBA(1,1,1,1)
72 self.
_js_pub = rospy.Publisher(
'/joint_states', sensor_msgs.msg.JointState, queue_size=1)
73 self.
_marker_pub = rospy.Publisher(
'/object_marker', visualization_msgs.msg.Marker, queue_size=1)
79 print(
"ShowGraspsRvizServer: action started...")
84 rospy.loginfo(
'Show grasp %i for object %s using gripper_type %s' % (goal.grasp_id, goal.object_name, goal.gripper_type))
86 if grasp_query_utils.check_database(goal.object_name, goal.gripper_type):
87 self.marker.mesh_resource =
"package://cob_grasp_generation/files/meshes/"+goal.object_name+
".stl" 88 grasp_list = grasp_query_utils.get_grasps(goal.object_name, goal.gripper_type, goal.gripper_side, goal.grasp_id, 1)
91 self.js.name = grasp_list[0].pre_grasp_posture.joint_names
92 self.js.position = grasp_list[0].grasp_posture.points[0].positions
94 idx = grasp_list[0].pre_grasp_posture.joint_names.index(joint.mimic.joint)
95 self.js.name.append(joint.name)
96 self.js.position.append(grasp_list[0].grasp_posture.points[0].positions[idx])
97 self.t.transform.translation = grasp_list[0].grasp_pose.pose.position
98 self.t.transform.rotation = grasp_list[0].grasp_pose.pose.orientation
103 rospy.logerr(
'GraspTable for Object %s does not exist!' % (goal.object_name))
105 result = cob_grasp_generation.msg.ShowGraspsResult()
106 result.success = success
109 rospy.loginfo(
'Show: Succeeded')
110 self._as_show.set_succeeded(result)
112 rospy.logwarn(
'Show: Failed')
113 self._as_show.set_aborted(result)
116 self.t.header.stamp = event.current_real
117 self.js.header.stamp = event.current_real
118 self.marker.header.stamp = event.current_real
120 self._br.sendTransform(self.
t)
121 self._js_pub.publish(self.
js)
122 self._marker_pub.publish(self.
marker)
125 if __name__ ==
'__main__':
126 rospy.init_node(
'show_grasps_rviz_server')
def timer_cb(self, event)