Calculate best car gear

Started by
4 comments, last by CombatWombat 10 years, 6 months ago

Hi. I'm having some trouble trying to determine the best gear a car should be in to maximize acceleration.

I'm not looking for the perfect point at which to change gears to maximize acceleration.

I can get the current rpm of the car, the current speed, the current torque, optimal RPM's for gear ratios, engine torque for rpm, rpm from speed, and gear ratios.

I'm just not sure how to figure out what gear I should be in to get the best acceleration possible.

for example:

say I'm driving my car, I manage to shift all the way to 5th gear, going very fast. I suddenly crash, my speed reduces (but not to 0), I'm still in 5th gear. My acceleration now is very small, I should change gears, but to which gear in order to accelerate the fastest?

another example:

say I'm in 5th gear travelling very fast, I accidentally shift into 2nd, the rpm's rise quickly to the redline, my speed drops. What gear should I change into so that my engine doesn't explode and my acceleration will continue to increase?

Advertisement
You could just search sequentially, trying each gear until the RPMs get close enough to where they should be. e.g.
if RPM < optimal_RPM-threshold and gear > 1
  gear --
 
if RPM > optimal_RPM+threshold and gear < max_gear
  gear ++

wait half a second for the engine to respond to new gear
repeat

thanks for the reply. However, I'm looking at something that can give me an instant estimate.

The reason being that the gear is used as an indication/guide to the player so that they can change gears appropriately.

The player needs almost instant feedback so they can make the required actions.

The variable `gear' in Hodgman's code could represent the current recommendation, and the "wait half a second" can be skipped if it's not appropriate for what you have in mind.

I ended up with something like this:


//find the current gear ratio
float currentRatio = gearRatios[currentGear];

if (currentRatio > 0) {

	float bestDist = float.PositiveInfinity;
	int bestGear = currentGear;
	
	int i, len = gears.Length;
	
	//start at index 2 (gear 1)
	//index 0 = reverse
	//index 1 = neutral

	for (i = 2; i < len; i++) {
	
		//find the gear ratio and the ratio to move into this gear from the current
		float gearRatio = gearRatios[i];
		float moveRatio = gearRatio / currentRatio;
		
		//find Optimal rpm. These are pre-calculated for each gear. They are generally around the redline mark (8000rpm for my car)
		float rpmOptimal = optimalRPM[i];
		
		//find the next rpm which the engine would produce if moving into this gear		
		float rpmNext = moveRatio * currentRPM;
		
		//find distance between optimal and next		
		float rpmDist = rpmOptimal - rpmNext;
		
		//if the next rpm is < maxRPM, the distance is above 0 (hasn't crossed optimal) and is < the current best, then this is a contender for the best gear

		if (rpmNext < maxRPM && rpmDist >= 0 && rpmDist < bestDist) {

			bestDist = rpmDist;
			bestGear = i;
		}
	}
}

So far it's working nicely.

It will be the gear which puts your engine at the highest point of it's power curve.

This topic is closed to new replies.

Advertisement