cumulative distance constraint

Post Reply
patrick80
Posts: 5
Joined: Wed Sep 16, 2015 9:22 am

cumulative distance constraint

Post by patrick80 »

Hi everyone,
is it possible to simulate the following constraint using bullet?
We have n dynamic bodies b1...bn with there centers of mass at cm1(t)...cmn(t).
The cumulative distance d(t)=sum(|cmi(t)-cm{i-1}(t)|,i=2...n) must remain constant d(t)=d(0).

The jacobian can be calculated as shown in the btDistanceConstraint example at
http://bulletphysics.org/Bullet/phpBB3/ ... int#p17937

But I don't know how I can use a constraint between more than two bodies in bullet.
Please let me know if you can outline the required steps or if you have some example bullet code (for any n-body constraint, n>2).

Thank you
Patrick
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: cumulative distance constraint

Post by Basroil »

The current constraint methods are meant for two bodies, as almost every simplified system can be defined by constraints between two bodies.

For example, if your bodies are all connected by linear constraints to begin with, the distance constraint can be made with an extra linear constraint between the first and last body, where the linear constraint has bounds of +- max length. The main reason you can do this is because the overall system unconstrained DOF is just one (until you add the last constraint, in which case you have zero).

If you connect them all with 6DOF constraints, the problem is actually underdefined (underconstrained). If the length is exceeded, what internal constraints are made smaller? How are they limited? You'll need to ask yourself these same questions, and then you might be able to re-define your system much like the above example.

And a word of caution, by doing this you will have a dynamic loop, which will slow convergence and may give unstable solutions if you do not have reasonable torque limits.
patrick80
Posts: 5
Joined: Wed Sep 16, 2015 9:22 am

Re: cumulative distance constraint

Post by patrick80 »

patrick80 wrote:For example, if your bodies are all connected by linear constraints to begin with, the distance constraint can be made with an extra linear constraint between the first and last body, where the linear constraint has bounds of +- max length. The main reason you can do this is because the overall system unconstrained DOF is just one (until you add the last constraint, in which case you have zero).
Sorry, I don't get what you are suggesting.
Assume a chain of 4 bodies b1...b4. If b2 and b3 are fixed, the constraint between b1 and b4 is

Code: Select all

C=|cm1-cm2|+|cm3-cm4|-const=0,
of course. When cm2 and cm3 are known, this can be solved in almost the same way as the linked btDistanceConstraint.

However, b2 and b3 move freely given applied and constraint forces, and I cannot assume the distance |cm2-cm3| to be constant. For this reason I don't understand how to solve the problem by formulating a constraint between b1 and b4 without taking into account all constraint forces on b2,b3 simultaneously.

Could you please elaborate on which linear/6dof constraints you suggest to use exactly to describe this 4-body problem?

Thank you
Patrick
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: cumulative distance constraint

Post by Basroil »

You need to do some simple arithmetic to figure out how many constraints you need to define the system.

With linear constraints, bodies can only move in one direction, and if you put them in a line then the system itself actually has only one DOF. You actually don't need to know the bodies in between, just the first and last, since the system itself has just one DOF. What you need to do is figure out how many DOF the system has, and then match the number of DOF to new constraints necessary to do what you want.
patrick80
Posts: 5
Joined: Wed Sep 16, 2015 9:22 am

Re: cumulative distance constraint

Post by patrick80 »

Basroil wrote:You need to do some simple arithmetic to figure out how many constraints you need to define the system.
The n-body system has 6n DOFs, and the cumulative distance constraint removes 1, leaving 6n-1 DOFs or 23 DOFs in the 4-body example.
Basroil wrote:With linear constraints, bodies can only move in one direction, and if you put them in a line then the system itself actually has only one DOF. You actually don't need to know the bodies in between, just the first and last, since the system itself has just one DOF. What you need to do is figure out how many DOF the system has, and then match the number of DOF to new constraints necessary to do what you want.
What do you mean by linear constraints? A function C(x,q,t)=0, which is linear in x,q and t? A constraint which effects only the position, not the rotations of rigid bodies (this seems to be a "linear constraint" in bullet-speak)? A constraint which forces the n bodies to be co-linear (never talked about this)?
It is simply not true that a system chained in the described way has only 1 DOF. Already the two bodies in the end have 5 DOFs. If you are talking about the system of bodies in between (assuming bodies in the end are fixed), even they have well more than 1 DOF.

Let's come back to my original question.

My constraint is:

Code: Select all

C=|cm2-cm1|+|cm3-m2|+...+|cmn-cm{n-1}|=d0.
It is straightforward to calculate constraint forces and torques on each of the n bodies (done that already).

