Ejemplo n.º 1
0
def parse_config_files_and_bindings(args):
    """Parse the config files and the bindings.

    Args:
        args: The arguments.

    Returns:
        env_config: Environment configuration.
        policy_config: Policy configuration.
    """
    if args.env_config is None:
        env_config = dict()
    else:
        env_config = YamlConfig(args.env_config).as_easydict()

    if args.policy_config is None:
        policy_config = dict()
    else:
        policy_config = YamlConfig(args.policy_config).as_easydict()

    if args.config_bindings is not None:
        parsed_bindings = ast.literal_eval(args.config_bindings)
        logger.info('Config Bindings: %r', parsed_bindings)
        env_config.update(parsed_bindings)
        policy_config.update(parsed_bindings)

    logger.info('Environment Config:')
    pprint.pprint(env_config)
    logger.info('Policy Config:')
    pprint.pprint(policy_config)

    return env_config, policy_config
Ejemplo n.º 2
0
 def default_config(self):
     """Load the default configuration file."""
     config_path = os.path.join('configs', 'policies',
                                'antipodal_grasp_4dof_policy.yaml')
     assert os.path.exists(config_path), (
         'Default configuration file %s does not exist' % (config_path))
     return YamlConfig(config_path).as_easydict()
Ejemplo n.º 3
0
 def default_config(self):
     """Load the default configuration file."""
     env_name = camelcase_to_snakecase(type(self).__name__)
     config_path = os.path.join('configs', 'envs', '%s.yaml' % (env_name))
     assert os.path.exists(config_path), (
         'Default configuration file %s does not exist' % (config_path))
     return YamlConfig(config_path).as_easydict()
Ejemplo n.º 4
0
    def __init__(self, config=None):
        """Initialize.

        config: The configuartion as a dictionary.
        """
        self.config = config or self.default_config
        if isinstance(self.config, str):
            self.config = YamlConfig(self.config).as_easydict()
Ejemplo n.º 5
0
def parse_config_files_and_bindings(args):
    if args.env_config is None:
        env_config = None
    else:
        env_config = YamlConfig(args.env_config).as_easydict()

    if args.policy_config is None:
        policy_config = None
    else:
        policy_config = YamlConfig(args.policy_config).as_easydict()

    if args.config_bindings is not None:
        parsed_bindings = ast.literal_eval(args.config_bindings)
        logger.info('Config Bindings: %r', parsed_bindings)
        env_config.update(parsed_bindings)
        policy_config.update(parsed_bindings)

    return env_config, policy_config
Ejemplo n.º 6
0
    def __init__(self, mode, config, debug, assets_dir):
        """Initialize.

        Args:
            mode: 'sim' or 'real'.
            config: The configuration file for the environment.
            debug: True if it is debugging mode, False otherwise.
            assets_dir: The assets directory.
        """

        self.mode = mode
        self.config = YamlConfig(config).as_easydict()
        self.debug = debug
        self.assets_dir = assets_dir

        # Command line client input history.
        readline.parse_and_bind('tab: complete')
        history_file = os.path.join('.python_history')

        try:
            readline.read_history_file(history_file)
        except IOError:
            pass

        atexit.register(readline.write_history_file, history_file)

        # Set up the scene.
        if self.mode == 'sim':
            print('Setting up the environment in simulation...')
            self.simulator = Simulator(use_visualizer=self.debug,
                                       assets_dir=self.assets_dir)
            self.simulator.reset()
            self.simulator.start()

            self.ground = self.simulator.add_body(self.config.SIM.GROUND.PATH,
                                                  self.config.SIM.GROUND.POSE,
                                                  is_static=True,
                                                  name='ground')

            self.table_pose = Pose(self.config.SIM.TABLE.POSE)
            self.table_pose.position.z += np.random.uniform(
                *self.config.SIM.TABLE.HEIGHT_RANGE)
            self.simulator.add_body(self.config.SIM.TABLE.PATH,
                                    self.table_pose,
                                    is_static=True,
                                    name='table')

            # Camera.
            self.camera = BulletCamera(simulator=self.simulator, distance=1.0)

        elif self.mode == 'real':
            print('Setting up the environment in the real world...')
            self.table_pose = Pose(self.config.SIM.TABLE.POSE)
            self.table_pose.position.z += np.random.uniform(
                *self.config.SIM.TABLE.HEIGHT_RANGE)
            self.camera = Kinect2(packet_pipeline_mode=0,
                                  device_num=0,
                                  skip_regirobovation=False,
                                  use_inpaint=True)
            self.simulator = None

        else:
            raise ValueError

        # Set up the robot.
        self.robot = franka_panda.factory(simulator=self.simulator,
                                          config=self.config.SIM.ARM.CONFIG)

        # Start the camera camera.
        self.camera.set_calibration(
            intrinsics=self.config.KINECT2.DEPTH.INTRINSICS,
            translation=self.config.KINECT2.DEPTH.TRANSLATION,
            rotation=self.config.KINECT2.DEPTH.ROTATION)
        self.camera.start()

        if self.simulator:
            camera_pose = [
                self.config.KINECT2.DEPTH.TRANSLATION,
                self.config.KINECT2.DEPTH.ROTATION
            ]
            camera_pose = Pose(camera_pose).inverse()
            self.simulator.plot_pose(camera_pose, axis_length=0.05)