• Create Account

## How to make a stable car physics?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

24 replies to this topic

157
Like
0Likes
Like

Posted 31 January 2014 - 02:43 AM

Hello,

Well, I'm currently confused on how to achieve a stable simulation. My current simulation is good in terms of driveline, suspension and tires.
It works good with Joysticks and keyboard. But what I noticed is that when I use a ffb wheel, I notice that after a heavy braking the car wants to spin out. And I cant seem to recover. The car setup is a FR drivetrain, with a weight balance of 52/48

I use a raycast method for the whole wheel/suspension setup.
I use the calcualted suspension force as the load for the wheel.

I calculate the SlipAngle and SlipRatio the SAE950311 algorithm(with relaxations).
Tho I have to localize the tanSlipAngle and differentialRatio variables, otherwise the car will start springing around on bare ground, mostly caused by slip ratio.

The tiremodel I'm using is Pacejka89 + Beckman combined slip model.
I add the tire forces to 4 points of the car (mainly the wheel position + rollcenter offset (I dont know if this is correct, but it seems to make the simulation a little more realistic)

So lately I was looking into another method, that seemed to work better under braking.

Applying forces and torque directly do the body depending on the cg position + roll center positions (as jacking)

But this method seems to not entirely like my wheel load method (because of bumpstops and antirol bar calcs, I have to disable them to get it working) Also at low speed, it seems like this method wants to float sideways.

So I finally decided to come here and ask for some help. How are you guys initialising vechicles these days Do you apply forces to 4 points of the rigid body? Or do you apply the forces & torque directly do the body?
And how to calculate the wheel loads / weight transfer if usuing the cgOriented method?

Also about roll centers, where to use them exactly if I'm using the 4 point method?

Any help would be apriciated!

### #2bmarci  Members

746
Like
0Likes
Like

Posted 31 January 2014 - 03:53 AM

Hi, we are doing pretty much the same, simulation wise

I was also playing with jacking forces and roll centers but the whole thing proven to be much better without them.

Probably because my not so proper suspension geometry and here would the "super-knowledge-of-setting-up-a-race-car" come handy. Calculating upan a bad setup .... hmm

I apply every forces (tire/aero..etc) on the body.

Quick cheats you may try;

1. Lower the CG a bit (not much, centimeters, or inches maybe )

2. Use stiffer suspensions at the front

3. Check the brake bias, rear wheels should not lock prior to fronts

Also make sure your rear wheels touch the groundwhen braking. I had issues with suspension and tire movements (oscillations), and big pitch torques made the rear wheels pop up from ground. So I'm using some threshold, the tires don't lose traction at once when they lift off.

Hope some of these help.

Edited by bmarci, 31 January 2014 - 04:22 AM.

157
Like
0Likes
Like

Posted 31 January 2014 - 05:06 AM

Thanks for the reply, this is exactly what I have done to get stability but, this results in Forza like cars.
You know, behaving correctly, but theres minimal bodyroll and the simulation doesnt seem soo real visually.

I mean when you are going fast, and brake hard the car will introduce bodyroll even with stiff suspesnsion. This is the real behaviour of a car, you can see this sort of behaviour in nfs shift and rfactor. For example a car produces 800nm of torque and has a coilover set of like 80kNm at front and 70kNm at back. At launch and braking you will see the weight transfer, body pitch?.

Anyway I have seen some videos of your sim and its quite impressive. But I have a question, the head movement inside the car, is it caused by G's, like in shift or do you have that bodyroll aswell?

..oh and are you using rays or 5 rigid bodys?

Edited by vadevaman, 31 January 2014 - 05:09 AM.

4090
Like
0Likes
Like

Posted 31 January 2014 - 06:25 AM

Where are you applying the suspension spring forces? at the contact patch or the wheel hub?

Edit: I have only fiddled around a little bit with vehicle physics, so I'm no pro at that, at all. But I have found that applying the forces not at the contact point, but a little higher up has resulted in a much more stable and believable car model, even if it might not be realistic.

Edited by Madhed, 31 January 2014 - 06:31 AM.

### #5bmarci  Members

746
Like
0Likes
Like

Posted 31 January 2014 - 06:29 AM

I mean when you are going fast, and brake hard the car will introduce bodyroll even with stiff suspesnsion. This is the real behaviour of a car, you can see this sort of behaviour in nfs shift and rfactor. For example a car produces 800nm of torque and has a coilover set of like 80kNm at front and 70kNm at back. At launch and braking you will see the weight transfer, body pitch?

My "race suspension" has a spring rate betwen 55 and 70kNm.

And can see the body pitch (more visible outside) even when shifting.

The "F1 suspension" has 120kNm, so not too many visible body movements.

Anyway I have seen some videos of your sim and its quite impressive. But I have a question, the head movement inside the car, is it caused by G's, like in shift or do you have that bodyroll aswell?

..oh and are you using rays or 5 rigid bodys?

Thanks!

The head movement is caused by G's and some speed related random shake. Could be done with a spring, though

And I'm using only one rigid body and 4 rays, but "multisampling", so technically 12 rays, and the actual ground position is aproximated with some bezier stuff.

I've just read something about suspensions' anti-pitch properties, but I don't realy have the idea how to code that yet. Not sure if I even need it

157
Like
0Likes
Like

Posted 31 January 2014 - 07:54 AM

Where are you applying the suspension spring forces? at the contact patch or the wheel hub?

I'm applying the forces to wheel hub minus a correction factor(wich I call rollcenter at the moment, but obviously is false), so front wheels have their forces applyed lower than ground patch and rear wheels higher on Y axis.

And I'm using only one rigid body and 4 rays, but "multisampling", so technically 12 rays, and the actual ground position is aproximated with some bezier stuff.

Hmm what do you mean by multisampling exactly? And the ground position bezier stuff... as I understand is some sort of a blend between tris, to get a smooth ground right? Like in Racer where there is a road spline mesh to get that smoothness.

Anyway, what are your typical brake friction torques and how much of pressure do you but on them and is there some sort of damping done aswell?
For my example car I use braking torque of 1350 at front and 950 at back.

The overall braking im doing like this (per wheel):

brakingTorque = brakingFrictionTorque * brakePressure; // brakepressure is user input in a range of 0 to 1
brakingAngularDelta = brakingTorque * dT / totalInertia;

And the angularVelocity(omega) implementation for braking

if (Abs(omega) > brakingAngularDelta)
omega -= Sign(omega) * brakingAngularDelta;

else

omega = 0;

Everything seems to be ok codewise but this oversteering issue is getting on my nerves.

Also what do you use as your wheel load? Total suspension forces or do you do some weight transfer calculations depending on the G's?
And do you add some lowspeed friction forces to your car aswell?

Seems like my car wants to slide to somewehere, even if the force is 0, ...actually this is somewhat logical codewise because there is no forces that should be resisting the movement. I'm thinking of using slip velocityes for low speed friction modeling...

### #7bmarci  Members

746
Like
0Likes
Like

Posted 31 January 2014 - 09:03 AM

Hmm what do you mean by multisampling exactly? And the ground position bezier stuff... as I understand is some sort of a blend between tris, to get a smooth ground right? Like in Racer where there is a road spline mesh to get that smoothness.

That's right, I make 3 ray-casts for each wheel. The rays' distances depend on the speed. And between the 3 intersections I fit a curve.

MSPaint forever:

I use the red dots (intersection points) as the control points for the bezier curve. So I just load a "polygon soup" and voila no need to create a spline mesh for the track. Works nicely on banked curves too.

Anyway, what are your typical brake friction torques and how much of pressure do you but on them and is there some sort of damping done aswell?
For my example car I use braking torque of 1350 at front and 950 at back.

Now I use 2500Nm maximum brake torque 50:50 works well, probably because the low CG.

I'm in a middle of rewriting the whole driveline since it's a big magic, nothing to do with physics

Also what do you use as your wheel load? Total suspension forces or do you do some weight transfer calculations depending on the G's?

Total suspension forces and tire forces when there is no more spring.

I have a concern about suspension's anti-pitch because in this case the weight is transferred through suspension links instead of the spring. So in my interpretation the tire deflates more than the spring. Not sure though.

Seems like my car wants to slide to somewehere, even if the force is 0, ...actually this is somewhat logical codewise because there is no forces that should be resisting the movement. I'm thinking of using slip velocityes for low speed friction modeling...

Also just an idea:

It might be because of the relaxation length, since the tires don't "react" instantly to the slip angles/ratios.

This effect will be even worse if you use camber/toe in.

157
Like
0Likes
Like

Posted 31 January 2014 - 10:54 AM

Hmm your method actually looks pretty cool. And one of my friend does something simmilar actually I personaly stick with the single ray per wheel at the moment.

Total suspension forces and tire forces when there is no more spring.

What does your suspension force consist? Mine is spring + damper + antiroll. When bumpstop is reached I switch the spring and damper forces. I dont use tire deflection forces at the moment, because I want to sort out the instability issue first.

It might be because of the relaxation length

Could you tell me how you calculate your slip angle and slip ratio? because when I try changing the relaxation lengths all sorts of crazy stuff happen when the tanSlipAngle and differentialSlipRatio are global variables. When they are local variables (in method) things stabilize a a bit but it's still quite strange.

Also I dont want to complicate things with camber/toe at the moment. I just want to get the simulation stable at first.

### #9bmarci  Members

746
Like
0Likes
Like

Posted 31 January 2014 - 11:14 AM

What does your suspension force consist? Mine is spring + damper + antiroll

The suspension forces are all those you mentioned, but the load is spring only (k*x).

Take a 50kNm spring rate. That means 50000N force is needed to shrink the spring by one meter.

So if your spring is depressed by 1cm (x=0.01, actually -0.01 when shrinking) it means the spring is being pressed by 500N force, that is the force pushing the wheels down.

I use the normal slip angle/ratio calculations. For low speed slip ratio I'm working on an alternative method which is similar to SAE950311. It works so far but not sure if it will with the new driveline sim.

Could you tell me how you calculate your slip angle and slip ratio? because when I try changing the relaxation lengths all sorts of crazy stuff happen when the tanSlipAngle and differentialSlipRatio are global variables. When they are local variables (in method) things stabilize a a bit but it's still quite strange.

In case of global var, is it possible you have tanSlipAngle instead of tanSlipAngle[4]  ?? ;)

