Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Programming & Software Development

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 12th September 2002, 10:38 AM   #1
BAC :S Thread Starter
Member
 
BAC :S's Avatar
 
Join Date: Dec 2001
Location: Melbourne
Posts: 1,392
Question Car Acceleration?

Me and my little car game again I've finally got myself some torque curves, but I'm having a problem with accelerating my car. It seems that it hits it's highest speed if first gear, and then slows down when you change up... All values are for an Audi 1998 A8 Here is my code:

Set up all car values:
Code:
	corvette.cartype.GearRatio[1] = 3.570f;
	corvette.cartype.GearRatio[2] = 2.200f;
	corvette.cartype.GearRatio[3] = 1.500f;
	corvette.cartype.GearRatio[4] = 1.000f;
	corvette.cartype.GearRatio[5] = 0.800f;

	corvette.cartype.Diff = 2.73f;

	corvette.cartype.Mass = 1792;

	corvette.cartype.WheelRadius = 0.4f;

	corvette.rpm = 1000;

	corvette.gear = 1;

	corvette.vel = 0;
Here is the code that calculates the speed of the car:

Code:
int MoveCar(CAR &car, float delta)
{
	float max_torque, engine_torque, drag, friction;

	max_torque = car.cartype.Torque[(int)car.rpm]; //Get max torque at a given RPM
	engine_torque = max_torque * (car.throttle / 100); //Multiply it by throttle position
	
	drive_force = engine_torque * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * corvette.cartype.WheelRadius * 0.7f; //Calculate drive force

	drag = - CDrag * car.vel * ABS(car.vel); //Calculate Drag

	friction = - CFric * car.vel;	//Calcualte Friction 

	car.force = drive_force + drag + friction;	//Find sum of forces acting on car

	car.accel = car.force / car.cartype.Mass;	//F = m / a, to find acceleration

	car.vel = car.vel + car.accel  * delta;	//calculate car velocity using v = u + at



	car.rpm = ((car.vel / corvette.cartype.WheelRadius) * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * 60) / (2 * (float)PI); //Workout RPM off new speed, for next set of calculations

	if (car.rpm < 1000) //Make sure RPM doesn't go under engine idling RPM
		car.rpm = 1000;

	return 1;

}
My drag and friction constants (CDrag, and CFric) are equal to:
const float CDrag = 0.4257f;
const float CFric = 12.8f;
I got these values from http://home.planet.nl/~monstrous/tutcar.html

Any suggests would be a great help.
__________________
"One good thing about music, when it hits you, you feel no pain." - Bob Marley
OCAU Guitar Players Club
OCAU Magic Club

Last edited by BAC :S; 12th September 2002 at 10:40 AM.
BAC :S is offline   Reply With Quote

Join OCAU to remove this ad!
Old 12th September 2002, 11:26 AM   #2
Pacifist
Member
 
Join Date: Mar 2002
Location: Gosford
Posts: 1,950
Default

Well, when your going up a steep hill 1st gear is actually the fastest gear in some cars, the rest are unable to overcome the force of going up the hill.

I think you have a similar problem as you have probably made your drag and friction constants too high.
Pacifist is offline   Reply With Quote
Old 13th September 2002, 3:36 PM   #3
mnemtsas
Member
 
Join Date: Jun 2001
Location: Adelaide
Posts: 73
Default

I would suggest you have units wrong somewhere. If you are reaching maximum speed in first gear this means that the torque of the engine multiplied by your gearing is more than your friction and drag ONLY in this gear. So, check your CFric and CDrag units, your CFric units in particular look too high to me. Of course your units for these may be fine and your units for your car force / gear ratio things may be screwed. But as an engineer, I would say UNITS UNITS UNITS!!!
mnemtsas is offline   Reply With Quote
Old 14th September 2002, 9:34 AM   #4
BAC :S Thread Starter
Member
 
BAC :S's Avatar
 
Join Date: Dec 2001
Location: Melbourne
Posts: 1,392
Default

I found one little mistake (that makes a fair difference)

drive_force = engine_torque * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * corvette.cartype.WheelRadius * 0.7f;

This should be:
drive_force = engine_torque * car.cartype.GearRatio[(int)car.gear] * car.cartype.Diff * 0.7f / corvette.cartype.WheelRadius;


Your supposed to divide the wheel radius, this gives a fair bit more drive force to overcome the drag.

Now the car makes it to 3rd gear, but when you change into 4th it starts slowing down

The only problem is when I lower the friction, and drag the car goes to quick. At the lowest friction and drag that I can get the car into 5th gear its going about 360 km/h, and really the car only has a top speed of about 205 - 210km/h.

Also, this makes the car take ages to slow down when there is little drag.

As for my units:

mass - kgs
speed - m/s
drive, drag, friction forces = N(ewtons)

so I think they are all right?
__________________
"One good thing about music, when it hits you, you feel no pain." - Bob Marley
OCAU Guitar Players Club
OCAU Magic Club

Last edited by BAC :S; 14th September 2002 at 9:50 AM.
BAC :S is offline   Reply With Quote
Old 14th September 2002, 10:57 AM   #5
Pacifist
Member
 
Join Date: Mar 2002
Location: Gosford
Posts: 1,950
Default

You could put in some engine friction.
ie. an engine at 6000rpm will have more friction than an engine at 2000rpm
This means that it will be better to go into a higher gear with low RPM
Pacifist is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 4:19 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!