Go to the documentation of this file.00001 import roslib; roslib.load_manifest('iri_wam_smach')
00002 import rospy
00003 import smach
00004 import smach_ros
00005
00006 from iri_wam_common_msgs.srv import wamInverseKinematics
00007
00008 class GetJointsFromPose(smach.State):
00009 """
00010 Obtain joints positions from a given pose
00011
00012 Use inverse kinematic to get corresponding joints positions from a
00013 cartesian pose.
00014
00015 @type ik_service: string
00016 @param ik_service: URI of inverse kinematic service
00017 @type pose_st : PoseStamped [input_key]
00018 @param pose_st : Pose to move the
00019
00020 @rtype : sensor_msgs/JointState
00021 @return : joints_to_position [output_key]
00022 """
00023 def __init__(self, ik_service):
00024 smach.State.__init__(self,
00025 outcomes = ['success','empty','no_kinematic_solution'],
00026 input_keys = ['pose_st'],
00027 output_keys = ['joints_to_position'])
00028
00029 self.ik_service = ik_service
00030 def execute(self, userdata):
00031 if (userdata.pose_st == None):
00032 rospy.logwarn("Empty pose received. No movement needed")
00033 return 'empty'
00034
00035 try:
00036 handler = rospy.ServiceProxy(self.ik_service, wamInverseKinematics)
00037 response = handler(userdata.pose_st)
00038 print response
00039 if response:
00040 userdata.joints_to_position = response.joints
00041
00042 except rospy.ServiceException, e:
00043 return 'no_kinematic_solution'
00044
00045 return 'success'
00046