157
Like
0Likes
Like

Posted 31 January 2014 - 02:00 PM

In case of global var, is it possible you have tanSlipAngle instead of tanSlipAngle[4] ?? ;)

Well, I have a tanSlipAngle per wheel clas, so no I dont have them in an array. Basically whay happens is that the car starts jerking left to right and gains speed, its like I need to reset the value, this is why I use it as a local variable and set it to zero at initialization. The same goes with slip ratio.

I wish it were 2004 when there were al lsorts of private sim projects and sourcecodes to learn from. I remember some demos made with newton physics engine but they are all gone now.

Currently Im doing some tests on 5 rigidbody methods, trying to see if there is some stability in this method.

### #11bmarci  Members

746
Like
0Likes
Like

Posted 31 January 2014 - 05:58 PM

Basically whay happens is that the car starts jerking left to right and gains speed, its like I need to reset the value, this is why I use it as a local variable and set it to zero at initialization. The same goes with slip ratio.

You can abandon slip angle relaxation, since it doesn't affect wheel rotation. It'll oscillate but you won't see it,

At least you'll see if the problem is in there

I wish it were 2004 when there were al lsorts of private sim projects and sourcecodes to learn from. I remember some demos made with newton physics engine but they are all gone now.

Ohh, yes, good old days.

