[ODE] AutoDisable

Jani Laakso jani.laakso at itmill.com
Sun Feb 29 15:00:16 MST 2004


DjArcas wrote:

> /* These functions are not yet implemented by ODE. */
>
> /*
>
> dReal dBodyGetAutoDisableThresholdSF1(dBodyID);
>
> void dBodySetAutoDisableStepsSF1(dBodyID, int AutoDisableSteps);
>
> int dBodyGetAutoDisableStepsSF1(dBodyID);
>
> void dBodySetAutoDisableSF1(dBodyID, int doAutoDisable);
>
> int dBodyGetAutoDisableSF1(dBodyID);
>
> */
>
> Are they lurking around anywhere as a patch or something? Seems like 
> autodisabling bodies should really be in there!
>
I assume you already know this but you can implement auto disabling 
without the upper methods already.

Here's how I do it on Odejava project. Just before stepping the world I 
call autoDisableBodies method below. Each body has it's own setup for 
stepcount and threshold (angular/linear velocity). I assume this does 
exactly the same trick what upper not yet implemented methods should do, 
am I correct?

// Automatically disable bodies which angular and linear velocities
// are below threshold for n steps
JNIEXPORT void JNICALL 
Java_org_odejava_collision_JavaCollision_autoDisableBodies
(JNIEnv *env, jobject obj) {
  for (int i=0; i < maxAutoDisableSize; i++) {
    dBodyID b = autoDisableBodies[i];
    if (!b) return;
    if (dBodyIsEnabled(b)) {
      // Check if slow enough linear velocity
      const dReal *linVel = dBodyGetLinearVel(b);
    dReal lspeed = 
linVel[0]*linVel[0]+linVel[1]*linVel[1]+linVel[2]*linVel[2];
    if (lspeed < autoDisableBodiesThreshold[i]) {
       // Check if slow enough angular velocity
           const dReal *angVel = dBodyGetAngularVel(b);
      dReal aspeed = 
angVel[0]*angVel[0]+angVel[1]*angVel[1]+angVel[2]*angVel[2];
      if (aspeed < autoDisableBodiesThreshold[i]) {
        autoDisableBodiesCurrentSteps[i]++;
        // Check if body has been moving slow for long enough time
        if (autoDisableBodiesCurrentSteps[i] > autoDisableBodiesSteps[i])
            dBodyDisable(b);
        } else {
          autoDisableBodiesCurrentSteps[i] = 0;
        }
      } else {
        autoDisableBodiesCurrentSteps[i] = 0;
      }
    }
  }
}

This surely makes e.g. brick of walls more stable and stops bodies 
trembling against terrain on obvious cases when bodies should be 
completely stable, not moving (disabled).

There's also some speed gain if most of your objects seem to be not 
moving, in other worlds they can be disabled most of the time of your 
simulation.

-- 
Jani Laakso / IT Mill Ltd | Tel. +358 40 5898086 | http://www.itmill.com




More information about the ODE mailing list