Skip to main content
GameDev.net gamedev.net
🔒 Locked

Car Physics - Loose speed when shift up gear !?

Started by jujunosuke Jul 29, 2010 at 9:49 AM 25 replies 13.7k views
Original Post
jujunosuke
jujunosuke
Hello everyone !

I have problem with my car simulation when i shift up gears.
I am loosing engine rpm and speed.

I work with the Marco Monster Car Physics Tutorial as reference.


In fact, i understand why i loose rpm, it is pretty logic, but i can't figure how to fix it.

Here is the demo i have done so far.
demo 1.0
Arrows Forward and Back = Acceleration, Brake.
Arrows Up Down = Shift gears.

If i shit up gear, i will have less power right ?
So, if i have less Fdrive and a Air Drag that grew up with the speed, how can my rpm go up ?

This is my problem actually...
Everything looks normal, the faxt that rpm go down when i shift up gear looks ok, but then, i need to get more rpm in order to see the difference of speed.


By the way, the problem may come from here :
This is how i calculate the km/h of the car.


In the first part of the tutorial, i move my car with the posX update.
on my simulation, my car have a 42.5 pixel of radius wheel.

simWheelLength = (42.5 * 2 * PI);degreesOfRotationPerFrame = (engine.velocity / simWheelLength) * 360;degreesOfRotationPerSecond = degreesOfRotationPerFrame * 30;			rps = degreesOfRotationPerSecond / 360;//this is how i get my km/h (0.34 meters is my car wheel value)kmh = ((rps * 0.34) * 3600) / 1000;										var t = kmh * 1000 / 3600;//then i pass the rpm of the wheelengine.rpmWheel = t / 0.34;



Inside my Engine Class
//=========================================================================// GET RPM ENGINE		//=========================================================================public function getRpmEngine():Number {     rpmEngine = ((rpmWheel * gearRatios[currentGear] * differentialRatio) * 60) / (2 * PI);     return rpmEngine;}//This is how i get my FdrivemaxTorque = getTorqueCurve( getRpmEngine() );Tdrive =  maxTorque * gearRatios[currentGear] * differentialRatio;Fdrive = Tdrive / 0.34;



I don't know how to get the the angular velocity properly, so i used the tricky way of the km/h technique in order to get the rpm...

Any help would be greatly appreciated !

Thank you for reading !


// fixed title - missing f in shift

[Edited by - LessBread on July 29, 2010 12:04:47 PM]
kunos
kunos
Quote:
Original post by jujunosuke
In the first part of the tutorial, i move my car with the posX update.
on my simulation, my car have a 42.5 pixel of radius wheel.


that's suspicious. a "pixel" isn't a physical valid value. If you're using real values (at least in the same ballpark as the real ones) you shouln't mix it with non physical values like pixels... you might be simulating a car with a 42 meters radius wheel.. that's one HUGE wheel.

jujunosuke
jujunosuke
I know what you mean here, but, the car and the pixels values are just a graphical representation of the car.

Based on the tutorial, the velocity i get from the equation allow me to move my car ?
The graphical representation just help me to see how fast the car is moving forward to get the rpm of the rear wheel.

I may be wrong, but i don't think that the graphical representation perturb the other values.
Noobico
Noobico
Hi,

I just took a look at your simulation...
How do you get the right torque? For the right torque it seems you need the Rpm of the engine and to know on which gear you are running.

Did you take this image into account?
Torque curve per Gear

It shows that the torque of gear 1 for example only works well till ~600rpm after that the torque does not grow anymore (maybe even become 0???) -> you do not accelerate anymore (hopefully i got that right)

I do not study physics and i never coded anything regarding physics but maybe i pointed you in the right direction.

Regards,
Noobico

PS: if you got the torque right maybe you missed this part of your reference.
Quote:
The Chicken and the Egg

Some people get confused at this point. We need the rpm to calculate the torque, but the rpm depends on the rear wheel rotation rate which depends on the torque. Surely, this is a circular definition, a chicken and egg situation?

