pacejka implementation

Started by
65 comments, last by johnstanp 16 years ago
Hey guys! I'm trying to implement pacejka for my racing type game and I don't quite understand how to do it. I understand the basic formulas and can't figure out how it plugs into a "real" car. Do you make a pacejka class for each tire? The source code I'm staring at only has 1 value for camber so I'm assuming you need to make a class and do calculations per tire. The outputs of the pacejka formulas give 3 major numbers, lateral/longitudinal/aligning moment (I still dont get what aligning moment is). These three numbers are floats. I don't get how these numbers correspond to the direction the car is traveling and its relative slip angle. So far my car game stores the over all car motion as a vector. Would slip angle simply turn the model of the car and have everything still travel along the same path? That doesnt sound very accurate though. Help! I'm misguided!
Advertisement
Hi.

I've used the Pacejka formulas quite sucesfully in my racing game

www.kjmsoftware.co.uk/

theres also a car physics resource download available on my site too.

There are two differetn versions of the pacejka formula, Longtitude and Lateral versions as far as i am aware.

As far as i can remember, aligning moment is the force returned for the steering wheel, used for force feedback joysticks.

Either the long or lat versions should only return a force. ie, 1 variable. You shouldnt be getting several outputs.

You call the pacejka formula with camber, load and slip angle, i think and you get a force returned based on those inputs.

Each pacejka requires a set of coeficient constants too, which specify the tire attributes.


The longitude slip angle is the amount of wheel spin you have, ie traction of wheel, forward rolling angular velocity over ground velocity.
The force returned from longtitude pacejka is the amount of traction your tire has with the ground which basically equates to longtitude acceleration.

The lateral slip angle, is the direction of travel of the car over its yaw orientation. Oversteer if you will.
The force returned from lateral pcejka is used to change the direction of travel of the car and also to slow down it's yaw angular velocity.

To start with, you can just treat your whole car as 1 tire and call the pacejka routines based on the lateral slip angle of the car and use a long slip angle variable for acceleration.

Both long and lat pacejkas should be treated as seperate routines.

A slightly more advanced approach is to combine both returned forces and to treat them as a x,y vector, and crop them to fit a circle or oval of output forces. Probably best to google it, as i'm not explaining this part very well.

Incidentaly, the racer website has the best pacejka pages i've seen and is what i have used.

http://www.racer.nl/

Hope that helps.

KJM
I love you :) It makes sense. I guess the force returned is the acceleration in a direction?
Well, the force returned for the longtitude pacejka can be either positive +, or negative -, so it can be either acceleration or decelleration.

If the wheel is rotating ( angular velocity ) slower than the road speed, then it will be skidding on the road, thus causing decelleration, a negative force.

If it's spinning faster than the road speed, then there is normal wheel spin, causing acceleration for the car.

For the lateral pacejka, this too can return a positive or negative force, but this specifies a direction , left or right.

as an example.

Take a toy car, place it on a slightly slippy table, rotate it to say 45 degrees to the right and push it forwards.

The car will slide forwards at an angle of 45 degrees, untill enough friction is built up to change the cars direction of travel until it travels in the direction it is pointing.

In this case, the slip angle is 45 degrees, and the sign of the force returned tells you what direction you need to alter your cars direction of travel. In this case say, a positive force is returned which means you need to rotate your direction of travel vector to the right.
A negative force would be to rotate left.


If the car has any angular yaw velocity, ie, it's spinning like a top, then you will need to slow that down too.

If the toy car is spinning on it's spot, ie no linear velocity, then all the wheels are in effect sliding sideways, although the car is spinning on its spot.

I used a constant friction value to slow down any yaw spin of the car. I'm not sure if this is entirely correct, but gives good results for a game.

Considering that the lateral pacejka needs a slip angle, calculated from the difference between the cars longtitude and lateral velocities, a 0 force will be returned if the car is stationary but spinning on it's spot. Because both long and lat car velocities will be 0.

Incidentally, to calculate the lateral slipangle, use

atan2(lateral_car_velocity , longtitude_car_velocity)

The order , lat long, might be wrong i can never remember off the top of my head. And the velocities are in car frame coordinates, and not world frame coordinates. A car in a game for instance, might be travelling forwards , but its world coordinates might be x = 1, going sideways left to right in the world. Whereas the cars local coordinates would be long velocity = 1, lat = 0.

Therefore, i assume that a constant friction value is used to slow down the cars stationary spin.

But in real life, a car can be yaw spinning as well as having linear velocities, so the pacejka force is used to change the direction of travel for the car only.

Marco monsters tutorial explains how to calculate the lateral slip angle and has c source code too. It can be found within my car physics download.

Hope that sheds a bit more light on the subject.

KJM
I'll have to read that a few times through. I have been reading through that download you pointed at. I am trying to integrate the Pacejka formula into an existing physics engine and they just dont seem to want to match up. Figures. I managed to get the pacejka.cpp file into a C#/XNA format, I just need to integrate all of that into

From what I can tell. before you calculate pacejka, you need to update:
slipangle
slipratio
normalforce
camber

and as you said the two outputs are the lateral and longitude forces.

