Bullet Vehicles

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Bullet Vehicles

Post by sparkprime »

I've been looking at the vehicle stuff in Bullet. I'm confused by some of the subtleties with the suspension calculations. This is what I can gather so far:

For each wheel:
  • Ray is shot from the start of the spring downwards (vehicle space) for a distance of the resting length of the spring + the radius of the wheel.
  • This gives the compression of the spring (wheel radius is subtracted to get this), and the normal of the ground at the contact point
  • Then two forces are calculated, a spring force proportional to compression and a damping force proportional to velocity.
However if you look closer, there is another component in the spring force:

Code: Select all

                                force = wheel_info.m_suspensionStiffness
                                        * length_diff * wheel_info.m_clippedInvContactDotSuspension;
this clippedInvContactDotSuspension comes from here (some code omitted for clarity):

Code: Select all

                btScalar denominator= wheel.m_raycastInfo.m_contactNormalWS.dot( wheel.m_raycastInfo.m_wheelDirectionWS );

                if ( denominator >= btScalar(-0.1))
                {
                        wheel.m_clippedInvContactDotSuspension = 10;
                }
                else
                {
                        wheel.m_clippedInvContactDotSuspension = -1 / denominator;
                }

So the two vectors are:

wheel.m_raycastInfo.m_contactNormalWS (the normal of the ground, in world space, typically "up")
wheel.m_raycastInfo.m_wheelDirectionWS (the direction of the "action" of the spring, in world space, typically "down")

so denominator will typically be -1

So as far as I can tell, m_clippedInvContactDotSuspension is usually 1 which makes no difference to the force.

As the car tips away from the vertical (e.g. going round corners) this factor is increased to 10.

What's the purpose of this denominator mechanism? Is it to provide more springiness for when the car is balancing on two wheels?


I have a separate question about damping. There are really two damping coefficients, one for when the wheel is moving up and one when it is moving down. Is this important for stability? I seem to get pretty good results when I use the same value for both.

Usually I would choose damping coefficients so that the system is critically damped. With one damping factor this is easy but I'm not sure how to do it with more than one.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Bullet Vehicles

Post by sparkprime »

Also, why clamp the force positive in updateSuspension? Are there cases when it is not positive?
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Bullet Vehicles

Post by sparkprime »

Is there a reason why, when the suspension impulse is finally applied to the chassis, it is applied at the ground contact point, not the point on the chassis where the suspension is attached, the "hard point"?

Also, why is the direction of the impulse taken from the contact normal rather than along the spring?
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: Bullet Vehicles

Post by hiker »

Hi,

I recently had a look at the vehicle, too - perhaps I can give you at least my best guess as an answer :)

...
sparkprime wrote: So as far as I can tell, m_clippedInvContactDotSuspension is usually 1 which makes no difference to the force.

As the car tips away from the vertical (e.g. going round corners) this factor is increased to 10.

What's the purpose of this denominator mechanism? Is it to provide more springiness for when the car is balancing on two wheels?
This appears to be used e.g. when the kart is starting to go uphill: the forward movement of the kart up the hill causes the suspension to be pushed in. Not sure how to interprete this when the kart is going downhill :) Then this code apparently created an additional force 'pulling' the suspension down(???) - here is where I get confused

...
Also, why clamp the force positive in updateSuspension? Are there cases when it is not positive?
Yes, it can happen: when the kart goes downhill, the 2nd force (pulling the suspension down as mentioned above) can become greater than the compression force, resulting in a negative force. This depends obviously on the various parameters, perhaps I was using a particularly incorrect set of values *blush*

Otherwise I can only add to the questions: in updateFriction the foll influence is used as:

Code: Select all

rel_pos[2] *= wheelInfo.m_rollInfluence;
Shouldn't the [2] be m_indexForwardAxis?

Another oddity is mentioned in the 'Vehicle Suspension question' thread.

HtH
Joerg
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Bullet Vehicles

Post by sparkprime »

Yeah I think understanding this isn't important for understanding Bullet itself but would be really useful to know more about vehicle simulation in general. The knowledge must be out there somewhere, it just needs "extracting", perhaps surgically :)

About denominator? You mean when the front wheels are on the hill and the back wheels aren't? You get a sort of bump as the car hits the bottom of the hill. I guess that is what happens in real life so maybe it's just to hide the jaggedness of the terrain, something you don't normally get in real life.

And yeah I guess if you add extra forces to tweak the system, you have to be prepared to cap the resultant force. It's possible with damping too, I guess. Although damping is usually small enough to not matter.

As for applying the impulse at the bottom rather than the top of the spring, I recently tried the latter and it was unstable, so I don't know why the former is correct, but it's probably more to do with fundamental mechanics than it is about software simulation.

I dunno about your question though :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bullet Vehicles

Post by Erwin Coumans »

With just a single rigid body to represent the chassis, the ray cast vehicle contains a lot of approximations.
Also, why is the direction of the impulse taken from the contact normal rather than along the spring?
It takes the contact normal to register sloped surfaces. If you would use a wheel shape, it would automatically register those sloped surfaces, but a ray lacks this dimension.

You might want to download the free Havok SDK and documentation, and learn about their ray cast vehicle model. It is not the same, but there are similarities.
Shouldn't the [2] be m_indexForwardAxis?
It could be a bug, haven't had time to look into that.

If you have a bugfix or other improvement, can you submit a patch in the issue tracker?

Hope this helps,
Erwin
Verbo
Posts: 39
Joined: Fri May 08, 2009 9:27 pm

Re: Bullet Vehicles

Post by Verbo »

Hi,

I have an extra question about the suspension calculation in Bullet. From what I see in the code, the spring force is calculated this way, and I am totally confused about the units. If spring force is in Newton (F = -k*X) then why do we multiply the resulting force by the vehicle mass? Wouldn't this result in N * Kg ( Kg * Kg * m )/ (s*s) ) ?? :?

// Spring force
force = pWheel_info->m_suspensionStiffness * length_diff * pWheel_info->m_clippedInvContactDotSuspension;

// Damper
force -= susp_damping * projected_rel_vel;


// RESULT
pWheel_info->m_wheelsSuspensionForce = force * chassisMass;


Thx.

Verbo