def set_params(self, params_path): loaded = self.loaded_params_path if loaded is None: self.load_params(WorkspaceParams.load_from_file(params_path), params_path) return True else: if loaded != params_path: self.remove_objects() self.load_params(WorkspaceParams.load_from_file(params_path), params_path) return True return False
def get_manager_for_workspace(workspace_id, config): directory = os.path.abspath( os.path.expanduser(config['data']['directory'])) workspace_dir = os.path.join(directory, workspace_id) potential_points = PotentialPoint.from_config(config) openrave_manager = OpenraveManager( config['data']['joint_segment_validity_step'], potential_points) workspace_params = WorkspaceParams.load_from_file( data_filepaths.get_workspace_params_path(workspace_dir)) openrave_manager.load_params(workspace_params) return openrave_manager, workspace_dir
def __init__(self, params_directory, create_images=True): self.items = {} self._create_images = create_images source_dir = os.path.expanduser(params_directory) for dirpath, dirnames, filenames in os.walk(source_dir): for filename in filenames: if not filename.endswith('.pkl'): continue full_file_path = os.path.join(source_dir, filename) params = WorkspaceParams.load_from_file(full_file_path) np_array = None if create_images: image_filename = filename.replace('.pkl', '.image_pkl') full_image_file_path = os.path.join( source_dir, image_filename) if os.path.isfile(full_image_file_path): np_array = pickle.load(open(full_image_file_path, 'r')) else: np_array = self._get_image_as_numpy(params) pickle.dump(np_array, open(full_image_file_path, 'w')) self.items[filename] = ImageCacheItem(filename, full_file_path, params, np_array)
show_goal_end_effector_pose = True # load configuration config_path = os.path.join(os.getcwd(), 'config/config.yml') with open(config_path, 'r') as yml_file: config = yaml.load(yml_file) # load the workspace openrave_manager = OpenraveManager( config['openrave_rl']['segment_validity_step'], PotentialPoint.from_config(config)) params_file = os.path.abspath( os.path.expanduser( os.path.join('~/ModelBasedDDPG/scenario_params', scenario, 'params.pkl'))) openrave_manager.load_params(WorkspaceParams.load_from_file(params_file)) openrave_manager.robot.SetDOFValues([0.0] + goal_joints, [0, 1, 2, 3, 4]) openrave_manager.get_initialized_viewer() red_color = np.array([1.0, 0.0, 0.0]) yellow_color = np.array([1.0, 1.0, 0.0]) green_color = np.array([0.0, 1.0, 0.0]) def create_sphere(id, radius, openrave_manager): body = RaveCreateKinBody(openrave_manager.env, '') body.SetName('sphere{}'.format(id)) body.InitFromSpheres(np.array([[0.0] * 3 + [radius]]), True) openrave_manager.env.Add(body, True) return body