Map joint name to generalized coordinate index #2525
Answered
by
yuvaltassa
artificial-tapir
asked this question in
Asking for Help
-
IntroHi, I'm a student working on robot simulations. My setupMuJoCo 3.2.5 Python My questionHow does one find the index or indices in mujoco's generalized coordinate system that correspond to a given joint name?
corresponding to a given joint name. Is there a method that gives the index-range of a subtree? For instance, when having multiple robots within a scene, it would be nice to get the individual robots' mass matrices and jacobians. Thanks for your help Minimal model and/or code that explain my question
Confirmations
|
Beta Was this translation helpful? Give feedback.
Answered by
yuvaltassa
Apr 6, 2025
Replies: 1 comment 8 replies
-
def dof_width(joint_type: mujoco.mjtJoint) -> int:
"""Get the dimensionality of the joint in qvel."""
return {0: 6, 1: 3, 2: 1, 3: 1}[joint_type]
def qpos_width(joint_type: mujoco.mjtJoint) -> int:
"""Get the dimensionality of the joint in qpos."""
return {0: 7, 1: 4, 2: 1, 3: 1}[joint_type]
qvel_ids = []
qpos_ids = []
for joint_name in joint_names:
jnt_id = model.joint(joint_name).id
jnt_type = model.jnt_type[jnt_id]
vadr = model.jnt_dofadr[jnt_id]
qadr = model.jnt_qposadr[jnt_id]
vdim = dof_width(jnt_type)
qdim = qpos_width(jnt_type)
qvel_ids.extend(range(vadr, vadr + vdim))
qpos_ids.extend(range(qadr, qadr + qdim))
qvel_ids = np.array(qvel_ids)
qpos_ids = np.array(qpos_ids) |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mmmm, I fixed the error message and added a test in 305b68e ?