Creating a vehicle with btGeneric6DofSpring2Constraint questions

Post Reply
jabbathefrukt
Posts: 2
Joined: Wed Oct 16, 2019 5:29 pm

Creating a vehicle with btGeneric6DofSpring2Constraint questions

Post by jabbathefrukt »

Hello fellow Bullet people! I'm currently working on creating a vehicle using btGeneric6DofSpring2Constraint and have some trouble understanding the parameters. From what I understand the only changeable parameters are which two boxes that are constrained together:

btRigidBody* box1, btRigidBody* box2

And how the quaternion transformation will work;

btTransform(btQuaternion::getIdentity(), { 0.0f, -1.5f, 0.0f }),
btTransform(btQuaternion::getIdentity(), { 0.0f, 0.0f, 0.0f }))

And then the additional changeable spring properties:

spring1->setLinearLowerLimit(btVector3(0.0f, 0.0f, 0.0f));
spring1->setLinearUpperLimit(btVector3(0.0f, 0.56f, 0.0f));
spring1->enableSpring(1, true);
spring1->setStiffness(1, 65.0f);
spring1->setDamping(1, 0.5f);

When joining the boxes together the spring always goes between their origins, but if I'd want the wheel to connect to the vehicle body at the correct spot at the front/back/left/right wheel position, is this possible with the changeable parameters? I figured changing the x and z values of the lower/upper limits would move the origin of the connection points but it just changes the angle of the spring and often results in uncontrollable spinning.

Changing the btTransform(btQuaternion::getIdentity(), { 0.0f, -1.5f, 0.0f }) also doesn't bring the desired outcome. So at this point the only idea I can think of is to create 4 rigidbodies that are connected to the vehicle body and positioned at the top of the wheel arch and then connect those 4 rigidbodies to the wheels using the spring constraint. So I guess my question is am I completely clueless or is this the only way to do it? If the latter, how do I connect the 4 rigidbodies to the vehicle rigidbody?
I'd love to understand the changeable parameters without having to change each one of them using trial and error to figure out what they do. They only really useful information from the Bullet user manual is how to make the limit axis locked/free/limited. If there is any detailed documentation on how to use the btGeneric6DofSpring2Constraint I'd love to read it.

I appreciate any response and I just have to mention that I'm not at all familiar with Bullet physics and only recently got the linkage working and 3D objects to properly use the bullet rigidbody transformations. Thank you for your time!
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Creating a vehicle with btGeneric6DofSpring2Constraint questions

Post by drleviathan »

When I look at the btGeneric6DofSpring2Constraint code I see many parameters that can be changed. Most of these have default values assigned in the various helper class ctors, while the frameInA and frameInB parameters are required input to the btGeneric6DofSpring2Constrain ctor. Those frame parameters are important. For best results for getting help I would suggest you either post more of your code or better yet put the experimental code up on github so others can examine it with full context, however without that info I submit the following advice:

In the simplest case: box car with simple wheels and identity rotation between all local transforms I would expect the right front wheel constraint would be added like so:

Code: Select all

// chassis has dimensions <x,y,z>
// x = left
// y = up
// z = forward
btTransform rightFront(btQuaternion()::getIdentity(), 0.5 * btVector3(-x, -y, z));
btTransform center(btQuaternion()::getIdentity(), btVector3(0.0, 0.0, 0.0));
btGeneric6DofSpring2Constraint* rightFrontWheelConstriant = new btGeneric6DofSpring2Constraint(chassis, rightFront, rightFrontWheel, center);

// 6Dof means "six degrees of freedom" but we want to start with a 2Dof "car spring"
// with vertical (y-axis) linear spring and free angular rotation about the x-axis.
// The default values for stiffness are 0.0 across the board, and we want custom values:
rightFrontWheelConstriant->setStiffness(0, 1.0); // linear X (left-right)
rightFrontWheelConstriant->setStiffness(1, 0.5); // linear Y (up-down)
rightFrontWheelConstriant->setStiffness(2, 1.0); // linear Z (forward-back)
rightFrontWheelConstriant->setStiffness(3, 0.0); // angular X (free spin)
rightFrontWheelConstriant->setStiffness(4, 1.0); // angular Y (no spin)
rightFrontWheelConstriant->setStiffness(5, 1.0); // angular Z (no spin)
jabbathefrukt
Posts: 2
Joined: Wed Oct 16, 2019 5:29 pm

Re: Creating a vehicle with btGeneric6DofSpring2Constraint questions

Post by jabbathefrukt »

Thank you very much for the response! I think I will be able to make something out of this and I hope it might be useful for other trying to do the same. If I have further questions I will respond back to this, but for now you got me occupied.
If only there existed some web tutorial that would show a detailed step by step guide on how to make a vehicle in bullet. I know there are old demos to check out, which I have, but they are a lot more tricky to follow than a basic tutorial would be.
Post Reply