tuck_arms.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Tuck-Arms Action Server for Rosie (using the armhand action server)
00004 # Mimics the PR2 tuck interface
00005 #
00006 # Copyright (c) 2010 Alexis Maldonado <maldonado@tum.de>
00007 # Technische Universitaet Muenchen
00008 #
00009 # This program is free software: you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation, either version 3 of the License, or
00012 # (at your option) any later version.
00013 #
00014 # This program is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 #
00019 # You should have received a copy of the GNU General Public License
00020 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 import roslib; roslib.load_manifest('rosie_tuck_arms_action')
00023 import rospy
00024 
00025 from actionlib_msgs.msg import *
00026 from pr2_common_action_msgs.msg import *
00027 import actionlib
00028 import cogman_msgs.msg
00029 
00030 class TuckArmsActionServer:
00031     def __init__(self, node_name):
00032         self.node_name = node_name
00033         self.action_server = actionlib.simple_action_server.SimpleActionServer(node_name,TuckArmsAction, self.executeCB)
00034 
00035         self.l_action_client = actionlib.SimpleActionClient('left_arm', cogman_msgs.msg.ArmHandAction)
00036         self.r_action_client = actionlib.SimpleActionClient('right_arm', cogman_msgs.msg.ArmHandAction)
00037     
00038 
00039     def executeCB(self, goal):
00040         if goal.tuck_right:
00041             self.tuckR()
00042         else:
00043             self.untuckR()
00044             
00045         if goal.tuck_left:
00046             self.tuckL()
00047         else:
00048             self.untuckL()
00049 
00050         self.l_action_client.wait_for_result(rospy.Duration(20.0))  #Wait up to 20s for the server
00051         self.r_action_client.wait_for_result(rospy.Duration(20.0))  #Wait up to 20s for the server
00052             
00053         result = TuckArmsResult()
00054             
00055         self.success = True  #FIXME: Check for success from the armhand server
00056         if self.success:
00057             result.tuck_right = goal.tuck_right
00058             result.tuck_left = goal.tuck_left
00059             self.action_server.set_succeeded(result)
00060         else:
00061             rospy.logerr("Tuck or untuck arms FAILED: %d %d"%(result.left, result.right))
00062             self.action_server.set_aborted(result)
00063 
00064 
00065     def tuckL(self):
00066         side = 'left'
00067         pose_name = 'parking'
00068         goal = cogman_msgs.msg.ArmHandGoal()
00069         goal.command = 'arm_joint_pose'
00070         goal.pose_name = side + "_" + pose_name
00071         self.l_action_client.send_goal(goal)
00072     
00073     def untuckL(self):
00074         side = 'left'
00075         pose_name = 'open'
00076         goal = cogman_msgs.msg.ArmHandGoal()
00077         goal.command = 'arm_joint_pose'
00078         goal.pose_name = side + "_" + pose_name
00079         self.l_action_client.send_goal(goal)
00080 
00081     def tuckR(self):
00082         side = 'right'
00083         pose_name = 'parking'
00084         goal = cogman_msgs.msg.ArmHandGoal()
00085         goal.command = 'arm_joint_pose'
00086         goal.pose_name = side + "_" + pose_name
00087         self.r_action_client.send_goal(goal)    
00088     
00089     def untuckR(self):
00090         side = 'right'
00091         pose_name = 'open'
00092         goal = cogman_msgs.msg.ArmHandGoal()
00093         goal.command = 'arm_joint_pose'
00094         goal.pose_name = side + "_" + pose_name
00095         self.r_action_client.send_goal(goal)
00096     
00097 def main():
00098     action_name = 'rosie_tuck_arms_action'
00099     action_name = 'tuck_arms'
00100     rospy.loginfo("%s: Starting up!" %(action_name))
00101     
00102     rospy.init_node(action_name)
00103     tuck_arms_action_server = TuckArmsActionServer(action_name)
00104     rospy.spin()
00105 
00106 if __name__ == '__main__':
00107     main()
00108 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


rosie_tuck_arms_action
Author(s): Alexis Maldonado
autogenerated on Thu May 23 2013 17:41:18