The online racing simulator
Simulating Acceleration
(5 posts, started )
Simulating Acceleration
hello all i'm making a simple drag racing simultaion using MAX/MSP for a project at a design school. the important part of the assignment is how i handel video and audio in the program, what i need help with is an algorythm that could somewhat simulate acceleration.
current inputs
throttle
rpm
gear ratio
final drive ratio
i would think this is all i need for a decent simulation but i could be wrong, any and all help would be greatly apreciated. oh and i almost forgot, max natevly supports java script, if there are any max gurus out there that know how to impliment any other language that would be better i'll take what i can get.
thnx in advance
it's pretty easy tbh, however it sounds like you want to be able to see everything in realtime (rather than have the computer work it all out in an instant) there'll be some more complications, but anyway the same underlying methods remain.

To test acceleration somewhat accurately I'd say you'd need at least this:
* Engine torque curve (however rudimentary)
* Gearing (to get wheel torque)
* Wheel size (to get driving force)
* CdA to calculate aero drag (to get some resistance or your car will accelerate forever )
* Vehicle mass (to then determine acceleration)
* Tyre grip (to limit acceleration)


I went into further detail with GRC, taking drivetrain type, torque split, downforce, rolling resistance, tyre deformation, CoG y & z positions (for weight transfer) and gear change times all into account. But that would probably be overkill for your simple project.
Just to give you some basic equations to work from:

Acceleration (in metres per second) = Force (in Newtons)/Mass (in Kilograms)

So at any given moment in your simulation, to work out the instantaneous acceleration, you just need to know the vehicle mass, the force being exerted at the contact patch and the forces resisting forward motion (ie. air resistance, rolling resistance etc.)

To work out your linear force at the contact patch, you need to work from the engine down. You'll need either an algorithm or a table which can tell you what torque the engine will output at a given RPM (at full throttle). This can be either a look up table which interpolates between values, or a fancy equation like what Scawen does .

From this torque value you need to multiply by the current gear ratio to give you torque at the driveshaft. Engines are nearly always geared down, so torque at the drive shaft will be greater, and RPM lower.

Its preferable to use units of Nm for torque just to make things easier. Now to convert this driveshaft torque to linear force at the contact patch, you need to divide by the wheel/tyre radius.
So if you have a driveshaft torque of 1000Nm, and a tyre radius of 0.5m, you will get a linear force pushind the car forwards of 2000N.

linear driving force = (engineTorque*gearRatio)/tyreRadius

Resistance force from the air is basically proportional to the square of the velocity, so your equation for resistance is simply CdA*VelocitySquared (velocity in m/s). CdA is the coefficient of drag and is simply a constant that depends on the size and shape of the car, you can probably just play around with that value to get reasonable behaviour, or do some googling to find out what the typical values are for drag racers.

So now your actual net force (N)= Driving Force - Resistance Force

So your vehicle acceleration(m/s/s) = netForce(N) / vehicleMass(kg)

Now the question of turning these equations for a given moment in time into a continuous simulation is one I havent got much experience of, but if I was going to set out to do it, it would be like this.

We basically need to perform these equations to determine acceleration at one moment in time, then assume we have continued to accelerate at the same rate until the next time we calculate the acceleration, which should ideally be a fixed length of time, for simplicity of coding, although this may be difficult in javascript.

So assume we are travelling at 50m/s, and our calcs reveal we are accelerating at 10m/s/s. At that rate, in 1 second we would be travelling at 60m/s, but say our calculation rate is 50hz that means in 0.02s we will have increased our velocity by 10*0.02, or 0.2m/s.
So we add that to our velocity giving us 50.2m/s and start all over again.

The main difficulty with this approach is getting to and from stationary, as if your velocity is 0, all kinds of things go horribly wrong with the calcs, but given that you are doing drag racing, you can probably just script the start to give the car a small initial velocity, then then the simulation take over from there.

A further complication of the timestep method is if you cant rely on fixed lengths of time between your calcuations, then you need some method of keeping track of how much actually passed between frames, and putting that value into the equations. Again, I dont know if javascript in max can do this.

Anyway, enough rambling. Sounds like an interesting project, good luck with it.
As far as I can tell, for simple acceleration testing, it doesn't matter if your speed is zero, since you're only adding to the initial speed, but not fussed about what it actually is. Braking to a halt, or keep a vehicle stationary (when not on a perfectly flat surface), is a different story altogether.
thnx for the help, i've come a little way since the origional post and the project is getting much more complicated, just in case anyone is interested here are some details:

g25 input
system clock decides what you can see through the virtural sun roof (sun, moon, stars, etc...)
sound of real engines (ferrari 308, gti 2.0l 16v, dodge coronet) so far
force feedback for speed sensation
opengl cluster as well as a real VW MKIII VR6 cluster running in real time

i will post the javascript when it is closer to being completed, just you you know the precision of the simulation is not a big factor in the porject, but i do want a small sence of reality.

Simulating Acceleration
(5 posts, started )
FGED GREDG RDFGDR GSFDG