btRaycastVehicle Wheel rotation

Show what you made with Bullet Physics SDK: Games, Demos, Integrations with a graphics engine, modeler or any other application
Post Reply
686insomnia686
Posts: 8
Joined: Mon Apr 02, 2012 10:15 am

btRaycastVehicle Wheel rotation

Post by 686insomnia686 »

Hi,
As you can see, when I put a steering, my wheels turn but without steering, they don't.
This is my fonction where I modify the position and the rotation of each wheels :

Code: Select all

BOOLEAN PhysicsWorldBullet::DoProcessRayCastVehicle (RayCastVehicle* _rayCastVehicle)
{	
	if (!GetSingleDelegate(_rayCastVehicle) || !_rayCastVehicle->m_vehicle ||  !_rayCastVehicle->m_vehicleRayCaster) return false;

	//Engine Force, Breaking Force and Vehicule Steering Definition
	float	gEngineForce =  _rayCastVehicle->m_engineForce.GetValue();
	float	gBreakingForce = _rayCastVehicle->m_brake.GetValue();
	float	gVehicleSteering = -_rayCastVehicle->m_steering.GetValue();

	//Motor Wheels Definition
	int wheelIndex = 0;
	if(gBreakingForce>0)
	{
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->setBrake(gBreakingForce,wheelIndex);
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->applyEngineForce(0,wheelIndex);
	}
	else
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->applyEngineForce(gEngineForce,wheelIndex);
	wheelIndex = 1;
	if(gBreakingForce>0)
	{
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->setBrake(gBreakingForce,wheelIndex);
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->applyEngineForce(0,wheelIndex);
	}
	else
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->applyEngineForce(gEngineForce,wheelIndex);
	//Steering Front Wheels
	wheelIndex = 0;
	((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->setSteeringValue(gVehicleSteering,wheelIndex);
	wheelIndex = 1;
	((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->setSteeringValue(gVehicleSteering,wheelIndex);
	
	((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->getRigidBody()->activate();
	int i=0;
	float ajustementZ = 0.05;//put the 3D wheels upside the floor
	for ( IteratorEx(it, _rayCastVehicle, Geometry3D); i<((btRaycastVehicle*)_rayCastVehicle->m_vehicle)->getNumWheels(); it++)
	{
		it->Process(this);
		//Position
		((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->updateWheelTransform(i,true);
		btTransform newTransform = ((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->getWheelInfo(i).m_worldTransform;
		MATRIX Local = BtUtils3D::GetTransform(newTransform);//Get the Local matrix of the wheel
		it->SetWorldPosition(Local._41, Local._42, Local._43+ajustementZ);
				//Orientation
				float rotation = (float)((btRaycastVehicle*) _rayCastVehicle->m_vehicle)->getWheelInfo(i).m_rotation;
				//for the front wheels
		if (i<2)
		{
			if (gVehicleSteering<0)
				it->SetOrientation(NULL, -rotation, 0, gVehicleSteering + PI_2);
			else
				it->SetOrientation(NULL, rotation, 0, gVehicleSteering + PI_2);
		}
				//for the back wheels
		else
		{
			if (gVehicleSteering<0)
			{
				if (gEngineForce<0)
					it->SetOrientation(NULL, -rotation, 0, PI_2);
				else
					it->SetOrientation(NULL, rotation, 0, PI_2);
			}
			else
			{
				if (gEngineForce<0)
					it->SetOrientation(NULL, rotation, 0, PI_2);
				else
					it->SetOrientation(NULL, -rotation, 0, PI_2);
			}
		}
		i++;
	}
return true;
}
For the parameter, I have tried a lot of solution and I never find a real good result:

Code: Select all

        m_engineForce.SetRange(-1000.0, 2000.0, 0.0);//(Min, Max, Init)
	m_brake.SetRange(0.0, 100.0, 0.0);//(Min, Max, Init)
	m_steering.SetRange(-0.3, 0.3, 0.0);//(Min, Max, Init)

	m_wheelDirectionCS.SetValues(0, 0, -1);
	m_wheelAxleCS.SetValues(0, -1, 0);

	m_wheelRadius = 0.31265;//Defaut : 0.5f, Subaru : 0.31265
	m_wheelWidth = 0.215f;//Defaut : 0.4f, Subaru : 0.215f
	m_wheelFriction = 10.5;//1000.0;//2.0;

	m_maxSuspensionTravelCm = 20.0f;//500.0;
	m_suspensionStiffness = 40.0f;//5.8f;//Defaut : 20.0, Subaru : 15.0
	m_suspensionDamping = 2.3f;//0.88;//2.3;
	m_suspensionCompression = 2.4;//0.83;//4.4;
	m_rollInfluence = 0.2f;
	m_suspensionRestLength = 0.1;
	m_connectionHeight = -0.4;//1.2;

	m_chassisLenght = 4.8;//Defaut : 2, Subaru : 4.8
	m_chassisWidth = 2; //Defaut : 1, Subaru : 2
	m_chassisHeight = 1.3;//Defaut : 0.5 , Subaru : 1.5

	m_SpeedKmH = 0;
The value of SpeedKmH changes it sign everytime, it's really boring, I have to put a condition like that :

Code: Select all

it->m_SpeedKmH = ((btRaycastVehicle*)it->m_vehicle)->getCurrentSpeedKmHour();
if(it->m_SpeedKmH.GetValue() < 0) 
{
        it->m_SpeedKmH*=-1;
}
The value m_skidInfo stay always to "1.0", that is good! =)
In the video, we see that the color of the raycast change in blue when they are in contact with the ground.
The value m_rotation is increase by m_deltaRotation everytime (in btRaycastVehicle::updateVehicle( btScalar step )), but when there is no steering, m_deltaRotation is really small like "0.0000004" (in radian).

I hope you can help me because I'm totaly blocked for now.
Thank for your help,
Cordialy,
InSomNia.
686insomnia686
Posts: 8
Joined: Mon Apr 02, 2012 10:15 am

Re: btRaycastVehicle Wheel rotation

Post by 686insomnia686 »

I have found my error, this is a problem in btRaycastVehicle::updateWheelTransform().

The basis is caculate with the Bullet Coordinate, so you have to change for your own coordinate.
My Coordinate System is :
+ Forward : X
+ Right : -y
+Up : Z

So my basis is :
btMatrix3x3 basis2(
fwd[0],-right[0],up[0],
fwd[1],-right[1],up[1],
fwd[2],-right[2],up[2]);

"If you have well define the setCoordinateSystem(), the m_wheelDirectionCS() and the m_wheelAxleCS().
It will be work fine..."

I'm little busy for now, but I gonna made a global correction for everyone, stay tune...
686insomnia686
Posts: 8
Joined: Mon Apr 02, 2012 10:15 am

Re: btRaycastVehicle Wheel rotation

Post by 686insomnia686 »

I have a new problem and I think you can help me.
YOU, the one of the 127 viewers who hasn't answer yet to my first post... :twisted:

When my wheel rotate too fast, there are a logical effect, the wheel look like rotate in the opposite direction...
I would like had any advise for counter this effect and keep a the good rotation direction.

I have try to decrease the rotation when it is too fast, but it's not a success "that's why I repost here...".

Thanx for your help and your particitation, don't be shy! :oops:
686insomnia686
Posts: 8
Joined: Mon Apr 02, 2012 10:15 am

Re: btRaycastVehicle Wheel rotation

Post by 686insomnia686 »

I have a new resquest for you, guys.
The rotation is now fine, but I think, the setup of my car is wrong :

Code: Select all

m_engineForce.SetRange(-1000.0, 2000.0, 0.0);
   m_brake.SetRange(0.0, 100.0, 0.0);
   m_steering.SetRange(-0.3, 0.3, 0.0);

   m_wheelRadius = 0.31265;
   m_wheelWidth = 0.215f;
   m_wheelFriction = 500;

   m_maxSuspensionTravelCm = 20.0f;
   m_suspensionStiffness = 40.0f;
   m_suspensionDamping = 2.3f;
   m_suspensionCompression = 2.4;
   m_rollInfluence = 0.2f;
   m_suspensionRestLength = 0.1;
   m_connectionHeight = -0.4;

   m_chassisLenght = 4.8;
   m_chassisWidth = 2;
   m_chassisHeight = 1.3;
   m_chassisShape->SetMass(800);//Defaut : 800, Subaru : 1498
What do you think?
I don't know if my friction is enough or too much.
I don't know if my suspension is well tuned...
Thanx for your help.
Post Reply