[ODE] Help with car simulation pls! :/

Craig Edwards 0011490 at abertay.ac.uk
Fri Apr 4 13:17:27 2003


Hi,

I've been trying to get a car simulation to work much in the same way as
buggydemo, test_buggy, silkworm, however for some reason mine just doesn't
want to behave itself.. I must be doing something wrong in either way the
way I'm creating the model/joints or my nieve attempts to get the bloody
thing to move :p

The symptons are like this.. when I just steer left or right the front
wheels do rotate in the desired direction by the car "jerks" violently and
actually rotates around its y-axis (even if I haven't applied any forward
velocity, just moved the wheels..) if I keep steering left or right the car
will rotate  faster and faster.. also when I go would go to accelerate
forward or backwards the car rotates around its x-axis (at a stupidly fast
speed.. but thats a value that needs tweaked probably?).. instead of what I
would have thought (want to happen) move in the direction the wheels are
pointing..

I uploaded a test build at http://www.bl33t.co.uk/ode/Um.zip if my
explaination is a bit crappy :( (cursor keys to control))

I have two hunches on why, but I can't seem to fix them.

One is that I don't have a ground plane so thats why the car is rotating
around itself.. but then that doesn't explain why the actually chassis moves
when I just steer left or right... and I'm trying to push it forward... not
down :/

I thought it might have something to do with the way I've created the Hinge2
joint between the chassis and the wheels, but it seems logically to me,
steering is done on the y-axis (rotating wheels in the desired direction)
and the moving is down on x-axis of the wheel :(

// 0-1 = FRONT | 2-3 = BACK
for(i = 0; i != 4; ++i)
{

// Create a Hinge 2 joint
m_WheelJoints[i] = dJointCreateHinge2(GetWorldID(), 0);

// Attach joint to the vehicle chassis
dJointAttach(m_WheelJoints[i], m_BodyID, m_WheelBodies[i]);

// What is the wheels position? (will create a 3-element array)
const dReal* const vWheelPos = dBodyGetPosition(m_WheelBodies[i]);

// Axis 1 - Steering-Axis (Y)
// Axis 2 - Wheel Turning-Axis (X)
dJointSetHinge2Anchor(m_WheelJoints[i], vWheelPos[0], vWheelPos[1],
vWheelPos[2]);
dJointSetHinge2Axis1(m_WheelJoints[i], 0, 1, 0);
dJointSetHinge2Axis2(m_WheelJoints[i], 1, 0, 0);

// Joint suspension
dJointSetHinge2Param(m_WheelJoints[i], dParamSuspensionERP, 0.4);
dJointSetHinge2Param(m_WheelJoints[i], dParamSuspensionCFM, 1.5);

// Wheels aligned along steering axis
dJointSetHinge2Param(m_WheelJoints[i], dParamLoStop, 0);
dJointSetHinge2Param(m_WheelJoints[i], dParamHiStop, 0);

}

The way I attempt to move the car is pretty much taken from the silkworm
source. From what I understand instead of applying a force to the chassis
body via dApplyForce to get the car to move, the wheel joints/bodies have
motors which will "move" the car.

// Update speed/steering
void CCar::Update()
{
if(m_VehicleMovement & ACCEL_FORWARD)
{
m_VehicleSpeed += 0.2;
}
if(m_VehicleMovement & ACCEL_BACKWARD)
{
m_VehicleSpeed -= 0.2;
}
if(m_VehicleMovement & STEER_LEFT)
{
m_VehicleSteer = -1.0;
}
if(m_VehicleMovement & STEER_RIGHT)
{
m_VehicleSteer = 1.0;
}
MoveVehicle();
m_VehicleMovement = NULL;
}

// "Move" the vehicle
void CVehicle::MoveVehicle()
{
int w;
for (w = 0; w < 4; w++)
{
dJointSetHinge2Param (m_WheelJoints[w], dParamVel2, m_VehicleSpeed);
dJointSetHinge2Param (m_WheelJoints[w], dParamFMax2, 0.4);
}

// steering
bool steer_pressed = false;
if (m_VehicleMovement & STEER_LEFT) { steer_pressed = true; }
if (m_VehicleMovement & STEER_RIGHT) { steer_pressed = true; }
for (w = 0; w < 4; w++)
{
if (w < 2)
{
dJointSetHinge2Param (m_WheelJoints[w],dParamVel, m_VehicleSteer);
}
/* else
{
dJointSetHinge2Param (m_WheelJoints[w],dParamVel, -m_VehicleSteer);
}
*/
if (!steer_pressed)
{
dJointSetHinge2Param (m_WheelJoints[w],dParamLoStop,-0.00);
dJointSetHinge2Param (m_WheelJoints[w],dParamHiStop, 0.00);
}
else
{
dJointSetHinge2Param (m_WheelJoints[w],dParamLoStop,-0.50);
dJointSetHinge2Param (m_WheelJoints[w],dParamHiStop, 0.50);
}
dJointSetHinge2Param (m_WheelJoints[w],dParamFMax, 2.0);
dJointSetHinge2Param (m_WheelJoints[w],dParamFudgeFactor, 0.1);
}
}

Any help, tips, hints anything to help me solve this would be greatly
appericated! I know im so close.. but so far :(

Regards

Craig