# Pacejka stuff (car physics)

## Recommended Posts

solinent    124
I'm trying to implement the longitudal version of pacejka's formula. Short: I don't know how to properly accelerate the drive wheels based on engine torque to generate a good slip ratio. Long: However, it doesn't seem to be working well (quarter mile times for real values are like 18 seconds, and it takes 10 just to go from 0-60). Anyways, this is how I'm currently calculating it, could someone point me in the right direction? First, I calculate the engine RPM by:
        engine.RPM = (groundSpeed / 2*M_PI*wheelRadius) * finalRatio * gearRatio[currentGear] * 60;

Then, the drive torque is calculated using an estimated torque curve:
	float torque () { return -0.00001*(RPM-4400)*(RPM-4400) + 800; }

like so:
	driveTorque = engine.torque() * gearRatio[currentGear] * finalRatio * .7; // .7 efficiency

So this torque is torque at the wheel. The slip ratio is calculated using:
	wheelSlipRatio = ((wheelAngVel * wheelRadius)-groundSpeed)/groundSpeed;

and the traction force is calculated using:
	float tractionForce = pacejkaLongitudal (wheelSlipRatio*100);
float tractionTorque = tractionForce * wheelRadius;

(where pacejkaLongitudal is the pacejka formulae. This is correct, I've graphed it and it compares to the graph in the Physics of racing series, same with the values) This is where I start becoming unsure of myself, but this is the next bit of code that calculates and integrates into wheel angular velocity (all values that say "wheel" refer to drive wheels).
	float totalTorque = driveTorque - tractionTorque; // + brakeTorque
float wheelAngAccel = totalTorque / wheelInertia;
wheelAngVel += wheelAngAccel * seconds;
float driveForce = tractionForce;

float acceleration = driveForce / mass;

Then acceleration is integrated into groundSpeed (will use vectors later once I get longitudal) and then finally integrated into position. I understand the concept, but the one thing I dont' understand is that how to integrate torque into the drive wheels in order to generate an acceleration. Right now it's going to slow, and I haven't even put in drag or other resistance forces, so it is my opinion that something is defintely wrong. I know, I should be calculating engine rpm like this:
        engine.RPM = wheelAngVel * finalRatio * gearRatio[currentGear] * 60 / 2*M_PI;

However, it hardly moves then. Please ask if more details are required, and help is appreciated! I'm really confused :). [Edited by - solinent on October 22, 2008 7:23:27 PM]

##### Share on other sites
kunos    2254

What is the max slipRatio value you are getting during the simulation?

You are calling pacejkaLongitudal with a % of slip, are you sure the units are consistent? Usually it is:

0 = free rolling
-1 = locked

Also get a printout of "driveForce / mass".

Consider that pacejika was not designed to simulate starts from speed=0.
It is likely that, during the first seconds of your simulation the tyres are spinning like crazy. You need some graphs to understand what it is going on.

##### Share on other sites
solinent    124
Hi,

Thanks alot, that makes sense. My slip ratios can go up to 5 times (500%), which means they are slipping a whole lot.

So, when should the longitudal version of it be used? Maybe only after a certain speed? Is there any literature on this specific topic?

I'll try to output some values to a file to get a good estimate of what's happening.

I'll figure out how to use gnuplot to get an acceleration vs time, and slip ratio vs time.

Final question: is there any data for one specific car that I can use that has alot of this info? Like acceleration vs time and slip ratio vs time? This would be very useful.

I don't have any calculus knowledge, other than basic stuff you learn in precalculus (I have intro calculus/vectors next semester, gr 12).

I'm aiming for it to be a 2d simulation, but if I can get a good feeling demo (in line with real physics) I want to do 3d, so that is the basis of using very accurate models (also because it's challenging/fun).

##### Share on other sites
solinent    124
Ok, the first graph here is the acceleration/time for using pure dynamics (ie a engine torque -> wheel torque -> wheel force -> acceleration)

