Go to the documentation of this file.00001
00002
00003 import roslib; roslib.load_manifest('tidyup_arm_services')
00004 import rospy
00005 import actionlib
00006 import threading
00007 import sys, traceback, math, copy
00008 from tidyup_msgs import msg
00009 from tidyup_msgs import srv
00010 from std_srvs.srv import Empty, EmptyRequest
00011 from arm_navigation_msgs.msg import PlanningScene, SyncPlanningSceneGoal, SyncPlanningSceneAction
00012 from pr2_python import planning_scene_interface
00013
00014
00015 class PlanningSceneSync():
00016 def __init__(self):
00017 self._lock = threading.Lock()
00018 self._latest_planning_scene = PlanningScene()
00019 subscribe_service_name = rospy.resolve_name('register_planning_scene')
00020 rospy.wait_for_service(subscribe_service_name)
00021 self._sync_action_server = actionlib.SimpleActionServer('~sync_planning_scene', SyncPlanningSceneAction, self._planning_scene_sync_execute, False)
00022 self._sync_action_server.start()
00023 self._subscribe_planning_scene_client = rospy.ServiceProxy(subscribe_service_name, Empty)
00024 self._subscribe_planning_scene_client.call(EmptyRequest())
00025 rospy.loginfo('planning scene sync initialized.')
00026
00027 def _planning_scene_sync_execute(self, goal):
00028 with self._lock:
00029 rospy.loginfo('planning scene sync.')
00030 self._latest_planning_scene = goal.planning_scene
00031 self.print_robot_pose()
00032 self.print_attached()
00033 self._sync_action_server.set_succeeded()
00034 rospy.loginfo('planning scene sync finished.')
00035
00036 def update_planning_scene(self, psi):
00037 with self._lock:
00038 rospy.loginfo('planning scene updated.')
00039
00040 psi.current_diff.planning_scene_diff = copy.deepcopy(self._latest_planning_scene)
00041
00042 def print_attached(self):
00043 for attached in self._latest_planning_scene.attached_collision_objects:
00044 rospy.loginfo('attached : {0}, op: {1}, link: {2}'.format(attached.object.id, attached.object.operation.operation, attached.link_name[0]))
00045
00046 def print_robot_pose(self):
00047 pose = self._latest_planning_scene.robot_state.multi_dof_joint_state.poses[0]
00048 rospy.loginfo('robot_pose: {0}, {1}'.format(pose.position.x, pose.position.y))
00049