[ODE] I have buckling joints with 4 wheeled vehicle
Pawel S
unixbird at yahoo.se
Tue Jun 14 13:48:05 MST 2005
I found the carworld source a little bit hard to follow. Here is part of
what I use in my program. It simulates a streetracer. It can do fast accs
and nice drifts.
At program start:
World attributes:
dWorldSetContactMaxCorrectingVel( MyWorld, 0.5 );
dWorldSetContactSurfaceLayer( MyWorld, 0.01 );
// Should this be updated every frame?
dWorldSetCFM( MyWorld, 0.000005 );
dWorldSetERP( MyWorld, 0.8 );
Body weights are:
1600 kilograms for the car's body and
30 kilograms each for wheels
fMaxSteeringAngle = 45.0 degrees
fSk = 100000.0 // spring
fDk = 3000.0 // damper
vUp = a global vector pointing stright up
Every frame:
SimClock.Update();
// update dampers
SCALAR fERP, fCFM;
fERP = SimClock.GetDeltaTime() * fSk / ( SimClock.GetDeltaTime() * fSk +
fDk );
fCFM = 1.0 / ( SimClock.GetDeltaTime() * fSk + fDk );
dJointSetHinge2Param( JointFL, dParamSuspensionERP, fERP );
dJointSetHinge2Param( JointFL, dParamSuspensionCFM, fCFM );
dJointSetHinge2Param( JointFR, dParamSuspensionERP, fERP );
dJointSetHinge2Param( JointFR, dParamSuspensionCFM, fCFM );
dJointSetHinge2Param( JointRL, dParamSuspensionERP, fERP );
dJointSetHinge2Param( JointRL, dParamSuspensionCFM, fCFM );
dJointSetHinge2Param( JointRR, dParamSuspensionERP, fERP );
dJointSetHinge2Param( JointRR, dParamSuspensionCFM, fCFM );
// setup front wheel turn
cMatrix mSteering = TransformsSim.Body.mOrientation; // copy car body
orientation
mSteering.RotateAxisAngle( vUp, -VehicleInputSim.fSteeringWheel *
fMaxSteeringAngle ); // rotate it
// restrict front wheel rotation to the steering's right axis
dBodySetFiniteRotationAxis( BodyWheelFL,
mSteering.RowAsVector( cMatrix::RIGHT ).x,
mSteering.RowAsVector( cMatrix::RIGHT ).y,
mSteering.RowAsVector( cMatrix::RIGHT ).z );
dBodySetFiniteRotationAxis( BodyWheelFR,
mSteering.RowAsVector( cMatrix::RIGHT ).x,
mSteering.RowAsVector( cMatrix::RIGHT ).y,
mSteering.RowAsVector( cMatrix::RIGHT ).z );
// restrict rear wheel rotation to car body's right axis
dBodySetFiniteRotationAxis( BodyWheelRL,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).x,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).y,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).z );
dBodySetFiniteRotationAxis( BodyWheelRR,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).x,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).y,
TransformsSim.Body.mOrientation.RowAsVector( cMatrix::RIGHT ).z );
// turn the front wheels
dJointSetHinge2Param( JointFL, dParamVel, 50.0 * (
-VehicleInputSim.fSteeringWheel * fMaxSteeringAngle -
dJointGetHinge2Angle1( JointFL ) ) );
dJointSetHinge2Param( JointFR, dParamVel, 50.0 * (
-VehicleInputSim.fSteeringWheel * fMaxSteeringAngle -
dJointGetHinge2Angle1( JointFR ) ) );
// apply torque to rear wheels
if ( ( VehicleInputSim.fEngineTorque != 0.0 ) && ( bKeyState[
KbKeys.Forward.nKeyCode ] || bKeyState[ KbKeys.Backward.nKeyCode ] ) )
{
dJointSetHinge2Param( JointFL, dParamVel2, 90.0 *
-VehicleInputSim.fEngineTorque );
dJointSetHinge2Param( JointFR, dParamVel2, 90.0 *
-VehicleInputSim.fEngineTorque );
dJointSetHinge2Param( JointRL, dParamVel2, 90.0 *
-VehicleInputSim.fEngineTorque );
dJointSetHinge2Param( JointRR, dParamVel2, 90.0 *
-VehicleInputSim.fEngineTorque );
SCALAR l_fTorque = 4500.0 * fabs( VehicleInputSim.fEngineTorque );
dJointSetHinge2Param( JointFL, dParamFMax2, 0.0 );
dJointSetHinge2Param( JointFR, dParamFMax2, 0.0 );
dJointSetHinge2Param( JointRL, dParamFMax2, l_fTorque );
dJointSetHinge2Param( JointRR, dParamFMax2, l_fTorque );
}
else
{
dJointSetHinge2Param( JointFL, dParamVel2, 0.0 );
dJointSetHinge2Param( JointFR, dParamVel2, 0.0 );
dJointSetHinge2Param( JointRL, dParamVel2, 0.0 );
dJointSetHinge2Param( JointRR, dParamVel2, 0.0 );
dJointSetHinge2Param( JointFL, dParamFMax2, 20.0 );
dJointSetHinge2Param( JointFR, dParamFMax2, 20.0 );
dJointSetHinge2Param( JointRL, dParamFMax2, 20.0 );
dJointSetHinge2Param( JointRR, dParamFMax2, 20.0 );
if ( VehicleInputSim.fBrakes > 0.0 )
{
dJointSetHinge2Param( JointFL, dParamVel2, 0.0 );
dJointSetHinge2Param( JointFR, dParamVel2, 0.0 );
dJointSetHinge2Param( JointRL, dParamVel2, 0.0 );
dJointSetHinge2Param( JointRR, dParamVel2, 0.0 );
dJointSetHinge2Param( JointFL, dParamFMax2, 3000.0 *
VehicleInputSim.fBrakes );
dJointSetHinge2Param( JointFR, dParamFMax2, 3000.0 *
VehicleInputSim.fBrakes );
dJointSetHinge2Param( JointRL, dParamFMax2, 3000.0 *
VehicleInputSim.fBrakes );
dJointSetHinge2Param( JointRR, dParamFMax2, 3000.0 *
VehicleInputSim.fBrakes );
}
}
// step world
dSpaceCollide( WorldSpace, 0, &NearCallback );
dWorldStep( MyWorld, SimClock.GetDeltaTime() );
dJointGroupEmpty( MyContactGroup );
/Pawel S
---
As we enjoy great advantages from inventions of others, we should be glad of an opportunity to serve others by any invention of ours; and this we should do freely and generously.
Benjamin Franklin
More information about the ODE
mailing list