I think the source of an early version of Racer is still available.

Also you may want to check out REC.AUTOS.SIMULATORS google group, and search for "Car Physics". Lots of interesting topics

157
Like
0Likes
Like

Posted 01 February 2014 - 04:04 AM

You can abandon slip angle relaxation, since it doesn't affect wheel rotation

Well if I abandon it and use the regular slipangle formula then there is alot more jerking. This is why I started using the SAE method.

As for racer, this is the game that inspired me to do my own sim stuff back in the day and I have learned alot fro mracers old source, tho it has some pretty messy code, but its a pleasure t ostill have it online.
And yeah I have been at the gropu but totally forgot it. Thanks for reminding it!

As for the sim itself, I switched back to spring force only ( I used to use it but for some reason started using the total suspension force) Ad everything seems to work far better now. Was able to drift the car with ease. Dunno why I made such a change before. Thanks for pointing this out.

### #13bmarci  Members

746
Like
0Likes
Like

Posted 01 February 2014 - 05:36 PM

Well if I abandon it and use the regular slipangle formula then there is alot more jerking. This is why I started using the SAE method.

Yes, much more, but should not be seen The wheels constantly get like (Fy) +1000N, -1000N, +1000N, -1000N ... and at the end of the simulation step they will remain at the same spot.

As for racer, this is the game that inspired me to do my own sim stuff back in the day and I have learned alot fro mracers old source, tho it has some pretty messy code, but its a pleasure t ostill have it online.