This is an example of a Differential Equation: we have equations for different variables that mutually depend on each other. But we've already seen another example of this before: air resistance depends on speed, yet the speed depends on air resistance because that influences the acceleration.

To solve differential equations in computer programs we use the technique of numeric integration: if we know all the values at time t, we can work out the values at time t + delta. In other words, rather than trying to solve these mutually dependent equations by going into an infinite loop, we take snapshots in time and plug in values from the previous snapshot to work out the values of the new snapshot. Just use the old values from the previous iteration to calculate the new values for the current iteration. If the time step is small enough, it will give you the results you need.

There's a lot of theory on differential equations and numeric integration. One of the problems is that a numeric integrator can "blow up" if the time step isn't small enough. Instead of well-behaved values, they suddenly shoot to infinity because small errors are multiplied quickly into larger and larger errors. Decreasing the time step can help, but costs more cpu cycles. An alternative is to use a smarter integrator, e.g. RK4. For more information on this topic, see my article on numerical stability:Achieving a Stable Simulator


[Edited by - Noobico on July 29, 2010 2:18:15 PM]
jujunosuke
jujunosuke
Hello ! thank you for taking time to reply.

The article say :
Quote:

The engine's torque curve is shown as well for reference, it's the bottom one in black. The other curves show the torque on the rear axle for a given rpm of the axle (!), rather than the engine.


So, when you talk about 600 rpm, you should precise wheels rpm, and not engine rpm. An engine need about ~1000 rpm, otherwise it will stall.


Than mean with a Differential ratio of 3.42 and a first gear of 2.66 = ~9.1 of total rate.

so, if the engine run at 1000 rpm
the rear wheel will rotate at (1000 rpm / 9.1 ratio) = ~110 rpm.

Engine 1000 rpm == Wheel 110 rpm.

Then, the article say :
Quote:

This means 1000 rpm of the rear axle is 36 m/s or 128 km/h car speed.


Wheel 1000 rpm == 128 km/h

And if you look at my simulation, when the rpm of the wheel are at 1000, i am really close to that speed !


That mean that my Torque curve is quite well implemented and very close to the original one !
In a previous post, unbird help me to implement it.

So, everything looks very correct mechanically, that's why i still do not understand why i am loosing speed and rpm when shift up gear :(
Katie
Katie
Is it possible you're shifting up too early? Generally when driving a non-diesel, one shifts up at 4-5000 rpm. If you're driving a sports car properly, you do it at the top of the rev range (which is usually about 6000 - 6500, unless you've bought a Honda with their bonkers 2litre).



The engine torque output looks like this;

http://www.corvettemuseum.com/specs/2001/images/graph.jpg

Note how the peak torque is at about 5500. Since the gears provide a constant torque adjustment, the peak torque in a gear is in the SAME PLACE in the engine rev range. It's only at a different road wheel speed. One should change up just after that peak.


Noobico
Noobico
Your RPMEngine is directly connected to the gear ratio, which decreases if you shift up -> RPMEngine decrease -> Fdrive decreases (if torque does not increase) -> car slower(?)

The acceleration is slower on high gears so acceleration seems alright.

But obviously something is wrong because the highest speed is achieved with the lowest gear.

How do you calculate the acceleration? (seems to be connected with engine.velocity). Which parameters/constants are limiting the maximum speed? Is the maximum speed directly connected with Fdrive (if so it needs to increase after shifting up in some way)


mrchrismnh
mrchrismnh
The speed becomes loose? How so?
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

hangfire
hangfire
How bizarre, i'm trying to do the same thing and getting the same issue.

My "Corvette" is way faster in 1st gear than in 6th.

Here’s my pseudo code

1) Take current speed and convert to engine RPM (e.g. 25mph = 11.2 mps = 2860 RPM)
2) Convert RPM to Torque using linear interpolation and percentage of throttle (2600 RPM = 451 Nm @100% throttle)
3) Convert Torque to driving force (Torque * diff * gear * trans efficiency / wheel radius) 451 Nm = 8447 N
4) Convert that force to acceleration (8447 / 1500 = 5.6m/s)
5) Calculate new speed from current speed and acceleration.

