[ODE] Speeding up a chain simulation

Adam D. Moss aspirin at ntlworld.com
Fri Jan 3 05:50:02 2003


Shree Kumar wrote:
> After fixing a few problems due to the step-size, I was able
> to get a good simulation.  There was only one hitch - it was
> terribly slow! [The simulation itself took more than a few
> secs on my P4]
> 
> On close examination, I found that at each step, approximately
> 240 contact joints were being generated and this was the chief
> cause of the slowdown.
> 
> Can anyone give me some hints on what I can do to improve
> the simulation speed?

Two main suggestions:

1) Use your existing chain model with simpler restraints:
  a) Only ask for 1 contact point per link-link collision in the
near-callback (you're currently getting an average of ~2.5).  Your
chains aren't likely to come to rest with only one contact point
though.
  b) Make link-link collision frictionless (contact.surface.mu = 0)
which (I believe) yields a contact joint with fewer degrees of
freedom restricted (or is at the very least faster overall).

2) See test_chain1 and test_chain2; depending on what it is you're
actually trying to simulate with your chain, you probably don't want
the minutiae of link-link interaction, but rather the hinging that
results from the collision of the two inner surfaces of the
links.  Hence you could simply connect each link body to the next
with a joint (say, universal), with some physical overlap
between the geoms of each link to they still seem interlocked, then
don't bother to collide geoms of a chain with itself (hence no
contact joints, which is good for speed, but the chain won't
self-collide).

In ODE, joints (collision or otherwise) are the enemies of speed
because of the degrees of freedom they restrict.

ODE is O(n^3) for the number of degrees of freedom restricted in
the simulation, so just halving the number of contact joints in the
system might make your simulation 8 times faster.

Other optimizations that come to mind:
* Model your links with four cylinders rather than four boxes,
which should be faster to collide.
* Put each chain into a hash space.
* Put each link into a simple space.
(Possibly you're already doing these latter two.)

-- 
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3