Constraint Motor at zero velocity

jamesm6162
Posts: 6
Joined: Fri Mar 23, 2012 7:18 am

Constraint Motor at zero velocity

Post by jamesm6162 »

Hi

I have a situation where I need to suspend a rigid body in the air. This rigid body is attached to another (larger) rigid body that is at rest by means of a horizontal btHingeConstraint. (e.g. The boom of an Excavator). The body is successfully lifted off the ground using the angular motor and a target velocity.
Once I have lifted the body I set the target velocity to zero, still using the same Impulse (very large).
However, the motor seems unable to keep the body in the air and it slowly drifts down.

Do you have any idea what is the problem and what I can do to prevent this?

The construction code is shown below:
Note: the limits are not the problem, I have double checked them.

Code: Select all

btCollisionShape* pShapeBody = new btBoxShape(btVector3(1,1,1));
	m_collisionShapes.push_back(pShapeBody);
	btTransform mBodyTrans;
	mBodyTrans.setIdentity();
	mBodyTrans.setOrigin(btVector3(0,0,0));
	btRigidBody* pBody = localCreateRigidBody(1000,mBodyTrans, pShapeBody);
	pBody->setActivationState(DISABLE_DEACTIVATION);

	btCollisionShape* pShapeBoom = new btBoxShape(btVector3(0.7, 0.7, 0.7));
	m_collisionShapes.push_back(pShapeBoom);
	btTransform mBoomTrans;
	mBoomTrans.setIdentity();
	mBoomTrans.setOrigin(btVector3(3,0,0));
	btRigidBody* pBoom = localCreateRigidBody(200,mBoomTrans, pShapeBoom);
	pBoom->setActivationState(DISABLE_DEACTIVATION);

	pBoomHinge = new btHingeConstraint(*pBody, *pBoom, btVector3(1,0,0), btVector3(-2,0,0), btVector3(0,0,1), btVector3(0,0,1));
	pBoomHinge->setLimit(-1.5, 0);
	m_dynamicsWorld->addConstraint(pBoomHinge);
And the updating of the motors is simple:

Code: Select all

	if (up)
	{	
		pBoomHinge->enableAngularMotor(true, -0.1, 1000);
	} else if (down)
	{
		pBoomHinge->enableAngularMotor(true, 0.1, 1000);
	} else {
		pBoomHinge->enableAngularMotor(true, 0.0, 100000);
	}
Thanks
note173
Posts: 16
Joined: Wed Jan 25, 2012 6:32 pm

Re: Constraint Motor at zero velocity

Post by note173 »

I have tried this approach to create wheel brakes, but it doesn't work. I ended up calculating the amount of distance a body moved from it's equilibrium and setting it's velocity to (-distance / fps).
Bigpet
Posts: 10
Joined: Fri Oct 28, 2011 5:14 am

Re: Constraint Motor at zero velocity

Post by Bigpet »

I'm having the same problem. The method that note173 suggested is probably the most accurate but you could also do this:

Code: Select all

//define somewhere relevant:
btScalar actualLowerLimit = -0.5;
btScalar actualUpperLimit = 0.5;
btScalar epsilon = 0.01;

 if (up)
   {   
      pBoomHinge->setLimit(actualLowerLimit,actualUpperLimit);
      pBoomHinge->enableAngularMotor(true, -0.1, 1000);
   } else if (down)
   {
      pBoomHinge->setLimit(actualLowerLimit,actualUpperLimit);
      pBoomHinge->enableAngularMotor(true, 0.1, 1000);
   } else {
      pBoomHinge->enableAngularMotor(true, 0.0, 100000);
      pBoomHinge->setLimit(pBoomHinge->getHingeAngle()-epsilon,pBoomHinge->getHingeAngle()+epsilon);
   }
I haven't tried setting limits mid-simulation but the basic idea is that limits are enforced quite well and so utilizing them to lock your motors works quite well.
note173
Posts: 16
Joined: Wed Jan 25, 2012 6:32 pm

Re: Constraint Motor at zero velocity

Post by note173 »

This would lead to jittering and instability, you wouldn't be able to find correct coefficients for motors, and there will be an accumulating offset in every frame. This is how I actually got to my solution — motors are just a way to set velocities, so why not set it directly.