can constraint motors affect only one rigid body?

Post Reply
roguecodemonkey
Posts: 6
Joined: Thu Mar 12, 2015 1:11 pm
Location: Dundee, Scotland, UK

can constraint motors affect only one rigid body?

Post by roguecodemonkey »

I'm trying to connect 2 box shaped rigid bodies in a parent/child style relationship with a hinge constraint and control the rotation of the child rigid body with the motor.

rigid bodyA position = (0, 0.5, 0) half extents = (0.025, 1, 0.025) mass = 1
rigid bodyB position = (0, 1.5, 0) half extents = (0.025, 1, 0.025) mass = 1

I create the constraint with the following code:

Code: Select all

btVector3 pivot_in_a(0.0f, 0.5f, 0.0f);
btVector3 axis_in_a(0.0f, 0.0f, 1.0f);
btVector3 pivot_in_b(0.0f, -0.5f, 0.0f);
btVector3 axis_in_b(0.0f, 0.0f, 1.0f);

btHingeConstraint* hinge_constraint = new btHingeConstraint(*rigid_body_a, *rigid_body_b, pivot_in_a, pivot_in_b, axis_in_a, axis_in_b);
bullet_world_->addConstraint(hinge_constraint, true);
hinge_constraint->enableAngularMotor(true, 5.05f, 0.5f);
This causes both the rigid bodies to rotate. Is there a way just to drive the second rigid body with the motor while remaining connected to the first?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: can constraint motors affect only one rigid body?

Post by Flix »

roguecodemonkey wrote:This causes both the rigid bodies to rotate. Is there a way just to drive the second rigid body with the motor while remaining connected to the first?
If the first object can't be static, then the only other solution I can think about is playing with the masses and/or local inertias of the two bodies. I'd try to increase the mass and/or local inertia of one body and decrease the mass and/or local inertia of the other (of a big factor) and see if something improves...
roguecodemonkey
Posts: 6
Joined: Thu Mar 12, 2015 1:11 pm
Location: Dundee, Scotland, UK

Re: can constraint motors affect only one rigid body?

Post by roguecodemonkey »

Thanks for the speed reply. I suspected as much.

Not sure I'm approaching my overall aim the right way.

I ultimately want to create a ragdoll that can follow skeletal animation data and was hoping to using constraint motors to drive the limbs into the correct pose, but not sure if this approach will work if the constraint motor affects both the rigid bodies that are connected to it.

Should I perhaps be looking at btMultiBody for this?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: can constraint motors affect only one rigid body?

Post by drleviathan »

Beware: if the mass discrepancy between jointed parts is too high then you can get instabilities. Best if the two connected masses are not more than a factor of 10 from each other. The closer to unity the better, especially when simulating more joints.

I once hacked the Bullet RagdollDemo to use btFixedConstraints between joints of a more realistic skeleton. I used the inverse inertia trick on the torso (mentioned below) to keep the avatar upright. From my experience the humanoid skeleton with constraints between bones could be stable at 9 joints but would go unstable at 10 or 11. This with a simulation step frequency of 60Hz. I might have been able to maintain stability at higher joint count by stepping at 120Hz, but I never did try it.

The movement of one part of a jointed set affecting the motion of the other is physically correct, however you can cheat in some cases. If it is OK for one part to be constrained about one axis (for example, if you know the torso of your skeleton should ALWAYS be upright) then you can constrain its motion by zeroing two elements of its inverse inertia. That is, use btRigidBody::setAngularFactor() to <0, 1, 0> to make that body only able to rotate about the yAxis. This would be enough to keep a humanoid skeleton upright if the rest of the limbs had stiff enough constraints. I think setAngularFactor() works in the world-frame, not the local frame, so it probably won't work for you if you wanted to constrain about some non-cannonical axis (I'm not 100% sure of this).

It sounds like what you're aiming for is similar to the Dynamo Data Driven Character project. There is a link to it in this thread.
Post Reply