At the moment I’m not accounting for weight shift.

As you can see 1st will always be preferable as it delivers more force thus more acceleration. My sim car actually tops out at 295mph!!!

Somewhere, there is a step missing but I can't figure it out.

Hang
Emergent
Emergent
Quote:
Original post by hangfire
My "Corvette" is way faster in 1st gear than in 6th.
[...]
As you can see 1st will always be preferable as it delivers more force thus more acceleration. My sim car actually tops out at 295mph!!!

Somewhere, there is a step missing but I can't figure it out.


You need to cap your engine RPM at its maximum. What would your engine RPM need to be for your car to achieve 200 mph in first gear?
hangfire
hangfire
Hi Emergent,
Thanks for the response.

I'm clamping the RPM between 1000 and 6000.

It's a vicious circle, as the speed increases so the RPM increases and so the Torque increases. In first gear it gets to 6000 RPM quite quick, but according to the equations that leaves bags of power to keep on accelerating.

Eventually the amount of Force being output by the engine matches the resistive forces and you get a max speed, this is working out at about 135mph in 6th, but 295 in 1st.

Any other thoughts?

Hang

Noobico
Noobico
Yes i see this vicious cycle too...

The problem seems to be in the calculation of Torque? If higher RPMEngine automatically means higher torque something is terribly wrong.

Maybe you forgot the slip ratio mentioned in the reference?
Gear 1 gives you a lot of power but you cannot get it on the ground. To be honest i did not actually get the content of the chapter but it is possibly the solution. (Slip ratio and traction force at Marco Monster Car Physics Tutorial)




hangfire
hangfire
I must admit i haven't programmed that in, but I've got a text box showing me the drive force which I make sure doesn't go over 7350 N.

I have an idea, but I can't try it out until monday - doh!

I interpolate between 395N and 490N when rpm is 1000-4400 and then interpolate between 490N and 395N when rpm 4400-6000.

Perhaps I should clamp rpm to 7000, but interpolate between 490N and 0. Might simulate the needle bouncing when in the red zone and would mean the engine outputs alot less torque at high revs.

I'll have a go and see what happens.

hang
Emergent
Emergent
Quote:
Original post by hangfire
I'm clamping the RPM between 1000 and 6000.


Then how are you going any faster, in first gear, than

6000 RPM * GEAR_RATIO_IN_FIRST_GEAR * WHEEL_CIRCUMFERENCE ?


Quote:
In first gear it gets to 6000 RPM quite quick, but according to the equations that leaves bags of power to keep on accelerating.


...which is why you need to switch to second gear at that point?

Quote:
It's a vicious circle, as the speed increases so the RPM increases and so the Torque increases.


...up until about 4.5k RPM, at which point, according to your graph, torque starts to drop off, right?

Quote:
I interpolate between 395N and 490N when rpm is 1000-4400 and then interpolate between 490N and 395N when rpm 4400-6000.


I'm confused. Newtons (N) are a unit of force. Your engine produces torque, which is in Newton-meters (N-m).
kunos
kunos
Quote:
Original post by hangfire
I'm clamping the RPM between 1000 and 6000.


you mustn't clamp it, you should let it accelerate, after 6000 you should have the torque delivered quickly falling towards 0.
In case you want to simulate a rev limiter you need to consider a torque of 0 when the rpm are > than the rev rpm limit.


Emergent
Emergent
Quote:
Original post by kunos
you mustn't clamp it, you should let it accelerate, after 6000 you should have the torque delivered quickly falling towards 0.
In case you want to simulate a rev limiter you need to consider a torque of 0 when the rpm are > than the rev rpm limit.


Yeah, that's better advice in the long run.
jujunosuke
jujunosuke
Quote:
How bizarre, i'm trying to do the same thing and getting the same issue.


