highfidelity/hifi — pull request #3109 by AndrewMeadows (2014-07-02 17:14:00+00:00)
Title: stable arm IK without constraints

The problem: applying the eulerian constraints from the model can make the arm IK to go crazy. The instability is caused by two things:

(1) The Eulerian decomposition has a singularity (aka gimbal lock). For our safeEulers() method this singularity is at yaw = +/- PI/2.

(3) Naive clamping in Eulerian space doesn't necessarily provide the closest quaternion with in the accepted zone. Hence we get sudden jerks and snaps when the limits are enforced.

The solution: temporarily disable enforcement of constraints during IK. Instead use some new IK that can iterate up the "free lineage" of the end joint multiple times and that also blends in some "default pose" in the process. This blending provides stability and removes the necessity of computing a gravitational effect.

Some known problems:

(a) It is possible to orient the arm such that the wrist or shoulder is bent too far ("broken arm effect"), however it won't oscillate.

(b) There is a side effect where the roll of the forearm may drift a little bit into a stable position after a wide swing from forward to side (and vice versa). This is because the elbow constraint is not actually being enforced yet. The effect is slight and not as terrible as the instability we should go ahead and use this for now and implement stable constraints in a subsequent PR.