[ammo] Problems with rigidity of sequential constraints

Post Reply
mooflaur
Posts: 2
Joined: Thu Oct 13, 2022 8:16 pm

[ammo] Problems with rigidity of sequential constraints

Post by mooflaur »

I should preface this post by saying that I am working with ammo.js, which is based on a version of Bullet that is several years old now, so maybe this problem is already fixed.

Screen Shot 2022-10-14 at 5.06.32 PM.png
Screen Shot 2022-10-14 at 5.06.32 PM.png (539.19 KiB) Viewed 3650 times
Animated version: https://youtu.be/mv1f-HllwEI

This scene illustrates a problem I've been having with chaining several constraints together. The places where blue and purple objects meet are connected by hinge constraints. The colors of the meshes indicate which rigid body they belong to, with the exception of the orange sphere, which shares a rigid body with the two small purple cylinders adjacent to it. Everything in the scene has a density of 1 and a mass calculated according to its size and density, with the exception of the orange sphere, which has a density of 0.01. The rigid bodies that contain cubes are kinematic, while all of the others are dynamic. All of the constraints in the scene have exactly the same parameters, other than the bodies they connect and the pivot point of the connection.

The problem I'm experiencing is that the rigidity of the constraints when chained together like this seems to depend on the relative masses (or perhaps the relative rotational inertias) of the two linked objects. The center and top examples both work about as expected: there's a little bit of wobble in the constraints but not so much as to be a problem. On the left, though, the purple body is much less massive than the other two, with the result that the constraint practically falls apart under gravity. On the right is a similar situation, although either because of the additional mass of the orange sphere, the separation between the constraints, or both, the wobble isn't quite as extreme.

I can produce similar results by having the entire system of constraints be dynamic and balancing it on a static object such that the more massive parts hang off to the sides. This example happens to use hinges but I've had the same problem with sliders and Generic6Dof constraints as well.

My questions are as follows:
- Is this problem reproducible in more recent versions of bullet?
- If so, is there any fix or workaround to this?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: [ammo] Problems with rigidity of sequential constraints

Post by drleviathan »

Yes, I think you are right: large ratios between the mass/inertia of constrained objects are contributing to the error of the constraint solution. I believe the problem still reproduces in the latest version of Bullet, but I haven't tested constraints in a while. Your example is probably using the btSequentialImpulseConstraintSolver which is described in the comments like this:
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (iterative LCP) method.
I think it solves a matrix equation Mb=x (where b is unknown) for each constraint, independently of other constraints. By iterating over each individual constraint multiple times it converges toward a final solution. Large mass ratios cause the solution to converge slower so and since the number of iterations is limited... there is still large error at the end.

As to workarounds... I only have one idea when it comes to solving general (e.g. non-fixed) constriants: throw more CPU resources at the problem:
(1) Reduce the substep duration and take smaller steps --> the result is effectively more constraint solver iterations per second of simulation.
(2) Looking at the C++... it appears to be possible to increase the number of iterations of the constraint solver (per substep) in two ways: (a) set the btContactSolverInfo::m_numIterations passed to the solver, or (b) call Constraint::setOverrideNumSolverIterations() on each constraint. Dunno if these knobs are exposed in ammo.js.
mooflaur
Posts: 2
Joined: Thu Oct 13, 2022 8:16 pm

Re: [ammo] Problems with rigidity of sequential constraints

Post by mooflaur »

Thanks for the reply. Ammo.js doesn't expose those options, unfortunately. I tried increasing the number of substeps globally and did get better results that way but that's not a practical long-term solution for performance reasons.

I'm going to see if I can make this work better just by fudging the numbers on mass and/or inertia; it would be better in my case to have inaccurate values for those than to have constraints that don't work as expected. I'll post an update later with results.
Post Reply