def __init__(self, name): self.name = name self.gripper = ReflexSFHand(name) self.pub = rospy.Publisher('/gripper_%s/command'%(name), Pose, queue_size=10) self._joint_positions = [0]*4 self._joint_command = [0]*4 self._FINGER_CLOSED = 4.6 self._FINGER_PINCH = 2.5 self._PRESHAPE_CYLINDER = 0 self._PRESHAPE_SPHERICAL = 1.5 self._PRESHAPE_PINCH = 2.5 self._valid_shape_names = {'cylinder' : 'cylinder', 'c' : 'cylinder', 'sphere' : 'sphere', 's' : 'sphere', 'pinch' : 'pinch', 'p' : 'pinch'}
#!/usr/bin/env python from gripper import ReflexSFHand import argparse, sys if __name__ == "__main__": parser = argparse.ArgumentParser( description="Calibrate a Gripper Hand") parser.add_argument('name', help="The name of the gripper hand to calibrate") args = parser.parse_args(sys.argv[1:]) name = args.name hand = ReflexSFHand(name) hand.calibrate()
class Gripper_impl(object): def __init__(self, name): self.name = name self.gripper = ReflexSFHand(name) self.pub = rospy.Publisher('/gripper_%s/command'%(name), Pose, queue_size=10) self._joint_positions = [0]*4 self._joint_command = [0]*4 self._FINGER_CLOSED = 4.6 self._FINGER_PINCH = 2.5 self._PRESHAPE_CYLINDER = 0 self._PRESHAPE_SPHERICAL = 1.5 self._PRESHAPE_PINCH = 2.5 self._valid_shape_names = {'cylinder' : 'cylinder', 'c' : 'cylinder', 'sphere' : 'sphere', 's' : 'sphere', 'pinch' : 'pinch', 'p' : 'pinch'} def close(self): self.gripper.disableTorque() @property def joint_positions(self): self._joint_positions = self.gripper.getMotorPositions() return self._joint_positions def setJointCommand(self, command): #may need to pass 'command' as 'Pose(command)' self._joint_command = command self.pub.publish(*self._joint_command) return def closeGrip(self): if self._joint_command[3] == self._PRESHAPE_CYLINDER: self._joint_command[0:3] = [self._FINGER_CLOSED]*3 elif self._joint_command[3] == self._PRESHAPE_SPHERICAL: self._joint_command[0:3] = [self._FINGER_PINCH]*3 elif self._joint_command[3] == self._PRESHAPE_PINCH: self._joint_command[0:2] = [self._FINGER_PINCH]*2 self.pub.publish(*self._joint_command) return def openGrip(self): self._joint_command[0:3] = [0]*3 self.pub.publish(*self._joint_command) return def setGripShape(self, shape): shape = shape.lower() if not shape in self._valid_shape_names.keys(): return if self._valid_shape_names[shape] == 'cylinder': self._joint_command[3] = self._PRESHAPE_CYLINDER elif self._valid_shape_names[shape] == 'sphere': self._joint_command[3] = self._PRESHAPE_SPHERICAL elif self._valid_shape_names[shape] == 'pinch': self._joint_command[3] = self._PRESHAPE_PINCH self.pub.publish(*self._joint_command) return def resetHand(self): self._joint_command = [0]*4 self.pub.publish(*self._joint_command) return