cob_multi_pick_place_client.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 import random
19 import numpy
20 from math import pi
21 
22 import rospy
23 import actionlib
24 from geometry_msgs.msg import PoseStamped
25 from tf.transformations import *
26 import simple_moveit_interface as smi_
27 import cob_pick_place_action.msg
28 
29 ### Helper function
30 def gen_pose(frame_id="/base_link", pos=[0,0,0], euler=[0,0,0]):
31  pose = PoseStamped()
32  pose.header.frame_id = frame_id
33  pose.header.stamp = rospy.Time.now()
34  pose.pose.position.x, pose.pose.position.y, pose.pose.position.z = pos
35  pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w = quaternion_from_euler(*euler)
36  return pose
37 
39  psi = smi_.get_planning_scene_interface()
40  rospy.sleep(1.0)
41 
42  #smi_.clear_objects("arm_7_link")
43  smi_.clear_objects("arm_left_7_link")
44 
45  ### Add a floor
46  smi_.add_ground()
47 
48  ### Add table
49  pose = PoseStamped()
50  pose.header.frame_id = "/base_footprint"
51  pose.header.stamp = rospy.Time.now()
52  pose.pose.position.x = -0.9
53  pose.pose.position.y = 0
54  pose.pose.position.z = 0.39
55  pose.pose.orientation.x = 0
56  pose.pose.orientation.y = 0
57  pose.pose.orientation.z = 0
58  pose.pose.orientation.w = 1
59  psi.add_box("bookcase", pose, size=(0.5, 1.5, 0.78))
60  rospy.sleep(1.0)
61 
62 
63 
64 def cob_pick_action_client(object_class, object_name, object_pose):
65  pick_action_client = actionlib.SimpleActionClient('cob_pick_action', cob_pick_place_action.msg.CobPickAction)
66 
67  pick_action_client.wait_for_server()
68 
69  # Creates a goal to send to the action server.
70  goal = cob_pick_place_action.msg.CobPickGoal()
71  goal.object_class = object_class
72  goal.object_name = object_name
73  goal.object_pose = object_pose
74 
75  goal.gripper_type = "sdh"
76  #goal.gripper_side = ""
77  goal.gripper_side = "left"
78 
79  #goal.grasp_id = 21
80  #goal.grasp_database = "KIT"
81  goal.grasp_database = "OpenRAVE"
82  goal.support_surface = "bookcase"
83 
84  #print goal
85  # Sends the goal to the action server.
86  pick_action_client.send_goal(goal)
87 
88  # Waits for the server to finish performing the action.
89  finished_before_timeout=pick_action_client.wait_for_result(rospy.Duration(300, 0))
90 
91  if finished_before_timeout:
92  state=pick_action_client.get_state()
93  print "Action finished: %s"%state
94  # Prints out the result of executing the action
95  return state # State after waiting for PickupAction
96 
97 
98 def cob_place_action_client(object_class, object_name, destinations):
99  # Creates the SimpleActionClient, passing the type of the action
100  # (CobPlaceAction) to the constructor.
101  place_action_client = actionlib.SimpleActionClient('cob_place_action', cob_pick_place_action.msg.CobPlaceAction)
102 
103  # Waits until the action server has started up and started
104  # listening for goals.
105  place_action_client.wait_for_server()
106 
107  # Creates a goal to send to the action server.
108  goal = cob_pick_place_action.msg.CobPlaceGoal()
109  goal.object_class = object_class
110  goal.object_name = object_name
111  goal.destinations = destinations
112  goal.support_surface = "bookcase"
113 
114  #print goal
115  # Sends the goal to the action server.
116  place_action_client.send_goal(goal)
117 
118  # Waits for the server to finish performing the action.
119  finished_before_timeout=place_action_client.wait_for_result(rospy.Duration(300, 0))
120 
121  if finished_before_timeout:
122  state=place_action_client.get_state()
123  print "Action finished: %s"%state
124  # Prints out the result of executing the action
125  return state # State after waiting for CobPlaceAction
126 
127 
128 if __name__ == '__main__':
129  try:
130  # Initializes a rospy node so that the SimpleActionClient can
131  # publish and subscribe over ROS.
132  rospy.init_node('CobPickAction_client_py')
133 
135 
136  psi = smi_.get_planning_scene_interface()
137  rospy.sleep(1.0)
138 
139  filename = roslib.packages.get_pkg_dir('cob_grasp_generation')+"/files/meshes/yellowsaltcube.stl"
140  pose1 = gen_pose(pos=[-0.7, 0.0, 0.85], euler=[random.uniform(-pi, pi), random.uniform(-pi, pi), random.uniform(-pi, pi)])
141  psi.add_mesh("cube1", pose1, filename)
142  rospy.sleep(1.0)
143 
144  pose2 = gen_pose(pos=[-0.7, 0.2, 0.85], euler=[random.uniform(-pi, pi), random.uniform(-pi, pi), random.uniform(-pi, pi)])
145  psi.add_mesh("cube2", pose2, filename)
146  rospy.sleep(1.0)
147 
148  destinations = []
149  for x in numpy.arange(-0.9, -0.6, 0.1):
150  for y in numpy.arange(-0.3, -0.2, 0.1):
151  for theta in numpy.arange(-pi, pi, pi/2):
152  destination = gen_pose(pos=[x,y,0.78], euler=[0,0,theta])
153  destinations.append(destination)
154 
155 
156  result = cob_pick_action_client(18, "cube1", pose1)
157 
158  #destinations = []
159  #destination1 = gen_pose(pos=[-0.7, -0.15, 0.78])
160  #destinations.append(destination1)
161  result = cob_place_action_client(18, "cube1", destinations)
162 
163  result = cob_pick_action_client(18, "cube2", pose2)
164 
165  #destination2 = gen_pose(pos=[-0.7, -0.30, 0.78])
166  #destinations.append(destination2)
167  #destinations.append(pose1)
168  #destinations.append(pose2)
169  result = cob_place_action_client(18, "cube2", destinations)
170 
171 
172  except rospy.ROSInterruptException:
173  print "program interrupted before completion"
def cob_place_action_client(object_class, object_name, destinations)
def cob_pick_action_client(object_class, object_name, object_pose)
def gen_pose(frame_id="/base_link", pos=[0, euler=[0)
Helper function.


cob_pick_place_action
Author(s): Felix Messmer
autogenerated on Mon Jun 10 2019 13:10:02