HOWTO Damping

From ODE
Revision as of 20:46, 6 January 2019 by Russ (talk | contribs) (Created page with "Strictly speaking, [http://en.wikipedia.org/wikiold/Damping damping] is a force that reduces the amplitude of an oscillating system over time, although the term is often used...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Strictly speaking, damping is a force that reduces the amplitude of an oscillating system over time, although the term is often used to mean just about anything that removes energy from the system.

Damping in ODE

ODE doesn't model friction on joints (except contact joints), and there's no rolling friction. The result is that objects seem to never lose energy (sometimes it might be a good thing), and even gain extra energy out of nowhere. (never a good thing)

As of version 0.9, ODE has built-in damping functions. See World Damping is the manual. It doesn't take mass into account, so it's not suited for friction nor aerodynamic drag. Another note is that it is applied after the body is moved by the stepper, so it doesn't introduce error in joints.

Also for ODE version 0.9 and later the function dBodySetMovedCallback() can be used to register a callback to be called right after the body was moved. You can perform damping in this callback without introducing error in joints. If you use the built-in damping API together with this function, remember that the built-in damping (if activated for the current body) will only be applied after the callback is executed. This way you always have access to the original, untouched velocity in the callback.

Damping can be implemented in many ways. If you want to approximate a particular effect such as rolling friction or aerodynamic drag, you might want to try one of the alternative implementations below.

Custom Damping

To apply damping to a moving body:

  • Compute the velocity of the object that's supposed to slow down: dBodyGetLinearVel().
  • Multiply that velocity by a negative damping coefficient, like -0.01 -- this is your damping force.
  • Apply that force with dBodyAddForce().

Tweak the damping coefficient to get the object to slow down at the rate you want.

Rolling Friction

To simulate rolling friction, you can do the same thing with angular velocity rather than linear velocity, and dBodyAddTorque rather than dBodyAddForce, and make the damping coefficient greater (in absolute value) than -1.0. Note that when simulating rolling friction, you should only apply the damping when the object is actually touching the ground. Check for the existence of a contact joint between the object and the ground, for example.

Aerodynamic Drag

To simulate aerodynamic drag it is better to use the square of the velocity; that's how drag works in reality - certainly at the relatively high Reynolds numbers that most simulations are interested in. The force should also be applied at the object's aerodynamic center rather than at the body's center of mass. These may be the same, but if you're using geometry transforms they may not be. The center of the object's cross section would probably be close to the aerodynamic center, at least for non-engineering purposes. In any case, dBodyAddForceAtRelPos() will allow you to apply the force at a specific point in the body's frame of reference.