Sign in to follow this  

Car transmission model

This topic is 818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, 

 

I'm reviewing a car transmission model for a basic racing game, and I've noticed a slight discrepancy between what I would expect of the macroscopic properties of the model (when changing gear) and the numerical results.

 

Here is the basic model:

from math import pi
import numpy as np


class Car:

	gearRatios = []
	maxTorqueArray = []
	rpmAtMaxTorque = []

	wheelRadius = 0.0
	differentialRatio = 0.0
	Cd = 0.0
	Crr = 0.0
	transmissionEfficiency = 0.0
	mass = 0

	def __init__(self):
		self.speed = 0.0
		self.acceleration = 0.0
		self.currentGear = 1
	
	def update(self, dt):
		throttle = 1.0

		# Gear ratios
		assert self.currentGear > 0
		currentGearRatio = self.gearRatios[self.currentGear - 1]
		effectiveGearRatio = self.differentialRatio * currentGearRatio
		transmission = effectiveGearRatio * self.transmissionEfficiency

		wheelCircumference = 2 * pi * self.wheelRadius

		# Find RPM
		wheelRPM = (self.speed / wheelCircumference) * 60
		engineRPM = wheelRPM * transmission
		engineRPM = min(max(engineRPM, self.rpmAtMaxTorque[0]), self.rpmAtMaxTorque[-1])

		# Find torque at RPM
		maxTorque = np.interp(engineRPM, self.rpmAtMaxTorque, self.maxTorqueArray)
		engineTorque = maxTorque * throttle
		wheelTorque = engineTorque * transmission
		tractionForce = wheelTorque / self.wheelRadius

		# Resolve forces
		dragForce = -self.Cd * self.speed * abs(self.speed)
		rollingResistanceForce = -self.Cd * 30 * self.speed

		# Resultant
		resultantForce = tractionForce + dragForce + rollingResistanceForce

		self.acceleration = resultantForce / self.mass
		self.speed += self.acceleration * dt

		self.currentForce = resultantForce
		self.currentRPM = engineRPM
		self.currentSpeed = self.speed
		self.currentTorque = wheelTorque


class BoxsterS2004(Car):

	gearRatios = [3.82, 2.20, 1.52, 1.22, 1.02, 0.84]
	maxTorqueArray = [220, 220, 310, 220]
	rpmAtMaxTorque = [0, 1000, 4500, 6600]

	wheelRadius = 0.345
	differentialRatio = 3.42
	Cd = 0.32
	transmissionEfficiency = 0.7
	mass = 1300


if __name__ == "__main__":
	car = BoxsterS2004()
	dt = 1 / 60
	
	while True:
		car.update(dt)

Now, in it's actual implementation, I'm running the update function in a fixed-step game loop, which allows me to inspect the car state and shift gear at runtime.

 

Now, the behaviour:

It is to be expected that the force of the car drops according to the speed for the same power.

It is also to be expected that the car cannot reach as high a speed in lower gears.

 

Yet, for these parameters, the top speed can only be reached in 1st gear, and decelerates according as the gears are shifted higher.

I'm not sure why this happens. It makes sense that the acceleration rate is lesser for higher speeds, because the drag force is proportional to v^2, and the force of the engine falls with higher gears, but my resultant forces are negative for higher gears when they're not for the lower gears. Shifting at any point reduces the max speed achievable.

 

Evidently, I don't quite understand the model well enough, could anyone point me in the right direction?

To my mind, given that the driving force of the car falls off at 

Share this post


Link to post
Share on other sites

Ddoes your engine model have a torque curve?

This is really the reason we have multiple gears in a combustion engine in the first place.

 

As you increase the rpm in a low gear, The torque will rise up to a peak and then fall down again, forcing you to shift up to get back into the peak region.

Share this post


Link to post
Share on other sites

Indeed, the torque curve is defined as follows (see the BoxsterS2004 class)

maxTorqueArray = [220, 220, 310, 220]
rpmAtMaxTorque = [0, 1000, 4500, 6600]

Where maxTorqueArray are the Y values for the rpmAtMaxTorque X values.

 

I can see that the descending gear ratios will shift the engine back into the max torque region, but the applied force is reduced because the transmission factor (gear * differential * loss factor) is reduced by the gear reduction. 

From this, I am led to believe that the model is fine, but good data is required.

Edited by Angus Hollands

Share this post


Link to post
Share on other sites

Did you experiment with the drag coefficient?

Your calculations seem to be correct

 

Edit: I played around with the drag in my simulation and get the same behaviour. If the drag is too big the car reaches top speed only in 1st gear

Edited by Madhed

Share this post


Link to post
Share on other sites

Your rolling resistance force is all wrong

 

It should be in the region of 0.010 to 0.015 for a car tire on tarmac.

 

You have a value of around 0.32 * 30 = 9.6 

 

A little bit of a difference biggrin.png

Share this post


Link to post
Share on other sites

This topic is 818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this