Advertisement

Car Physics: RPM/Torque and max speed problem.

Started by November 19, 2011 03:45 PM
4 comments, last by kunos 12 years, 10 months ago
Hello,

I am currently implementing 2d car physics for my game and I am facing a problem that somehow I cannot overcome on my own.

I am using this paper/tutorial as a reference:

http://regedit.i365....or%20Games.html

The problem is the following.

I calculate RPM from wheel angular velocity. That value I plug-in to an equation that lookups engine torque from a curve. Generally the higher RPM the grater value of torque up to some point (lets say 4500 rpm).

Then as the paper says I use those multiplayers that converts the engine(crankshaft?) torque to rear axle torque using gear ratios and differential.

Because of that when I use 1st gear I get highest rear axle torque therfore highest top speed. When I gear up I loose speed. This should not happen and I tried a lot of different things modifications etc.

The way I update physics looks like this:


void DoPhysics(float dt)
{
UpdateDrag(); UpdateFriction(); // drag/friction

// Calculate drive wheel Angular Velocity.
AngularVelocity = GetWheelAngularVelocity(dt);
//AngularVelocity = Speed / WheelRadius; // <- suggested easy solution (sort of a hack) but it also did not gave good result.
// Plug-in to calculate engine RPM.
RPM = CalculateRPM(AngularVelocity);
// Use RPM to get the engine Torque.
EngineTorque = Throttle * m_engine.GetTorque(RPM);

Direction = Vec2(-sinf(Rotation), cosf(Rotation));

float CrankshaftMultiplyer = GearRatios[CurrentGear] * DifferentialRatio;
DriveTorque = EngineTorque * CrankshaftMultiplyer * TransmissionEfficiency;
DriveForce = Direction * (DriveTorque / WheelRadius);

// Update Traction force taking Dynamic Weight Transfer into account.
UpdateAxlesWeight();
if(RearAxleWeight*TyreFrictionCoefficient < DriveForce.y)
TractionForce = Direction*RearAxleWeight*TyreFrictionCoefficient;
else
TractionForce = DriveForce;

float sign = fast_sign(TractionForce.y);

LongtitudinalForce = sign * D3DXVec2Length(&TractionForce) + (-Direction.y)*(DragForce + WheelFrictionForce);

Acceleration = LongtitudinalForce / Mass;

// Hack ?
if(Acceleration <= 1.0f*D3DX_16F_EPSILON && Acceleration >= 1.0f*D3DX_16F_EPSILON)
Acceleration = 0.0f;

//float WheelRPM = RPM / CrankshaftMultiplyer;
//float RevolutionDisplacement = 2.0f * D3DX_PI * WheelRadius;
//float WheelRotationsPerSecond = WheelRPM / 60.0f;
//float WheelMetersPerSecond = WheelRotationsPerSecond * RevolutionDisplacement;

//if(Speed > WheelMetersPerSecond)
// Speed = WheelMetersPerSecond;

Speed += Acceleration * dt;

Position += Direction* Speed * dt * 10.0f;
}



And this is how I calculate WheelAngularVelocity and RPM

float GetWheelAngularVelocity(float dt)
{
float TractionTorque = TractionForce.y * WheelRadius;
float TotalTorque = TractionTorque + EngineTorque*GearRatios[CurrentGear] * DifferentialRatio * TransmissionEfficiency;
AngularAcceleration = TotalTorque / AxleInertia;

AngularVelocity += AngularAcceleration * dt;

if(Speed/WheelRadius > AngularVelocity)
AngularVelocity = Speed / WheelRadius;

return AngularVelocity;
}

float CalculateRPM(float wheelAngularVelocity)
{ // Calculates the RPM from wheel angular velocity.
float rpm = wheelAngularVelocity * GearRatios[CurrentGear] * DifferentialRatio; /* * 60.0f / (2.0f*D3DX_PI); */

if(rpm < 1000)
rpm = 1000;

return rpm; }



Did anyone use the mentioned tutorial for reference and managed to implement proper RPM/torque/gearing behaviour ?

Thanks in advance for all replies.

Edit:

I have tried playing around with those values and I noticed one thing. If I hardcode RPM to be equal 4500 in the code and use those commented out lines just before integration of speed I get the result similar to the one from the paper.

I mean:



float WheelRPM = RPM / CrankshaftMultiplyer;
float RevolutionDisplacement = 2.0f * D3DX_PI * WheelRadius;
float WheelRotationsPerSecond = WheelRPM / 60.0f;
float WheelMetersPerSecond = WheelRotationsPerSecond * RevolutionDisplacement;
Speed = WheelMetersPerSecond;


[font="Arial"]Then the car has proper speed.[/font][font="Arial"]4500 RPM @ 1 gear gives approx 62km/h[/font][font="Arial"]4500 RPM @ 2 gear makes it faster and faster till 5th gear which gives 220km/h. This is realistic behaviour since at 4500RPM the engine gives the highest value of torque.[/font][font="Arial"]But I notice that acceleration is negative that is why when I do calculation of speed using this acceleration it is capped and never reaches those proper values.[/font]
"[color=#1C2837][size=2]Because of that when I use 1st gear I get highest rear axle torque therfore highest top speed.[color=#1C2837][size=2] "
[color="#1c2837"]

[color="#1c2837"]that's wrong. higher torque in no way affects your top speed.
[color="#1c2837"]in fact, due to mechanical limitations of the combustion engine, a higher torque ratio will produce a lower top speed.
[color="#1c2837"]

[color="#1c2837"]First gear should max out at around 40mph, 2nd at 60, and so on.
[color="#1c2837"]As your transmission ratio goes up, torque goes down and top speed goes up.
[color="#1c2837"]

