Skip to content

Commit d603b6b

Browse files
authored
Merge pull request #161 from gbionics/copilot/update-usd-section-clarity
docs: Improve usd documentation
2 parents ce01c4c + ab1afc3 commit d603b6b

8 files changed

Lines changed: 36 additions & 31 deletions

File tree

README.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,41 +304,46 @@ J = kinDyn.jacobian('frame_name', w_H_b, joints)
304304
305305
### OpenUSD
306306

307-
adam supports both exporting a model to OpenUSD and loading it back for computations.
307+
adam supports loading robot models directly from OpenUSD files and exporting models to OpenUSD.
308+
309+
**Loading directly from a USD file:**
308310

309311
```python
310312
import numpy as np
311313
from adam import Representations
312-
from adam.model import Model, build_model_factory
313314
from adam.numpy import KinDynComputations
314-
from adam.numpy.numpy_like import SpatialMath
315-
316-
# You can convert a URDF to a USD
317-
model_path = "robot.urdf"
318-
joints_name_list = ["joint_1", "joint_2"]
319315

320-
factory = build_model_factory(description=model_path, math=SpatialMath())
321-
model = Model.build(factory=factory, joints_name_list=joints_name_list)
322-
323-
# Export robot articulation to USD (use .usda for text, .usdc for binary)
324-
usd_path = "robot.usda"
325-
model.to_usd(usd_path, robot_prim_path="/Robot")
326-
327-
# If you have an existing USD file, start from this to create a KinDynComputations instance
316+
# Load directly from any existing USD file
328317
kinDyn = KinDynComputations.from_usd(
329-
usd_path,
318+
"robot.usd",
330319
robot_prim_path="/Robot",
331-
joints_name_list=joints_name_list,
320+
joints_name_list=["joint_1", "joint_2"],
332321
)
333322
kinDyn.set_frame_velocity_representation(Representations.MIXED_REPRESENTATION)
334323

335324
# Compute quantities as usual
336325
w_H_b = np.eye(4)
337-
q = np.zeros(len(joints_name_list))
326+
q = np.zeros(kinDyn.NDoF)
338327
M = kinDyn.mass_matrix(w_H_b, q)
339328
com = kinDyn.CoM_position(w_H_b, q)
340329
```
341330

331+
**Exporting a model to USD** (e.g. to convert a URDF to USD):
332+
333+
```python
334+
from adam.model import Model, build_model_factory
335+
from adam.numpy.numpy_like import SpatialMath
336+
337+
model_path = "robot.urdf"
338+
joints_name_list = ["joint_1", "joint_2"]
339+
340+
factory = build_model_factory(description=model_path, math=SpatialMath())
341+
model = Model.build(factory=factory, joints_name_list=joints_name_list)
342+
343+
# Export to USD
344+
model.to_usd("robot.usd", robot_prim_path="/Robot")
345+
```
346+
342347
### Visualization
343348

