def database_delete_grasps(self, object_name): # load gripper gripper = RobotGripper.load(GRIPPER_NAME, gripper_dir='/home/silvia/dex-net/data/grippers') # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) dexnet_handle.dataset.delete_grasps(object_name, gripper=gripper.name) dexnet_handle.close_database()
def get_stable_pose_transform(self, object_name, stable_pose_id): # load gripper gripper = RobotGripper.load( GRIPPER_NAME, gripper_dir='/home/silvia/dex-net/data/grippers') # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) stable_pose = dexnet_handle.dataset.stable_pose( object_name, stable_pose_id=('pose_' + str(stable_pose_id))) dexnet_handle.close_database() return stable_pose
def database_save(self, object_name, filepath, stable_poses_n, force_overwrite=False): # load gripper gripper = RobotGripper.load(GRIPPER_NAME, gripper_dir='/home/silvia/dex-net/data/grippers') # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) mass = CONFIG['default_mass'] if object_name in dexnet_handle.dataset.object_keys: graspable = dexnet_handle.dataset[object_name] mesh = graspable.mesh sdf = graspable.sdf stable_poses = dexnet_handle.dataset.stable_poses(object_name) else: # Create temp dir if cache dir is not provided mp_cache = CONFIG['cache_dir'] del_cache = False if mp_cache is None: mp_cache = tempfile.mkdtemp() del_cache = True # open mesh preprocessor mesh_processor = MeshProcessor(filepath, mp_cache) mesh_processor.generate_graspable(CONFIG) mesh = mesh_processor.mesh sdf = mesh_processor.sdf stable_poses = mesh_processor.stable_poses[:stable_poses_n] # write graspable to database dexnet_handle.dataset.create_graspable(object_name, mesh, sdf, stable_poses, mass=mass) # write grasps to database grasps, metrics = antipodal_grasp_sampler_for_storing(mesh, sdf, stable_poses) id = 0 for grasps_for_pose, metrics_for_pose in zip(grasps, metrics): if (grasps_for_pose == None): continue dexnet_handle.dataset.store_grasps_and_metrics(object_name, grasps_for_pose, metrics_for_pose, gripper=gripper.name, stable_pose_id=('pose_'+str(id)), force_overwrite=force_overwrite) id = id + 1 dexnet_handle.close_database()
def delete_graspable(self, object_name): # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) dexnet_handle.dataset.delete_graspable(object_name) # delete files related to object path_to_obj_file = ".dexnet/" + object_name if os.path.exists(path_to_obj_file + "_proc.sdf"): print("sdf file removed") os.remove(path_to_obj_file + "_proc.sdf") if os.path.exists(path_to_obj_file + "_proc.obj"): print("obj file removed") os.remove(path_to_obj_file + "_proc.obj") dexnet_handle.close_database()
def get_stable_pose(self, object_name, stable_pose_id): # load gripper gripper = RobotGripper.load(GRIPPER_NAME, gripper_dir='/home/silvia/dex-net/data/grippers') # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) # read the most robust grasp stable_pose = dexnet_handle.dataset.stable_pose(object_name, stable_pose_id=('pose_'+str(stable_pose_id))) dexnet_handle.close_database() pose_matrix = np.eye(4,4) pose_matrix[:3,:3] = stable_pose.T_obj_world.rotation pose_matrix[:3, 3] = stable_pose.T_obj_world.translation return pose_matrix
def database_save(self, object_name, filepath, stable_poses_n, metric, overwrite_object=False, force_overwrite=False): # load gripper gripper = RobotGripper.load( GRIPPER_NAME, gripper_dir='/home/silvia/dex-net/data/grippers') # open Dex-Net API dexnet_handle = DexNet() dexnet_handle.open_database(self.database_path) dexnet_handle.open_dataset(self.dataset_name) mass = CONFIG['default_mass'] if object_name in dexnet_handle.dataset.object_keys: if not overwrite_object: dexnet_handle.close_database() print(object_name + " already exists in database, not overwriting") return graspable = dexnet_handle.dataset[object_name] mesh = graspable.mesh sdf = graspable.sdf stable_poses = dexnet_handle.dataset.stable_poses(object_name) else: # Create temp dir if cache dir is not provided mp_cache = CONFIG['cache_dir'] del_cache = False if mp_cache is None: mp_cache = tempfile.mkdtemp() del_cache = True # open mesh preprocessor graspable = MeshProcessor(filepath, mp_cache) graspable.generate_graspable(CONFIG) mesh = graspable.mesh sdf = graspable.sdf stable_poses = graspable.stable_poses[:stable_poses_n] # write graspable to database dexnet_handle.dataset.create_graspable(object_name, mesh, sdf, stable_poses, mass=mass) if force_overwrite: dexnet_handle.dataset.delete_grasps(object_name, gripper=gripper.name) # calculate or retrieve grasps loaded_grasps = dexnet_handle.dataset.grasps(object_name, gripper=gripper.name) if loaded_grasps == []: print("No grasps in database, calculating") grasps = antipodal_grasp_sampler_for_storing(graspable) if (grasps != None): print("Saving grasps") dexnet_handle.dataset.store_grasps( object_name, grasps, gripper=gripper.name, force_overwrite=force_overwrite) loaded_grasps = dexnet_handle.dataset.grasps( object_name, gripper=gripper.name) print("Calculating grasp quality") metrics = grasp_quality_calculator(mesh, sdf, loaded_grasps, metric) print("Grasp quality calculated") grasp_metrics = {} for g in loaded_grasps: grasp_metrics[g.id] = {} grasp_metrics[g.id][metric] = metrics[g.id] dexnet_handle.dataset.store_grasp_metrics(object_name, grasp_metrics, gripper=gripper.name) dexnet_handle.close_database()