Search Unity

Featherstone's solver for articulations

Discussion in 'Physics Previews' started by yant, Dec 11, 2019.

  1. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    Hi

    As of Unity 2020.1a15, there is a new feature called articulations available. An articulation in this context is a set of bodies that have their relative movement constrained. It's a bit like using Rigidbody in conjunction with ConfigurableJoint but there is now only one component to deal with, and the benefit is that all joints in an articulation are unstretchable by default (thanks to the new Featherstone solver). This means the locked degrees of freedom will never be violated, which is guaranteed by simulating in reduced coordinates.

    Articulations were a new feature in PhysX 4, have a look at this promotional video for inspiration:
    . PhysX 4 upgrade was made available in Unity 2019.3, so articulations can now be exposed too. The current featureset will be somewhat limited though, with the plan of making more available in the later versions, based on your feedback and requests. For now, only forward dynamics are available (=you set forces and drives to obtain poses of all articulation parts). Later on, inverse dynamics might be featured too (=calculate joint forces based on observations).

    As you might have noticed, the main use case for articulations is more or less robotics -- that is areas where accurate body simulation is key. However, it can be applied to traditional game problems too: think ragdolls for instance, various in-game mechanics as well as puzzles that need extra precision.

    I wrote this brief technical intro if you're interested: https://docs.google.com/document/d/1YSbqXH5Pn844-nnstBOFtPtfXJIcjGIA0zQQpaAaX70

    There is also an Nvidia doc: https://gameworksdocs.nvidia.com/Ph...lations.html#reduced-coordinate-articulations

    Known issues:

    • Spherical joint with twist locked or limited to [0, 0] may cause instability
    • Need to fix hierarchical deactivation, currently we only allow bottom to top
    • Articulation bodies have sleeping weirdness
    • Friction type cannot be set to anything other than Patch
    • Articulations without Colliders make the system really unstable
    • Revolute joint will explode if rotated more than 360 deg by target pose
    • Physics.IgnoreCollider has no effect on articulation bodies (adjacent)
    • Revolute joint will crash if twist is locked

    Please let me know what you think. Thanks!

    Anthony
     
    Last edited: Jan 14, 2020
  2. mvaandrager

    mvaandrager

    Joined:
    Apr 24, 2018
    Posts:
    3
    Thanks Yant! some comments on the technical intro:

    I don’t get to see all the joint information when I add a artictulationbody component. I only see the mass field and that’s it.. Ah now I see you have to put it in the hierarchy under the root body to make it appear. Perhaps good to know for others. But if the hierarchy is the way to define connections, how do we create circular joint configurations?

    the damping ratio d is also allowed to be larger than 1. (In this case it is 'overdamped' and really slows down the dynamics.) Is the ‘Damping’ of the drive the actual damping or the damping ratio? My quess it is the damping ratio?

    I’m also very interested in how these articulationbodies are supposed to interact with rigidbodies. Simply through their colliders and that’s it? It seems like it is that simple.. no caveats?
     
    Last edited: Dec 11, 2019
    tigerleapgorge likes this.
  3. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Thanks for creating new thread!
     
    tigerleapgorge and yant like this.
  4. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    The idea is you get to see what's relevant, as opposed to just a dump of everything (compare to ConfigurableJoint). I understand it requires to get the idea that there is a root body that shows just a few settings applicable and you need to add more to get to see the joint-specific settings, but I hope that's for a good reason after all. Articulation body can't be connected to a world point, it's not exactly a good old D6 doodle there inside.

    I left a comment regarding 'd' value on the doc, but will repeat here: stiffness/damping you see as drive parameters are just raw coefficients, not frequency or damping ratios.
     
  5. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    They get simulated in the same scene - so rigidbodies bounce off articulations and vice versa naturally by definition. For now, loop joints are not supported so you can't attach articulation to a rigidbody directly.
     
  6. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Suggestion:

    Add planar joint type, you can build this behind the scenes with two prismatic joints to form a plane :)
     
    tigerleapgorge likes this.
  7. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Suggestion/need #2:

    Would be nice to have way to update inertia tensor & center of mass of each ArticulationBody, but is not critical at the moment :D
     
    tigerleapgorge likes this.
  8. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    56
    I wrote an extension to ArticulationBody for GetPointVelocity and AddForceAtPosition. I attached the file to this post but here's the code, too. Please check if I got my math right. Testing with simple configurations it intuitively seems correct to me.

    Code (CSharp):
    1. public static class MyExtensions
    2. {
    3.     public static Vector3 GetPointVelocity(this ArticulationBody ab, Vector3 worldPosition)
    4.     {
    5.         var v = ab.velocity;
    6.         var w = ab.angularVelocity;
    7.         var lever = worldPosition - ab.centerOfMass;
    8.  
    9.         return v + Vector3.Cross(w, lever);
    10.     }
    11.  
    12.     public static void AddForceAtPosition(this ArticulationBody ab, Vector3 force, Vector3 worldPosition)
    13.     {
    14.         var lever = worldPosition - ab.centerOfMass;
    15.         ab.AddTorque(Vector3.Cross(lever, force));
    16.         ab.AddForce(force);
    17.     }
    18. }
     

    Attached Files:

    tigerleapgorge, Kobix and yant like this.
  9. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Seems fine:

    https://github.com/NVIDIAGameWorks/.../PhysXExtensions/src/ExtRigidBodyExt.cpp#L397
     
  10. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    hey @Kobix, are you sure about Physics.IgnoreCollision not working with articulations? I can't seem to confirm, here is an example that does work for me

    a4075c5b3dfb0a3fec6ce61d13366d8b.gif
     

    Attached Files:

    tigerleapgorge likes this.
  11. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Hi.

    I will have to test it again. Quick note: The colliders were children GameObjects of ArticulationBody GOs, which doesn't seem to be case in your scenario. Will report ASAP.
     
    tigerleapgorge likes this.
  12. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    btw - feel free to file bugs using the bug reporter inside Editor. Articulations are now part of an official build so we can enjoy tracking and so on. Thanks!
     
    tigerleapgorge likes this.
  13. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Ok, never used this. As I see it, it also sends Unity project, right? I shall create separate project so you can get clean scenes/scenarios :). Should speed things up for you and me :).
     
    tigerleapgorge likes this.
  14. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    Kobix likes this.
  15. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    If anyone needs to set axis in ArticulationBody


    Code (CSharp):
    1. UnityArticulation.anchorRotation = Quaternion.FromToRotation(axis, Vector3.right);
    2.  
     
  16. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Unity crashes with 1 root articulation and 176 articulated prismatic joints. I could file a official bug but I think its no need to here.

    Ok exact number is 65 articulations (1 parent, 64 child). I don't know internals, but it's maybe cause max children is 64 = 2^6
     
    Last edited: Dec 13, 2019
  17. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    No, it still crashes :I.
     
  18. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    162
    Articulations are something I was waiting for.

    btw. is this formula F = (currentPosition - target) * stiffness - (currentVelocity - targetVelocity) * damping
    The same for linear movement and angular movement ?

    I'm a little concerned about the fact that articulated body will be something different than Rigidbody. What will be the interaction, will we be able to connect normal joints to Articulated body ?
    Since unity moved totally into c# maybe it is time to reconsider some interfaces instead of solid classes.

    Secondly will disabling and enabling Articulation reset the initial settings like with normal joints ?
     
  19. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    There is a max limit on the amount of links in the whole articulation in physx.
     
  20. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Isn't it possible to relax this limit? I know that upping it may impose bigger memory hit and CPU hit, but it's just non-sense limit tbh. Isn't it possible to make it modifiable in Project Setting->Physics menu?

    Anyway - I think I figured out that there might be no need for 64 links at the moment.
     
    Last edited: Dec 15, 2019
  21. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Request, not a bug:

    If possible, getting a current position (not just target position) of articualted joint would be nice. I am doing a workaround by tracking local transform rotation :).
     
    flimflamm likes this.
  22. flimflamm

    flimflamm

    Joined:
    Jan 6, 2020
    Posts:
    1
    Oh god yes. I need this for rotation. Tracking the current rotation away from the starting rotation (within a configurable joint) is, for whatever reason, a nightmare.
     
  23. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Here, I did workaround:

    Code (CSharp):
    1.  
    2.     public class RotationTracker : MonoBehaviour {
    3.  
    4.         public Vector3 LocalRotationAxis;
    5.  
    6.         Vector3 _ortho;
    7.  
    8.         public float Rotation {
    9.             get {
    10.  
    11.                 Vector3 currOrtho = transform.localRotation * _ortho;
    12.                 return  Vector3.SignedAngle(_ortho, currOrtho, LocalRotationAxis);
    13.             }
    14.         }
    15.  
    16.         private void Awake() {
    17.  
    18.             _ortho = transform.localRotation * new Vector3(LocalRotationAxis.y, LocalRotationAxis.z, LocalRotationAxis.x);
    19.         }
    20.     }
    Still gotta calculate LocalRotationAxis from ArticulationBody somehow
     
  24. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    354
    Thanks for exposing this feature, looks promising!

    I made a few tests, most of it just worked. Here are a few things I think are missing, broken or could be improved:
    • It's not possible to set velocity and angular velocity of a body.
    • A way to connect articulations to rigidbodies would be really useful.
    • Setting target velocity doesn't seem to work in my tests. I tried it with a revolute joint, but there was just no force applied when I set a target speed. Target positions worked.
    • Support for the other friction types would be nice to have.
    • Better gizmos would be nice (currently it's a bit confusing with the overlapping transform handles).
    • Immovable checkbox doesn't update the body if the value is changed in play mode
    I also had a few crashes in the cases mentioned in this thread (revolute joint with default settings, adding too many articulations in a hierarchy).
     
    hippocoder likes this.
  25. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Max 16 articulation bodies can exist for one articulation (which can be limiting)

    Agree about connecting articulations to rigidbodies would be quite super.

    Other friction types would be amazing addition too for more accurate contact simulation (e.g. grabbing).
     
    mvaandrager likes this.
  26. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
    Thanks for your input here on this thread, taking notes re: everything posted here.

    In other topics, there will be 2020.1a20 released soon, and it contains a few changes made around Christmas break there, namely:

    • fix misbehaviour when an articulation was rotated due to drive's target pose over 360 degrees
    • guard from setting invalid over-constrained configurations, make the valid ones explicit in Editor (case 1201743
    • don't display drive limit value properties in articulation body editor inspector when the drive type is not limited (case 1201457)
    • fix ArticulationBody.TeleportRoot that didn't work as expected
    • edit articulation body joints anchors visually from the editor, using transform tools (initial iteration)

    Notice that there was a slight facelift to the ArticulationBody inspector with the aim of making correct states explicit while protecting from entering the invalid configurations. For instance, one can't apparently lock all DoF of a joint - since that degenerates to a Fixed joint, which should be used instead; Prismatic joint expects that only one axis is unlocked and others are locked, and so on.

    Hope that helps.
     
  27. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
    Glad to hear 360° issue was fixed, it was important fix :).
     
    yant likes this.
  28. z26

    z26

    Joined:
    Mar 15, 2014
    Posts:
    11
  29. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    72
  30. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    362
unityunity