I am happy to know that i am not getting this vicious circle alone...

Quote:
I'm clamping the RPM between 1000 and 6000.

I am doing the same ! :(

Quote:
you mustn't clamp it, you should let it accelerate, after 6000 you should have the torque delivered quickly falling towards 0.
In case you want to simulate a rev limiter you need to consider a torque of 0 when the rpm are > than the rev rpm limit.


I will try that and see what's happen.

Thank you everyone for your great help !

hangfire, if you make it work please explain ;)

If i can make it work i will definitely post the sources somewhere.
This can be great help for a lot of people.

Jujunosuke
unbird
unbird
Well, since I was "responsible" for your one-gear solution then, here my question: Do you still use the hack with the parabola for the torque-per-gear curve ? If so, make sure it looks closely to the graph in the article (draw the graphs or at least show us the code). Maybe your simulation is not wrong at all but instead the numbers you feed are not appropriate (again: remember, you had a too fast car then using a unrealistic power, not because the formulas were wrong).

Other than that: Make sure you got your units right (this applies to you, too, hangfire, you once called an acceleration m/s, which is actually the unit for velocity). And don't mix it with screen/pixel units at all. This should be done only at the rendering step. Personally, I wouldn't use degrees either and prefer radians during the calculation, too. Those conversions can likely be overlooked or forgotten.

In this regard, one thing caught my eye:
var t = kmh * 1000 / 3600;//then i pass the rpm of the wheelengine.rpmWheel = t / 0.34;

So t's unit is m/s, the 0.34 is meter, so the unit of (t / 0.34) is 1/s. This is rate per second, not rate per minute. So it should rather be
engine.rpmWheel = t / 0.34 * 60;

Sure, later, in your getRpmEngine() function you got this *60 scale, so maybe the calculation is ok, but it's preferable to match variable names to the unit they represent.

Can you both post your full (simulation-relevant) source code, please ? Maybe I find some time to look into it.
jujunosuke
jujunosuke
Omg, Unbird !
Miss you :D

Quote:
since I was "responsible"

You are only responsible to make me understand a lot of stuff, so thank you !

Quote:

Do you still use the hack with the parabola for the torque-per-gear curve ?


In fact, yes and no, i explain.
Since i was not familiar with the formulas that you gave to me, i just change it a little bit in order to get more control with the values.

I am sure that i can get as much control with your parabola, but i just needed to get something easier for me.

So basically i came out with 2 Cubic curves.
Here is the code :

//=========================================================================// POW2//=========================================================================public function pow2( value:Number ):Number {	return (value * value);}//=========================================================================// GET TORQUE CURVE//=========================================================================public function getTorqueCurve( rpm:Number ):Number {	var TorqueStart:Number = 395;	var TorqueMax:Number = 475;	var TorqueEnd:Number = 390;	var rpmMin:Number = 1000;	var rpmMax:Number = 4400;	var redLine:Number = 6000;	if (rpm <= rpmMin) {		rpm = rpmMin;	}	if (rpm >= redLine) {		rpm = redLine;	}	if (rpm <= rpmMax) {		return easeOut((rpm-rpmMin) * (1/rpmMax), TorqueStart, (TorqueMax-TorqueStart));	}else {		return easeIn((rpm-rpmMax) * (1/(redLine-rpmMax)), TorqueMax, -(TorqueMax-TorqueEnd));	}}


The wrong point is that i thaught it would be better to clamp values between 1000 and 6000...

But beside that the curve looks pretty similar to the one in the article.


Thank you very much for your help, i will post the full code in my next post very soon.
I just need to take a little time to clean it up and put comments for easy understanding.

In fact, the code is not that long.

That is just a bunch of functions with some conversion values.
But cannot make it work though :)
unbird
unbird
Quote:
You are only responsible to make me understand a lot of stuff, so thank you !
That's why I put quotes [smile].

Update: Since both of you experience the same erroneous behavior I suspect some error in the article. I'm currently investigating...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.