[ODE] Damping without adding forces

Joe Ante joe at otee.dk
Tue Oct 26 14:18:09 MST 2004


> Hi, all
> 
> I've just realized damping in my version of ODE, just by modifying
> body's velicity in dxStepBody:
> 
>   // handle linear velocity
>   for (j=0; j<3; j++)
>   {
> 
>  // inserted code
>       if( b->flags & dxBodyDamping )
>           b->lvel[ j ] *= REAL( 1.0 ) - b->damping.linearDamping * h;
>  // end of inserted code
>           
>       b->pos[j] += h * b->lvel[j];
>   }
This code is not timestep independent.
This is very important because when you either want to change the fixed
timestep or are using dynamic timestepping the simulation will behave
differently.

You can make it timestep independent using pow (1.0 - dampingScale, h).
The other instability is that your damping code doesn't handle the case
where b->damping.linearDamping * h is larger than 1.0.

Now using pow to do damping is quite expensive and that makes using forces
to simulate damping faster. Plus they could in some situations be more
stable since the solver can disregard any damping applied based on the
constraints it applies. It can't do that if you just set the velocity.

When doing force based damping it is very important for stability to clamp
the force you apply to the force that will make the body come to complete
stop within one timestep.

   Vector3f maxDragVec = Vector3f (vel[0], vel[1], vel[2]) * -rb.GetMass ()
* invDeltaTime;
If (SqrMagnitude (dragVec) > SqrMagnitude ( maxDragVec ))
    dragVec = maxDragVec;

If you don't do this, then large delta times or high damping can make your
bodies start swinging and build up more and more energy ... to infinity and
beyond.

Lastly i believe adding linearDrag to ode core is not a good idea since you
almost always want something custom eg. In a lot of cases you want sqred
drag. Sometimes you want constant drag.
For a complete solution you need the same for angular drag.
Thus i think you should either do it right (supply constant, linear, sqr
drag for both velocity and angular velocity) or leave it out of the ode
core.

Joachim Ante




More information about the ODE mailing list