Is there a function that returns the starting index of a body in the q vector given its name?

Discussion in 'Support requests' started by Pedro Morais, Jul 30, 2019.

  1. It'd be very convenient to be able to index into qpos/qvel and sensordata using the name of a body/data (e.g. through a function that returns a pointer to the start of the relevant sub-array in e.g. qpos). I looked in the API reference and I couldn't find anything that does this, although I may have missed it. Is this something that is implemented, or do we have to implement this ourselves if we want it?

    Thank you,
    Pedro
    DRL
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    bodyid = mj_name2id(model, mjOBJ_BODY, name) is the index of the body with a given name

    jntid = model->body_jntadr[bodyid] is the index of the first joint for that body

    model->jnt_qposadr[jntid] is the first position of that joint in the system qpos vector

    for indexing into qvel and qfrc, you need the dof_XXX arrays in mjModel. the first velocity index in this example is given by body_dofadr[bodyid], which equals jnt_dofadr[jntid]
     
  3. Thank you. Is there way of indexing into data->ctrl like this as well?