Description
Question
I added static obstacles (box geoms) to the half_cheetah.xml
model, and I would like to randomize their position and size during training at the beginning of each episode (by adding a small random number to their original position and size). To do this, I set the following in the reset_model()
method
self.model.geom(f"geom_{i}").pos[0] += np.random.uniform(a, b) # Position.
self.model.geom(f"geom_{i}").size[0] += np.random.uniform(c, d) # Depth.
self.model.geom(f"geom_{i}").size[2] += np.random.uniform(e, f) # Height.
The call to self.set_state()
comes after setting the above.
However, it seems that this leads to some discrepancy within MuJoCo, as the box geoms become partially penetrable after modifying their position and size (i.e., the cheetah's body partially penetrates the box geoms, and sometimes even gets stuck inside them).
ChatGPT suggested adding mujoco.mj_forward(self.model, self.data)
or self.sim.forward()
before or after the call to self.set_state()
, but this made no difference.
I am using
gymnasium 0.28.1
mujoco 3.2.3