Hi! I am looking for a good transmission calculations based on speed.
I have following variables:
speed = current car speed
maxSpeed = maximum speed car can achieve
gears = the count of gears aviable for car, usually it is 5 or 6
rpms = maximum possible RPM car can achieve before setting next gear(usually 6000-9000)
Truth is, physics behind engines is immensely complicated.
For example:
A real engine has a torque-speed curve. It does not output a constant torque at any speed, but it varies hugely. For instance, see this: link
You’ll notice that each gear has a different torque-speed curve, but they are all just different scalings of the same shape. So we can just have a single engine-speed-torque function, and scale it based on gear.
If you want to be accurate (as you seem to be), you’ll have to model that here’s how I would structure it:
engine_rpm = getEngineSpeed(carVelocity, gear) #Simple linear relationship with gear as a factor
engine_torque = getTorque(engine_rpm) #Either a crazy math equation or a lookup table
wheel_torque = getWheelTorque(engine_torque, gear) #Simple linear relationship with gear as a factor.
applyWheelTorque(wheel_torque)
Assuming you have drag set up on your car sensibly (not damping, but mathematically modelled in (such as rolling resistance, wind resistance etc.), simply apply the torque to the wheels and your car will find a maximum speed where the output power is equal to the friction power.
“speed = current car speed”
This is the forward coordinate of the linear velocity. You can directly read it from there.
“maxSpeed = maximum speed car can achieve
gears = the count of gears aviable for car, usually it is 5 or 6
rpms = maximum possible RPM car can achieve before setting next gear(usually 6000-9000)”
These are settings. They do not belong to the physics model as … it is no car, just a wire-frame cage with some rays.
You can use them as configuration for your car model (model = what you think your car should be). So you can use that to calculate the forces you want to apply to the vehicle wrapper (applyEngineForce() per wheel).
The typical implementation in this forum is to apply constant forces when a key is pressed. You do not need to do this. You can add forces dependent on the current speed, or whatever condition you like.
For example your car model (not the mesh object) could have a “moment of force” or “torque”. Usually there is a fluent transition in changing it’s values. e.g when braking it will not suddenly stop, it will strongly decrease down to zero because of the feedback of the wheels. The opposite is similar, when you give power it will not suddenly have a million rpm. There is a transition dependent on the current moment, and the forces involved. The gear will influence the forces.
You could implement some formulas that calculate the forces (per wheel).
def calculateForce(gear, momentum, power):
if gear == 1:
return momentum + power # whatever formula you want
if gear == 2
return momentum + power*0.2 # whatever formula you want
lol nobody knows. That’s why you can invent whatever you want.
I suggest to orient on the expectations.
As less momentum you currently have as less power you get from the engine (to result in a force -> acceleration).
At a certain momentum the the power has it’s maximum and will decrease with more momentum
You can “scale” the curve with different gears (that is why they are there).
The time to switch gears is when the curves crosses.
Are the curves real? No. They might even be bullshit Can anybody tell? No.
So use curves as you like. I suggest to use different curves for different car types. The spike can be at different places. The curves can be wider, smaller whatever.
OK! Sounds quite good, but I have never written curve calculations, I will have curve math this year(class 9), but haven’t had it before. I don’t know how to struct a curve.
import bgefrom bge import logic
from gamesystem import gaudges
def gearbox(cont):
own = cont.owner
speed = gaudges.speed
maxSpeed = own["maxSpeed"]
gearcount = own["gears"]
rpms = own["rpms"]
div = maxSpeed / gearcount
gear = ((speed - 1) / div) + 1 # a common way, I will use something better later
gaudges.gear = gear
gaudges.rpm = #WHAT TO DO HERE!?
own["Gear"] = gaudges.gear
own["RPM"] = gaudges.rpm
Now I need to have 7000 RPM(rpms = 7000) when having 50 km/h, 100 km/h or any other maximum km/h at any gear(because maxSpeed = 250, gearcount is 5 in my example). SO what to do in gaudges.rpm to make sure that 0 km/h = 0 RPM, 1-50 km/h ir 1000-7000(approximately) RPM, 51-100 km/h = 1000-7000 km/h(approximately) or something like that? What equation to write?
I think I just confused you (and me). The above curves are not the how to convert from rpm of an engine to speed of a wheel. They are more the speed increase on different rpm (momentum).
The relation between engine angular speed and wheel angular speed is due to the mechanics … linear. The only flaxible part is the gear which adds a scale.
This makes the formula pretty simple:
TRANSMISSION_FACTOR = 1/100 # up to the gear box = whatever you want
...
def calculateWheelSpeed(engineSpeed, gear):
return engineSpeed * TRANSMISSION_FACTOR * gear
Interpretation:
in gear 1 you get in normal range (2100 rpm) 21 km/h in gear 6 you get 126 km/h
While this sounds like you can “simply” switch to gear 6 and power your engine with 6900 rpm to get 414 km/h -> this does not consider the forces you need to increase the engine speed.
That is where the above curves come into play. In a normal car the highest forces are in the range around 2000-3000 rpm. This means if you provide full gas it results in most power. Outside this range the same gas results in less power.
Less power means it takes longer to increase the rpm (and the speed) by a constant value (e.g. 1 rpm) . More power means it is faster to increase the power.
There are additional forces the counters the engine force e.g. the air resistance. The air resistance gets stronger as faster the car is driving.
All of that results in a limit. That means regardless how much gas you provide the engine will not be able to increase the speed anymore, because the counter forces will nullify any additional force from the engine.
I do not have a formula yet that helps you calculating the forces or the speed increase from gas to rpm or wheel speed.