Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculateInverseDynamics losing one joint DOF for floating bodies #4585

Conversation

ConnorTingley
Copy link
Contributor

resolves #4578

The issue here is that the last positional degree of freedom of floating bodies is ignored in calculateInverseDynamics.
This is because the indexing of q does not account for the drop in degree of freedom when converting from a quaternion angle (4 DOF) to an Euler angle (3 DOF).

int baseDofQ = bodyHandle->m_multiBody->hasFixedBase() ? 0 : 7;

With a floating body, baseDofQ is set to be 7.

if (baseDofQ)
{
btVector3 pos(clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[0],
clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[1],
clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[2]);
btQuaternion orn(clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[3],
clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[4],
clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[5],
clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[6]);
btScalar yawZ, pitchY, rollX;
orn.getEulerZYX(yawZ, pitchY, rollX);
q[0] = rollX;
q[1] = pitchY;
q[2] = yawZ;
q[3] = pos[0];
q[4] = pos[1];
q[5] = pos[2];
}
for (int i = 0; i < num_dofs; i++)
{
q[i + baseDofQ] = clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ[i + baseDofQ];
}

q[0] through q[5] are set in the if statement. However the for loop starts at q[7], meaning that q[6] is never set and the last joint position is excluded from the array.

This can be fixed by subtracting 1 from the indexing of q (not clientCmd.m_calculateInverseDynamicsArguments.m_jointPositionsQ as this uses a quaternion) in the case of a floating body.

@erwincoumans
Copy link
Member

Good catch and thanks for the fix. Let's merge it.

@erwincoumans erwincoumans merged commit 43d336f into bulletphysics:master Apr 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pybullet: calculateInverseDynamics ignores some joint rotations but not others
2 participants