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
00023
00024
00025
00026
00027
00028
00029
00030 """
00031 Baxter RSDK Gripper Action Client Example
00032 """
00033 import sys
00034 import argparse
00035
00036 import rospy
00037
00038 import actionlib
00039
00040 from control_msgs.msg import (
00041 GripperCommandAction,
00042 GripperCommandGoal,
00043 )
00044
00045 import baxter_interface
00046
00047 from baxter_interface import CHECK_VERSION
00048
00049
00050 class GripperClient(object):
00051 def __init__(self, gripper):
00052 ns = 'robot/end_effector/' + gripper + '_gripper/'
00053 self._client = actionlib.SimpleActionClient(
00054 ns + "gripper_action",
00055 GripperCommandAction,
00056 )
00057 self._goal = GripperCommandGoal()
00058
00059
00060 if not self._client.wait_for_server(rospy.Duration(10.0)):
00061 rospy.logerr("Exiting - %s Gripper Action Server Not Found" %
00062 (gripper.capitalize(),))
00063 rospy.signal_shutdown("Action Server not found")
00064 sys.exit(1)
00065 self.clear()
00066
00067 def command(self, position, effort):
00068 self._goal.command.position = position
00069 self._goal.command.max_effort = effort
00070 self._client.send_goal(self._goal)
00071
00072 def stop(self):
00073 self._client.cancel_goal()
00074
00075 def wait(self, timeout=5.0):
00076 self._client.wait_for_result(timeout=rospy.Duration(timeout))
00077 return self._client.get_result()
00078
00079 def clear(self):
00080 self._goal = GripperCommandGoal()
00081
00082
00083 def main():
00084 """RSDK Gripper Example: Action Client
00085
00086 Demonstrates creating a client of the Gripper Action Server,
00087 which enables sending commands of standard action type
00088 control_msgs/GripperCommand.
00089
00090 The example will command the grippers to a number of positions
00091 while specifying moving force or vacuum sensor threshold. Be sure
00092 to start Baxter's gripper_action_server before running this example.
00093 """
00094 arg_fmt = argparse.RawDescriptionHelpFormatter
00095 parser = argparse.ArgumentParser(formatter_class=arg_fmt,
00096 description=main.__doc__)
00097 parser.add_argument(
00098 '-g', '--gripper', dest='gripper', required=True,
00099 choices=['left', 'right'],
00100 help='which gripper to send action commands'
00101 )
00102 args = parser.parse_args(rospy.myargv()[1:])
00103 gripper = args.gripper
00104
00105 print("Initializing node... ")
00106 rospy.init_node("rsdk_gripper_action_client_%s" % (gripper,))
00107 print("Getting robot state... ")
00108 rs = baxter_interface.RobotEnable(CHECK_VERSION)
00109 print("Enabling robot... ")
00110 rs.enable()
00111 print("Running. Ctrl-c to quit")
00112
00113 gc = GripperClient(gripper)
00114 gc.command(position=0.0, effort=50.0)
00115 gc.wait()
00116 gc.command(position=100.0, effort=50.0)
00117 gc.wait()
00118 gc.command(position=25.0, effort=40.0)
00119 gc.wait()
00120 gc.command(position=75.0, effort=20.0)
00121 gc.wait()
00122 gc.command(position=0.0, effort=30.0)
00123 gc.wait()
00124 gc.command(position=100.0, effort=40.0)
00125 print gc.wait()
00126 print "Exiting - Gripper Action Test Example Complete"
00127
00128 if __name__ == "__main__":
00129 main()