當前位置: 首頁>>代碼示例>>Python>>正文


Python mujoco_py.MujocoException方法代碼示例

本文整理匯總了Python中mujoco_py.MujocoException方法的典型用法代碼示例。如果您正苦於以下問題:Python mujoco_py.MujocoException方法的具體用法?Python mujoco_py.MujocoException怎麽用?Python mujoco_py.MujocoException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mujoco_py的用法示例。


在下文中一共展示了mujoco_py.MujocoException方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: step

# 需要導入模塊: import mujoco_py [as 別名]
# 或者: from mujoco_py import MujocoException [as 別名]
def step(self, action):
        assert not self.episode_error, "Won't Continue Episode After Mujoco Exception -- \
            Please discard episode and reset. If info['discard_episode'] is True the episode\
            should be discarded"
        try:
            obs, rew, done, info = self.env.step(action)
            info['discard_episode'] = False
        except MujocoException as e:
            self.episode_error = True
            # Done is set to False such that rollout workers do not accidently send data in
            # the event that timelimit is up in the same step as an error occured.
            obs, rew, done, info = {}, 0.0, False, {'discard_episode': True}
            logging.info(str(e))
            logging.info("Encountered Mujoco Exception During Environment Step.\
                          Reset Episode Required")

        return obs, rew, done, info 
開發者ID:openai,項目名稱:multi-agent-emergence-environments,代碼行數:19,代碼來源:util.py

示例2: reset

# 需要導入模塊: import mujoco_py [as 別名]
# 或者: from mujoco_py import MujocoException [as 別名]
def reset(self):
        try:
            obs = self.env.reset()
        except MujocoException:
            logging.info("Encountered Mujoco Exception During Environment Reset.\
                          Trying Reset Again")
            obs = self.reset()
        self.episode_error = False
        return obs 
開發者ID:openai,項目名稱:multi-agent-emergence-environments,代碼行數:11,代碼來源:util.py

示例3: _mj_warning_fn

# 需要導入模塊: import mujoco_py [as 別名]
# 或者: from mujoco_py import MujocoException [as 別名]
def _mj_warning_fn(warn_data: bytes):
    """Warning function override for mujoco_py."""
    try:
        user_warning_raise_exception(warn_data)
    except mujoco_py.MujocoException as e:
        logging.error('MuJoCo Exception: %s', str(e)) 
開發者ID:google-research,項目名稱:robel,代碼行數:8,代碼來源:mjpy_sim_scene.py

示例4: _reset_sim

# 需要導入模塊: import mujoco_py [as 別名]
# 或者: from mujoco_py import MujocoException [as 別名]
def _reset_sim(self):
        self.sim.set_state(self.initial_state)
        self.sim.forward()

        initial_qpos = self.sim.data.get_joint_qpos('object:joint').copy()
        initial_pos, initial_quat = initial_qpos[:3], initial_qpos[3:]
        assert initial_qpos.shape == (7,)
        assert initial_pos.shape == (3,)
        assert initial_quat.shape == (4,)
        initial_qpos = None

        # Randomization initial rotation.
        if self.randomize_initial_rotation:
            if self.target_rotation == 'z':
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = np.array([0., 0., 1.])
                offset_quat = quat_from_angle_and_axis(angle, axis)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation == 'parallel':
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = np.array([0., 0., 1.])
                z_quat = quat_from_angle_and_axis(angle, axis)
                parallel_quat = self.parallel_quats[self.np_random.randint(len(self.parallel_quats))]
                offset_quat = rotations.quat_mul(z_quat, parallel_quat)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation in ['xyz', 'ignore']:
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = np.random.uniform(-1., 1., size=3)
                offset_quat = quat_from_angle_and_axis(angle, axis)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation == 'fixed':
                pass
            else:
                raise error.Error('Unknown target_rotation option "{}".'.format(self.target_rotation))

        # Randomize initial position.
        if self.randomize_initial_position:
            if self.target_position != 'fixed':
                initial_pos += self.np_random.normal(size=3, scale=0.005)

        initial_quat /= np.linalg.norm(initial_quat)
        initial_qpos = np.concatenate([initial_pos, initial_quat])
        self.sim.data.set_joint_qpos('object:joint', initial_qpos)

        def is_on_palm():
            self.sim.forward()
            cube_middle_idx = self.sim.model.site_name2id('object:center')
            cube_middle_pos = self.sim.data.site_xpos[cube_middle_idx]
            is_on_palm = (cube_middle_pos[2] > 0.04)
            return is_on_palm

        # Run the simulation for a bunch of timesteps to let everything settle in.
        for _ in range(10):
            self._set_action(np.zeros(20))
            try:
                self.sim.step()
            except mujoco_py.MujocoException:
                return False
        return is_on_palm() 
開發者ID:ArztSamuel,項目名稱:DRL_DeliveryDuel,代碼行數:61,代碼來源:manipulate.py

示例5: _reset_sim

# 需要導入模塊: import mujoco_py [as 別名]
# 或者: from mujoco_py import MujocoException [as 別名]
def _reset_sim(self):
        self.sim.set_state(self.initial_state)
        self.sim.forward()

        initial_qpos = self.sim.data.get_joint_qpos('object:joint').copy()
        initial_pos, initial_quat = initial_qpos[:3], initial_qpos[3:]
        assert initial_qpos.shape == (7,)
        assert initial_pos.shape == (3,)
        assert initial_quat.shape == (4,)
        initial_qpos = None

        # Randomization initial rotation.
        if self.randomize_initial_rotation:
            if self.target_rotation == 'z':
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = np.array([0., 0., 1.])
                offset_quat = quat_from_angle_and_axis(angle, axis)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation == 'parallel':
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = np.array([0., 0., 1.])
                z_quat = quat_from_angle_and_axis(angle, axis)
                parallel_quat = self.parallel_quats[self.np_random.randint(len(self.parallel_quats))]
                offset_quat = rotations.quat_mul(z_quat, parallel_quat)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation in ['xyz', 'ignore']:
                angle = self.np_random.uniform(-np.pi, np.pi)
                axis = self.np_random.uniform(-1., 1., size=3)
                offset_quat = quat_from_angle_and_axis(angle, axis)
                initial_quat = rotations.quat_mul(initial_quat, offset_quat)
            elif self.target_rotation == 'fixed':
                pass
            else:
                raise error.Error('Unknown target_rotation option "{}".'.format(self.target_rotation))

        # Randomize initial position.
        if self.randomize_initial_position:
            if self.target_position != 'fixed':
                initial_pos += self.np_random.normal(size=3, scale=0.005)

        initial_quat /= np.linalg.norm(initial_quat)
        initial_qpos = np.concatenate([initial_pos, initial_quat])
        self.sim.data.set_joint_qpos('object:joint', initial_qpos)

        def is_on_palm():
            self.sim.forward()
            cube_middle_idx = self.sim.model.site_name2id('object:center')
            cube_middle_pos = self.sim.data.site_xpos[cube_middle_idx]
            is_on_palm = (cube_middle_pos[2] > 0.04)
            return is_on_palm

        # Run the simulation for a bunch of timesteps to let everything settle in.
        for _ in range(10):
            self._set_action(np.zeros(20))
            try:
                self.sim.step()
            except mujoco_py.MujocoException:
                return False
        return is_on_palm() 
開發者ID:joanby,項目名稱:ia-course,代碼行數:61,代碼來源:manipulate.py


注:本文中的mujoco_py.MujocoException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。