| import copy |
| import os |
| import trimesh.transformations as tra |
| import trimesh |
| import numpy as np |
| import pickle |
| import torch |
|
|
| class PandaGripper(object): |
| """An object representing a Franka Panda gripper.""" |
|
|
| def __init__(self, q=None, num_contact_points_per_finger=10, root_folder="./hand_model/panda_gripper_description"): |
| """Create a Franka Panda parallel-yaw gripper object. |
| |
| Keyword Arguments: |
| q {list of int} -- opening configuration (default: {None}) |
| num_contact_points_per_finger {int} -- contact points per finger (default: {10}) |
| root_folder {str} -- base folder for model files (default: {''}) |
| """ |
| self.joint_limits = [0.0, 0.04] |
| self.root_folder = root_folder |
| |
| self.default_pregrasp_configuration = 0.04 |
| if q is None: |
| q = self.default_pregrasp_configuration |
|
|
| self.q = q |
| fn_base = os.path.join(root_folder, 'gripper_models/panda_gripper/hand.stl') |
| fn_finger = os.path.join(root_folder, 'gripper_models/panda_gripper/finger.stl') |
|
|
| self.base = trimesh.load(fn_base) |
| self.finger_l = trimesh.load(fn_finger) |
| self.finger_r = self.finger_l.copy() |
|
|
| |
| self.finger_l.apply_transform(tra.euler_matrix(0, 0, np.pi)) |
| self.finger_l.apply_translation([+q, 0, 0.0584]) |
| self.finger_r.apply_translation([-q, 0, 0.0584]) |
| |
| self.fingers = trimesh.util.concatenate([self.finger_l, self.finger_r]) |
| self.hand = trimesh.util.concatenate([self.fingers, self.base]) |
|
|
|
|
| self.contact_ray_origins = [] |
| self.contact_ray_directions = [] |
|
|
| |
| with open(os.path.join(root_folder,'gripper_control_points/panda_gripper_coords.pickle'), 'rb') as f: |
| self.finger_coords = pickle.load(f, encoding='latin1') |
| finger_direction = self.finger_coords['gripper_right_center_flat'] - self.finger_coords['gripper_left_center_flat'] |
| self.contact_ray_origins.append(np.r_[self.finger_coords['gripper_left_center_flat'], 1]) |
| self.contact_ray_origins.append(np.r_[self.finger_coords['gripper_right_center_flat'], 1]) |
| self.contact_ray_directions.append(finger_direction / np.linalg.norm(finger_direction)) |
| self.contact_ray_directions.append(-finger_direction / np.linalg.norm(finger_direction)) |
|
|
| self.contact_ray_origins = np.array(self.contact_ray_origins) |
| self.contact_ray_directions = np.array(self.contact_ray_directions) |
| self.mesh=trimesh.util.concatenate([self.finger_l, self.finger_r, self.base]) |
| self.points=trimesh.sample.sample_surface(self.mesh, 1024)[0] |
| |
| def get_meshes(self,transform): |
| """Get list of meshes that this gripper consists of. |
| |
| Returns: |
| list of trimesh -- visual meshes |
| """ |
| |
| mesh_copy=copy.deepcopy(self.mesh) |
| |
| return mesh_copy.apply_transform(transform) |
| |
| |
| def get_points(self,angle): |
| point_copy=copy.deepcopy(self.points) |
| return torch.tensor(trimesh.points.PointCloud(point_copy).apply_transform(angle).vertices) |