Soft constraint derivation

Please don't post Bullet support questions here, use the above forums instead.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Soft constraint derivation

Post by Dirk Gregorius »

It is (J*W*JT + gamma). No division by h. Please check out the mouse joint in Box2D. This example should answer all your questions. I use these formulas myself and they work.

As for the stability issues that you are seeing remember warmstarting and Baumgarte don't work nicely together in many cases and you cannot fix it easily be softening the constraints. You have to ramp up the iteration count dramatically. This is why Box2D uses position projection.
c0der
Posts: 74
Joined: Sun Jul 08, 2012 11:32 am

Re: Soft constraint derivation

Post by c0der »

I had a thorough look at b2MouseJoint and the only difference between that and my code is the fact that Erin uses the mass of bodyB instead of the mass JM^-1JT seen by the impulse to compute the spring constant k and damping coefficient d.

I did this and reproduced the same behaviour. Technically from the harmonic oscillator derivation, we have only one body involved in the equation, and the same applies for the constraint equation for d^2x/dt^2 = lambda/m.

For the revolute joint, it seems as though we should take the average mass between the two planks, as two bodies are involved as opposed to the mouse joint, which is what was done in Box2D lite for the revolute joint.

For the line joint, we should take the mass of the anchored free body.

So Baumgarte stabilisation (dependent on beta, h and C) along with warm starting is still used in the mouse joint as:

(JM^-1JT + gamma/h)*LambdaImpulse = -Jvi - Beta/dt*C - gamma*AccumulatedLambdaImpulse

What do you mean by position projection Dirk? Thanks for all your help.
c0der
Posts: 74
Joined: Sun Jul 08, 2012 11:32 am

Re: Soft constraint derivation

Post by c0der »

Solved. The effective mass used to compute the spring constants and damping coefficients should be Meff = 1/Keff = (JM^-1JT)^-1 and this is the mass seen by the constraint. I was making the mistake of using JM^-1JT. This means that we have a spring constant matrix K and damping coefficient matrix D

K = Meff * wn^2
D = 2 * Meff * wn * zeta

However it is not wrong to choose a mass from either body as this works equally as well, perhaps Erin can explain if it's derived or purely experimental
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Soft constraint derivation

Post by Dirk Gregorius »

I am glad you found it. People sometimes call J*W*JT the effective mass though it is the inverse. I did this even myself :shock: . Anyway, the effective mass is the mass seen/felt by the constraint and it also considers the rotational effect. If you just use the plain mass you ignore these rotational effects. For the mouse joint it is a hack, but ok. Also note that it is a 3d constraint and the effective mass is a 3x3 matrix. I dont know now, but maybe there is a better mass approximation in this case.

Look at Box2D how it solves position constraints. The easiest example is the revolute joint. Also search for NGS in the code and maybe in the forum.

I also recommend looking into the Spook solver. Search for it here.
c0der
Posts: 74
Joined: Sun Jul 08, 2012 11:32 am

Re: Soft constraint derivation

Post by c0der »

Thanks Dirk, I am glad we got somewhere. It's an easy mistake to make. I will look into the solvers as you advised.
Post Reply