Me too, but unfortunately when it first came out around 2001, I didn't understand the first thing from it, I wasn't "smart" enough, physics wise. Reading the the "Physics of Racing Series", packed with funny units like, foot-pounds and slugs, didn't help too much either So I just dropped the topic..

And yeah I have been at the gropu but totally forgot it. Thanks for reminding it!

Lucky you, I haven't even head of it until maybe a year ago

Anyway, maybe you could help me too;

As I mentioned I'm rewriting the whole driveline and the torque transfer is not getting to work. Especially with inertias and accelerations.

What I achieved so far.

The whole driveline has 2 states: The clutch is locked or not.

1:

If locked, the output torque is calculated down to each wheels (only locked diff for now)

The wheels are accelerated with their inertia (not effective)

Based on the wheels angular velocity I calculate the engine speed.

The clutch has a maximum torque that it can transfer based on the pedal (clutch_factor)

If the torques going through the clutch exceed the maximum, it gets unlocked.

2:

The clutch is slipping, the output torque accelerates the flywheel with the effective inertia (engine to wheel)

Transfer the torque to the wheels and accelerate them with their self inertia as with locked clutch.

All the torques from engine and back from the wheels are clamped to the current max clutch torque (see above)

Also while the clutch is not locked both parts get the clutch torque to reduce the difference in angular velocities.

Once the velocity difference (engine/gearbox) switches sign, the clutch is locked again

Probably this is the method we all use, but:

Not sure where should I use effective inertias and where not, and which?

For example at the wheel

this is the method that seems to work, but where is the inertia from the wheel to the engine

If I make it like:

anv_vel+=acc*dt;

acc=T_Brake / Inertia_wheel_to_engine;

ang_vel+=acc*dt;

It "sucks" big time, so to say... I have pain keeping the car on the road even moving straight.

Calculating the t_road_reaction with t_brake even worse.

I don't have a clue yet, just trying different variations hoping for any of them will work.

157
Like
0Likes
Like

Posted 02 February 2014 - 03:12 AM

Yes, much more, but should not be seen The wheels constantly get like (Fy) +1000N, -1000N, +1000N, -1000N ... and at the end of the simulation step they will remain at the same spot.

Thats what I thought, but the force seems to be constant to one side with sae formula, like -100N per wheel.
If I use the standard formula then there is jerking because of the small ocalisions I guess, the slip angle at rest is jumping from -10 deg to 10 deg (just example values) If I cut the longitudinal speed to 0 at some low speed value then there still is that jerking. Dunno what Im doing wrong.

Me too, but unfortunately when it first came out around 2001, I didn't understand the first thing from it, I wasn't "smart" enough, physics wise. Reading the the "Physics of Racing Series", packed with funny units like, foot-pounds and slugs, didn't help too much either So I just dropped the topic..

Exactly the same to me and I started my coding with Blitz3d even made a small demo to racesimcentral
Now I have steped my game into c# and c++ world

Anyway, maybe you could help me too;

Sure thing
First of all, if you are using the common method of angular velocity simulation that counts in road torque, drive torque, braking torque.

As I found out then You cant simulate locked diff's with ease, the simplest Differentials you will simulate are open Differentials.
As I understand by locked you are doing this:
leftWheel = driveTorqueFromDriveline * 0.5f;
rightWheel = driveTorqueFromDriveline * 0.5f;

This Is the simplest differential you can model, but it will simulate open differentials.

