locking down a constraint (6dof)

kuma
Posts: 3
Joined: Sun Nov 24, 2013 2:56 am

locking down a constraint (6dof)

Post by kuma »

Hi, I've started a small racing game project which I hope to port to android.
I'm doing OK, but I have a couple of issues.

My car uses a 6dof for each wheel, however when the friction is high and I bank sharply the wheel angles sideways against the ground.. Of course I'd like the wheel to remain perpendicular to the ground at all times.. the below screenshot shows the problem.

Image
Sorry for poor quality.

This is a similar to the below post, but I have been unable to fix it..
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3402

I've tried adjusting CFM with setParam, setting angularFactor (but this is global space) without success.

I'm curious why this happens even though I've locked the limits on the 6dof.
This is my basic configuration.

Code: Select all

void BulletFramework::createWheelSuspensionJoint(MdlParser::mdl_joint joint, int oid_a, int oid_b) {

    btVector3 posa = btVector3(joint.position[0],joint.position[1],joint.position[2]);
    btVector3 posb = btVector3(0.0,0.0,0.0);

    btVector3 axis = btVector3(joint.axis[0],joint.axis[1],joint.axis[2]);

    btQuaternion rota = btrigidbodies[oid_a]->getOrientation();
    btQuaternion rotb; rotb.setEuler(joint.axis[0],joint.axis[1],joint.axis[2]);
    btTransform transformA = btTransform(rota,posa);
    btTransform transformB = btTransform(rotb,posb);

    btGeneric6DofSpringConstraint* hingeConstraint = new btGeneric6DofSpringConstraint(*btrigidbodies[oid_a],*btrigidbodies[oid_b], transformA, transformB, true);

    const btScalar low = 0;
    const btScalar high = 0;

    hingeConstraint->setLimit( 0, low, high );
    hingeConstraint->setLimit( 1, joint.suspension_limit[0], joint.suspension_limit[1] );
    hingeConstraint->setLimit( 2, low, high );
    hingeConstraint->setLimit( 3, 1, 0 );
    hingeConstraint->setLimit( 4, -joint.steer_limit, joint.steer_limit );
//  hingeConstraint->setLimit( 4, low, high );
    hingeConstraint->setLimit( 5, low, high );
    hingeConstraint->setLimit( 6, low, high );

//  hingeConstraint->setParam(BT_CONSTRAINT_STOP_CFM, 0, 4);
//  hingeConstraint->setParam(BT_CONSTRAINT_CFM, 0);

//  hingeConstraint->setAngularUpperLimit(btVector3(0., 0., 0.));
//  hingeConstraint->setAngularLowerLimit(btVector3(0., 0., 0.));

    hingeConstraint->enableSpring( 1, true );
    hingeConstraint->setStiffness( 1, joint.suspension_stiffness );
    hingeConstraint->setEquilibriumPoint(1,joint.suspension_equilibrium);

    const bool isDisableCollisionsBetweenLinkedBodies = true;
    bulletworld->addConstraint( hingeConstraint, isDisableCollisionsBetweenLinkedBodies );
    bt6dofconstraints.push_back(hingeConstraint);

    bConstraint thisConstraint;
    thisConstraint.c_id = constraint_id++;
    thisConstraint.type = "bt6dofconstraint";
    bConstraints.push_back(thisConstraint);
    cout << "c_id " << constraint_id << endl;

}
Any ideas on how I could fix this or even just improve the quality would be really appreciated.

update: Erwins suggestion to use

Code: Select all

constraint->setOverrideNumSolverIterations(40);
in the referenced thread does help ! although it's not completely perfect, it's good enough, I guess if anyone has any input that would be good anyway.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: locking down a constraint (6dof)

Post by Basroil »

Any reason why you are using the 6dof method rather than hinge joint for wheel and cone/pair of hinge for suspension? It does make the simulation run a bit slower, but the way it's implemented is supposed to be different (hinge2 states it's the 6dof based hinge) so perhaps it'll work without needing as many iterations.
kuma
Posts: 3
Joined: Sun Nov 24, 2013 2:56 am

Re: locking down a constraint (6dof)

Post by kuma »

Not particularly, the 6Dof just seemed like a one stop solution, integrated suspension and ability to provide steering / rotation all at the same time by applying torque. I figured less constraints would mean less complexity, and possibly better performance.
I had a very similar setup before when using ODE with the hinge2 joint, that worked well, bullets 6Dof is similar so I went for that. Actually it's mostly OK now that I've increased the iterations.
I'll give your suggestion a go for comparison once I get the time!

Thanks!