Truck and trailer simulation

Hi everyone,
I need to simulate a truck with an attached trailer. I implemented the truck as a PxVehicleDrive4W. It correctly works, but I can’t make a trailer. Since all the wheels of the trailer are non-driven, I first implement it as a PxVehicleNoDrive with setDriveTorque and setBrakeTorque set to 0 for all the wheels. I then attached the two vehicles by a spherical joint. The problem is the wheels of the trailer can’t freely rotate. The truck can’t push or pull the trailer at all. Wheels only rotate if I set the torque at a value > 0. In this case, the trailer can follow the truck, but the wheels slowly rotate even at rest. Then I tried to implement the trailer as a PxVehicleDriveNW, with all the wheels set as non-driven in the PxVehicleDifferentialNWData structure. Again, the wheels can’t freely rotate.

Which is the correct way to implement a trailer?

Thanks in advance.

Hi,

You’ve done everything correct so far. The problem here is a bug in the vehicle code. The bug is already tracked by the sdk team but not yet fixed or released. The good news is that there is a simple workaround. The best news of all is that you’ve already implemented the workaround.

I’ll quickly describe the problem. When a vehicle comes close to rest the tire forces are replaced with velocity constraints. The target velocities at each wheel decrease each frame so that the vehicle is brought completely to rest over several frames. The constraints are released as soon as the car receives a non-zero accelerator value. If both jointed vehicles come to rest then they are both held there by velocity constraints. When you accelerate the front vehicle it will release its velocity constraints. The rear vehicle, however, doesn’t know that it should also release its velocity constraints. As a consequence, it is stubbornly held where it is with constraint forces.

You’ve already seen that applying a torque to a towed PxVehicleNoDrive releases its velocity constraints when it is at rest. This is pretty much the workaround that I would recommend. Every frame that you set a non-zero accelerator value to your front vehicle also apply a vanishingly small torque to the rear vehicle.

Something like this:

vehDrive4W->mDriveDynData.setAnalogInput(PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL, myAccel);
if(myAccel > 0)
{
vehNoDrive->setDriveTorque(frontLeftWheel, 1e-5f);
vehNoDrive->setDriveTorque(frontRightWheel, 1e-5f);
}
else
{
vehNoDrive->setDriveTorque(frontLeftWheel, 0.0f);
vehNoDrive->setDriveTorque(frontRightWheel, 0.0f);
}

In the above pseudo-code I applied a vanishingly small torque to the front-left and front-right wheel to preserve symmetry. This probably isn’t necessary because a torque of 1e-5f will be so small that it will have no affect on the car at all.

I hope this is acceptable,

Gordon

The workaround seems to be fine. Thank you very much. Anyway, I look forward to an official bug fix.

Paolo