Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import sys
00018
00019 import baxter_interface
00020 from baxter_rpc_msgs.srv import (
00021 SolvePositionIkParts, SolvePositionIkPartsResponse
00022 )
00023 from geometry_msgs.msg import Pose, Quaternion
00024 import rospy
00025
00026 from tork_rpc_util.rpc_servers_handler import ActionServiceInfo, RpcServersHandler
00027
00028
00029 class ActionServiceNameDict(object):
00030 '''
00031 Static, entity class to hold name for ROS Actions for the robot.
00032 '''
00033 cartesian_move = 'srv_cartesian_move'
00034
00035
00036 class BaxterRpcServer(RpcServersHandler):
00037
00038 def __init__(self):
00039 '''
00040 @param args: TODO
00041 '''
00042 rospy.init_node('baxter_rpc_servers_handler')
00043
00044
00045 self._limb_left = baxter_interface.Limb('left')
00046 self._limb_right = baxter_interface.Limb('right')
00047
00048 self.action_infos = {
00049 ActionServiceNameDict.cartesian_move: ActionServiceInfo(
00050 ActionServiceNameDict.cartesian_move, SolvePositionIkParts, self._cb_cartesian_move)
00051 }
00052 super(BaxterRpcServer, self).__init__(self.action_infos)
00053
00054 rospy.loginfo(sys._getframe().f_code.co_name + '__init__ done.')
00055
00056 def _cb_cartesian_move(self, service_req):
00057 '''
00058 Computer IK and set the resulted joint angles to the robot's limb.
00059 '''
00060 body_part = service_req.body_part
00061 rospy.loginfo('IN {} Limb: {}'.format(sys._getframe().f_code.co_name, body_part))
00062 baxter_interface_bodypart = None
00063 if body_part == 'left':
00064 baxter_interface_bodypart = self._limb_left
00065 elif body_part == 'right':
00066 baxter_interface_bodypart = self._limb_right
00067 joint_positions = baxter_interface_bodypart.ik(service_req.pose)
00068 rospy.loginfo('service_req.pose:\n{}\njoint_positions: {}'.format(service_req.pose,
00069 joint_positions))
00070 if not joint_positions:
00071
00072 return SolvePositionIkPartsResponse(False)
00073
00074
00075 baxter_interface_bodypart.set_joint_positions(joint_positions)
00076
00077 return SolvePositionIkPartsResponse(True)