本文整理汇总了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
示例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
示例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))
示例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()
示例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()