-
Notifications
You must be signed in to change notification settings - Fork 8
Add NewtonJointAPI and newton:jointModel #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
84d4575
Fix license_format.py to accept current-year-only copyright headers
andrewkaufman cb76500
Add newton:jointModel attribute to NewtonArticulationRootAPI
andrewkaufman e1fabb3
Add NewtonJointAPI schema for joint solver configuration
andrewkaufman 447a3a9
docs(JointAPI): document inf limitStiffness as hard-limit semantics
andrewkaufman f4fdb6d
docs(JointAPI): clarify armature, friction, and limit attribute seman…
andrewkaufman da17c01
Replace jointModel token with jointsAddMobility bool
andrewkaufman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 The Newton Developers | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import math | ||
| import unittest | ||
|
|
||
| from pxr import Plug, Usd, UsdPhysics | ||
|
|
||
| import newton_usd_schemas # noqa: F401 | ||
|
|
||
| USD_HAS_LIMITS = Usd.GetVersion() >= (0, 25, 11) | ||
|
|
||
|
|
||
| class TestNewtonJointAPI(unittest.TestCase): | ||
| def setUp(self): | ||
| self.stage: Usd.Stage = Usd.Stage.CreateInMemory() | ||
| self.revolute: Usd.Prim = UsdPhysics.RevoluteJoint.Define(self.stage, "/Revolute").GetPrim() | ||
|
|
||
| def test_api_registered(self): | ||
| plug_type = Plug.Registry().FindTypeByName("NewtonPhysicsJointAPI") | ||
| self.assertEqual(plug_type.typeName, "NewtonPhysicsJointAPI") | ||
| schema_type = Usd.SchemaRegistry().GetSchemaTypeName("NewtonPhysicsJointAPI") | ||
| self.assertEqual(schema_type, "NewtonJointAPI") | ||
|
|
||
| def test_api_application(self): | ||
| self.assertFalse(self.revolute.HasAPI("NewtonJointAPI")) | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| self.assertTrue(self.revolute.HasAPI("NewtonJointAPI")) | ||
|
|
||
| self.assertTrue(self.revolute.HasAttribute("newton:armature")) | ||
| self.assertTrue(self.revolute.HasAttribute("newton:damping")) | ||
| self.assertTrue(self.revolute.HasAttribute("newton:friction")) | ||
| self.assertTrue(self.revolute.HasAttribute("newton:velocityLimit")) | ||
| self.assertTrue(self.revolute.HasAttribute("newton:limitStiffness")) | ||
| self.assertTrue(self.revolute.HasAttribute("newton:limitDamping")) | ||
|
|
||
| def test_api_application_prismatic(self): | ||
| prismatic = UsdPhysics.PrismaticJoint.Define(self.stage, "/Prismatic").GetPrim() | ||
| self.assertTrue(prismatic.CanApplyAPI("NewtonJointAPI")) | ||
| prismatic.ApplyAPI("NewtonJointAPI") | ||
| self.assertTrue(prismatic.HasAPI("NewtonJointAPI")) | ||
|
|
||
| def test_api_application_spherical(self): | ||
| spherical = UsdPhysics.SphericalJoint.Define(self.stage, "/Spherical").GetPrim() | ||
| self.assertTrue(spherical.CanApplyAPI("NewtonJointAPI")) | ||
| spherical.ApplyAPI("NewtonJointAPI") | ||
| self.assertTrue(spherical.HasAPI("NewtonJointAPI")) | ||
|
|
||
| def test_api_application_d6(self): | ||
| d6 = UsdPhysics.Joint.Define(self.stage, "/D6").GetPrim() | ||
| self.assertTrue(d6.CanApplyAPI("NewtonJointAPI")) | ||
| d6.ApplyAPI("NewtonJointAPI") | ||
| self.assertTrue(d6.HasAPI("NewtonJointAPI")) | ||
|
|
||
| def test_api_limitations(self): | ||
| xform: Usd.Prim = self.stage.DefinePrim("/NotJoint", "Xform") | ||
| self.assertFalse(xform.CanApplyAPI("NewtonJointAPI")) | ||
|
|
||
| def test_armature(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:armature") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.0) | ||
|
|
||
| success = attr.Set(0.01) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.01) | ||
|
|
||
| if USD_HAS_LIMITS: | ||
| hard = attr.GetHardLimits() | ||
| self.assertTrue(hard.IsValid()) | ||
| self.assertAlmostEqual(hard.GetMinimum(), 0.0) | ||
| self.assertIsNone(hard.GetMaximum()) | ||
|
|
||
| def test_damping(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:damping") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.0) | ||
|
|
||
| success = attr.Set(5.0) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 5.0) | ||
|
|
||
| if USD_HAS_LIMITS: | ||
| hard = attr.GetHardLimits() | ||
| self.assertTrue(hard.IsValid()) | ||
| self.assertAlmostEqual(hard.GetMinimum(), 0.0) | ||
| self.assertIsNone(hard.GetMaximum()) | ||
|
|
||
| def test_friction(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:friction") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.0) | ||
|
|
||
| success = attr.Set(0.5) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.5) | ||
|
|
||
| if USD_HAS_LIMITS: | ||
| hard = attr.GetHardLimits() | ||
| self.assertTrue(hard.IsValid()) | ||
| self.assertAlmostEqual(hard.GetMinimum(), 0.0) | ||
| self.assertIsNone(hard.GetMaximum()) | ||
|
|
||
| def test_velocity_limit(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:velocityLimit") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertEqual(attr.Get(), math.inf) | ||
|
|
||
| success = attr.Set(360.0) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 360.0) | ||
|
|
||
| if USD_HAS_LIMITS: | ||
| hard = attr.GetHardLimits() | ||
| self.assertTrue(hard.IsValid()) | ||
| self.assertAlmostEqual(hard.GetMinimum(), 0.0) | ||
| self.assertIsNone(hard.GetMaximum()) | ||
|
|
||
| def test_limit_stiffness(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:limitStiffness") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertEqual(attr.Get(), -math.inf) | ||
|
|
||
| success = attr.Set(174.5) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 174.5) | ||
|
|
||
| def test_limit_damping(self): | ||
| self.revolute.ApplyAPI("NewtonJointAPI") | ||
| attr = self.revolute.GetAttribute("newton:limitDamping") | ||
| self.assertIsNotNone(attr) | ||
| self.assertFalse(attr.HasAuthoredValue()) | ||
| self.assertEqual(attr.Get(), -math.inf) | ||
|
|
||
| success = attr.Set(0.1745) | ||
| self.assertTrue(success) | ||
| self.assertTrue(attr.HasAuthoredValue()) | ||
| self.assertAlmostEqual(attr.Get(), 0.1745) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.