raycast vehicle problems

romulox_x
Posts: 2
Joined: Fri Oct 05, 2007 8:19 pm

raycast vehicle problems

Post by romulox_x »

Hello,

I've set up a vehicle simulation. I based it on the vehicle demo that comes with Bullet. I have the suspension stiffness set extremely high, so the wheels are very rigid and won't more up and down as the terrain changes. When I try to adjust each wheel's m_suspensionStiffness, m_wheelsDampingRelaxation, and m_wheelsDampingCompression to allow the wheels to "give", the wheels simply sink into the ground until the bottom of the chassis is resting on the ground, at which point the vehicle obviously can't move. Can someone help me understand exactly how I should be adjusting these parameters to allow the wheels to move up and down as they do in the demo? Is there a tutorial out there explaining how to use the vehicle parameters? I've included the code I feel is relevant below. Sorry, I know it's kind of sloppy, but I've been tearing it apart trying to figure this out. Thank you very much.

Code: Select all


float	gEngineForce = 0.f;

float	gBrakingForce = 0.f;



float	maxEngineForce = 1000.f;//this should be engine/velocity dependent

float	maxBrakingForce = 1000.f;



float	gVehicleSteering = 0.0f;

float	steeringIncrement = 0.06f;

float	steeringClamp = .6f;

float	wheelRadius = .436f;

float	wheelWidth = 0.3f;

float	wheelFriction = 1000.0f;

float	suspensionStiffness = 10000.0f;

float	suspensionDamping = 10.3f;

float	suspensionCompression = 20.4f; 

float	rollInfluence = 1.0f;

int rightIndex = 0;

int upIndex = 1;

int forwardIndex = 2;

btVector3 wheelDirectionCS0(0,-1,0);

btVector3 wheelAxleCS(-1,0,0);



//other irrelivant code...


	btCollisionShape* chassisShape = new btBoxShape(btVector3(0.8f, 0.4f, 2.0f));
	btCompoundShape* compound = new btCompoundShape();

	btTransform localTrans;

	localTrans.setIdentity();

	//localTrans effectively shifts the center of mass with respect to the chassis

	localTrans.setOrigin(btVector3(0,0,0));





	compound->addChildShape(localTrans,chassisShape);

		
	btVector3 inertia;
	compound->calculateLocalInertia(200.0f, inertia);


	btMotionState * s = new btDefaultMotionState();
	btMatrix3x3 m;
	m.setIdentity();
	s->setWorldTransform(btTransform(m, btVector3(5,3,-12)));

	v->chassis = new btRigidBody(200.0f, s, compound, inertia, 0, 0, 1000, 0);

	
	physics_world->addRigidBody(v->chassis);
	v->chassis->setLinearVelocity(btVector3(0,0,0));
	v->chassis->setAngularVelocity(btVector3(0,0,0));


	

	v->raycaster = new btDefaultVehicleRaycaster(physics_world);

	v->vehicle = new btRaycastVehicle(v->tuning, v->chassis, v->raycaster);

	

	///never deactivate the vehicle

	v->chassis->setActivationState(DISABLE_DEACTIVATION);



	physics_world->addVehicle(v->vehicle);



	
	float connectionHeight = -0.35f;
	


	bool isFrontWheel=true;



	//choose coordinate system

	v->vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);



	float x = .85f;
	
	btVector3 connectionPointCS0(x,connectionHeight,1.5f);

	v->vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,v->tuning,isFrontWheel);
	

	
	connectionPointCS0 = btVector3(-x,connectionHeight,1.5f);

	v->vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,v->tuning,isFrontWheel);



	
	connectionPointCS0 = btVector3(-x,connectionHeight,-1.5f);

	isFrontWheel = false;

	v->vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,v->tuning,isFrontWheel);




	connectionPointCS0 = btVector3(x,connectionHeight,-1.5f);

	v->vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,v->tuning,isFrontWheel);


	int i;

	for (i=0;i<v->vehicle->getNumWheels();i++)

	{

		btWheelInfo& wheel = v->vehicle->getWheelInfo(i);

		wheel.m_suspensionStiffness = suspensionStiffness;

		wheel.m_wheelsDampingRelaxation = suspensionDamping;

		wheel.m_wheelsDampingCompression = suspensionCompression;

		wheel.m_frictionSlip = wheelFriction;

		wheel.m_rollInfluence = rollInfluence;

	}

//more irrelivant code...

User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: raycast vehicle problems

Post by Erwin Coumans »

It is better to start with identical settings from the VehicleDemo, including chassis mass and all tuning parameters.

Make sure that this works fine, and then change/tune the parameters one at a time. Once the vehicle stops working, it will give you an indication which parameter causes the trouble.

Hope this helps,
Erwin
User avatar
kenshin
Posts: 36
Joined: Fri Oct 31, 2008 5:10 pm

Re: raycast vehicle problems

Post by kenshin »

Erwin Coumans wrote:It is better to start with identical settings from the VehicleDemo, including chassis mass and all tuning parameters.

Make sure that this works fine, and then change/tune the parameters one at a time. Once the vehicle stops working, it will give you an indication which parameter causes the trouble.

Hope this helps,
Erwin

Very helpful to me