From 60a4cf11d613faeeaf21cf9bf470bf6478fd11a3 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sun, 18 Jun 2023 12:10:01 +0200 Subject: [PATCH] Fix: Some envs used no longer existing binding to mujoco --- fancy_gym/envs/mujoco/beerpong/beerpong.py | 8 +++++--- fancy_gym/envs/mujoco/hopper_jump/hopper_jump.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fancy_gym/envs/mujoco/beerpong/beerpong.py b/fancy_gym/envs/mujoco/beerpong/beerpong.py index fd1a5dc..802776f 100644 --- a/fancy_gym/envs/mujoco/beerpong/beerpong.py +++ b/fancy_gym/envs/mujoco/beerpong/beerpong.py @@ -7,6 +7,8 @@ from gymnasium.core import ObsType from gymnasium.envs.mujoco import MujocoEnv from gymnasium.spaces import Box +import mujoco + MAX_EPISODE_STEPS_BEERPONG = 300 FIXED_RELEASE_STEP = 62 # empirically evaluated for frame_skip=2! @@ -61,9 +63,9 @@ class BeerPongEnv(MujocoEnv, utils.EzPickle): self.repeat_action = 2 # TODO: If accessing IDs is easier in the (new) official mujoco bindings, remove this self.model = None - self.geom_id = lambda x: self._mujoco_bindings.mj_name2id(self.model, - self._mujoco_bindings.mjtObj.mjOBJ_GEOM, - x) + self.geom_id = lambda x: mujoco.mj_name2id(self.model, + mujoco.mjtObj.mjOBJ_GEOM, + x) # for reward calculation self.dists = [] diff --git a/fancy_gym/envs/mujoco/hopper_jump/hopper_jump.py b/fancy_gym/envs/mujoco/hopper_jump/hopper_jump.py index f7936c7..b77cab1 100644 --- a/fancy_gym/envs/mujoco/hopper_jump/hopper_jump.py +++ b/fancy_gym/envs/mujoco/hopper_jump/hopper_jump.py @@ -7,6 +7,8 @@ from gymnasium import utils from gymnasium.envs.mujoco import MujocoEnv from gymnasium.spaces import Box +import mujoco + MAX_EPISODE_STEPS_HOPPERJUMP = 250 @@ -244,12 +246,12 @@ class HopperJumpEnv(HopperEnvCustomXML): # floor_geom_id = self.model.geom_name2id('floor') # foot_geom_id = self.model.geom_name2id('foot_geom') # TODO: do this properly over a sensor in the xml file, see dmc hopper - floor_geom_id = self._mujoco_bindings.mj_name2id(self.model, - self._mujoco_bindings.mjtObj.mjOBJ_GEOM, - 'floor') - foot_geom_id = self._mujoco_bindings.mj_name2id(self.model, - self._mujoco_bindings.mjtObj.mjOBJ_GEOM, - 'foot_geom') + floor_geom_id = mujoco.mj_name2id(self.model, + mujoco.mjtObj.mjOBJ_GEOM, + 'floor') + foot_geom_id = mujoco.mj_name2id(self.model, + mujoco.mjtObj.mjOBJ_GEOM, + 'foot_geom') for i in range(self.data.ncon): contact = self.data.contact[i] collision = contact.geom1 == floor_geom_id and contact.geom2 == foot_geom_id