Unstable constraints on kinematic objects?

kate
Posts: 41
Joined: Thu Jan 08, 2009 11:20 am
Location: London, UK

Unstable constraints on kinematic objects?

Post by kate »

Hi,

I just wondered if anyone had had problems with constraints attached to kinematic objects being unstable? I'm finding that - with any sort of constraint (even point2point) - while I can constrain a dynamic cube to a static one and it works fine, if I change the static cube to a kinematic one; i.e. do

Code: Select all

rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
rb->setActivationState(DISABLE_DEACTIVATION);
instead of

Code: Select all

rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
rb->setActivationState(ACTIVE_TAG);
then the constrained dynamic object jumps about all over the place (NB the kinematic object isn't animated at all). I expect I'm doing something wrong when I'm creating the kinematic object, but as the code above is the only difference to when I create a static object, I'm at a loss as to what it could be...

Any suggestions will be much appreciated!

Thanks :)

Kate
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Unstable constraints on kinematic objects?

Post by Erwin Coumans »

Did you make sure to assign zero mass/inertia to the kinematic object?

Thanks,
Erwin
kate
Posts: 41
Joined: Thu Jan 08, 2009 11:20 am
Location: London, UK

Re: Unstable constraints on kinematic objects?

Post by kate »

Hi Erwin,

Yep; as well as setting the collision flags and activation state as above, I do:

Code: Select all

btVector3 inertia(0, 0, 0);
rb->setMassProps(0.0, inertia);
rb->updateInertiaTensor();
for both the kinematic and static case.

Is there anything else I need to do to a kinematic rigid body?

Thanks,

Kate

P.S. I am using motionStates, but it doesn't seem to make a difference if I don't. Also, I noticed that the problem doesn't occur if I place the kinematic object at the origin with no rotation, so I tried explicitly setting its world transform to the identity before setting the mass/inertia but that didn't help (which kinda figures, since my objects are all created and set up at the origin and then moved in any case).
kate
Posts: 41
Joined: Thu Jan 08, 2009 11:20 am
Location: London, UK

Re: Unstable constraints on kinematic objects?

Post by kate »

I've done some further investigation, and discovered that the problem only occurs when I set the kinematic rigid body's position after I create it, rather than in a MotionState passed to the constructor. That is to say, if I do:

Code: Select all

btCollisionShape* shape = new btBoxShape(btVector3(0.5, 0.5, 0.5));
btVector3 inertia(0, 0, 0);
double mass = 0.0;
	
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(0, 10, 0));
myMotionState* msFixed = new myMotionState(trans);

btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, msFixed, shape, inertia);
btRigidBody* fixedRB = new btRigidBody(rbInfo);
world->addRigidBody(fixedRB);
it works fine, but if I do:

Code: Select all

btTransform trans;
trans.setIdentity();
myMotionState* msFixed = new myMotionState(trans);

btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, msFixed, shape, inertia);
btRigidBody* fixedRB = new btRigidBody(rbInfo);
world->addRigidBody(fixedRB);

trans.setOrigin(btVector3(0, 10, 0));
dynamic_cast<myMotionState*>(fixedRB->getMotionState())->setKinematicTransform(trans);
the dynamic rigid body constrained to fixedRB behaves oddly.

This only happens with kinematic objects, i.e. when I set

Code: Select all

fixedRB->setCollisionFlags(fixedRB->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- when it's set to btCollisionObject::CF_KINEMATIC_OBJECT then it behaves the same way regardless of when I set the position.

The MotionState class I'm using is just a simple kinematic one, like the one in the docs, but the same thing happens if I use the btDefaultMotionState and do fixedRB->getMotionState()->setWorldTransform(trans) to set the position after creation, or if I don't use a motion state at all.

Can anyone tell me why this should be?? (Obviously, I can get round it for now, but it would make my code much nicer if I could set the transforms after creation!)

Thanks :)

Kate
RulonR
Posts: 2
Joined: Mon Jun 22, 2009 9:33 pm

Re: Unstable constraints on kinematic objects?

Post by RulonR »

Has anyone been able to solve this issue? I'm running across the same thing (on Bullet 2.73) and not sure exactly what's going on.
Ellon
Posts: 10
Joined: Wed Jul 29, 2009 4:04 am
Location: Seoul, Korea

Re: Unstable constraints on kinematic objects?

Post by Ellon »

Hi,

I've met similar problem before.

Kinematic objects have interpolation version of transform and lin & ang velocities.
I suppose that when object is changed to kinematic, these interpolations have undetermined value and these values are added to velocity at next simulationStep() and transferred to constraint solvers which makes solvers unstable.

So when you change the position of kinematic objects, you should care about these interpolations.

Try following clean-up code after 1) changing from static to kinematic or 2) changing kinematic object's position at first time:

Code: Select all

rb->setInterpolationWorldTransform(rb->getWorldTransform());
rb->setInterpolationLinearVelocity(btVector3(0,0,0));
rb->setInterpolationAngularVelocity(btVector3(0,0,0));
Thanks
kate
Posts: 41
Joined: Thu Jan 08, 2009 11:20 am
Location: London, UK

Re: Unstable constraints on kinematic objects?

Post by kate »

Hi Ellon,

Thanks for the suggestion - it's actually helped me with another problem I've been having :)

I'll see if it fixes the constraint issue for me too...

Kate