The question is only, how to put these forces into bullet's constraint loop framework, because I don't know any example that involves a constraint between more than 2 bodies. This is not a theoretical problem, but a question about implementation.

Thank you#Patrick
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: cumulative distance constraint

Post by Basroil »

patrick80 wrote: What do you mean by linear constraints? A function C(x,q,t)=0, which is linear in x,q and t?
I was talking about the linear slider constraint, which is basically a piston. With that constraint, it's quite easy because no matter how many bodies you put in a line the system as a whole as only one DOF.
patrick80 wrote:It is simply not true that a system chained in the described way has only 1 DOF. Already the two bodies in the end have 5 DOFs. If you are talking about the system of bodies in between (assuming bodies in the end are fixed), even they have well more than 1 DOF.
1) You never defined your system properly in the original post. You simply said connected bodies without any qualifications.
2) I specifically stated system DOF, but the implication is system DOF in respect to the origin body. For a list of bodies connected by linear constraints, the first body has 6DOF, and every single body after that has zero unconstrained DOF
patrick80 wrote: Let's come back to my original question.

My constraint is:

Code: Select all

C=|cm2-cm1|+|cm3-m2|+...+|cmn-cm{n-1}|=d0.
It is straightforward to calculate constraint forces and torques on each of the n bodies (done that already).

The question is only, how to put these forces into bullet's constraint loop framework, because I don't know any example that involves a constraint between more than 2 bodies. This is not a theoretical problem, but a question about implementation.
The main issue you have there is that the system is under-constrained and won't have a well defined solution. The default rigid bodies and settings for Bullet only works on two-body physics, so you'll probably need to define your own 6DOF constraints using the btMultibody stuff rather than the regular methods. As far as I know there are no constraints in there that would fit your needs, so you'll have to write your own.

On an aside, I don't know any physical systems that work in the method you are describing, perhaps your problem is non-mechanical and instead a more theoretical one?
patrick80
Posts: 5
Joined: Wed Sep 16, 2015 9:22 am

Re: cumulative distance constraint

Post by patrick80 »

Basroil wrote: The main issue you have there is that the system is under-constrained and won't have a well defined solution.
NO. Given a constraint function C(t)=0, you can derive all forces from dC/dt=0 and advance the system in time, which is well defined. I get the impression that for you every system with DOF>0 has no well defined solution (which would imply that only a static system is well defined). Have a look at https://box2d.googlecode.com/files/GDC2 ... nCatto.zip which may clarify the difference between a "constraint" and a linear slider "joint". (I had a small typo in the given constraint function - what I meant is: C=|cm2-cm1|+|cm3-cm2|+...+|cmn-cm{n-1}|-d0=0.)
Basroil wrote:The default rigid bodies and settings for Bullet only works on two-body physics, so you'll probably need to define your own 6DOF constraints using the btMultibody stuff rather than the regular methods. As far as I know there are no constraints in there that would fit your needs, so you'll have to write your own.
If the "btMultiBody stuff" is the road to take, I am asking people, who have used this stuff before, whether they can outline the steps to apply it to the given constraint. Again, I HAVE written the constraint (which is nothing more than C=0) with all jacobians and resulting constraint forces, and all I am asking is how to get these into bullet without violating existing constraints.
Basroil wrote: On an aside, I don't know any physical systems that work in the method you are describing, perhaps your problem is non-mechanical and instead a more theoretical one?
With a lot of simplification, think of some underwater vehicle which is connected with a string to some "floating" body (which is drifting below the water surface). There are a few other drifting bodies, which are threaded to the string (which passes through a hole in each body), and which will cause the string to have a kink at each body. The bodies can slide along the string, but any movement which would change the string length will cause constraint forces on all (or at least some) bodies to correct the string length.

Patrick
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: cumulative distance constraint

Post by Basroil »

