Hello, i was wondering if anyone here knows good methods to integrate 3 torques into a wheel's angular velocity in a physically correct manner? The 3 torque's i have are:
- Torque from drivetrain
- Torque from brakes
- Torque from friction
For now the friction torque is calculated as the following pseudo code:
frictionTorque = sign(vehicleLinearVelocity / radius - angularVelocity) * 1000 * frictionCoefficient * radius; // 1000 is Nm normalForce
The brakeTorque is just calculated as:
singedbrakeTorque = -sign(angularVelocity) * abs(brakeTorque);
The total torque i apply to the wheel is just a sum of the 3:
netTorque = drivetrainTorque + frictionTorque + signedBrakeTorque;
The issue here is that integrating the net torque like this does not display correct results. If the brakeTorque dominates, the angular velocity will try to go to 0 but there is no limit on the brake torque and this can cause overshooting. If the frictionTorque dominates, the angular velocity will try to match the vehicle speed, here overshoot is also possible.
I have now calculated a limit for the brake torque and for the friction torque which states how much we need to reach the desired angular velocity instantly.
maxFrictionTorque = (vehicleVelocity / radius - angularVelocity) / deltaTime * inertia;
maxBrakeTorque = -(angularVelocity) / radius * inertia;
If we apply these limits before adding the torque to the net torque then we get something more correct if the other torques were 0 but that's not the case in 99.99% of the time. I was thinking about applying to the netTorque but i have no idea how to detect when to limit a torque like the brake or friction torque.
This is where i kind of am lost. Below is the full pseudo code what i know is probably correct so far if i could get the clamps to work after the net torque.
frictionTorque = sign(vehicleLinearVelocity / radius - angularVelocity) * 1000 * frictionCoefficient;
signedBrakeTorque = sign(angularVelocity) * abs(brakeTorque);
netTorque = frictionTorque + signedBrakeTorque + drivetrainTorque;
maxFrictionTorque = (vehicleLinearVelocity / radius - angularVelocity) / deltaTime * inertia; // angular vel to force
maxBrakeTorque = (angularVelocity) / deltaTime * inertia; // angular vel to force
// TODO: adjust netTorque if neccesary based on conditions like the dominant force of the 3
angularVelocity = angularVelocity + (netTorque / inertia * deltaTime);
If anyone has experience with this it would be of great help. I hope i can figure out how to integrate the 3 torques correctly into the wheel angular velocity.