Generic6DofConstraint is unstable

Post Reply
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Generic6DofConstraint is unstable

Post by dudosee »

So I'm using Generic 6Dof Constraint with quite restrictive limits, basically I restrict rotation to only Y axis, similarly to Hinge joint, but while Hinge joint works perfectly, 6Dof makes two bodies explode and I'm not sure what is exactly causing this type of behaviour, am I doing something wrong here?

6Dof:
Image
Hinge:
Image

Code: Select all

			
			btTransform BulletChildFrame;
			BulletChildFrame.setIdentity();
			BulletChildFrame.setOrigin(BulletChildLocalPoint);

			btTransform BulletParentFrame;
			BulletParentFrame.setIdentity();
			BulletParentFrame.setOrigin(BulletParentLocalPoint);
			
			btGeneric6DofConstraint* Constraint =
				new btGeneric6DofConstraint(*Parent->PhysicBody, *Child->PhysicBody, BulletParentFrame, BulletChildFrame, true);

			Constraint->setLinearLowerLimit(btVector3(0, 0, 0));
			Constraint->setLinearUpperLimit(btVector3(0, 0, 0));
			Constraint->setAngularLowerLimit(btVector3(0, -M_PI * 0.5, 0));
			Constraint->setAngularUpperLimit(btVector3(0,  M_PI * 0.5, 0));

			Parent->PhysicBody->setActivationState(DISABLE_DEACTIVATION);
			Child->PhysicBody->setActivationState(DISABLE_DEACTIVATION);
			
			World->addConstraint(Constraint, true);
Mwni
Posts: 9
Joined: Thu Jul 12, 2018 4:43 pm

Re: Generic6DofConstraint is unstable

Post by Mwni »

Hey dudosee,

This is a know issue. Because the constraints use Euler angles, one axis has to be limited to -90 to 90 degrees to avoid gimbal lock. That axis happens to be the y-axis. As shown in your gif, the constraint goes bananas exactly when it reaches 90 degrees.

My advice would be to rely on the x or y axis, you can do that by rotating the A/B reference frame.
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Re: Generic6DofConstraint is unstable

Post by dudosee »

Thanks for your help Mwni. X and Z axis are actually working properly. I just... I can't believe that rotation along Y axis can be some kind of a problem in such widely used engine. It's baffling to say the least
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Re: Generic6DofConstraint is unstable

Post by dudosee »

jesus christ, I just want to define three ranges of angles, one for each axis, and I want to enforce restriction to this exact ranges, that is for example, -20..80 degrees on Y axis, -50..50 for Z axis, -30..30 for X axis. Is there any way to make this in Bullet without extreme fuckery? It seems like even cone twist joint is going mad sometimes for whatever reason, I mean exactly how should I implement joint for Head for example? It's not Hinge, it's not Cone because you can lean your head forward more than backward, which is not possible for cone twist joint if I'm not mistaking. So the only way I see it, is to make X axis the one that can only go -90..90, right? It's just so inconvenient, I have a feeling I'm not getting something extremely important for this to make sense
Mwni
Posts: 9
Joined: Thu Jul 12, 2018 4:43 pm

Re: Generic6DofConstraint is unstable

Post by Mwni »

I feel your pain, dudosee. I'm currently trying to build a ragdoll aswell.
Initially I implemented it using conetwist, however it was too unstable. Additionally conetwist seems to ignore the damping factor and various other settings. Afterall I switched to Generic6DofSpring2, as it is the newest one and has many pros:
- Much more accurate and stable in a lot of situation. (Especially when a sleeping chain of RBs connected with 6dof2 is pulled)
- Stable and accurate spring with minimal energy loss that works with all of the solvers. (latter is not true for the original 6dof spring)
- Servo motor functionality
- Much more accurate bouncing. 0 really means zero bouncing (not true for the original 6odf) and there is only a minimal energy loss when the value is 1 (because of the solvers' precision)
- Rotation order for the Euler system can be set. (One axis' freedom is still limited to pi/2)
I found it worked best when you enable the angular spring even though you dont use it (stiffness=0).
Another thing i noticed is, that the constraint goes nuts if the upper and lower limits are too close together (<0.1).
Mwni
Posts: 9
Joined: Thu Jul 12, 2018 4:43 pm

Re: Generic6DofConstraint is unstable

Post by Mwni »

Oh and you need to increase the solver iteration count.

Code: Select all

world->getSolverInfo()->m_numIterations = 30
30 works well, 10 is default, and it's too low for this kind of simulation.
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Re: Generic6DofConstraint is unstable

Post by dudosee »

Mwni, thanks for your tips, Spring2 seems to be actually less jittery, but still make body fly away because of still same gimbal lock. I also noticed that lower step time makes explosions even more noticeable. For example 2400 Hz is just flying straight away like a bird, while 240 Hz is just slight jerk and fall down. Okay, I guess I'll try to make do, thank god for knees and elbows, at least some joints are on my side.
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Re: Generic6DofConstraint is unstable

Post by dudosee »

Well it's at LEAST something, at least something...

Image
Mwni
Posts: 9
Joined: Thu Jul 12, 2018 4:43 pm

Re: Generic6DofConstraint is unstable

Post by Mwni »

Nice! All you now need is some damping/elasticity.

Btw, heres mine:
Image
dudosee
Posts: 8
Joined: Mon Jul 16, 2018 1:11 pm

Re: Generic6DofConstraint is unstable

Post by dudosee »

Wow, now that's a ragdoll, impressive. I have to get some sleep now, or I'm gonna be a ragdoll myself
Post Reply