So that means I need to make my physics engine calculate and plug in those 4 forces right?
Yes you only really need the slipangle and slipratio as inputs, the normalforce or load / weight on the tire and camber can be constants. In real life of course, as the car pitches and rolls the camber and loads on each tire change dynamicaly.

But in actual fact, you dont really need the pacejka formula to return a force, but instead use the slip angle / ratio as the force to use. Although you would probably have to scale it to some arbitry value that works for your physics engine.

The pacejka formula just returns a good real world approximation of tire force, ie, a very accurate model of a real tire, based on the coeficients used. But it's not necesary to start with.

I used the ODE physics engine in my game along with the pacejka implementation, so it can be done and works quite well.

I would first concentrate on the lateral force first by getting your cars longtitude and lateral velocities. These would be your car chassis linear x,z velocities for the ground plane in 3d, treated as a 2d vector and then rotated to the yaw angle of your car chassis.

This transforms your cars world linear x,z velocities into car frame velocities, forwards speed ( as you see on a car speedo ) and sideways speed.

Then it's a simple case of using

slipangle = atan2 (sideways speed , forwards speed)

force = slipangle / scale amount to work with your physics engine

to calculate the slipangle, which can be used as the force to turn the car chasis left or right until it's slip angle becomes 0, which is when the car is traveling in the direction it is pointing with no lateral velocity.

KJM
Ok. I think I'm starting to get this. Still a few Qs.

Slip Angle = the current angle the car IS (45 degrees in your example) right?
What is slip ratio?

And I don't quite get what "force" is. Would that be the change in velocity or just a factor I should be using for the rest of the car physics?

I'm so frustrated. The JigLibX Library I have has really simple vehicle physics to the point where I cant even tell if there is a suspension.
Double post!

Slip Ratio = [(Vehicle Speed – Wheel Speed)/Vehicle Speed] x 100

So slip ratio is the diff between the car speed and the wheel speed. So doesnt that mean slip ratio can be a negative number? IE the wheels are going faster than the car (acceleration)
Q - "Slip Angle = the current angle the car IS (45 degrees in your example) right?

Not just the angle the car is, but the angle between the direction of travel of the car and it's yaw orientation. This is oversteer, as in a rally car, when the rear steps out causing a skid.
Any sideways velocity will cause a lateral slip angle.

If the car is travelling normaly down a road in a straight line, rolling forwards, then there is no slip angle.

If the car has no forwards speed, but is sliding sideways only, it has a slip angle of 90 degrees.

Here is the code i used to get the slip angle and force. Blitz basic source.

;get the real world x,z velocities of the car, returned from your physics engine.
x_velocity# = dBodyGetLinearVelX#(car)
z_velocity# = dBodyGetLinearVelZ#(car)

;rotatate the x,z velocities of the car in world frame coordinates to local frame car coordinates. Simple 2d rotation.

yaw# = dBodyGetYaw#(car) ; get the yaw orientation of the car
s# = Sin(yaw#)
c# = Cos(yaw#)
lateral_velocity# = (x_velocity# * c#) + (z_velocity# * s#)
longitude_velocity# = (x_velocity# * -s#) + (z_velocity# * c#)

; get the angle between the two velocities.
slip_angle# = ATan2(lateral_velocity# , longitude_velocity#)

;either use the slip_angle# as the force to change the cars direction of travel or call a pacejka function for a more accurate force.

; lateral pacejka force based on slip_angle#
lateral_force# = lateral_pacejka(slip_angle#)

Now that you have worked out the slip angle, and a force for that slip angle, you can use that to change your cars direction of travel.

Again it's simply a case of a 2d rotation of your x_velocity#, z_velocity# to either left or right by the amount of force thats been worked out.

Then to set cars actual velocities in your physics engine with the new velocities.


"What is slip ratio?"

The slip ratio is just the difference between the road speed (car speed) and wheel speed.

So.

Slip Ratio = Vehicle Speed – Wheel Speed

The slip ratio can be positive or negative, but youll have to take into account the direction of each. The car could be moving backwards along the road, negative longtitude velocity, but the wheels could be spinning forwards giving positive angular velocity.

The slip ratio again can be used directly as the force to alter the cars acceleration / deceleration or passed to the longtitude pacejka function to return a more accurate force.


"I'm so frustrated. The JigLibX Library I have has really simple vehicle physics to the point where I cant even tell if there is a suspension."

I can sympathise, there is really very little information regarding car physics programming available, period.

Are there any other physics libraries available for XNA ?

KJM
Thanks again. I think I get it now.

unfortunately, there really arent any good physics libraries for XNA. All are in alpha stages. My current phys library basically said that if there was more than X amount of lateral force, that it would change the lateral forces. It had nothing for slip angle or slip ratio.

I got everything in and decided to check numbers out last night. Somehow the vehicle speed and wheel speed are in two different units. So I get to figure out how to make them play nice. Even with that, I think my values for slip angle are wrong since I think they should be 0-360 not 1000+ so I need to figure that part out.

What are example numbers for the lateral and long forces outputted?

BTW thanks for being so helpful. Youre the only good source so far lol.

This topic is closed to new replies.

Advertisement