cob_pick_action_client.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 
00017 
00018 import random
00019 from math import pi
00020 
00021 import rospy
00022 import actionlib
00023 from geometry_msgs.msg import PoseStamped
00024 from tf.transformations import *
00025 import simple_moveit_interface as smi_
00026 import cob_pick_place_action.msg
00027 
00028 
00029 def setup_environment():
00030         psi = smi_.get_planning_scene_interface()
00031         rospy.sleep(1.0)
00032 
00033         #smi_.clear_objects("arm_7_link")
00034         smi_.clear_objects("arm_left_7_link")
00035 
00036         ### Add a floor
00037         smi_.add_ground()
00038 
00039         ### Add table
00040         pose = PoseStamped()
00041         pose.header.frame_id = "/base_footprint"
00042         pose.header.stamp = rospy.Time.now()
00043         pose.pose.position.x = -0.9
00044         pose.pose.position.y = 0
00045         pose.pose.position.z = 0.39
00046         pose.pose.orientation.x = 0
00047         pose.pose.orientation.y = 0
00048         pose.pose.orientation.z = 0
00049         pose.pose.orientation.w = 1
00050 
00051         psi.add_box("bookcase", pose, size=(0.5, 1.5, 0.78))
00052 
00053         rospy.sleep(1.0)
00054 
00055 
00056 def cob_pick_action_client():
00057         pick_action_client = actionlib.SimpleActionClient('cob_pick_action', cob_pick_place_action.msg.CobPickAction)
00058 
00059         pick_action_client.wait_for_server()
00060 
00061         setup_environment()
00062 
00063         # Creates a goal to send to the action server.
00064         goal = cob_pick_place_action.msg.CobPickGoal()
00065         #goal.object_class = 18
00066         #goal.object_name = "yellowsaltcube"
00067         #goal.object_class = 50
00068         #goal.object_name = "instantsoup"
00069         #goal.object_class = 103
00070         #goal.object_name = "instanttomatosoup"
00071         goal.object_class = 5001
00072         goal.object_name = "pringles"
00073         goal.object_pose.header.stamp = rospy.Time.now()
00074         goal.object_pose.header.frame_id = "base_footprint"
00075 
00076         ### cob3
00077         #goal.object_pose.pose.position.x = random.uniform(-0.8, -0.6)
00078         #goal.object_pose.pose.position.y = random.uniform(-0.3,  0.3)
00079         #goal.object_pose.pose.position.z = random.uniform( 0.8,  1.1)
00080         #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))
00081         #goal.gripper_type = "sdh"
00082         #goal.gripper_side = ""
00083 
00084         ### cob4
00085         goal.object_pose.pose.position.x = 0.617 + random.uniform(-0.1, 0.1)
00086         goal.object_pose.pose.position.y = 0.589 + random.uniform(-0.1, 0.1)
00087         goal.object_pose.pose.position.z = 0.979 + random.uniform(-0.1, 0.1)
00088         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))
00089         #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)
00090         goal.gripper_type = "sdhx"
00091         #goal.gripper_side = ""
00092         goal.gripper_side = "left"
00093 
00094         #goal.grasp_database = "KIT"
00095         goal.grasp_database = "OpenRAVE"
00096         #goal.grasp_database = "ALL"
00097         #goal.grasp_id = 2
00098         goal.support_surface = "bookcase"
00099 
00100         # Sends the goal to the action server.
00101         pick_action_client.send_goal(goal)
00102 
00103         # Waits for the server to finish performing the action.
00104         finished_before_timeout=pick_action_client.wait_for_result(rospy.Duration(300, 0))
00105 
00106         if finished_before_timeout:
00107                 state=pick_action_client.get_state()
00108                 print "Action finished: %s"%state
00109         else:
00110                 print "Action did not finish within timeout"
00111         return
00112 
00113 if __name__ == '__main__':
00114         try:
00115                 # Initializes a rospy node so that the SimpleActionClient can
00116                 # publish and subscribe over ROS.
00117                 rospy.init_node('CobPickAction_client_py')
00118                 cob_pick_action_client()
00119         except rospy.ROSInterruptException:
00120                 print "program interrupted before completion"


cob_pick_place_action
Author(s): Felix Messmer
autogenerated on Thu Jun 6 2019 21:23:15