Jump to content

  • Log In with Google      Sign In   
  • Create Account


Calculate best car gear


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.

  • You cannot reply to this topic
5 replies to this topic

#1 mr_malee   Members   -  Reputation: 135

Like
0Likes
Like

Posted 23 September 2013 - 08:34 PM

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?



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 23992

Like
2Likes
Like

Posted 23 September 2013 - 08:38 PM

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

Edited by Hodgman, 23 September 2013 - 08:39 PM.


#3 mr_malee   Members   -  Reputation: 135

Like
1Likes
Like

Posted 23 September 2013 - 10:55 PM

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.



#4 Álvaro   Crossbones+   -  Reputation: 10625

Like
0Likes
Like

Posted 24 September 2013 - 02:28 AM

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.

#5 mr_malee   Members   -  Reputation: 135

Like
1Likes
Like

Posted 25 September 2013 - 01:33 PM

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. 


Edited by mr_malee, 25 September 2013 - 01:35 PM.


#6 CombatWombat   Members   -  Reputation: 370

Like
0Likes
Like

Posted 27 September 2013 - 10:02 AM

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






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.



PARTNERS