cob_pick_action_client.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('cob_pick_place_action')
00004 import rospy
00005 import actionlib
00006 import random
00007 from math import pi
00008 from tf.transformations import *
00009 
00010 from geometry_msgs.msg import PoseStamped
00011 import simple_moveit_interface as smi_
00012 import cob_pick_place_action.msg 
00013 
00014 
00015 def setup_environment():
00016         psi = smi_.get_planning_scene_interface()
00017         rospy.sleep(1.0)
00018         
00019         smi_.clear_objects()
00020         
00021         ### Add a floor
00022         smi_.add_ground()
00023         
00024         ### Add table
00025         pose = PoseStamped()
00026         pose.header.frame_id = "/base_footprint"
00027         pose.header.stamp = rospy.Time.now()
00028         pose.pose.position.x = -0.9
00029         pose.pose.position.y = 0
00030         pose.pose.position.z = 0.39
00031         pose.pose.orientation.x = 0
00032         pose.pose.orientation.y = 0
00033         pose.pose.orientation.z = 0
00034         pose.pose.orientation.w = 1
00035         psi.add_box("bookcase", pose, size=(0.5, 1.5, 0.78))
00036         
00037         rospy.sleep(1.0)
00038 
00039 
00040 def cob_pick_action_client():
00041         pick_action_client = actionlib.SimpleActionClient('cob_pick_action', cob_pick_place_action.msg.CobPickAction)
00042         
00043         pick_action_client.wait_for_server()
00044         
00045         setup_environment()
00046         
00047         # Creates a goal to send to the action server.
00048         goal = cob_pick_place_action.msg.CobPickGoal()
00049         goal.object_class = 18
00050         goal.object_name = "yellowsaltcube"
00051         #goal.object_class = 50
00052         #goal.object_name = "instantsoup"
00053         #goal.object_class = 103
00054         #goal.object_name = "instanttomatosoup"
00055         
00056         goal.object_pose.header.stamp = rospy.Time.now()
00057         goal.object_pose.header.frame_id = "base_footprint"
00058         #goal.object_pose.pose.position.x = random.uniform(-0.8, -0.6)
00059         #goal.object_pose.pose.position.y = random.uniform(-0.3,  0.3)
00060         #goal.object_pose.pose.position.z = random.uniform( 0.8,  1.1)
00061         #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)) 
00062         goal.object_pose.pose.position.x = -0.7
00063         goal.object_pose.pose.position.y = 0.0  
00064         goal.object_pose.pose.position.z = 0.78
00065         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(0,0,0) 
00066         
00067         #goal.grasp_id = 21
00068         #goal.grasp_database = "KIT"
00069         goal.grasp_database = "OpenRAVE"
00070         goal.support_surface = "bookcase"
00071         
00072         # Sends the goal to the action server.
00073         pick_action_client.send_goal(goal)
00074         
00075         # Waits for the server to finish performing the action.
00076         finished_before_timeout=pick_action_client.wait_for_result(rospy.Duration(300, 0))
00077         
00078         if finished_before_timeout:
00079                 state=pick_action_client.get_state()
00080                 print "Action finished: %s"%state
00081         # Prints out the result of executing the action
00082         return state  # State after waiting for PickupAction
00083 
00084 if __name__ == '__main__':
00085         try:
00086                 # Initializes a rospy node so that the SimpleActionClient can
00087                 # publish and subscribe over ROS.
00088                 rospy.init_node('CobPickAction_client_py')
00089                 result = cob_pick_action_client()
00090         except rospy.ROSInterruptException:
00091                 print "program interrupted before completion"


cob_pick_place_action
Author(s): Felix Messmer
autogenerated on Wed Aug 26 2015 11:01:29