hi emo, we would like to get the position and orientation of a known object within the xml file while manipulating it. how can we get it's pos and quat throughout the simulation ? (i can get the object id and name using mj_id2name and mj_name2id respectively) thanks

Assuming the body id is n, the 3D position is at mjData.xpos+3n and the quaternion orientation is at mjData.xquat+4*n. You can also get the orientation as a 3x3 orthonormal matrix at mjData.xmat+9*n. Note that all these quantities are computed by forward kinematics, which is called from within forward dynamics (with mj_forward). If you call mj_step, it will advance the state (qpos, qvel) while the kinematics (xpos, xquat) still correspond to the previous state.

I'm confused about this sentence. After loading a model, I check the values of xpos, and they are 0s. Then, I set mjData.ctrl to a random vector, and call mj_step. The values of xpos change when I check again. Could you explain "the kinematics still correpsond to the previous state"?

Before mj_step() you have qpos(t), qvel(t), xpos(t-1) which may be 0 if t = 0. After mj_step() you have qpos(t+1), qvel(t+1), xpos(t). This is because mj_step() calls mj_forward() to compute everything at time t. Then it advances qpos and qvel to t+1 but does not recompute anything else at t+1.