Here it is:

The other graph is coming up, for some reason it's exporting corrupted data, give me a second.

edit:
Pacejka stuff, first gear is still done using non-pacejka stuff.

acceleration/time

slip ratio/time

[Edited by - solinent on October 23, 2008 2:31:11 PM]

##### Share on other sites
kunos    2254

Ok so 2 things to consider:

- It is clear from the graphs that as soon the 2nd gear is engaged and the magic formula kicks in (you said it is off for 1st) the longitudinal force drops down. So something is wrong in the MF output. Can you plot the result of slipRatio/Fx of the formula?

- Drivetrain inertia is not taken into account. The only inertia I see here is the wheel inertia. The problem is that, because of the gear and final ratio the inertia seen by the engine should be different from the inertia seen by the wheels. Ruud, author of Racer, has a nice page about this:

http://www.racer.nl/tech/effinertia.htm

##### Share on other sites
solinent    124
Thank you, I'll definitely look into those and generate that graph for you.

I'ved stopped doing longitudal for the moment, and was working on lateral, so I might take a little time to get back with that slip ratio graph.

Small question about the lateral pacejka, I can't find the units of the D, C, B, and E values of the lateral version (ruud doesn't seem to list them), I am trying to generate the appropriate curve using the PHOR's series explaination, but they dont' list the units either. I'll probably figure it out by the time you read this, but incase you see it earlier, it might help me out.

One problem is that I'm not accounting for extra vertical load on the rear due to acceleration yet. Is this affecting my values by alot? Also, does the suspension have anything to due with dampening the Fx values?

Thanks.

edit:
I think I got the units, and I got a graph that looks something like a pacejka curve, though it's obviously wrong since I get negative force at 0. This is how the function is set up (as per PHORS):
        D: 5957.2 | C: 1.779 | B: 0.340706 | E: -0.266611 | Sv: 0 | Sh: -0.0538066 | S = slipAngle + Sh        Fy = D * sin (C * atan(B*S + E*(atan(B*S) - B*S))) + Sv

[Edited by - solinent on October 24, 2008 9:04:33 AM]

##### Share on other sites
kunos    2254
Magic formula doesn't have a "physical" interpretation.
If you want to use it, the only way forward for you is to build a simple editor that, given some MF paramteters is plotting the curve.
Then, try to get hold of some real tyre test curves and try to match either by hand (so you will also learn the effect on the paramters on the curve) or by formulas.
Pacejika's book has a nice explanation about calculating paramters from given data (ex. max slip angle, friction after the peak etc.).

Anyway, in few words, here is what each parameter does:

B - In my experience is never expressed directly, but rather calculated from another important value called Cornering Stiffness, that is, the slope of the curve at 0 slip. Basically you have a stiffness and calculate B as:

B=CS / C*D

Being:

CS=BCD

C - Curvature factor. Its main effect is in the "drop off" of the curve after the limit of adehsion. It is typically in the range of 1.3-1.4 for lateral and 1.6 for longitudinal.

D - is the peak value the curve will reach. You can use N (0..5000 for example) or friction coefficient (ex. 0...1.8) to later multiply by normal load on the tyre. Usually D comes, like CS, from more calculations to take into account load sensitivity, camber in Pacejika most advanced version.. temperature, pressure, speed, in custom variations.

E - This controls the beginning of the sliding area making it very abrupt or more soft.

Weight shifting is very important under acceleration because it allows the rear tyres to support more longitudinal force. Of course the springs/damper are controlling the rate of weight shifting around the car under dynamic manouvers.

Anyway, as I have said, if you are into car simulations, do yourself a favour: invest a couple of weeks into a tyre curve editor, you will never regret it and will be using it forever.

##### Share on other sites
solinent    124
Yeah, I'm writing this program without any written stuff, it's all in my head. Invest a few weeks? Normally it just takes me a weekend before I realize I'm in over my head and quit. But I did finish a almost-realtime raytracer.

