openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.81k stars 810 forks source link

'mujoco_py.cymj.PyMjData' object has no attribute '_xfrc_applied' #735

Closed romluis closed 2 years ago

romluis commented 2 years ago

Describe the bug Object has no attribute '_xfrc_applied'

To Reproduce force = [0, 0, 0] torque = [0, 0, 0]

    self._sim.data._xfrc_applied[self._sim.model._body_name2id["torso"],:] = force + torque

Expected behavior Expected behavior is to apply the force and torque to the 'torso' body part. Error Messages Including more/longer error messages gives us more information to work with.

Desktop (please complete the following information):

Environment

Additional context I uncompensated the example in mushroom_rl/environments/mujoco.py

def _simulation_pre_step(self): """ Allows information to be accesed and changed at every intermediate step before taking a step in the mujoco simulation. Can be usefull to apply an external force/torque to the specified bodies.

    ex: apply a force over X to the torso:
    """
    force = [0, 0, 0]
    torque = [0, 0, 0]

    self._sim.data._xfrc_applied[self._sim.model._body_name2id["torso"],:] = force + torque

    #pass
romluis commented 2 years ago

I made the mistake of adding an extra underscore before the 'xfrc'. The correct way is: self._sim.data.xfrc_applied[self._sim.model._body_name2id["torso"],:] = force + torque