Raycast vehicle bugs?

LEgregius
Posts: 26
Joined: Tue Oct 14, 2008 1:34 am

Raycast vehicle bugs?

Post by LEgregius »

I found two things in the raycast vehicle code that don't exactly break the behavior completely or can be worked around, but I believe are actually wrong.

The first is on lines 197/198 is btRaycastVehicle.cpp in 2.76

Code: Select all

		btScalar  minSuspensionLength = wheel.getSuspensionRestLength() - wheel.m_maxSuspensionTravelCm*btScalar(0.01);
		btScalar maxSuspensionLength = wheel.getSuspensionRestLength()+ wheel.m_maxSuspensionTravelCm*btScalar(0.01);

This doesn't make sense to me at all. In a real vehicle, the suspension can travel from the bump stop, called m_hardPointWS, to the end of the travel. The suspension rest length is always PAST the end of the travel so that the suspension still has some force is in even when it has reached the end of the travel. The raycast code even does

Code: Select all

	wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
	wheel.m_worldTransform.setOrigin(
		wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
Which means that raycast is from the hard point to the suspension rest length, so the suspension could never be
as long as maxSuspensionLength is capping it to be. The suspension, according to the raycast, can only go from 0 (the hard stop point) to rest length. That raycast should actually go from the hard stop to the max travel meaning that the two code snippets above should look like:

Code: Select all

		btScalar  minSuspensionLength = 0
		btScalar maxSuspensionLength = wheel.m_maxSuspensionTravelCm*btScalar(0.01);

Code: Select all

	wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
	wheel.m_worldTransform.setOrigin(
		wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_maxSuspensionTravelCm*btScalar(0.01);
I tested this change, and it worked well in the two demo applications that use the raycast vehicle.

Now for second issue...

on like 444 of btRaycastVehicle.cpp

Code: Select all

			wheel_info.m_wheelsSuspensionForce = force * chassisMass;
Why is the suspension force multiplied by the chassis mass? That really isn't a force any longer. It also means that the springs and dampers have to set in strange units.

For the spring constant, it would be in Newtons/Meter/Kg and the damper would be in Newtons/(Meter/second)/Kg.

It's conceptually similar to setting the spring using the frequency and damper based on the fraction of critical damping, but you need to know things like the number of wheels, the position of the center of mass, etc to calculate it that way.

I really think that line should just look like:

Code: Select all

			wheel_info.m_wheelsSuspensionForce = force;
That means you have to multiply the spring and damper values the demo apps by the mass, but other that it it works fine.