Anyways, before I do such a rash thing, please read my edit to my earlier post, I figured out the units and got something like a pacejka curve, but something is wrong. (get negative force at 0).

I'll start coding a pacejka curve editor, though that will take some time, it does seem like it will help me. Maybe I'll just use the racer.nl one.

edit: Is pacejka's book something a mere 12th grade student with no calculus knowledge will be able to understand?

##### Share on other sites
kunos    2254
Nothing is wrong.
Look here:

Sh: -0.0538066 | S = slipAngle + Sh

Sh is added to the slipAngle to simulate a tyre effect called ply-steer and/or conicity. If you set this param to 0, you will have 0 N at 0 slip angle.

EDIT: I don't understand what 12th grade is :D... we use different names for schools here in Italy. The book goes from simple math (I would say high school stuff, for the empirical models) to more complex derivative notation in other parts of the book. Consider that I have never been in college/university, just banging my head into books I have managed to figure it out.

##### Share on other sites
solinent    124
So I should get rid of Sh? Or maybe the lateral version of pacejka is only really good for high-speed simulation?

##### Share on other sites
kunos    2254
leave it in the formula, just set it to 0 until you are clear what it is doing..it is a subtle effect in the overall simulation, nothing you should be bothered really.

The MF is good for constant speed, constant load, constant everything :D situations.. that is, in high level real time simulators, = NEVER. But it is a very good first step into the world of tyre math models because its simplicity.

##### Share on other sites
solinent    124
Interesting. I'm getting some weird things happening with the pacejka formula still, but I think it's because it's not really supposed to be used for this kind of thing (low speeds), and I'm calculating slip angle only for the front (i should do both), and not even per wheel. I think right now it's spinning into infinity because there's no opposite force from the rear tyres.

Thanks for your help so far, it's really helped reassure me that everything I'm doing is corrrect. I'll get back to you with some graphs.

##### Share on other sites
solinent    124
Wow! I got something here, and it doesn't spin out of control right away either! Great!

I just need to figure out longitdual pacejka.

Anyways, I'll do that later when I'm braver. For now, I'm having but one problem, when the car is still, and the wheel is turned, shouldn't there be no force at all that's generated?

After all, if the car isn't moving, it shouldn't be rotating?

edit: I figured it out. Slip angle is undefined for velocity = (0,0), since there is no unit vector. So I have to create an error case.

Just tell me if I am correct, please :)

##### Share on other sites
kunos    2254
you are correct.

you will find that handling low speed situations (<5-10m/s) is quite tricky.
In my sim I am using a veeeery simple approach for such low speeds that is blended into the complex one as speed is increased.

##### Share on other sites
mac4004    122
Hello, i have some questions about wheels.

Anybody know, what precise physical meaning of wheel property, named MotorTorque and applies by SetMotorTorque()?
If it mean wheel axle torque, why when I apply same MotorTorque to wheels with different radius, they have different force in contact point.

That mean:

M1 = F1*r1

M1 - torque on wheel axle
F1 - force on wheel axle
r1 - radius of wheel axle

M2 = F2*r2

M2 - torque on wheel
F2 - force in wheel contact point

wheel an axle have stiff joint it mean.
M1 = M2.
F1*r1 = F2*r2

r2>r1
it mean
F1>F2

Maybe MotorTorque maen force on axle?

And such questuin.

What better, raycast wheel or rigidbody wheel?
What minus and plus for diffrent wheel models?

##### Share on other sites
solinent    124
Quote:
 Original post by mac4004Hello, i have some questions about wheels.Anybody know, what precise physical meaning of wheel property, named MotorTorque and applies by SetMotorTorque()?If it mean wheel axle torque, why when I apply same MotorTorque to wheels with different radius, they have different force in contact point. That mean:M1 = F1*r1M1 - torque on wheel axleF1 - force on wheel axler1 - radius of wheel axleM2 = F2*r2M2 - torque on wheelF2 - force in wheel contact pointr2 - radius of wheelwheel an axle have stiff joint it mean.M1 = M2.F1*r1 = F2*r2r2>r1it meanF1>F2Maybe MotorTorque maen force on axle?And such questuin.What better, raycast wheel or rigidbody wheel?What minus and plus for diffrent wheel models?

