# Get derivative of qpos

Discussion in 'Simulation' started by Robert, Jan 7, 2020.

1. ### Robert

For an application I am writing I need MuJoCo to function as the dynamics back-end. This is going so far so good, however, I'm running into a problem tying stuff together.

I need the system dynamics in terms of the state:
$\dot{\vec{x}} = f(\vec{x})$
Where the state typically contains positons and velocities:
$\vec{x}=(\vec{q}_{pos}, \vec{q}_{vel})^T$
This notation is nice because it allows you to tackle Eulrer angles vs. Angular velocity. (See this post.) In this case qpos has one more dimension than qvel.
The second part of the state derivative is easy:
$\dot{\vec{q}}_{vel} = \vec{q}_{acc}$

But what to do with $\dot{\vec{q}}_{pos}$ ? Is there a built-in function to get the derivative of d->qpos? I know it is not (always) equal to d->qvel, which is obvious when the dimensions are different. In the documentation this is glanced over without giving a real answer: http://www.mujoco.org/book/programming.html#siStateControl

I could find the derivative of the quaternion using qvel, however, for e.g. the Humanoid model with nq = 28 it is not trival to find which variables make up the freejoint rotation.

Thank you!

Last edited: Jan 7, 2020
2. ### florianw

Robert likes this.