Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Creating custom Joints? Simulating mechanical servos?

Discussion in 'Physics' started by CloudyVR, May 21, 2023.

  1. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    714
    Hi I am using Unity 2019.4 and need a rigid joint for a ML robot.

    Mini_Quadruped_Robot__For_SG90_Servos__by_Akagan_-_Thingiverse.png

    I am currently researching robotics controls and have spent the past few weeks trying to figure out how to use Unity joint system to no avail, it seems every time I try creating a joint system it becomes springy and the result is very unstable.

    I have tried using Articulation body in 2022 version of Unity but is not a option for my target editor. Also I found Articulation body more difficult to work with, impossible to reset to initial rotations, can't move the rigidbody directly, etc..

    In Unity 2019 I have tried configurable joint, hinge joint or character joint but the result is always springy non-rigid joints that seem to wobble, I try to keep the mass distribution even, increasing physics step but the robot's legs always have a noticeable spring. Even after setting force to infinity makes little difference.

    I also tried moving the robot without joints (using only a single rigid body and by moving the transforms) which appeared to move without any spring however the colliders were sliding on the ground so physics were not being calculated properly.

    I am hoping to create a custom joint, similar to articulation body but that can be used in my project for controlling the servos of the robot for locomotion.

    I have read that custom joints are possible, but I have no idea how to implement them. I think my application is simple needing only to rotate around one axis but the rotation should be very rigid. Forces like friction from the feet would need to be included,

    Is it possible to create a robot joint in Unity that acts more like a servo that doesn't spring or fall apart?

    Thank you
     
    Last edited: May 21, 2023
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,891
    You really, really want to use articulated bodies for this.

    It’s of course possible to write your own joints, at the end of the day they just calculate and apply positional/rotational impulses to the rigidbodies so that they meet specific constraints. However by the time you figure out the math for the general case you’d have reinvented the built-in Configurable Joint, and figured out that maximal-coordinate based joints (that remove DOFs from an otherwise free to move body) tend to be springy and unstable in all engines unless you use a really small timestep. The solution to this is using a reduced-coordinates approach, like Featherstone’s articulated body algorithm, which is what Unity’s articulated bodies implement.

    So save yourself the pain and just use articulations.

    (as a side note, moving a rigidbody by setting its transform values completely sidesteps velocity calculations such as friction -as a transform directly sets position/rotation-, so never use transforms when dealing with rigidbodies. Use rigidbody.MovePosition/Rotation instead)
     
    Last edited: May 22, 2023
  3. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    Also, you can reset joint rotations and velocities by setting their jointVelocities and jointPosition properties in their respective reduced coordinates. And you can also teleport the whole articulation tree by using TeleportRoot on the root articulation body. It just doesn’t work in the editor using the transform gizmos.