You'd probably get more help if you created a new thread.

I would assume motor torque to mean the torque before it gets amplified by the gearing to the drive axle.

##### Share on other sites
noisecrime    817
Quote:
 Original post by solinentWow! I got something here, and it doesn't spin out of control right away either! Great!

Care to share what you did to get that? Like many others i'm developing a car simulation and although its not gotten to the stage of including Pacejka, its something I want to try at some stage, so any and all information is welcomed.

Whilst this doesn't directly answer your questions you might find it interesting. Its an interview with Brian Beckman (the guy who wrote 'The Physics of Racing' series and worked on Forza 2. He does mention the issues about the physics falling apart at low speeds, but don't think he says how to address it.

However its really long, over an hour! Starts of with general (simple) discussion about game simulation and physics, then I think moves onto flight physics before looking at vehicle physics. If you're interested, probably better to download than stream it as i think you'll get a bigger size and can watch it at your leisure. I found him quite engaging and inspirational.

##### Share on other sites
Lord Crc    234
Quote:
 Original post by solinent engine.RPM = (groundSpeed / 2*M_PI*wheelRadius) * finalRatio * gearRatio[currentGear] * 60;

I don't know anything about pacejka's formula, and perhaps you just missed it when pasting, but aren't you missing a set of ()'s there? Ie

        engine.RPM = (groundSpeed / (2*M_PI*wheelRadius)) * finalRatio * gearRatio[currentGear] * 60;

If not, please excuse me :)

##### Share on other sites
solinent    124
Quote:
Original post by noisecrime
Quote:
 Original post by solinentWow! I got something here, and it doesn't spin out of control right away either! Great!

Care to share what you did to get that? Like many others i'm developing a car simulation and although its not gotten to the stage of including Pacejka, its something I want to try at some stage, so any and all information is welcomed.

Whilst this doesn't directly answer your questions you might find it interesting. Its an interview with Brian Beckman (the guy who wrote 'The Physics of Racing' series and worked on Forza 2. He does mention the issues about the physics falling apart at low speeds, but don't think he says how to address it.

However its really long, over an hour! Starts of with general (simple) discussion about game simulation and physics, then I think moves onto flight physics before looking at vehicle physics. If you're interested, probably better to download than stream it as i think you'll get a bigger size and can watch it at your leisure. I found him quite engaging and inspirational.

For lateral pacejka, I just calculate the slip angle and then calculate the force per tire (using Pacejka formula), then I get the net torque on the vehicle (something like frontForce * length/2 + rearForce * length/2) and integrate the angular velocity of the car over time.

I'm still working on longitudinal, but I got sidetracked by nice shadows and other interesting stuff.

I'll definitely check that video out. Right now I'm trying to implement a decent suspension.

##### Share on other sites
mac4004    122
Hello guys. I talking about MotorTorque. Now I use SetAxleSpeed (calculate and direct assign wheel angular speed).

Have you ideas about raycast wheel collision?
I have 3 tested variants, and I have bugs.

1. Rigig Body for wheel. Rigid cylinder convex. (Bug: rigid, not realistic frontal collisions)

2. Soft Body for wheel. Soft body have constraints on stiffness.

3. Adding aditional raycasts and calculate contact point. It's hard to calculate forces for all additional contact points.

##### Share on other sites
gusso    104

solinent: what are you using to plot your graphs? I liked the anti-aliased one, I've been looking for a graph plotting solution but none seem to be what I'm after.

##### Share on other sites
Lord Crc    234
I've used Gnuplot, which is quite nice. Either output as SVG or truecolor PNG and it should anti-alias (or eps+latex for inclusion in latex documents).