예제 #1
0
 def iter_render(self):
   """Returns an iterator that yields newly rendered frames as numpy arrays."""
   random_state = np.random.RandomState(self._seed)
   physics = mujoco.Physics.from_xml_string(self._xml_string)
   action_spec = mujoco.action_spec(physics)
   for _ in range(self._num_frames):
     for _ in range(self._steps_per_frame):
       actions = random_state.uniform(action_spec.minimum, action_spec.maximum)
       physics.set_control(actions)
       physics.step()
     for camera_spec in self._camera_specs:
       yield physics.render(**camera_spec._asdict())
예제 #2
0
파일: base.py 프로젝트: bycn/dm_control
    def action_spec(self, physics):
        """Returns a `BoundedArraySpec` matching the `physics` actuators."""
        from dm_env import specs

        # discrete for td3/ddpg
        # return specs.BoundedArray(shape=(5,),
        #                           dtype=mujoco.action_spec(physics).dtype,
        #                           minimum=[0,0,0,0,0],
        #                           maximum=[1,1,1,1,1],
        #                           name='hello')

        # original
        return mujoco.action_spec(physics)
예제 #3
0
    def action_spec(self, physics):
        """Returns an `BoundedArraySpec` matching the `Physics` actuators.

    BoundedArraySpec.name should contain a tab-separated list of actuator names.
    When overloading this method, non-MuJoCo actuators should be added to the
    top of the list when possible, as a matter of convention.

    Args:
      physics: used to query actuator names in the model.
    """
        names = [
            physics.model.id2name(i, 'actuator') or str(i)
            for i in range(physics.model.nu)
        ]
        action_spec = mujoco.action_spec(physics)
        return specs.BoundedArraySpec(shape=action_spec.shape,
                                      dtype=action_spec.dtype,
                                      minimum=action_spec.minimum,
                                      maximum=action_spec.maximum,
                                      name='\t'.join(names))
예제 #4
0
 def action_spec(self):
     """Returns a `BoundedArraySpec` matching the `physics` actuators."""
     return mujoco.action_spec(self.env.physics)
예제 #5
0
    def __init__(self,
                 model_path='rope.xml',
                 distance_threshold=5e-2,
                 frame_skip=2,
                 horizon=100,
                 goal_range=None,
                 image_size=512,
                 action_type='torque',
                 use_visual_observation=True,
                 camera_name='static_camera',
                 use_dof='both'):
        '''

        :param model_path:
        :param distance_threshold:
        :param frame_skip:
        :param horizon:
        :param goal_range:
        :param image_size:
        :param action_type:
        :param use_visual_observation:
        :param camera_name:
        :param use_dof: ['both', 'arm', 'gripper']
        Base class for sawyer manipulation environments
        '''

        if model_path.startswith("/"):
            fullpath = model_path
        else:
            fullpath = os.path.join(os.path.dirname(__file__), model_path)
        if not path.exists(fullpath):
            raise IOError("File %s does not exist" % fullpath)

        self.physics = Physics.from_xml_string(
            *self.get_model_and_assets(fullpath))
        self.np_random = None
        self.camera_name = camera_name
        self.data = self.physics.data
        self.viewer = None
        self.distance_threshold = distance_threshold
        self.frame_skip = frame_skip
        self.reward_type = 'sparse'
        self.horizon = horizon
        self.use_visual_observation = use_visual_observation
        self._max_episode_steps = horizon
        self.use_dof = use_dof
        self.time_step = 0
        self.image_size = image_size
        self.action_type = action_type
        self.goal_range = goal_range if goal_range is not None else [
            -0.16, 0.16
        ]
        self.configure_indexes()

        if self.use_dof == 'both':
            self.action_length = mujoco.action_spec(self.physics).shape[0]
        elif self.use_dof == 'arm':
            self.action_length = len(self.arm_inds)
        elif self.use_dof == 'gripper':
            self.action_length = len(self.gripper_inds)
        else:
            assert 'Wrong arguments'

        obs = self.reset()
        self.action_space = spaces.Box(-np.inf,
                                       np.inf,
                                       shape=(self.action_length, ),
                                       dtype='float32')
        self.observation_space = spaces.Dict(
            dict(
                desired_goal=spaces.Box(-np.inf,
                                        np.inf,
                                        shape=obs['achieved_goal'].shape,
                                        dtype='float32'),
                achieved_goal=spaces.Box(-np.inf,
                                         np.inf,
                                         shape=obs['achieved_goal'].shape,
                                         dtype='float32'),
                observation=spaces.Box(-np.inf,
                                       np.inf,
                                       shape=obs['observation'].shape,
                                       dtype='float32'),
            ))
        self.goal_dim = np.prod(obs['achieved_goal'].shape)
예제 #6
0
 def action_spec(self, physics):
     """Returns actions corresponding to the Mujoco actuators."""
     return mujoco.action_spec(physics)
예제 #7
0
 def action_spec(self):
     return mujoco.action_spec(self)