server_test.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2014, PAL Robotics SL
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of the PAL Robotics nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 # author: Bence Magyar
00035 
00036 import rospy
00037 from actionlib import SimpleActionClient
00038 from geometry_msgs.msg import PoseArray, Pose, Point
00039 from std_msgs.msg import Header
00040 from moveit_simple_grasps.msg import GenerateGraspsAction, GenerateGraspsGoal
00041 from moveit_msgs.msg import Grasp
00042 import geometry_msgs
00043 
00044 grasp_publisher = None
00045 grasps_ac = None
00046 
00047 def generate_grasps(pose, width):
00048         #send request to block grasp generator service
00049         grasps_ac.wait_for_server()
00050         rospy.loginfo("Successfully connected.")
00051         goal = GenerateGraspsGoal()
00052         goal.pose = pose.pose
00053         goal.width = width
00054         grasps_ac.send_goal(goal)
00055         rospy.loginfo("Sent goal, waiting:\n" + str(goal))
00056         t_start = rospy.Time.now()
00057         grasps_ac.wait_for_result()
00058         t_end = rospy.Time.now()
00059         t_total = t_end - t_start
00060         rospy.loginfo("Result received in " + str(t_total.to_sec()))
00061         grasp_list = grasps_ac.get_result().grasps
00062         return grasp_list
00063 
00064 def publish_grasps_as_poses(grasps):
00065         rospy.loginfo("Publishing PoseArray on /grasp_pose_from_block_bla for grasp_pose")
00066         graspmsg = Grasp()
00067         grasp_PA = PoseArray()
00068         header = Header()
00069         header.frame_id = "base_link"
00070         header.stamp = rospy.Time.now()
00071         grasp_PA.header = header
00072         for graspmsg in grasps:
00073                 p = Pose(graspmsg.grasp_pose.pose.position, graspmsg.grasp_pose.pose.orientation)
00074                 grasp_PA.poses.append(p)
00075         grasp_publisher.publish(grasp_PA)
00076         rospy.loginfo('Published ' + str(len(grasp_PA.poses)) + ' poses')
00077         rospy.sleep(2)
00078 
00079 
00080 if __name__ == '__main__':
00081         name = 'grasp_object_server'
00082         rospy.init_node(name, anonymous=False)
00083         rospy.loginfo("Connecting to grasp generator AS")
00084         grasps_ac = SimpleActionClient('/moveit_simple_grasps_server/generate', GenerateGraspsAction)
00085         grasp_publisher = rospy.Publisher("generated_grasps", PoseArray)
00086         object_pose = geometry_msgs.msg.PoseStamped()
00087         object_pose.pose.position.x = 1.0
00088         object_pose.pose.position.y = 1.0
00089         object_pose.pose.position.z = 1.0
00090         object_pose.pose.orientation.w = 1.0
00091         object_pose.pose.orientation.x = 0.0
00092         object_pose.pose.orientation.y = 0.0
00093         object_pose.pose.orientation.z = 0.0
00094         grasp_list = generate_grasps(object_pose, 0.06)
00095         rospy.loginfo('Generated ' + str(len(grasp_list)) + ' grasps.')
00096         publish_grasps_as_poses(grasp_list)
00097         rospy.sleep(10.0)


moveit_simple_grasps
Author(s): Dave Coleman
autogenerated on Thu Jun 6 2019 20:55:20