00001
00002
00003 import numpy as np, math
00004 import random
00005
00006 import roslib; roslib.load_manifest('pr2_grasp_behaviors')
00007 import rospy
00008 from grasp_manager import GraspBehavior
00009
00010 class SidewaysGrasp(GraspBehavior):
00011 def __init__(self, arm, use_coll_detection=False):
00012 super(OverheadGrasp, self).__init__(arm, use_coll_detection)
00013 self.SIDE_GRASP_DIST = 0.4
00014 self.TABLE_Z = -0.2
00015 self.JOINTS_BIAS = [0.0, 5.0, 0.0, -1.0, 4.0, -1.0, 0.0]
00016 if arm == 'l':
00017 for i in [0, 2, 4]:
00018 self.JOINTS_BIAS[i] *= -1
00019 self.BIAS_RADIUS = 0.012
00020 self.INIT_ANGS = [-0.05, -0.3, -3.1, -1.9, 3.1, -1.5, 0.0]
00021 self.GRASP_TIME = 2.0
00022 self.SETUP_VELOCITY = 0.8
00023 self.GRASP_VELOCITY = 0.4
00024
00025 def setup_move(self, params):
00026
00027 self.xyr = params
00028 rospy.loginfo("Moving to grasp position (%1.2f, %1.2f, %1.2f)" % self.xyr)
00029 grasp_pose = self.create_goal_pose(self.xyr[0], self.xyr[1], self.TABLE_Z,
00030 quaternion_about_axis(self.xyr[2], (0, 0, 1)))
00031 return self.cm.move_arm_pose_biased(grasp_pose, self.JOINTS_BIAS,
00032 self.SETUP_VELOCITY, blocking = True,
00033 init_angs=self.INIT_ANGS)
00034
00035 def execute_approach(self, block):
00036 rospy.loginfo("Moving arm sideways")
00037 goal_pose = self.create_goal_pose(
00038 self.xyr[0] + self.SIDE_GRASP_DIST * np.cos(-self.xyr[2]),
00039 self.xyr[1] - self.SIDE_GRASP_DIST * np.sin(-self.xyr[2]),
00040 self.TABLE_Z,
00041 quaternion_about_axis(self.xyr[2], (0, 0, 1)))
00042 goal_pose.header.stamp = rospy.Time.now()
00043 return self.cm.move_cartesian_ik(goal_pose, collision_aware = False,
00044 blocking = block,
00045 step_size = .005, pos_thres = .02, rot_thres = .1,
00046 settling_time = rospy.Duration(self.GRASP_TIME),
00047 joints_bias = self.JOINTS_BIAS, bias_radius = self.BIAS_RADIUS,
00048 vel = self.GRASP_VELOCITY)
00049
00050 def execute_retreat(self):
00051 rospy.logerr("Need to implement this!")
00052
00053
00054
00055 def random_generator(self):
00056 x = random.uniform(0.45, 0.75)
00057 y = random.uniform(-0.55, 0.10)
00058 r = random.uniform(0., np.pi/2.)
00059 return x, y, r