Page 1 of 1

btGeneric6DofSpringConstraint high damping

Posted: Sat Feb 21, 2015 10:22 pm
by eejin
Hi,

I am trying to implement this Stackoverflow answer in Bullet.
I have created a btGeneric6DofSpringConstraint with movement only on the Y axis. A kinematic body attached to the bottom and a capsule shape rigid body to the top.
Now the spring still bounces a lot even with damping set to 1 or higher. It also seems like the constraint blocks movement on the X and Z axis as applyCentralForce doesn't seem to move the capsule.

Here is the current setup:

Code: Select all

	btDefaultMotionState* pMotionState;
	btDefaultMotionState* pMotionState2;
	btGeneric6DofSpringConstraint* pGen6DOFSpring;

	btCollisionShape* capsuleShape = new btCapsuleShape(0.5, 0.5);
	btCollisionShape* emptyShape = new btEmptyShape();

	btVector3 inertia(0, 0, 0);
	pCollisionShape->calculateLocalInertia(2, inertia);

	pMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(10, 6, 10)));
	pMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(10, 4, 10)));
	
	pRigidBodyA = new btRigidBody(2, pMotionState, capsuleShape, inertia);
	pRigidBodyB = new btRigidBody(0, pMotionState2, emptyShape, inertia);
	pRigidBodyA->setActivationState(DISABLE_DEACTIVATION);
	pRigidBodyB->setActivationState(DISABLE_DEACTIVATION);
	pRigidBodyB->setCollisionFlags(pRigidBodyB->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);

	btTransform frameInA, frameInB;
	frameInA = btTransform::getIdentity();
	frameInA.setOrigin(btVector3(btScalar(0.), btScalar(-3.), btScalar(0.)));
	frameInB = btTransform::getIdentity();
	frameInB.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));

	pGen6DOFSpring = new btGeneric6DofSpringConstraint(*pRigidBodyA, *pRigidBodyB, frameInA, frameInB, true);
	pGen6DOFSpring->setLinearUpperLimit(btVector3(0., 3., 0.));
	pGen6DOFSpring->setLinearLowerLimit(btVector3(0., 0., 0.));
	pGen6DOFSpring->setAngularLowerLimit(btVector3(0.f, 0.f, 0.f));
	pGen6DOFSpring->setAngularUpperLimit(btVector3(0.f, 0.f, 0.f));
	pGen6DOFSpring->enableSpring(1, true);
	pGen6DOFSpring->setStiffness(1, 39.478f);
	pGen6DOFSpring->setDamping(1, 1.f);
	pGen6DOFSpring->setEquilibriumPoint();
	physics.dynamicsWorld->addRigidBody(pRigidBodyA);
	physics.dynamicsWorld->addRigidBody(pRigidBodyB);
	physics.dynamicsWorld->addConstraint(pGen6DOFSpring, true);
How would I let the capsule come to rest faster and how would I allow the capsule to be moved by applied forces horizontally (not by the spring itself though)?

Re: btGeneric6DofSpringConstraint high damping

Posted: Mon Feb 23, 2015 3:47 am
by Basroil
eejin wrote: How would I let the capsule come to rest faster
The primary way would be the same as with any harmonic system, tweak the damping ratio, higher damping means faster reduction to zero (but also messes with the shape of your oscillations) while lower ones are closer to spring-only conditions.
eejin wrote:how would I allow the capsule to be moved by applied forces horizontally (not by the spring itself though)?
I guess you mean apply forces to the body that is swinging right? If so, just apply a force directly to the body that is swinging in the direction that you want. Just remember to keep track of world vs local coordinates for bodies and your force definitions.

Re: btGeneric6DofSpringConstraint high damping

Posted: Tue Feb 24, 2015 2:54 am
by ratatouille
You can also look into btGeneric6DofSpring2Constraint (notice the 2), it uses a completely different implementation of the physics.

Re: btGeneric6DofSpringConstraint high damping

Posted: Fri Feb 27, 2015 11:50 pm
by Erwin Coumans
Yes, the btGeneric6DofSpring2Constraint was created partly to address the damping issue.

Please try it and let us if that works for you.
Thanks!
Erwin

Re: btGeneric6DofSpringConstraint high damping

Posted: Sun Mar 01, 2015 1:36 pm
by eejin
I am currently using Bullet 2.8.2 but it doesn't seem to have a btGeneric6DofSpring2Constraint. So I looked it up and it appears to be present in the newer Bullet 2 versions?
It seems to me that Bullet 3 only supports GPU physics and it states on the Github page that it needs a high end GPU for it to have decent performance, but I want this to run properly on laptops too. So I need a more recent Bullet 2. but it is merger into the Bullet 3 branch and I don't see a way to build it. How can I build a bullet CPU version with the Spring2 constraint?

Re: btGeneric6DofSpringConstraint high damping

Posted: Sun Mar 01, 2015 6:21 pm
by Erwin Coumans
The http://github.com/bulletphysics/bullet3 includes both latest Bullet 2 (it will become 2.83 soon) and also future Bullet 3.x for GPU. You can safely ignore the Bullet 3.x parts and just use the Bullet 2.x API.

I'll update the readme/info in the github repository to avoid confusion.
Thanks,
Erwin

Re: btGeneric6DofSpringConstraint high damping

Posted: Wed Mar 04, 2015 10:00 pm
by eejin
Thanks! I managed to build Bullet 2. from the Github source.
Now, I am still implementing the character controller and wondered how I could limit the maximum distance between the rigid body and a certain position. I created a Kinematic body at the position and added a slider constraint. Now this limits the distance on the z axis nicely, but also does this for the y and x axis. Is there a way to free the x and y axis movement or is there a more appropriate constraint? I could not really find such a constraint.