Sure if you initialise wheels with a if sentence you can do locked differentials, but I'm not sure if its the way to use.

if(driveTorque=0)

angularVelocity -= rollingAngularDelta:

This simply makes sure that there is no rolling torque applyed when there is driving torque. But id go for the first method and simulate open differentials at start and then advance to a locked differential through some modifications that read roling torque from the wheels, so you can easly simulate LSD differentials this way I havent done this myself yet, but I am using viscous lsd differentials (simplest diffs you can make with the firstly Described wheel code)
It goes something like this (writing from memory):
speedDifferene=leftSpeed-rightSpeed;
leftWheel = (driveTorqueFromDriveline - speedDifferene*lockingTorque) * 0.5f;
rightWheel = (driveTorqueFromDriveline + speedDifferene*lockingTorque) 0.5f;

I know it wasnt what you asked but As for the driveline, I'll write you a PM about this (have to go right now).

Edited by vadevaman, 02 February 2014 - 03:14 AM.

### #15bmarci  Members

746
Like
0Likes
Like

Posted 02 February 2014 - 01:28 PM

Thats what I thought, but the force seems to be constant to one side with sae formula, like -100N per wheel.

One more thing that I just realized a couple of months ago:

It happened to me that I started tweaking the tire curve so it fitted my needs and later realized it wasn't symmetric any more.

Why is that important?

In your situation when the wheel produces +90/-90 slip angles the tire formula returns different forces.

This is basically true for any slip angles:  Pacejke(SA=10).Fy != Pacejka(SA=-10).Fy

This causes your car to turn better left than right or vice versa, also it could start sliding one direction when stopped.

So I came up with the idea of flipping the curve depending on the side of the car. Left tires use the standard calculations and the right side negates the inputs and so the outputs.

In case of a right side tire:

In Pacejka calculation:

SA=-SA

Calculate as usual

Fy=-Fy

Mz=-Mz

This Is the simplest differential you can model, but it will simulate open differentials.

Hmmm this makes sense, as I'm checking the code there is nothing that prevents the wheels from accelerate away from each other.

Sure if you initialise wheels with a if sentence you can do locked differentials, but I'm not sure if its the way to use.
if(driveTorque=0)
angularVelocity -= rollingAngularDelta:

This simply makes sure that there is no rolling torque applyed when there is driving torque. But id go for the first method and simulate open differentials at start and then advance to a locked differential through some modifications that read roling torque from the wheels, so

And how about accelerating the output parts of the diff instead of the wheels? Thus locked diff could be made easily.

Edited by bmarci, 02 February 2014 - 01:28 PM.

### #16bmarci  Members

746
Like
0Likes
Like

Posted 04 February 2014 - 03:37 AM

The suspension forces are all those you mentioned, but the load is spring only (k*x).

I was browsing my code yesterday, and I'd correct myself:

I have a separate mass for the car body and for the wheels.

So my tire load is the suspension force (see above) and I add the force that the wheel generates due to gravity.

Transform the gravity vector (probably 0,-9.81,0) to the tire space and add the vertical component to the suspension force (k*x)

157
Like
0Likes
Like

Posted 04 February 2014 - 08:14 AM

Transform the gravity vector (probably 0,-9.81,0) to the tire space and add the vertical component to the suspension force (k*x)

So it would be like:
weight = 20 * 9.81;
Right?

Also I corrected my pacejka combining method, and now my slip angle and ratio calculations produce a bit better values(without relaaxation lengths). But I still have to use some damping values, otherwise id run into some numerical occlisions causing the car to jitter alot.

Heres some code:

w=tireVelocity;
u=lonVelocity;
v=latVelocity;

damping = Clamp01( localVelocityMagnitude/ 4.0f );
slipRatio = (w - u) / Abs(u) * damping;
slipAngle = Atan(v/Abs(u)) * damping;

This works quite ok, but the car is still slightly sliding forwards and to the right. Looking at the telemetry I see this:

(wheels: front left, front right, rear left, rear right)
->First frame:
sr: -0.02, -0.02, -0.02, -0.02
sa: -0.02, 0.02, 0.02, -0.02
Fz: 2112.88, 2112.87, 1944.72, 1944.72
Lon: -1228.94, -1228.93, -1146.63, -1146.62
Lat: 13.24, -13.24, -11.57, 11.59

