How to modify Drive > Angular > Max Force through Python code?

Important: Isaac Sim support

Note: For Isaac Sim support, the community is gradually transitioning from this forum to the Isaac Sim GitHub repository so that questions and issues can be tracked, searched, and resolved more efficiently in one place. Whenever possible, please create a GitHub Discussion or Issue there instead of starting a new forum topic.

Note: For any Isaac Lab topics, please submit your topic to its GitHub repo ( GitHub - isaac-sim/IsaacLab: Unified framework for robot learning built on NVIDIA Isaac Sim · GitHub ) following the instructions provided on Isaac Lab’s Contributing Guidelines ( Contribution Guidelines — Isaac Lab Documentation ).

Please provide all relevant details below before submitting your post. This will help the community provide more accurate and timely assistance. After submitting, you can check the appropriate boxes. Remember, you can always edit your post later to include additional information if needed.

6.0.0
5.1.0
5.0.0
4.5.0
4.2.0
4.1.0
4.0.0
4.5.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):

Operating System

Ubuntu 24.04
Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify):

How can I modify Drive > Angular > Max Force through Python code?

I tried using the following code, but it not work.

drive = UsdPhysics.DriveAPI.Get(prim, “angular”)

drive.GetMaxForceAttr().Set(target_mf)

Hi, I don’t see why your code shouldn’t work. Did you make sure the prim path is correct? Anyway, here’s a more complete example for your reference:

from pxr import UsdPhysics, Usd
import omni.usd

# Get the USD stage
stage = omni.usd.get_context().get_stage()

# Get the joint prim (replace with your joint path)
joint_path = "/World/Robot/joint_name"
joint_prim = stage.GetPrimAtPath(joint_path)

# Determine the drive type based on joint type
if joint_prim.IsA(UsdPhysics.RevoluteJoint):
    drive_type = "angular"
elif joint_prim.IsA(UsdPhysics.PrismaticJoint):
    drive_type = "linear"
else:
    print(f"Joint at {joint_path} is not a revolute or prismatic joint")
    exit()

# Get or apply the DriveAPI
if joint_prim.HasAPI(UsdPhysics.DriveAPI, drive_type):
    drive_api = UsdPhysics.DriveAPI.Get(joint_prim, drive_type)
else:
    drive_api = UsdPhysics.DriveAPI.Apply(joint_prim, drive_type)

# Set the max force value
max_force = 1000.0  # Set your desired max force value

if drive_api.GetMaxForceAttr():
    drive_api.GetMaxForceAttr().Set(max_force)
else:
    drive_api.CreateMaxForceAttr(max_force)

print(f"Set max force to {max_force} for {drive_type} drive on {joint_path}")

I discovered today that my prim specification was incorrect, which is why Maxforce wasn’t changing. Thank you for your assistance and the example you provided!