[ODE] car - drving on plane

Fabian Mathews supagu at hotmail.com
Fri Feb 27 12:55:19 MST 2004


i made a car to drive on a plane, but im having some issues as it some times 
drives at good speed,
other times it feels like its stuck in glue!

ive modified the buggy sample code for my vehicle:

set up code:

	#define LENGTH 12	// chassis length
	#define WIDTH 8	// chassis width
	#define HEIGHT 6	// chassis height
	#define RADIUS 2	// wheel radius
	#define STARTZ 10	// starting height of chassis
	#define CMASS 2		// chassis mass
	#define WMASS 5	// wheel mass

	dMass m;

	// chassis body
	body[0] = dBodyCreate( PhysicsMgr::GetInstance().GetWorld() );
	dBodySetPosition( body[0], 0, STARTZ, 0 );
	dMassSetBox( &m, 1, LENGTH, WIDTH, HEIGHT );
	dMassAdjust( &m, CMASS );
	dBodySetMass( body[0], &m );
/*	box[0] = dCreateBox( PhysicsMgr::GetInstance().GetSpace(), LENGTH, WIDTH, 
HEIGHT );
	dGeomSetBody( box[0], body[0] );
*/
	// wheel bodies
	for( int i=1; i<=4; i++)
	{
		body[i] = dBodyCreate( PhysicsMgr::GetInstance().GetWorld() );
		dQuaternion q;
		dQFromAxisAndAngle(q,1,0,0,M_PI*0.5);
		dBodySetQuaternion( body[i], q );
		dMassSetSphere( &m, 1, RADIUS );
		dMassAdjust( &m, WMASS );
		dBodySetMass( body[i], &m );
		sphere[i-1] = dCreateSphere( PhysicsMgr::GetInstance().GetSpace(), RADIUS 
);
		dGeomSetBody( sphere[i-1],body[i] );
	}
	dBodySetPosition( body[1], 0.5*LENGTH, STARTZ-HEIGHT*0.5, WIDTH*0.5 );
	dBodySetPosition( body[2], -0.5*LENGTH, STARTZ-HEIGHT*0.5, WIDTH*0.5 );
	dBodySetPosition( body[3], -0.5*LENGTH, STARTZ-HEIGHT*0.5, -WIDTH*0.5 );
	dBodySetPosition( body[4], 0.5*LENGTH, STARTZ-HEIGHT*0.5, -WIDTH*0.5 );

	// front and back wheel hinges
	for( i = 0; i < 4; ++i )
	{
		joint[i] = dJointCreateHinge2( PhysicsMgr::GetInstance().GetWorld(), 0 );
		dJointAttach( joint[i], body[0], body[i+1] );
		const dReal *a = dBodyGetPosition( body[i+1] );
		dJointSetHinge2Anchor( joint[i], a[0], a[1], a[2] );
		dJointSetHinge2Axis1( joint[i], 0, 1, 0 );
		dJointSetHinge2Axis2( joint[i], 0, 0, 1 );
	}

	// set joint suspension
	for (i=0; i<4; i++)
	{
		dJointSetHinge2Param( joint[i], dParamSuspensionERP, 0.0 );
		dJointSetHinge2Param( joint[i], dParamSuspensionCFM, 0.0 );
	}

	// lock back wheels along the steering axis
	for (i=1; i<3; i++)  //for (i=0; i<4; i++) //
	{
		// set stops to make sure wheels always stay in alignment
		dJointSetHinge2Param( joint[i], dParamLoStop, 0 );
		dJointSetHinge2Param( joint[i], dParamHiStop, 0 );


		// the following alternative method is no good as the wheels may get out
		// of alignment:
		//   dJointSetHinge2Param (joint[i],dParamVel,0);
		//   dJointSetHinge2Param (joint[i],dParamFMax,dInfinity);
	}



//update code:


	if( Input::GetInstance().KeyDown(SDLK_w) )
	{

		if( speed <= 30 )
			speed += 1;
	}
	else if( Input::GetInstance().KeyDown(SDLK_s) )
	{
		if( speed >= -30 )
			speed -= 1;
	}
	else
	{
		if( speed > 0 )
			speed -= 1;
		else if( speed < 0 )
			speed += 1;
	}

	if( Input::GetInstance().KeyDown(SDLK_a) )
	{
		if( steer < 0.78 )
			steer += 0.005;
	}
	else if( Input::GetInstance().KeyDown(SDLK_d) )
	{
		if( steer > -0.78 )
			steer -= 0.005;
	}
	else
	{
		steer = 0;
	}

	// motor

	for( int k = 0; k < 4; k++ )
	{
		//dJointSetHinge2Param(joint[k],dParamVel,speed * 1);
		dJointSetHinge2Param(joint[k],dParamVel2,speed );
		dJointSetHinge2Param(joint[k],dParamFMax2, 60.0);
	}
/*
    dJointSetHinge2Param(joint[0],dParamVel2,speed * 10);
    dJointSetHinge2Param(joint[0],dParamFMax2,100);
	dJointSetHinge2Param(joint[3],dParamVel2,speed * 10);
    dJointSetHinge2Param(joint[3],dParamFMax2,100);*/

    // steering
    dReal v = steer;// - dJointGetHinge2Angle1(joint[0]);
   /* if (v > 0.1)
		v = 0.1;
    if (v < -0.1)
		v = -0.1;
*/
    v *= 10.0;

	printf("speed: %f steer: %f\n", speed, v );
    dJointSetHinge2Param(joint[0],dParamVel,v);
    dJointSetHinge2Param(joint[0],dParamFMax,100);
    //dJointSetHinge2Param(joint[0],dParamLoStop,-0.75);
    //dJointSetHinge2Param(joint[0],dParamHiStop,0.75);
    //dJointSetHinge2Param(joint[0],dParamFudgeFactor,0.1);

	dJointSetHinge2Param(joint[3],dParamVel,v);
    dJointSetHinge2Param(joint[3],dParamFMax,100);
    //dJointSetHinge2Param(joint[3],dParamLoStop,-0.75);
    //dJointSetHinge2Param(joint[3],dParamHiStop,0.75);
    //dJointSetHinge2Param(joint[3],dParamFudgeFactor,0.1);



its driving along a plane, then all of a sudden its as if its hit something? 
or stuck in glue?!

so if you have any ideas why it would do this, give me a buzz :)



-------------------------------
Fabian "SupaGu" Mathews

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



More information about the ODE mailing list