online_collision_detection.py
Go to the documentation of this file.
00001 
00002 import roslib; roslib.load_manifest('arm_navigation_tutorials')
00003 import sys
00004 import rospy
00005 
00006 import hrl_lib.transforms as tr
00007 
00008 from planning_environment_msgs.srv import GetStateValidity
00009 from planning_environment_msgs.srv import GetStateValidityRequest
00010 from sensor_msgs.msg import JointState
00011 
00012 roslib.load_manifest('hrl_pr2_lib')
00013 import hrl_pr2_lib.pr2_arms as pa
00014 
00015 
00016 class online_collision_detector():
00017 
00018     def __init__(self):
00019         srv_nm = 'environment_server_right_arm/get_state_validity'
00020         rospy.wait_for_service(srv_nm)
00021         self.state_validator = rospy.ServiceProxy(srv_nm, GetStateValidity,
00022                                                 persistent=True)
00023 
00024     def check_validity(self, pr2_arms, arm):
00025         q = pr2_arms.get_joint_angles(arm)
00026 
00027         joint_nm_list = ['r_shoulder_pan_joint', 'r_shoulder_lift_joint',
00028                          'r_upper_arm_roll_joint', 'r_elbow_flex_joint',
00029                          'r_forearm_roll_joint', 'r_wrist_flex_joint',
00030                          'r_wrist_roll_joint']
00031 
00032         req = GetStateValidityRequest()
00033         req.robot_state.joint_state.name = joint_nm_list
00034         req.robot_state.joint_state.position = q
00035 
00036         req.robot_state.joint_state.header.stamp = rospy.Time.now()
00037         req.check_collisions = True
00038 
00039         res = self.state_validator.call(req)
00040         return res
00041     
00042 
00043 if __name__ == '__main__':
00044     rospy.init_node('get_state_validity_python')
00045 
00046     pr2_arms = pa.PR2Arms()
00047     r_arm, l_arm = 0, 1
00048     arm = r_arm
00049     col_det = online_collision_detector()
00050 
00051     while not rospy.is_shutdown():
00052         rospy.sleep(0.1)
00053         res = col_det.check_validity(pr2_arms, arm)
00054         if res.error_code.val == res.error_code.SUCCESS:
00055             rospy.loginfo('Requested state is not in collision')
00056         else:
00057             rospy.loginfo('Requested state is in collision. Error code: %d'%(res.error_code.val))
00058 
00059 
00060 


arm_navigation_tutorials
Author(s): Advait Jain
autogenerated on Wed Nov 27 2013 12:09:02