NVIDIAGameWorks / PhysX-3.4

NVIDIA PhysX SDK 3.4
https://www.nvidia.com/
2.34k stars 275 forks source link

Getting joint motor applied torque #118

Closed danielkrakowiak closed 4 years ago

danielkrakowiak commented 4 years ago

Hi, is there a way to get torque applied by a motor in a joint?

I also experience a problem where motor set to zero velocity never gets to stop the wheel when that wheel is propelled by friction from the ground. Could I fix that somehow? Is that because the motor only applies the torque needed to stop the rotating mass of given inertia? I hoped that motors have more info on the post-friction velocity and can be more precise then applying and calculating the torque myself in some "braking PID controller". Could you help me understand?

kstorey-nvidia commented 4 years ago

Are you using articulations or regular d6 joints? For absolute zero velocity (e.g. car handbrake) you might get better results switching to a positional drive that holds at current angle. This should correct any drift.

The applied motor forces aren't currently exposed via the API, but they are recorded internally.

danielkrakowiak commented 4 years ago

I'm using a D6 joint in Unreal. I need to apply the brake smoothly from zero braking torque to maximal braking torque. I don't want to explicitly stop the wheel but rather apply high torque that could stop the wheel. I will try the suggestion with positional drive.

kstorey-nvidia commented 4 years ago

You could use a velocity drive at higher speed, transitioning to a positional drive when velocity approaches zero to give you a handbrake-like effect. You could put a force limit on the positional drive and detect when velocity exceeds a certain amount to transition to velocity drive again.

danielkrakowiak commented 4 years ago

I am also wondering about the difference between using positional drive (which seems to require all axes to be free?) and using a normal joint spring or damper for this case of just wanting to slow down or stop the rotation. I would probably need to rotate the reference-frame to match the current twist I guess... Could you advise on that?

kstorey-nvidia commented 4 years ago

There's fundamentally little difference between the two. The positional drive is the same spring-damper. If you don't set a target relative transform, that relative transform is identity and the spring term will drive towards making the two joint frames coincide along/around and driven axes. If you provide a target pose, this is the offset between the joint frames it drives towards. The same effect could be achieved by rotating frames but this can be tricky if you have multiple rotational dofs and joint limits because the joint frames impact those as well.

You don't need all axes to be free/limits - only the ones you want the drive to influence

danielkrakowiak commented 4 years ago

Thank you for your help and all the suggestions and clarifications! I will try them all out.