baxter_rpc_server.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 # Copyright 2016 TORK (Tokyo Opensource Robotics Kyokai Association)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #     http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
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         # Init baxter_interface classes
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             # TODO Return meaningful error message why service failed.
00072             return SolvePositionIkPartsResponse(False)
00073 
00074         # Call set joint angles to execute the trajectory.
00075         baxter_interface_bodypart.set_joint_positions(joint_positions)
00076 
00077         return SolvePositionIkPartsResponse(True)


baxter_rpc_server
Author(s): TORK , Isaac I. Y. Saito
autogenerated on Thu Jun 6 2019 21:55:39