Go to the documentation of this file.00001
00002
00003
00004 import roslib; roslib.load_manifest('coverage_tools')
00005 import rospy
00006 import actionlib
00007 from actionlib_msgs.msg import *
00008 from pr2_controllers_msgs.msg import *
00009
00010
00011 import sys
00012
00013 class GripperController:
00014
00015 def open(self, arm='right'):
00016 '''
00017 Opens the gripper by setting up an action client
00018 Input:
00019 - arm: the arm ('left' or 'right') of which the gripper shall be opened
00020 The default is 'right'.
00021 '''
00022 action = 'r_gripper_controller/gripper_action'
00023 if arm =='left':
00024 action = 'l_gripper_controller/gripper_action'
00025
00026 client = actionlib.SimpleActionClient(action, Pr2GripperCommandAction)
00027 client.wait_for_server()
00028 client.send_goal(Pr2GripperCommandGoal(Pr2GripperCommand(position = 0.09, max_effort = -1)))
00029 client.wait_for_result()
00030 result = client.get_result()
00031 did = []
00032 if client.get_state() != GoalStatus.SUCCEEDED:
00033 did.append("failed")
00034 else:
00035 if result.stalled: did.append("stalled")
00036 if result.reached_goal: did.append("reached goal")
00037 print ' and '.join(did)
00038
00039 def close(self, arm='right'):
00040 '''
00041 Opens the gripper by setting up an action client
00042 Input:
00043 - arm: the arm ('left' or 'right') of which the gripper shall be closed
00044 The default is 'right'.
00045 '''
00046
00047 action = 'r_gripper_controller/gripper_action'
00048 if arm =='left':
00049 action = 'l_gripper_controller/gripper_action'
00050
00051 client = actionlib.SimpleActionClient(action, Pr2GripperCommandAction)
00052 client.wait_for_server()
00053 client.send_goal(Pr2GripperCommandGoal(Pr2GripperCommand(position = 0.02, max_effort = 50.0)))
00054 client.wait_for_result()
00055 result = client.get_result()
00056 did = []
00057 if client.get_state() != GoalStatus.SUCCEEDED:
00058 did.append("failed")
00059 else:
00060 if result.stalled: did.append("stalled")
00061 if result.reached_goal: did.append("reached goal")
00062 print ' and '.join(did)
00063
00064 if __name__ == '__main__':
00065
00066 if len(sys.argv) < 2:
00067 print "Please specify open 'o' or close 'c' command"
00068 sys.exit(0)
00069 rospy.init_node('move_the_gripper', anonymous=True)
00070
00071 gripper = GripperController()
00072 if sys.argv[1] =='o':
00073 gripper.open()
00074 elif sys.argv[1] =='c':
00075 gripper.close()