cob_pick_action_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 from math import pi
20 
21 import rospy
22 import actionlib
23 from geometry_msgs.msg import PoseStamped
24 from tf.transformations import *
25 import simple_moveit_interface as smi_
26 import cob_pick_place_action.msg
27 
28 
30  psi = smi_.get_planning_scene_interface()
31  rospy.sleep(1.0)
32 
33  #smi_.clear_objects("arm_7_link")
34  smi_.clear_objects("arm_left_7_link")
35 
36  ### Add a floor
37  smi_.add_ground()
38 
39  ### Add table
40  pose = PoseStamped()
41  pose.header.frame_id = "/base_footprint"
42  pose.header.stamp = rospy.Time.now()
43  pose.pose.position.x = -0.9
44  pose.pose.position.y = 0
45  pose.pose.position.z = 0.39
46  pose.pose.orientation.x = 0
47  pose.pose.orientation.y = 0
48  pose.pose.orientation.z = 0
49  pose.pose.orientation.w = 1
50 
51  psi.add_box("bookcase", pose, size=(0.5, 1.5, 0.78))
52 
53  rospy.sleep(1.0)
54 
55 
57  pick_action_client = actionlib.SimpleActionClient('cob_pick_action', cob_pick_place_action.msg.CobPickAction)
58 
59  pick_action_client.wait_for_server()
60 
62 
63  # Creates a goal to send to the action server.
64  goal = cob_pick_place_action.msg.CobPickGoal()
65  #goal.object_class = 18
66  #goal.object_name = "yellowsaltcube"
67  #goal.object_class = 50
68  #goal.object_name = "instantsoup"
69  #goal.object_class = 103
70  #goal.object_name = "instanttomatosoup"
71  goal.object_class = 5001
72  goal.object_name = "pringles"
73  goal.object_pose.header.stamp = rospy.Time.now()
74  goal.object_pose.header.frame_id = "base_footprint"
75 
76  ### cob3
77  #goal.object_pose.pose.position.x = random.uniform(-0.8, -0.6)
78  #goal.object_pose.pose.position.y = random.uniform(-0.3, 0.3)
79  #goal.object_pose.pose.position.z = random.uniform( 0.8, 1.1)
80  #goal.object_pose.pose.orientation.x, goal.object_pose.pose.orientation.y, goal.object_pose.pose.orientation.z, goal.object_pose.pose.orientation.w = quaternion_from_euler(random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2))
81  #goal.gripper_type = "sdh"
82  #goal.gripper_side = ""
83 
84  ### cob4
85  goal.object_pose.pose.position.x = 0.617 + random.uniform(-0.1, 0.1)
86  goal.object_pose.pose.position.y = 0.589 + random.uniform(-0.1, 0.1)
87  goal.object_pose.pose.position.z = 0.979 + random.uniform(-0.1, 0.1)
88  goal.object_pose.pose.orientation.x, goal.object_pose.pose.orientation.y, goal.object_pose.pose.orientation.z, goal.object_pose.pose.orientation.w = quaternion_from_euler(random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2))
89  #goal.object_pose.pose.orientation.x, goal.object_pose.pose.orientation.y, goal.object_pose.pose.orientation.z, goal.object_pose.pose.orientation.w = quaternion_from_euler(-1.571, -0.000, -1.400)
90  goal.gripper_type = "sdhx"
91  #goal.gripper_side = ""
92  goal.gripper_side = "left"
93 
94  #goal.grasp_database = "KIT"
95  goal.grasp_database = "OpenRAVE"
96  #goal.grasp_database = "ALL"
97  #goal.grasp_id = 2
98  goal.support_surface = "bookcase"
99 
100  # Sends the goal to the action server.
101  pick_action_client.send_goal(goal)
102 
103  # Waits for the server to finish performing the action.
104  finished_before_timeout=pick_action_client.wait_for_result(rospy.Duration(300, 0))
105 
106  if finished_before_timeout:
107  state=pick_action_client.get_state()
108  print "Action finished: %s"%state
109  else:
110  print "Action did not finish within timeout"
111  return
112 
113 if __name__ == '__main__':
114  try:
115  # Initializes a rospy node so that the SimpleActionClient can
116  # publish and subscribe over ROS.
117  rospy.init_node('CobPickAction_client_py')
119  except rospy.ROSInterruptException:
120  print "program interrupted before completion"


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