Go to the documentation of this file.00001 import roslib; roslib.load_manifest('pr2_precise_trajectory')
00002 import rospy
00003 from pr2_precise_trajectory import *
00004 from pr2_precise_trajectory.msg import *
00005 from pr2_controllers_msgs.msg import *
00006 from actionlib import SimpleActionClient, SimpleActionServer
00007
00008 OPEN = 0.09
00009 CLOSED = 0.002
00010
00011 ACTION_NAME = '/%s_gripper_controller/gripper_sequence'
00012
00013 class GripperController:
00014 def __init__(self, hand):
00015 arm = hand[0]
00016 self.effort = -1.0
00017
00018 self.server = SimpleActionServer(ACTION_NAME % arm, GripperSequenceAction, self.execute, False)
00019 self.server.start()
00020
00021 self.sub_client= SimpleActionClient("%s_gripper_controller/gripper_action"%arm, Pr2GripperCommandAction)
00022
00023 rospy.loginfo("[GRIPPER] Waiting for %s controllers"%arm)
00024 self.sub_client.wait_for_server()
00025 rospy.loginfo("[GRIPPER] Got %s controllers"%arm)
00026
00027 self.client = SimpleActionClient(ACTION_NAME % arm, GripperSequenceAction)
00028 rospy.loginfo("[GRIPPER] Waiting for self client")
00029 self.client.wait_for_server()
00030 rospy.loginfo("[GRIPPER] Got self client")
00031
00032 def send_goal(self, goal):
00033 self.client.send_goal(goal)
00034
00035 def execute(self, goal):
00036 rate = rospy.Rate(10)
00037 while rospy.Time.now() < goal.header.stamp:
00038 rate.sleep()
00039
00040 for position, time in zip(goal.positions, goal.times):
00041 self.change_position(position, False)
00042 rospy.sleep( time )
00043 self.server.set_succeeded(GripperSequenceResult())
00044 self.change_position(position, False, 0.0)
00045
00046
00047 def change_position(self, position, should_wait=True, effort=None):
00048 if effort is None:
00049 effort = self.effort
00050
00051 gg = Pr2GripperCommandGoal()
00052 gg.command.position = position
00053 gg.command.max_effort = effort
00054 self.sub_client.send_goal(gg)
00055 if should_wait:
00056 self.sub_client.wait_for_result()
00057