check_robot_locations.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('tidyup_tools')
00004 import rospy
00005 import sys
00006 import copy
00007 import numpy as np
00008 
00009 from hardcoded_facts.geometry_pose_loader import read_pose_stamped_file
00010 from pr2_python.base import Base
00011 from pr2_python.arm_planner import ArmPlanner
00012 
00013 def check_robot_locations(location_file_name):
00014   # get locations
00015   named_poses = read_pose_stamped_file(location_file_name)
00016   # get robot state
00017   base = Base()
00018   while not rospy.is_shutdown():
00019       with base._js_lock:
00020           if base._last_state is not None:
00021               robot_state = copy.deepcopy(base._last_state)
00022               break
00023       rospy.loginfo("Waiting for joint state")
00024       rospy.sleep(1.0)
00025       
00026   # load arm at side config
00027   side_joint_positions = {}
00028   arm_planners = {}
00029   for arm in ['left_arm', 'right_arm']:
00030     arm_planners[arm] = ArmPlanner(arm)
00031     side_joint_positions[arm] = rospy.get_param('/arm_configurations/side_tuck/position/'+arm)
00032     # replace in state
00033     arm_planners[arm].set_joint_positions_in_robot_state(side_joint_positions[arm], robot_state)
00034   robot_states = []
00035   for name, pose_stamped in named_poses.items():
00036     robot_state.multi_dof_joint_state.poses[0] = copy.deepcopy(pose_stamped.pose)
00037     robot_states.append(copy.deepcopy(robot_state))
00038     
00039   # call collision service
00040   error_codes = base._check_pose_srv(robot_states=robot_states).error_codes
00041   
00042   # evaluate response
00043   collision_free = True
00044   for i in range(len(named_poses)):
00045     error_code = error_codes[i]
00046     named_pose = named_poses[i]
00047   #for error_code, named_pose in error_codes, named_poses:
00048     if error_code.val != error_code.SUCCESS:
00049       collision_free = False
00050       rospy.logwarn('location {0} has returned collision error: {1}'.format(named_pose['name'], error_code.val))
00051   if collision_free: rospy.loginfo('all locations are collision free.')
00052   return collision_free
00053 
00054 if __name__ == '__main__':
00055   rospy.init_node('check_robot_locations', anonymous=True)
00056   if len(sys.argv) > 1:
00057     check_robot_locations(sys.argv[1])
00058   else:
00059     rospy.loginfo('checking current robot state for collisions...')
00060     base = Base()
00061     if base.check_base_pose(base.get_current_pose_stamped()):
00062       rospy.loginfo('current state is collision free.')
00063     else:
00064       rospy.logwarn('current state is in collision.')
00065 
00066   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


tidyup_tools
Author(s): Andreas Hertle, Christian Dornhege
autogenerated on Wed Dec 26 2012 15:50:57