google-deepmind / mujoco

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

Mapping between motors/joints and data.ctrl indexing #372

Closed rleontienrl closed 2 years ago

rleontienrl commented 2 years ago

Hi,

I'm trying to use MuJoCo for control of a robotic hand (with a robotic manipulator), attached to a robot dog.

Is there a way to find the mapping between motors/joints and data.ctr such that I can separate the control between the hand, manipulator, and dog kinematic chains so they can be controlled separately?

Thank you!

erez-tom commented 2 years ago

The relevant mjModel fields are actuator_trntype (which specifies whether the actuator controls a joint, site, or something else), and actuator_trnid (which gives you the index of the element, e.g., joint or site).

Note that actuator_trnid is of size nu x 2, so the indexing for joints and sites is with 2*i (like here). For example, if actuator i controls a joint, we have model->actuator_trntype[i] == mjTRN_JOINT, and the velocity of the joint controlled by actuator i is:

data->qvel[ model->jnt_dofadr[ model->actuator_trnid[2*i] ] ].