Articulations#

An articulation is a set of rigid parts, called links, connected by joints in a tree, such as a robot arm, a gripper, or a walking robot. ovphysx moves the links together, so the joints always hold exactly. Your program controls an articulation by setting target angles for its joints.

Top view of a robot arm on a fixed base. The program sets new targets for its two joints, drawn as a dashed outline, and the arm turns into that pose. A faint outline marks the starting pose. A plot shows the shoulder angle rising from 0 to 45 degrees and the elbow angle falling from 90 to 60 degrees, each settling on its dashed target line.

Drives and the Starting Pose#

Each motor of an articulation is a joint drive, which pulls its joint toward a target angle, as Joints explains. Your program usually writes new targets while the simulation runs.

Joints start at an angle of 0. To start a joint at another angle, apply PhysicsJointStateAPI:angular to it and set state:angular:physics:position in degrees. When ovphysx attaches the stage, it places the links to match these angles.

An Arm That Moves to Its Targets#

The following program, articulations_arm.py, builds a two-link arm that turns in a horizontal plane and writes targets of 45 and 60 degrees. The scene has these parts:

Scene Part

What It Does

Arm, with PhysicsArticulationRootAPI

Makes the links and joints under it one articulation.

BaseJoint

A fixed joint with only one body, so Base is fixed to the world.

Shoulder and Elbow

Revolute joints that turn around the vertical z axis. PhysicsDriveAPI:angular gives each one a drive.

PhysicsJointStateAPI:angular on Elbow

Starts the elbow at 90 degrees. Its drive target is also 90 degrees, so the elbow holds that angle.

The imports and the scene, in USD
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 robot arm that turns in a horizontal plane, like a pick-and-place robot:
# a base fixed to the world and two links on vertical revolute joints.
# The links are written in the zero pose, with the arm pointing along +X.
SCENE = """#usda 1.0
(
    metersPerUnit = 1
    kilogramsPerUnit = 1
    upAxis = "Z"
)

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

    def Xform "Arm" (
        prepend apiSchemas = ["PhysicsArticulationRootAPI"]
    )
    {
        def Cube "Base" (
            prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI"]
        )
        {
            double size = 0.2
            double3 xformOp:translate = (0, 0, 0.1)
            uniform token[] xformOpOrder = ["xformOp:translate"]
        }

        def PhysicsFixedJoint "BaseJoint"
        {
            rel physics:body1 = </World/Arm/Base>
        }

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

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

        def PhysicsRevoluteJoint "Shoulder" (
            prepend apiSchemas = ["PhysicsDriveAPI:angular"]
        )
        {
            uniform token physics:axis = "Z"
            rel physics:body0 = </World/Arm/Base>
            rel physics:body1 = </World/Arm/UpperArm>
            point3f physics:localPos0 = (0, 0, 0.15)
            point3f physics:localPos1 = (-0.25, 0, 0)
            float drive:angular:physics:stiffness = 1000
            float drive:angular:physics:damping = 200
        }

        def PhysicsRevoluteJoint "Elbow" (
            prepend apiSchemas = ["PhysicsDriveAPI:angular",
                                  "PhysicsJointStateAPI:angular"]
        )
        {
            uniform token physics:axis = "Z"
            rel physics:body0 = </World/Arm/UpperArm>
            rel physics:body1 = </World/Arm/Forearm>
            point3f physics:localPos0 = (0.25, 0, 0)
            point3f physics:localPos1 = (-0.25, 0, 0)
            float drive:angular:physics:stiffness = 1000
            float drive:angular:physics:damping = 200
            float drive:angular:physics:targetPosition = 90
            float state:angular:physics:position = 90
        }
    }
}
"""


def joint_angle(physx, joint):
    """Read the angle of one joint, in degrees."""
    with physx.read_sync(
        SimObjectType.ARTICULATION_JOINT,
        ["jointPosition"],
        pattern=f"/World/Arm/{joint}",
    ) as result:
        angles = result.groups[0].tensors[0].numpy()  # one row per joint axis
        return float(angles[0])


def set_target(physx, joint, degrees):
    """Write the drive target of one joint, in degrees."""
    with physx.write_sync(
        SimObjectType.ARTICULATION_JOINT,
        ["jointPositionTarget"],
        pattern=f"/World/Arm/{joint}",
    ) as session:
        group = session.groups[0]
        group.tensors[0].assign([degrees])  # one row: the joint's only axis
        session.commit_sync(group)


def print_angles(physx, t):
    shoulder = joint_angle(physx, "Shoulder")
    elbow = joint_angle(physx, "Elbow")
    print(f"t={t:.2f} s  shoulder = {shoulder:5.1f} deg  elbow = {elbow:5.1f} deg")


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

stage = ovstage.Stage("articulation_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))

# Set the drive targets once. They stay until the program writes new ones.
set_target(physx, "Shoulder", 45.0)
set_target(physx, "Elbow", 60.0)

print_angles(physx, 0.0)
for step in range(1, 91):
    physx.step_sync(1.0 / 60.0)
    if step % 15 == 0:
        print_angles(physx, step / 60)

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

It prints:

t=0.00 s  shoulder =   0.0 deg  elbow =  90.0 deg
t=0.25 s  shoulder =  32.1 deg  elbow =  68.6 deg
t=0.50 s  shoulder =  41.3 deg  elbow =  62.5 deg
t=0.75 s  shoulder =  43.9 deg  elbow =  60.7 deg
t=1.00 s  shoulder =  44.7 deg  elbow =  60.2 deg
t=1.25 s  shoulder =  44.9 deg  elbow =  60.1 deg
t=1.50 s  shoulder =  45.0 deg  elbow =  60.0 deg

Notice the following:

  • Joint angles are in degrees, both in the scene and in reads and writes.

  • A target stays until your program writes a new one, so one write is enough. An articulation that has almost stopped moving falls asleep to save work, and a new target wakes it.

Reading and Writing an Articulation#

An articulation has data at three levels, each with its own object type:

Object Type

One Entry Per

Examples of Attributes

ARTICULATION

Articulation

rootPosition, rootOrientation, rootLinearVelocity

ARTICULATION_LINK

Link

position, orientation, linearVelocity

ARTICULATION_JOINT

Joint, with one row per axis

jointPosition, jointVelocity, jointPositionTarget, jointVelocityTarget

Link poses are read-only, because the root and the joints decide where every link is. To move an articulation, write its root state or its joint values.

Read-only attributes of ARTICULATION map its parts back to the scene. linkPath holds the prim of each link, and linkInboundJoint holds the joint that leads into each link. dofJointPath and dofJointType hold the joint and joint type of each axis that can move. Each path comes as a handle, which result.dictionary.path_to_string(ovstage.PrimPath(handle)) turns into text.

More Detail#