Joints#

A joint connects two bodies and limits how they move relative to each other, like the hinge of a door.

Four panels, recorded together in one ovphysx run. A revolute joint lets an arm swing around a hinge. A prismatic joint lets a box slide down a tilted rail until it stops at the limit. A spherical joint lets a ball circle under its pivot. A distance joint lets a ball fall straight down until it is about 0.9 m from its anchor, then swing.

Joint Types#

Each type is its own prim type in USD:

Type

Prim Type

The Second Body Can

Example

Fixed

PhysicsFixedJoint

Not move relative to the first.

Two parts welded together.

Revolute

PhysicsRevoluteJoint

Turn around one axis.

A door hinge or a wheel.

Prismatic

PhysicsPrismaticJoint

Slide along one axis.

A drawer.

Spherical

PhysicsSphericalJoint

Turn in any direction around one point.

A shoulder.

Distance

PhysicsDistanceJoint

Move freely within a minimum and maximum distance.

A rope.

D6 (six degrees of freedom)

PhysicsJoint

Slide along and turn around each of three axes, each free, limited, or locked.

Anything the other types cannot do.

Connecting Two Bodies#

A joint prim names its bodies with the relationships physics:body0 and physics:body1. Leave one out to attach the other body to the world.

The joint holds a point of one body to a point of the other. You give each point, with its axes, as a joint frame:

Attribute

Meaning

physics:localPos0, physics:localRot0

Position and rotation of the joint frame on body 0, in body 0’s own coordinates. When body 0 is the world, they are in world coordinates.

physics:localPos1, physics:localRot1

The same for body 1.

physics:axis

The frame axis, "X", "Y", or "Z", that a revolute joint turns around or a prismatic joint slides along.

Place the bodies so that the two frames meet at the start. If they do not, ovphysx logs a warning and snaps the bodies into place in the first step.

The two bodies of a joint do not collide with each other. To let them collide, set the joint’s own physics:collisionEnabled to true.

Limits#

A limit stops a joint at a minimum or a maximum, like a door stop.

Joint

Limit Attributes

Unit

Revolute

physics:lowerLimit, physics:upperLimit

Degrees

Prismatic

physics:lowerLimit, physics:upperLimit

Distance

Spherical

physics:coneAngle0Limit, physics:coneAngle1Limit, which form a cone around the joint’s axis

Degrees

Distance

physics:minDistance, physics:maxDistance

Distance

D6

One PhysicsLimitAPI per axis, such as PhysicsLimitAPI:rotX

Degrees or distance

Drives#

A drive is a motor on a joint. It pushes the joint toward a target position, a target velocity, or both, like a spring with a damper:

force = stiffness × (target position − position)
      + damping × (target velocity − velocity)

On a revolute joint, apply PhysicsDriveAPI:angular and set these attributes:

Attribute

Meaning

drive:angular:physics:targetPosition

The angle the drive pulls toward, in degrees.

drive:angular:physics:targetVelocity

The speed the drive pushes toward, in degrees per second.

drive:angular:physics:stiffness

How strongly the drive pulls toward the target angle, as torque per degree.

drive:angular:physics:damping

How strongly the drive resists any speed other than the target velocity.

A prismatic joint takes PhysicsDriveAPI:linear with the same attributes, in distances. A drive that keeps a speed, such as a spinning wheel, sets the stiffness to 0 and uses damping with a target velocity.

The following program, joints_drive.py, turns an arm on a hinge to 90 degrees:

The imports and the scene, in USD
import math

import ovstage
from ovphysx.population import physics_population_descs
from ovphysx import PhysX
from ovphysx.samples.python_samples.schema_support import physx_schema_paths
from ovphysx.types import SimObjectType

# A 1 m arm that lies along the x axis. A hinge at the origin lets it turn
# around the vertical z axis, and a drive turns it to 90 degrees.
SCENE = """#usda 1.0
(
    metersPerUnit = 1
    kilogramsPerUnit = 1
    upAxis = "Z"
)

def Xform "World"
{
    def PhysicsScene "PhysicsScene" {}

    def Capsule "Arm" (
        prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI"]
    )
    {
        double radius = 0.05
        double height = 0.9
        uniform token axis = "X"
        double3 xformOp:translate = (0.5, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]
    }

    def PhysicsRevoluteJoint "Hinge" (
        prepend apiSchemas = ["PhysicsDriveAPI:angular"]
    )
    {
        rel physics:body1 = </World/Arm>
        uniform token physics:axis = "Z"
        point3f physics:localPos0 = (0, 0, 0)
        point3f physics:localPos1 = (-0.5, 0, 0)
        float drive:angular:physics:targetPosition = 90
        float drive:angular:physics:stiffness = 2
        float drive:angular:physics:damping = 0.6
    }
}
"""


def arm_angle(physx):
    """Read the arm's center and return its angle around the hinge in degrees."""
    with physx.read_sync(SimObjectType.RIGID_BODY, ["position"]) as result:
        x, y, _ = result.groups[0].tensors[0].numpy()[0]
        return math.degrees(math.atan2(y, x))


ovstage.population.register_usd_schemas([str(p) for p in physx_schema_paths()])

stage = ovstage.Stage("driven_arm")
ovstage.population.open_usd_from_string_with_desc(
    stage, SCENE, ordinal=1, time=ovstage.population.DEFAULT_TIME, descs=physics_population_descs(rendering=True)
)
stage.advance_write_floor(ordinal=1).wait()

physx = PhysX()
physx.wait_task(physx.attach_ovstage(stage, read_ordinal=1))

print(f"t=0.00 s  angle = {arm_angle(physx):3.0f} deg")
for step in range(1, 97):
    physx.step_sync(1.0 / 60.0)
    if step % 12 == 0:
        print(f"t={step / 60:.2f} s  angle = {arm_angle(physx):3.0f} deg")

physx.wait_task(physx.detach_ovstage())
physx.destroy()
stage.destroy()

It prints:

t=0.00 s  angle =   0 deg
t=0.20 s  angle =  32 deg
t=0.40 s  angle =  64 deg
t=0.60 s  angle =  80 deg
t=0.80 s  angle =  87 deg
t=1.00 s  angle =  89 deg
t=1.20 s  angle =  90 deg
t=1.40 s  angle =  90 deg
t=1.60 s  angle =  90 deg

Notice the following:

  • ovphysx reads joint angles only for the joints of an articulation, which Articulations introduces. The program computes the angle from the arm’s position instead.

  • The following figure shows the same arm with less and with more damping:

Three copies of the arm, seen from above, with a damping of 0.1, 0.6, and 3. A plot shows each arm's angle over 1.6 s. With 0.1, the arm swings past the 90-degree target to 140 degrees and back. With 0.6, it settles on the target. With 3, it moves slowly and reaches only about 57 degrees.

A drive acts like a spring, so a steady load, such as the weight of an arm held out sideways, holds the joint short of its target. A higher stiffness makes the gap smaller.

To change a drive target while the simulation runs, edit the joint in the stage, as Changing the Scene shows.

Turning a Joint Off#

To leave a joint out of the simulation, set physics:jointEnabled = false on the joint prim. Its bodies then move freely.

More Detail#