google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.31k stars 836 forks source link

Can `MjModel.jnt_dofadr` be used for accessing `MjData.qacc`? #1564

Closed adlarkin closed 8 months ago

adlarkin commented 8 months ago

Hello, I'm new to MuJoCo and I'm trying to test a simple two-link arm hitting a sphere in a zero gravity environment. I am recording the positions, velocities, and accelerations of the bodies after each simulation step so that I can plot this data.

The floating objects section of the documentation shows how to get the joint addresses for qpos and qvel. Is the address returned by MjModel.jnt_dofadr a valid address for accessing the joint's acceleration via MjData.qacc, or can this address only be used to access MjData.qvel? My intuition tells me that jnt_dofadr should work for both qvel and qacc (i.e., the dimensionality of the velocity and acceleration should be the same), but the documentation and code comments for jnt_dofadr indicate that this should only be used for qvel. Also, the fact that this field is called jnt_dofadr instead of something like jnt_qveladr makes me think that it's applicable to both qvel and qacc.

Here's the model I'm using:

simple_arm_zero_gravity.xml ```XML ```

Additional details: OS: Ubuntu 22.04 Python version: 3.10.12 MuJoCo version: 3.1.3 (installed in a venv with the Python version listed above)

Balint-H commented 8 months ago

Hello,

Your assumptions are correct, qvel and qacc are aligned, the same index refers to the same DoF on the model (unlike qpos). So you can use dofadr for both!

adlarkin commented 8 months ago

Awesome, thanks for confirming!