[color="#1c2837"]The equations:
[color="#1c2837"]Engine Torque / trans ratio = output torque
[color="#1c2837"]output speed / [color=#1C2837][size=2]trans [color="#1c2837"]ratio = engine speed
[color="#1c2837"]

[color="#1c2837"]Some numbers:
[color=#1C2837][size=2]trans[color=#1C2837][size=2] [color="#1c2837"]ratio = 0.5 (first gear)
[color="#1c2837"]engine torque = 100
[color="#1c2837"]output torque <- 200
[color="#1c2837"]

[color="#1c2837"]output speed = 10
[color="#1c2837"]engine speed <- 20
[color="#1c2837"]

[color="#1c2837"]2nd gear:
[color=#1C2837][size=2]trans[color=#1C2837][size=2] [color="#1c2837"]ratio = 0.75
[color="#1c2837"]engine torque = 100
[color="#1c2837"]output torque <- 133
[color="#1c2837"]

[color="#1c2837"]output speed = 10
[color="#1c2837"]engine speed <- 13
[color="#1c2837"]

[color="#1c2837"]third gear:
[color="#1c2837"]torque ratio = 1.0
[color="#1c2837"]engine torque = 100
[color="#1c2837"]output torque <- 100
[color="#1c2837"]

[color="#1c2837"]output speed = 10
[color="#1c2837"]engine speed <- 10
[color="#1c2837"]

[color="#1c2837"]

[color="#1c2837"]One thing to note, as the torque drops in higher gears, drag may overcome the the acceleration from the engine and net a negative acceleration.
Advertisement
The acceleration becomes negative in higher gears but modifying drag doesn't fix anything.

I guess that is why I can top my speed at 1 gear where I get highest drive troque, therfore force and acceleration in result.

There is a problem with RPM. When I change gear up, the RPM's of the engine drop which is obvious but the car does not gain speed, so it doesn't increase wheel angular velocity and because of that RPM don't increase.

It is a vicious circle.

First I calculate angular velocity of a wheel:
if(Throttle > 0.0f)
AngularVelocity = GetWheelAngularVelocity(dt); // calculate wheel velocity
else
AngularVelocity = Speed / WheelRadius; // no throttle wheels rolling


Then I use this velocity to get RPM:
// Plug-in to calculate engine RPM.
RPM = CalculateRPM(AngularVelocity);

// Use RPM to get the engine Torque.
EngineTorque = Throttle * GetEngineTorque(RPM);



When I have engine torque, I use those gearing ratios to calculate DriveTorque and from that by dividing by wheel radius I convert it to the actual driving force:
float CrankshaftMultiplyer = GearRatios[CurrentGear] * DifferentialRatio;
DriveTorque = EngineTorque * CrankshaftMultiplyer * TransmissionEfficiency;
DriveForce = Direction * (DriveTorque / WheelRadius);

// Update Traction force taking Dynamic Weight Transfer into account.
TractionForce = DriveForce;

UpdateAxlesWeight(dt);
if(RearAxleWeight*TyreFrictionCoefficient < DriveForce.y)
{
TractionForce = Direction*RearAxleWeight*TyreFrictionCoefficient;
}
else
TractionForce = DriveForce;



Above I also do the dynamic weight shifting calculation if there was more drive force provided than the load on the rear axle and if so I cap the drive force to the rear axle weight.

This TractionForce is used to calculate acceleration (a = F / m) so at this stage I apply drag with negative direction.

Rest is just plain and simple I use this Acceleration to change speed of the car and use speed to change position.

So the car accelerates and gains most speed on 1st gear with top RPM's (6000) change of gear to higher doesn't make it go faster. It just makes RPM's drop and result in less torque, therforce smaller TractionForce which in turn with a DragForce makes acceleration even smaller, eventually negative.

Where do I made a mistake ? I really don't know how to modify things I am calculating to eventually start working as they should.

I obviously must be missing something.

In first post I included those two functions that calculate RPM and WheelAngularVelocity but I analyzed the steps I did dozen of times and It pretty much covers with what was written in the article.
Did you ever solve this ?

I am using the same paper and ran into the same problem.
I think its because I still haven't got my head around how to calculate the drive force on the car using torque and angular acceleration of the wheel.

I can see how drag limits the cars top speed, because drag force is squared by velocity.
And as you change up gears to increase speed, you are reducing torque until the point where torque and drag cancel out.
So you don't have to program anything to put a fixed limit on the cars top speed as the physics will do it for you.

But how is the cars speed limited by the first gear ratio?
I know I could calculate out the max_speed for the gear your in, using the wheel size, gear, max rpm.
And then create a if (speed > max_speed) acceleration = 0;

But I was thinking that like drag is it calculated in linear equation that I am just not seeing ?
My advice would be to just delete the drag force for now, and just make your test again without it.
Some times ago i followed the same paper, and the drag force was too strong.

Also, what are your debug tools ?
You should log as many infos as possible on your sim.

But how is the cars speed limited by the first gear ratio?


it is limited by maximum engine speed. Engine cannot exceed a given rotation speed (this depends on the engine design itself). In first gear, speed is low so drag doesn't enter in the picture. The car accelerates until the engine reach it's maximum rpm. This happens very quickly because the gear will demultiplicate the engine speed at the wheel.. typical ratio for a road car is 12:1, so your engine will be rotating 12 times faster than the wheels. Most cars are fitted with a "rev limiter".. once a certain rpm is reached, the electric power is cut from the spark and the torque goes negative because of friction.. so you get the typical "rev limiter sound". Older cars were not fitted with a limiter, here the available torque quickly goes down after the max rpm point but the engine is not "protected" against over revvs, and it is up to the driver to avoid running for too long over the "red line".

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

This topic is closed to new replies.

Advertisement