publish_simple_scene.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 
00004 from geometry_msgs.msg import PoseStamped
00005 from moveit_msgs.msg import PlanningScene, PlanningSceneComponents, MoveGroupAction
00006 from moveit_msgs.srv import GetPlanningScene
00007 
00008 import rospy
00009 import moveit_commander
00010 import actionlib
00011 
00012 # workaround for core dump whenever exiting Python MoveIt script (https://github.com/ros-planning/moveit_commander/issues/15#issuecomment-34441531)
00013 import atexit, os
00014 atexit.register(lambda : os._exit(0))
00015 
00016 # init rospy
00017 rospy.init_node("publish_simple_scene")
00018 
00019 # init moveit_commander
00020 ac = actionlib.SimpleActionClient('move_group', MoveGroupAction)
00021 ac.wait_for_server()
00022 moveit_commander.MoveGroupCommander('manipulator')
00023 scene_interface = moveit_commander.PlanningSceneInterface()
00024 # get_planning_scene
00025 try:
00026     rospy.wait_for_service('/get_planning_scene', timeout=20);
00027     get_planning_scene = rospy.ServiceProxy("/get_planning_scene", GetPlanningScene)
00028 except:
00029     get_planning_scene = None
00030 
00031 # done
00032 rate = rospy.Rate(1)
00033 while not rospy.is_shutdown():
00034     pose = PoseStamped()
00035     pose.header.frame_id = 'BASE'
00036     pose.pose.position.x = 0.3
00037     pose.pose.position.y =-0.35
00038     pose.pose.position.z = 0.5
00039     pose.pose.orientation.w = 1.0
00040     scene_interface.add_box('simple_object_1', pose, (0.2,0.5,0.04))
00041     pose.pose.position.x = 0.3
00042     pose.pose.position.y =-0.12
00043     pose.pose.position.z = 0.72
00044     scene_interface.add_box('simple_object_2', pose, (0.2,0.04,0.4))
00045     pose.pose.position.x =-0.2
00046     pose.pose.position.y = 0.0
00047     pose.pose.position.z = 0.7
00048     scene_interface.add_box('simple_object_3', pose, (0.04,1.0,0.2))
00049     
00050     rate.sleep()
00051 
00052     print len(get_planning_scene(PlanningSceneComponents(components=PlanningSceneComponents.WORLD_OBJECT_NAMES)).scene.world.collision_objects)
00053     if get_planning_scene and len(get_planning_scene(PlanningSceneComponents(components=PlanningSceneComponents.WORLD_OBJECT_NAMES)).scene.world.collision_objects) >= 3:
00054         break
00055 


vs060
Author(s): Ryohei Ueda
autogenerated on Thu Jun 6 2019 20:15:26