->Second frame:

sr: 0.01, 0.01, 0.01, 0.01
sa: 0.01, -0.01, -0.01, 0.01
Fz: 2127.98, 2127.97, 1929.89, 1929.89
Lon: 1220.38, 1220.37, 1112.45, 1112.45
Lat: -13.13, 13.13, 11.17, -11.18
As I notice the jumping in sr and sa is about 0.02 in the first frame, its exactly the same as my simulation deltaTime (50hz)
But the second frame looks to be half of it (dunno if there is any sense) But this I guess is causing the movement, if the jump would be from -0.02 to 0.02 the car would not move from its position.

But the secodn thing is that if the road is angled, the car starts to slide. If I use the method described here (the sae damping) for low speeds the slip ratio gets better, but still jumps a little. When I use the lateral version I get some strange springi action after a stop in sideways (example a drift fail etc.).

So is there a cure for this behaviour?

Also, bmarci, Are you applying suspensiopn froces in world cordinates or car/wheel cordinates? As I understand suspension forces should be applyed in world cordinates, am I right?

### #18bmarci  Members

746
Like
0Likes
Like

Posted 04 February 2014 - 03:00 PM

So it would be like:
weight = 20 * 9.81;
Right?

Basically yes, but the "weight" vector can change depending on the wheel orientation, eg: on sloped surface it's smaller.

As I notice the jumping in sr and sa is about 0.02 in the first frame, its exactly the same as my simulation deltaTime (50hz)

Uhh-Uhh,

The 50Hz seems quite a big timestep, especially for stiff suspensions and tire. I'd suggest 500-1000Hz

Also, bmarci, Are you applying suspensiopn froces in world cordinates or car/wheel cordinates? As I understand suspension forces should be applyed in world cordinates, am I right?

Yes, I apply every forces in world space but calculate them in their own, tire forces in tire space...etc

If your physics engine supports eg: body->ApplyForceInBodySpace() you can use that and you save some tansformation since some of the forces are already in body space.

You can apply the suspension force at the attachment point at first.

It's an interesting topic because not all forces are applied at the contact point. And depending on the suspension geometry different forces act on the various suspension links, and this is the point where you get nowhere with your super formulas without exact knowledge of race car suspension setups.

So my rule of thumb is, simplify, simplify, simplify...

157
Like
0Likes
Like

Posted 05 February 2014 - 02:27 AM

The 50Hz seems quite a big timestep, especially for stiff suspensions and tire. I'd suggest 500-1000Hz

This is strange, because when I go from a fixed timestep of 0.02 to 0.002, a 500hz simulation (1/0.002) I get a pretty bouncy suspension with 50k springs.

How are you calculating your suspension compression? Is it normalized or in it's range, because when I normalize it (from range of 0 to 1) I get to stiff suspension with 50k springs... Also as for dampers, are you calculating the velocity over time like (compression-lastcompression)/timestep?

Currently I'm applying all the force to the contact patch position so I can get some bodyroll with realistic cg heights. Will try applying suspensions force at the spring connection position, see if something changes or not, one thing I'm thinking of is to angle the force towards tire contact patch to get some sort of physically correct feedback with it, dunno if it would work like i'm thinking hehe..

### #20bmarci  Members

746
Like
0Likes
Like

Posted 05 February 2014 - 12:11 PM

How are you calculating your suspension compression? Is it normalized or in it's range,

No, I use it as a length of compression in meters.

Also as for dampers, are you calculating the velocity over time like (compression-lastcompression)/timestep?

Exactly.

one thing I'm thinking of is to angle the force towards tire contact patch to get some sort of physically correct feedback with it, dunno if it would work like i'm thinking hehe..

First I just simply made a "spring" with damper, only one, that I dropped from 2-3 meters. No side forces, just vertical spring on a flat ground, and see how does it behave.

It is at least good to see the suspension in controlled envitonment.

A simple vertical model should work fine, adding angle to it just makes it more "difficult" because the forces don't neccesarily act along that axis, at least not at the contact point.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.