Vehicle engine forсe problem

Towelie
Posts: 9
Joined: Mon Sep 20, 2010 10:07 am

Vehicle engine forсe problem

Post by Towelie »

Hi,i'm trying to simmulate vehicle engine in my programm, but i have a few troubles. At first, i have used a torque curves from BMW M3 but in program car is too slow, i think it's because i incorrectly calculate RPM of the engine in accordance to rpm of wheels

Code: Select all

btScalar CarEngine::computeRpmFromWheels(float time)
{
	btScalar wheelRpms = 0;
	btScalar nbWheels = 0;
	for(int i = 0; i < mVehicle->getBulletVehicle()->getNumWheels(); i++)
	{
		if (mVehicle->getBulletVehicle()->getWheelInfo(i).m_bIsFrontWheel == false)
		{
			nbWheels++;
			wheelRpms += abs(mVehicle->getBulletVehicle()->getWheelInfo(i).m_deltaRotation);	
// yeah, i know that it`s not correctly at all, but i havn`t make a differential yet.		
		}
	}
	if(nbWheels > 0 && time > 0)
		return wheelRpms * 60 / (nbWheels * SIMD_2_PI * time);
	else
		return btScalar(0);
}
void CarEngine::computeTorque(float time)
{
	if(CurGear > 1)
	{
		btScalar RPM = computeRpmFromWheels(btScalar(time)) * Gears[CurGear] * MainGear;
		btScalar torque = Throttle * getTorque(RPM) * RPM / 5100;
		EngineForce = torque * Efficiency * Gears[CurGear] * MainGear;

		for (int i = 0; i < 4; i++)
			if (mVehicle->getBulletVehicle()->getWheelInfo(i).m_bIsFrontWheel == false)
				mVehicle->getBulletVehicle()->applyEngineForce(EngineForce , i);
	}
}
Can u please give me some advises how to slove this problem?
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle engine forсe problem

Post by mi076 »

Code: Select all

	for (i=0;i<m_wheelInfo.size();i++)
	{
		btWheelInfo& wheel = m_wheelInfo[i];
		btVector3 relpos = wheel.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition();
		btVector3 vel = getRigidBody()->getVelocityInLocalPoint( relpos );

		if (wheel.m_raycastInfo.m_isInContact)
		{
			const btTransform&	chassisWorldTransform = getChassisWorldTransform();

			btVector3 fwd (
				chassisWorldTransform.getBasis()[0][m_indexForwardAxis],
				chassisWorldTransform.getBasis()[1][m_indexForwardAxis],
				chassisWorldTransform.getBasis()[2][m_indexForwardAxis]);

			btScalar proj = fwd.dot(wheel.m_raycastInfo.m_contactNormalWS);
			fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;

			btScalar proj2 = fwd.dot(vel);
			
			wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelsRadius);
			wheel.m_rotation += wheel.m_deltaRotation;

		} else
		{
			wheel.m_rotation += wheel.m_deltaRotation;
		}
		
		wheel.m_deltaRotation *= btScalar(0.99);//damping of rotation when not in contact

	}
wheel_angular_velocity = proj2/(wheel.m_wheelsRadius); // rad/s
wheel_rpm = wheel_angular_velocity*60./2.*3.141592654;

BTW, Bullet's vehicle calculates it for update of wheel transform, it works for rolling wheels, front most likely, you have to handle rear wheels rpm and transform in engine ..