Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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))
00051 self.r_action_client.wait_for_result(rospy.Duration(20.0))
00052
00053 result = TuckArmsResult()
00054
00055 self.success = True
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