patrick80 wrote: NO. Given a constraint function C(t)=0, you can derive all forces from dC/dt=0 and advance the system in time, which is well defined. I get the impression that for you every system with DOF>0 has no well defined solution (which would imply that only a static system is well defined). Have a look at https://box2d.googlecode.com/files/GDC2 ... nCatto.zip which may clarify the difference between a "constraint" and a linear slider "joint". (I had a small typo in the given constraint function - what I meant is: C=|cm2-cm1|+|cm3-cm2|+...+|cmn-cm{n-1}|-d0=0.)
I was merely stating that the system you presented was not well defined because you gave only minimal explanation about the system or the constraint method. Things like how many partially constrained DOF between each body and how the constraint would apply forces to each body were just not given in any of your posts.
patrick80 wrote:Again, I HAVE written the constraint (which is nothing more than C=0) with all jacobians and resulting constraint forces, and all I am asking is how to get these into bullet without violating existing constraints.
In that case it's easy to just apply the constraint as external forces. Although it's not perfect (you have a one frame delay, so you'll need to increase simulation framerate to compensate), you can get a working model in minutes, and then you can worry about improving accuracy after that. Existing constraints will still function as intended, though they may be violated if external forces are higher than the maximum constraint impulses.
patrick80 wrote: With a lot of simplification, think of some underwater vehicle which is connected with a string to some "floating" body (which is drifting below the water surface). There are a few other drifting bodies, which are threaded to the string (which passes through a hole in each body), and which will cause the string to have a kink at each body. The bodies can slide along the string, but any movement which would change the string length will cause constraint forces on all (or at least some) bodies to correct the string length.
This is actually one of those edge cases that is not very friendly for bullet. If you don't care about performance, you can actually increase the number of "bodies" and make the rope fixed length from the get-go, and then apply forces from contact with the other bodies. If you need performance, completely ignoring bullet for the rope and other bodies can let you model the system exactly as you want.

Also, are you sure you can't rewrite the equations so that each constraint is independent of the constraints "above" it? Assuming one of the endpoints is fixed (system wise), then you should be able to estimate the motions of all the ones away from it more or less sequentially, with each body only requiring knowledge of the body below and above it in the chain. Only case where that won't work is if both ends are fixed (or external forces to the bodies in between are high enough to matter), but if you're talking about passive bodies floating behind a "fixed" point then it should work.
patrick80
Posts: 5
Joined: Wed Sep 16, 2015 9:22 am

Re: cumulative distance constraint

Post by patrick80 »

Basroil wrote: I was merely stating that the system you presented was not well defined because you gave only minimal explanation about the system or the constraint method.
Since I gave the constraint d(t)=d(0) in my original post, and constraints should not change the total energy there is not much freedom in the "contraint method" except from the implementation in the code, which is exactly what I have asked for.
Basroil wrote: Things like how many partially constrained DOF between each body and how the constraint would apply forces to each body were just not given in any of your posts.
The constraint d(t)=d(0) is a subsystem constraint, so there is no "partially constrained DOF between each body", just one constrained DOF for the whole subsystem. The constraint forces are evident. How they should be applied to each body is the point of my question. What you are saying repeatedly is that my question can only be answered by an answer to my question. Please stop it, because I would like to ask other bullet users about their suggestions for SOLUTIONS to my question and not discuss whether or not someone can fit my problem into his horizon.
Basroil wrote: In that case it's easy to just apply the constraint as external forces. Although it's not perfect (you have a one frame delay, so you'll need to increase simulation framerate to compensate), you can get a working model in minutes
I have done this a week ago. What I am asking is how to get these forces into bullet's constraint framework, because these forces work against other constraints in the global system.
Basroil wrote: and then you can worry about improving accuracy after that. Existing constraints will still function as intended, though they may be violated if external forces are higher than the maximum constraint impulses.
Yes, I am at the point of "worry about improving accuracy after that". This is why I have asked my original question.
Basroil wrote: This is actually one of those edge cases that is not very friendly for bullet. If you don't care about performance, you can actually increase the number of "bodies" and make the rope fixed length from the get-go, and then apply forces from contact with the other bodies. If you need performance, completely ignoring bullet for the rope and other bodies can let you model the system exactly as you want.
Again, I have a working model for the n-body subsystem. I need to integrate it into bullet's framework, because it interacts with other objects which are implemented in a bullet world.
If I don't care for performance, I have tons of solutions for this problem. But I use bullet, because I DO care about performance.
Basroil wrote: Also, are you sure you can't rewrite the equations so that each constraint is independent of the constraints "above" it?
Yes, I am sure. Any virtual movement of any of the n bodies which changes the system Lagrangian will cause a force on ALL (or almost all) n-1 other bodies.
Basroil wrote: Assuming one of the endpoints is fixed (system wise), then you should be able to estimate the motions of all the ones away from it more or less sequentially, with each body only requiring knowledge of the body below and above it in the chain. Only case where that won't work is if both ends are fixed (or external forces to the bodies in between are high enough to matter), but if you're talking about passive bodies floating behind a "fixed" point then it should work.
Sure, if I make some 342 assumptions to simplify the system, then I can reformulate it using the existing bullet joints.

BUT I HAVE ASKED HOW TO INTEGRATE THE CONSTRAINT d(t)=d(0) INTO BULLET's CONSTRAINT FRAMEWORK. PLEASE ANSWER THIS QUESTION OR STOP FILLING THIS THREAD WITH SUGGESTIONS WHICH OTHER PROBLEMS I MIGHT WANT TO SOLVE!

Patrick
Post Reply