344349
adam also provides a lightweight visualization layer based on [viser](https://viser.studio/).
@@ -349,7 +354,7 @@ For quick inspection from the terminal, use the bundled viewer command:
349354
```bash
350355
adam-model-view --urdf path/to/robot.urdf
351356
adam-model-view --mujoco path/to/model.xml
352-
adam-model-view --usd path/to/robot.usda --robot-prim-path /Robot
357+
adam-model-view --usd path/to/robot.usd --robot-prim-path /Robot
353358
```
354359

355360
```python
@@ -385,7 +390,7 @@ With other model sources, only the loader changes:
385390
kindyn = KinDynComputations.from_mujoco_model(mj_model)
386391

387392
# USD
388-
kindyn = KinDynComputations.from_usd("robot.usda", robot_prim_path="/Robot")
393+
kindyn = KinDynComputations.from_usd("robot.usd", robot_prim_path="/Robot")
389394
```
390395

391396
Batched visualization is available through the same `ModelHandle` API by passing

docs/guides/usd.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Use ``from_usd()`` with a USD path:
2929
from adam import Representations
3030
from adam.numpy import KinDynComputations
3131
32-
usd_path = "robot.usda"
32+
usd_path = "robot.usd"
3333
joints_name_list = ["joint_1", "joint_2"]
3434
3535
kinDyn = KinDynComputations.from_usd(
@@ -50,7 +50,7 @@ Use ``from_usd_stage()`` with an in-memory ``pxr.Usd.Stage``:
5050
from pxr import Usd
5151
from adam.numpy import KinDynComputations
5252
53-
stage = Usd.Stage.Open("robot.usda")
53+
stage = Usd.Stage.Open("robot.usd")
5454
kinDyn = KinDynComputations.from_usd_stage(
5555
stage,
5656
robot_prim_path="/Robot",
@@ -73,7 +73,7 @@ Build an adam model and export with ``model.to_usd()``:
7373
factory = build_model_factory(description=urdf_path, math=SpatialMath())
7474
model = Model.build(factory=factory, joints_name_list=joints_name_list)
7575
76-
model.to_usd("robot.usda", robot_prim_path="/Robot")
76+
model.to_usd("robot.usd", robot_prim_path="/Robot")
7777
7878
Conversion API
7979
--------------
@@ -84,7 +84,7 @@ You can also use the functional converter API:
8484
8585
from adam.model.conversions import model_to_usd
8686
87-
model_to_usd(model, "robot.usda", robot_prim_path="/Robot")
87+
model_to_usd(model, "robot.usd", robot_prim_path="/Robot")
8888
8989
9090
@@ -100,7 +100,7 @@ USD loading is available through all backend frontends:
100100
from adam.casadi import KinDynComputations as CasadiKinDynComputations
101101
from adam.pytorch import KinDynComputations as TorchKinDynComputations
102102
103-
kinDyn = NumpyKinDynComputations.from_usd("robot.usda", robot_prim_path="/Robot", joints_name_list=["joint_1", "joint_2"])
103+
kinDyn = NumpyKinDynComputations.from_usd("robot.usd", robot_prim_path="/Robot", joints_name_list=["joint_1", "joint_2"])
104104
105105
See Also
106106
--------

docs/guides/visualization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ If you just want to inspect a model quickly, use the bundled ``adam-model-view``
6262
6363
adam-model-view --urdf path/to/robot.urdf
6464
adam-model-view --mujoco path/to/model.xml
65-
adam-model-view --usd path/to/robot.usda --robot-prim-path /Robot
65+
adam-model-view --usd path/to/robot.usd --robot-prim-path /Robot
6666
6767
The viewer loads the requested model, starts a viser server, adds a default ground plane,
6868
and exposes one joint-slider panel per robot when the model has actuated joints.

docs/quickstart/casadi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Load models from OpenUSD for symbolic workflows:
222222
from adam.casadi import KinDynComputations
223223
224224
kinDyn = KinDynComputations.from_usd(
225-
"robot.usda",
225+
"robot.usd",
226226
robot_prim_path="/Robot",
227227
joints_name_list=["joint_1", "joint_2"],
228228
)

docs/quickstart/jax.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Load models from OpenUSD and use them with JAX transformations:
241241
from adam.jax import KinDynComputations
242242
243243
kinDyn = KinDynComputations.from_usd(
244-
"robot.usda",
244+
"robot.usd",
245245
robot_prim_path="/Robot",
246246
joints_name_list=["joint_1", "joint_2"],
247247
)

docs/quickstart/numpy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ You can also load models from OpenUSD:
111111
from adam.numpy import KinDynComputations
112112
113113
kinDyn = KinDynComputations.from_usd(
114-
"robot.usda",
114+
"robot.usd",
115115
robot_prim_path="/Robot",
116116
joints_name_list=["joint_1", "joint_2"],
117117
)

docs/quickstart/pytorch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Load models from OpenUSD and use them with autograd:
323323
from adam.pytorch import KinDynComputations
324324
325325
kinDyn = KinDynComputations.from_usd(
326-
"robot.usda",
326+
"robot.usd",
327327
robot_prim_path="/Robot",
328328
joints_name_list=["joint_1", "joint_2"],
329329
)

examples/visualization/visualize_usd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Usage
55
-----
66
PYTHONPATH=src python3 examples/visualization/visualize_usd.py
7-
PYTHONPATH=src python3 examples/visualization/visualize_usd.py --usd-path /path/to/robot.usda
7+
PYTHONPATH=src python3 examples/visualization/visualize_usd.py --usd-path /path/to/robot.usd
88
99
Dependencies
1010
------------

0 commit comments

Comments
 (0)