NVIDIAGameWorks / PhysX

NVIDIA PhysX SDK
Other
3.15k stars 796 forks source link

Reduced coordinate articulation revolute joint problem #531

Open zemlifr opened 2 years ago

zemlifr commented 2 years ago

Hello, I have reduced coordinate articulation consisting from two links connected by revolute joint with TWIST motion. Root link is connected by fixed joint to RigidBody vehicle. I am trying to make full circle with their drive, however I have problem, that my application controller gives values from -Pi to Pi, so when gradually changing rotation angle, in one moment target switches from -pi to pi in one step, which introduces huge error which obviously causes huge force applied.

It seems to work fine when I do same using regular rigid bodies and D6 joint with twist axis unlocked.

Is it bug, or I am required to provide values only in <0, 2pi> range?

kstorey-nvidia commented 2 years ago

The joint positions should operate in the range -2pi to 2pi and the integrator does differentiate between pi and -pi even though they both equate to the same orientation.

If this doesn't suit your needs, you can do a search for pieces of code that look like this:

if (jPos > PxTwoPi) jPos -= PxTwoPi2.f; else if (jPos < -PxTwoPi) jPos += PxTwoPi2.f;

and remove them.

In PhysX 5, there are two different kinds of revolute joints exposed - one that wraps at +/- 2pi and one that doesn't. For something like a wheel that is expected to spin infinitely, wrapping at 2pi is desirable to avoid hitting numerical issues after the wheel has rotated 1000s of times. However, if you want to simulate a robot with limits such that it can rotate +/- 1080 degrees, then hits a limit, a revolute joint that doesn't wrap at 2pi would be required.