warp-lang 1.0.2__py3-none-macosx_10_13_universal2.whl → 1.1.0__py3-none-macosx_10_13_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +115 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3425 -3354
- warp/codegen.py +2878 -2792
- warp/config.py +40 -36
- warp/constants.py +45 -45
- warp/context.py +5194 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +383 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -277
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +146 -146
- warp/examples/benchmarks/benchmark_launches.py +295 -295
- warp/examples/browse.py +29 -29
- warp/examples/core/example_dem.py +234 -219
- warp/examples/core/example_fluid.py +293 -267
- warp/examples/core/example_graph_capture.py +144 -126
- warp/examples/core/example_marching_cubes.py +188 -174
- warp/examples/core/example_mesh.py +174 -155
- warp/examples/core/example_mesh_intersect.py +205 -193
- warp/examples/core/example_nvdb.py +176 -170
- warp/examples/core/example_raycast.py +105 -90
- warp/examples/core/example_raymarch.py +199 -178
- warp/examples/core/example_render_opengl.py +185 -141
- warp/examples/core/example_sph.py +405 -387
- warp/examples/core/example_torch.py +222 -181
- warp/examples/core/example_wave.py +263 -248
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +407 -389
- warp/examples/fem/example_convection_diffusion.py +182 -168
- warp/examples/fem/example_convection_diffusion_dg.py +219 -209
- warp/examples/fem/example_convection_diffusion_dg0.py +204 -194
- warp/examples/fem/example_deformed_geometry.py +177 -159
- warp/examples/fem/example_diffusion.py +201 -173
- warp/examples/fem/example_diffusion_3d.py +177 -152
- warp/examples/fem/example_diffusion_mgpu.py +221 -214
- warp/examples/fem/example_mixed_elasticity.py +244 -222
- warp/examples/fem/example_navier_stokes.py +259 -243
- warp/examples/fem/example_stokes.py +220 -192
- warp/examples/fem/example_stokes_transfer.py +265 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +260 -246
- warp/examples/optim/example_cloth_throw.py +222 -209
- warp/examples/optim/example_diffray.py +566 -536
- warp/examples/optim/example_drone.py +864 -835
- warp/examples/optim/example_inverse_kinematics.py +176 -168
- warp/examples/optim/example_inverse_kinematics_torch.py +185 -169
- warp/examples/optim/example_spring_cage.py +239 -231
- warp/examples/optim/example_trajectory.py +223 -199
- warp/examples/optim/example_walker.py +306 -293
- warp/examples/sim/example_cartpole.py +139 -129
- warp/examples/sim/example_cloth.py +196 -186
- warp/examples/sim/example_granular.py +124 -111
- warp/examples/sim/example_granular_collision_sdf.py +197 -186
- warp/examples/sim/example_jacobian_ik.py +236 -214
- warp/examples/sim/example_particle_chain.py +118 -105
- warp/examples/sim/example_quadruped.py +193 -180
- warp/examples/sim/example_rigid_chain.py +197 -187
- warp/examples/sim/example_rigid_contact.py +189 -177
- warp/examples/sim/example_rigid_force.py +127 -125
- warp/examples/sim/example_rigid_gyroscopic.py +109 -95
- warp/examples/sim/example_rigid_soft_contact.py +134 -122
- warp/examples/sim/example_soft_body.py +190 -177
- warp/fabric.py +337 -335
- warp/fem/__init__.py +60 -27
- warp/fem/cache.py +401 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +15 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +744 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +441 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1630 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +294 -292
- warp/fem/space/basis_space.py +488 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +267 -267
- warp/fem/space/grid_3d_function_space.py +305 -306
- warp/fem/space/hexmesh_function_space.py +350 -352
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +368 -369
- warp/fem/space/restriction.py +158 -160
- warp/fem/space/shape/__init__.py +13 -15
- warp/fem/space/shape/cube_shape_function.py +738 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +294 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +223 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1072 -1025
- warp/native/builtin.h +1560 -1560
- warp/native/bvh.cpp +398 -398
- warp/native/bvh.cu +525 -525
- warp/native/bvh.h +429 -429
- warp/native/clang/clang.cpp +495 -464
- warp/native/crt.cpp +31 -31
- warp/native/crt.h +334 -334
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1498 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +293 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/NanoVDB.h +4782 -4782
- warp/native/nanovdb/PNanoVDB.h +2553 -2553
- warp/native/nanovdb/PNanoVDBWrite.h +294 -294
- warp/native/noise.h +850 -850
- warp/native/quat.h +1084 -1084
- warp/native/rand.h +299 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1132 -1132
- warp/native/volume.cpp +297 -297
- warp/native/volume.cu +32 -32
- warp/native/volume.h +538 -538
- warp/native/volume_builder.cu +425 -425
- warp/native/volume_builder.h +19 -19
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2943 -2828
- warp/native/warp.h +313 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3217 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1910 -1991
- warp/sim/integrator_xpbd.py +3294 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1227 -1227
- warp/stubs.py +2109 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +22 -22
- warp/tests/aux_test_grad_customs.py +23 -23
- warp/tests/aux_test_reference.py +11 -11
- warp/tests/aux_test_reference_reference.py +10 -10
- warp/tests/aux_test_square.py +17 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +239 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +157 -157
- warp/tests/test_arithmetic.py +1124 -1124
- warp/tests/test_array.py +2417 -2326
- warp/tests/test_array_reduce.py +150 -150
- warp/tests/test_async.py +668 -656
- warp/tests/test_atomic.py +141 -141
- warp/tests/test_bool.py +204 -149
- warp/tests/test_builtins_resolution.py +1292 -1292
- warp/tests/test_bvh.py +164 -171
- warp/tests/test_closest_point_edge_edge.py +228 -228
- warp/tests/test_codegen.py +566 -553
- warp/tests/test_compile_consts.py +97 -101
- warp/tests/test_conditional.py +246 -246
- warp/tests/test_copy.py +232 -215
- warp/tests/test_ctypes.py +632 -632
- warp/tests/test_dense.py +67 -67
- warp/tests/test_devices.py +91 -98
- warp/tests/test_dlpack.py +530 -529
- warp/tests/test_examples.py +400 -378
- warp/tests/test_fabricarray.py +955 -955
- warp/tests/test_fast_math.py +62 -54
- warp/tests/test_fem.py +1277 -1278
- warp/tests/test_fp16.py +130 -130
- warp/tests/test_func.py +338 -337
- warp/tests/test_generics.py +571 -571
- warp/tests/test_grad.py +746 -640
- warp/tests/test_grad_customs.py +333 -336
- warp/tests/test_hash_grid.py +210 -164
- warp/tests/test_import.py +39 -39
- warp/tests/test_indexedarray.py +1134 -1134
- warp/tests/test_intersect.py +67 -67
- warp/tests/test_jax.py +307 -307
- warp/tests/test_large.py +167 -164
- warp/tests/test_launch.py +354 -354
- warp/tests/test_lerp.py +261 -261
- warp/tests/test_linear_solvers.py +191 -171
- warp/tests/test_lvalue.py +421 -493
- warp/tests/test_marching_cubes.py +65 -65
- warp/tests/test_mat.py +1801 -1827
- warp/tests/test_mat_lite.py +115 -115
- warp/tests/test_mat_scalar_ops.py +2907 -2889
- warp/tests/test_math.py +126 -193
- warp/tests/test_matmul.py +500 -499
- warp/tests/test_matmul_lite.py +410 -410
- warp/tests/test_mempool.py +188 -190
- warp/tests/test_mesh.py +284 -324
- warp/tests/test_mesh_query_aabb.py +228 -241
- warp/tests/test_mesh_query_point.py +692 -702
- warp/tests/test_mesh_query_ray.py +292 -303
- warp/tests/test_mlp.py +276 -276
- warp/tests/test_model.py +110 -110
- warp/tests/test_modules_lite.py +39 -39
- warp/tests/test_multigpu.py +163 -163
- warp/tests/test_noise.py +248 -248
- warp/tests/test_operators.py +250 -250
- warp/tests/test_options.py +123 -125
- warp/tests/test_peer.py +133 -137
- warp/tests/test_pinned.py +78 -78
- warp/tests/test_print.py +54 -54
- warp/tests/test_quat.py +2086 -2086
- warp/tests/test_rand.py +288 -288
- warp/tests/test_reload.py +217 -217
- warp/tests/test_rounding.py +179 -179
- warp/tests/test_runlength_encode.py +190 -190
- warp/tests/test_sim_grad.py +243 -0
- warp/tests/test_sim_kinematics.py +91 -97
- warp/tests/test_smoothstep.py +168 -168
- warp/tests/test_snippet.py +305 -266
- warp/tests/test_sparse.py +468 -460
- warp/tests/test_spatial.py +2148 -2148
- warp/tests/test_streams.py +486 -473
- warp/tests/test_struct.py +710 -675
- warp/tests/test_tape.py +173 -148
- warp/tests/test_torch.py +743 -743
- warp/tests/test_transient_module.py +87 -87
- warp/tests/test_types.py +556 -659
- warp/tests/test_utils.py +490 -499
- warp/tests/test_vec.py +1264 -1268
- warp/tests/test_vec_lite.py +73 -73
- warp/tests/test_vec_scalar_ops.py +2099 -2099
- warp/tests/test_verify_fp.py +94 -94
- warp/tests/test_volume.py +737 -736
- warp/tests/test_volume_write.py +255 -265
- warp/tests/unittest_serial.py +37 -37
- warp/tests/unittest_suites.py +363 -359
- warp/tests/unittest_utils.py +603 -578
- warp/tests/unused_test_misc.py +71 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +566 -561
- warp/torch.py +321 -295
- warp/types.py +4504 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.2.dist-info → warp_lang-1.1.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.2.dist-info → warp_lang-1.1.0.dist-info}/METADATA +338 -400
- warp_lang-1.1.0.dist-info/RECORD +352 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp_lang-1.0.2.dist-info/RECORD +0 -352
- {warp_lang-1.0.2.dist-info → warp_lang-1.1.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.2.dist-info → warp_lang-1.1.0.dist-info}/top_level.txt +0 -0
warp/sim/import_urdf.py
CHANGED
|
@@ -1,516 +1,536 @@
|
|
|
1
|
-
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
-
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
-
# and proprietary rights in and to this software, related documentation
|
|
4
|
-
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
-
# distribution of this software and related documentation without an express
|
|
6
|
-
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
-
|
|
8
|
-
import os
|
|
9
|
-
import xml.etree.ElementTree as ET
|
|
10
|
-
from typing import Union
|
|
11
|
-
|
|
12
|
-
import numpy as np
|
|
13
|
-
|
|
14
|
-
import warp as wp
|
|
15
|
-
from warp.sim.model import Mesh
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
file = ET.parse(urdf_filename)
|
|
85
|
-
root = file.getroot()
|
|
86
|
-
|
|
87
|
-
contact_vars =
|
|
88
|
-
ke
|
|
89
|
-
kd
|
|
90
|
-
kf
|
|
91
|
-
ka
|
|
92
|
-
mu
|
|
93
|
-
restitution
|
|
94
|
-
thickness
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def parse_transform(element):
|
|
98
|
-
if element is None or element.find("origin") is None:
|
|
99
|
-
return wp.transform()
|
|
100
|
-
origin = element.find("origin")
|
|
101
|
-
xyz = origin.get("xyz") or "0 0 0"
|
|
102
|
-
rpy = origin.get("rpy") or "0 0 0"
|
|
103
|
-
xyz = [float(x) * scale for x in xyz.split()]
|
|
104
|
-
rpy = [float(x) for x in rpy.split()]
|
|
105
|
-
return wp.transform(xyz, wp.quat_rpy(*rpy))
|
|
106
|
-
|
|
107
|
-
def parse_shapes(link, geoms, density, incoming_xform=None, visible=True, just_visual=False):
|
|
108
|
-
shapes = []
|
|
109
|
-
# add geometry
|
|
110
|
-
for geom_group in geoms:
|
|
111
|
-
geo = geom_group.find("geometry")
|
|
112
|
-
if geo is None:
|
|
113
|
-
continue
|
|
114
|
-
|
|
115
|
-
tf = parse_transform(geom_group)
|
|
116
|
-
if incoming_xform is not None:
|
|
117
|
-
tf = incoming_xform * tf
|
|
118
|
-
|
|
119
|
-
for box in geo.findall("box"):
|
|
120
|
-
size = box.get("size") or "1 1 1"
|
|
121
|
-
size = [float(x) for x in size.split()]
|
|
122
|
-
s = builder.add_shape_box(
|
|
123
|
-
body=link,
|
|
124
|
-
pos=wp.vec3(tf.p),
|
|
125
|
-
rot=wp.quat(tf.q),
|
|
126
|
-
hx=size[0] * 0.5 * scale,
|
|
127
|
-
hy=size[1] * 0.5 * scale,
|
|
128
|
-
hz=size[2] * 0.5 * scale,
|
|
129
|
-
density=density,
|
|
130
|
-
is_visible=visible,
|
|
131
|
-
has_ground_collision=not just_visual,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# a
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
I_m =
|
|
293
|
-
I_m
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
base_joint
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
1
|
+
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
+
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
+
# and proprietary rights in and to this software, related documentation
|
|
4
|
+
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
+
# distribution of this software and related documentation without an express
|
|
6
|
+
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import xml.etree.ElementTree as ET
|
|
10
|
+
from typing import Union
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
import warp as wp
|
|
15
|
+
from warp.sim.model import Mesh
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def parse_urdf(
|
|
19
|
+
urdf_filename,
|
|
20
|
+
builder,
|
|
21
|
+
xform=None,
|
|
22
|
+
floating=False,
|
|
23
|
+
base_joint: Union[dict, str] = None,
|
|
24
|
+
density=1000.0,
|
|
25
|
+
stiffness=100.0,
|
|
26
|
+
damping=10.0,
|
|
27
|
+
armature=0.0,
|
|
28
|
+
contact_ke=1.0e4,
|
|
29
|
+
contact_kd=1.0e3,
|
|
30
|
+
contact_kf=1.0e2,
|
|
31
|
+
contact_ka=0.0,
|
|
32
|
+
contact_mu=0.25,
|
|
33
|
+
contact_restitution=0.5,
|
|
34
|
+
contact_thickness=0.0,
|
|
35
|
+
limit_ke=100.0,
|
|
36
|
+
limit_kd=10.0,
|
|
37
|
+
joint_limit_lower=-1e6,
|
|
38
|
+
joint_limit_upper=1e6,
|
|
39
|
+
scale=1.0,
|
|
40
|
+
parse_visuals_as_colliders=False,
|
|
41
|
+
force_show_colliders=False,
|
|
42
|
+
enable_self_collisions=True,
|
|
43
|
+
ignore_inertial_definitions=True,
|
|
44
|
+
ensure_nonstatic_links=True,
|
|
45
|
+
static_link_mass=1e-2,
|
|
46
|
+
collapse_fixed_joints=False,
|
|
47
|
+
):
|
|
48
|
+
"""
|
|
49
|
+
Parses a URDF file and adds the bodies and joints to the given ModelBuilder.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
urdf_filename (str): The filename of the URDF file to parse.
|
|
53
|
+
builder (ModelBuilder): The :class:`ModelBuilder` to add the bodies and joints to.
|
|
54
|
+
xform (:ref:`transform <transform>`): The transform to apply to the root body.
|
|
55
|
+
floating (bool): If True, the root body is a free joint. If False, the root body is connected via a fixed joint to the world, unless a `base_joint` is defined.
|
|
56
|
+
base_joint (Union[str, dict]): The joint by which the root body is connected to the world. This can be either a string defining the joint axes of a D6 joint with comma-separated positional and angular axis names (e.g. "px,py,rz" for a D6 joint with linear axes in x, y and an angular axis in z) or a dict with joint parameters (see :meth:`ModelBuilder.add_joint`).
|
|
57
|
+
density (float): The density of the shapes in kg/m^3 which will be used to calculate the body mass and inertia.
|
|
58
|
+
stiffness (float): The stiffness of the joints.
|
|
59
|
+
damping (float): The damping of the joints.
|
|
60
|
+
armature (float): The armature of the joints (bias to add to the inertia diagonals that may stabilize the simulation).
|
|
61
|
+
contact_ke (float): The stiffness of the shape contacts (used by the Euler integrators).
|
|
62
|
+
contact_kd (float): The damping of the shape contacts (used by the Euler integrators).
|
|
63
|
+
contact_kf (float): The friction stiffness of the shape contacts (used by the Euler integrators).
|
|
64
|
+
contact_ka (float): The adhesion distance of the shape contacts (used by the Euler integrators).
|
|
65
|
+
contact_mu (float): The friction coefficient of the shape contacts.
|
|
66
|
+
contact_restitution (float): The restitution coefficient of the shape contacts.
|
|
67
|
+
contact_thickness (float): The thickness to add to the shape geometry.
|
|
68
|
+
limit_ke (float): The stiffness of the joint limits (used by the Euler integrators).
|
|
69
|
+
limit_kd (float): The damping of the joint limits (used by the Euler integrators).
|
|
70
|
+
joint_limit_lower (float): The default lower joint limit if not specified in the URDF.
|
|
71
|
+
joint_limit_upper (float): The default upper joint limit if not specified in the URDF.
|
|
72
|
+
scale (float): The scaling factor to apply to the imported mechanism.
|
|
73
|
+
parse_visuals_as_colliders (bool): If True, the geometry defined under the `<visual>` tags is used for collision handling instead of the `<collision>` geometries.
|
|
74
|
+
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
|
|
75
|
+
enable_self_collisions (bool): If True, self-collisions are enabled.
|
|
76
|
+
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the URDF are ignored and the inertia is calculated from the shape geometry.
|
|
77
|
+
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
|
|
78
|
+
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
|
|
79
|
+
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
|
|
80
|
+
"""
|
|
81
|
+
if xform is None:
|
|
82
|
+
xform = wp.transform()
|
|
83
|
+
|
|
84
|
+
file = ET.parse(urdf_filename)
|
|
85
|
+
root = file.getroot()
|
|
86
|
+
|
|
87
|
+
contact_vars = {
|
|
88
|
+
"ke": contact_ke,
|
|
89
|
+
"kd": contact_kd,
|
|
90
|
+
"kf": contact_kf,
|
|
91
|
+
"ka": contact_ka,
|
|
92
|
+
"mu": contact_mu,
|
|
93
|
+
"restitution": contact_restitution,
|
|
94
|
+
"thickness": contact_thickness,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
def parse_transform(element):
|
|
98
|
+
if element is None or element.find("origin") is None:
|
|
99
|
+
return wp.transform()
|
|
100
|
+
origin = element.find("origin")
|
|
101
|
+
xyz = origin.get("xyz") or "0 0 0"
|
|
102
|
+
rpy = origin.get("rpy") or "0 0 0"
|
|
103
|
+
xyz = [float(x) * scale for x in xyz.split()]
|
|
104
|
+
rpy = [float(x) for x in rpy.split()]
|
|
105
|
+
return wp.transform(xyz, wp.quat_rpy(*rpy))
|
|
106
|
+
|
|
107
|
+
def parse_shapes(link, geoms, density, incoming_xform=None, visible=True, just_visual=False):
|
|
108
|
+
shapes = []
|
|
109
|
+
# add geometry
|
|
110
|
+
for geom_group in geoms:
|
|
111
|
+
geo = geom_group.find("geometry")
|
|
112
|
+
if geo is None:
|
|
113
|
+
continue
|
|
114
|
+
|
|
115
|
+
tf = parse_transform(geom_group)
|
|
116
|
+
if incoming_xform is not None:
|
|
117
|
+
tf = incoming_xform * tf
|
|
118
|
+
|
|
119
|
+
for box in geo.findall("box"):
|
|
120
|
+
size = box.get("size") or "1 1 1"
|
|
121
|
+
size = [float(x) for x in size.split()]
|
|
122
|
+
s = builder.add_shape_box(
|
|
123
|
+
body=link,
|
|
124
|
+
pos=wp.vec3(tf.p),
|
|
125
|
+
rot=wp.quat(tf.q),
|
|
126
|
+
hx=size[0] * 0.5 * scale,
|
|
127
|
+
hy=size[1] * 0.5 * scale,
|
|
128
|
+
hz=size[2] * 0.5 * scale,
|
|
129
|
+
density=density,
|
|
130
|
+
is_visible=visible,
|
|
131
|
+
has_ground_collision=not just_visual,
|
|
132
|
+
has_shape_collision=not just_visual,
|
|
133
|
+
**contact_vars,
|
|
134
|
+
)
|
|
135
|
+
shapes.append(s)
|
|
136
|
+
|
|
137
|
+
for sphere in geo.findall("sphere"):
|
|
138
|
+
s = builder.add_shape_sphere(
|
|
139
|
+
body=link,
|
|
140
|
+
pos=wp.vec3(tf.p),
|
|
141
|
+
rot=wp.quat(tf.q),
|
|
142
|
+
radius=float(sphere.get("radius") or "1") * scale,
|
|
143
|
+
density=density,
|
|
144
|
+
is_visible=visible,
|
|
145
|
+
has_ground_collision=not just_visual,
|
|
146
|
+
has_shape_collision=not just_visual,
|
|
147
|
+
**contact_vars,
|
|
148
|
+
)
|
|
149
|
+
shapes.append(s)
|
|
150
|
+
|
|
151
|
+
for cylinder in geo.findall("cylinder"):
|
|
152
|
+
s = builder.add_shape_capsule(
|
|
153
|
+
body=link,
|
|
154
|
+
pos=wp.vec3(tf.p),
|
|
155
|
+
rot=wp.quat(tf.q),
|
|
156
|
+
radius=float(cylinder.get("radius") or "1") * scale,
|
|
157
|
+
half_height=float(cylinder.get("length") or "1") * 0.5 * scale,
|
|
158
|
+
density=density,
|
|
159
|
+
up_axis=2, # cylinders in URDF are aligned with z-axis
|
|
160
|
+
is_visible=visible,
|
|
161
|
+
has_ground_collision=not just_visual,
|
|
162
|
+
has_shape_collision=not just_visual,
|
|
163
|
+
**contact_vars,
|
|
164
|
+
)
|
|
165
|
+
shapes.append(s)
|
|
166
|
+
|
|
167
|
+
for mesh in geo.findall("mesh"):
|
|
168
|
+
filename = mesh.get("filename")
|
|
169
|
+
if filename is None:
|
|
170
|
+
continue
|
|
171
|
+
if filename.startswith("package://"):
|
|
172
|
+
fn = filename.replace("package://", "")
|
|
173
|
+
package_name = fn.split("/")[0]
|
|
174
|
+
urdf_folder = os.path.dirname(urdf_filename)
|
|
175
|
+
# resolve file path from package name, i.e. find
|
|
176
|
+
# the package folder from the URDF folder
|
|
177
|
+
if package_name in urdf_folder:
|
|
178
|
+
filename = os.path.join(urdf_folder[: urdf_folder.index(package_name)], fn)
|
|
179
|
+
else:
|
|
180
|
+
wp.utils.warn(
|
|
181
|
+
f'Warning: package "{package_name}" not found in URDF folder while loading mesh at "{filename}"'
|
|
182
|
+
)
|
|
183
|
+
elif filename.startswith("http://") or filename.startswith("https://"):
|
|
184
|
+
# download mesh
|
|
185
|
+
import shutil
|
|
186
|
+
import tempfile
|
|
187
|
+
|
|
188
|
+
import requests
|
|
189
|
+
|
|
190
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
191
|
+
# get filename extension
|
|
192
|
+
extension = os.path.splitext(filename)[1]
|
|
193
|
+
tmpfile = os.path.join(tmpdir, "mesh" + extension)
|
|
194
|
+
with requests.get(filename, stream=True) as r:
|
|
195
|
+
with open(tmpfile, "wb") as f:
|
|
196
|
+
shutil.copyfileobj(r.raw, f)
|
|
197
|
+
filename = tmpfile
|
|
198
|
+
else:
|
|
199
|
+
filename = os.path.join(os.path.dirname(urdf_filename), filename)
|
|
200
|
+
if not os.path.exists(filename):
|
|
201
|
+
wp.utils.warn(f"Warning: mesh file {filename} does not exist")
|
|
202
|
+
continue
|
|
203
|
+
|
|
204
|
+
import trimesh
|
|
205
|
+
|
|
206
|
+
# use force='mesh' to load the mesh as a trimesh object
|
|
207
|
+
# with baked in transforms, e.g. from COLLADA files
|
|
208
|
+
m = trimesh.load(filename, force="mesh")
|
|
209
|
+
scaling = mesh.get("scale") or "1 1 1"
|
|
210
|
+
scaling = np.array([float(x) * scale for x in scaling.split()])
|
|
211
|
+
if hasattr(m, "geometry"):
|
|
212
|
+
# multiple meshes are contained in a scene
|
|
213
|
+
for geom in m.geometry.values():
|
|
214
|
+
vertices = np.array(geom.vertices, dtype=np.float32) * scaling
|
|
215
|
+
faces = np.array(geom.faces.flatten(), dtype=np.int32)
|
|
216
|
+
mesh = Mesh(vertices, faces)
|
|
217
|
+
s = builder.add_shape_mesh(
|
|
218
|
+
body=link,
|
|
219
|
+
pos=wp.vec3(tf.p),
|
|
220
|
+
rot=wp.quat(tf.q),
|
|
221
|
+
mesh=mesh,
|
|
222
|
+
density=density,
|
|
223
|
+
is_visible=visible,
|
|
224
|
+
has_ground_collision=not just_visual,
|
|
225
|
+
has_shape_collision=not just_visual,
|
|
226
|
+
**contact_vars,
|
|
227
|
+
)
|
|
228
|
+
shapes.append(s)
|
|
229
|
+
else:
|
|
230
|
+
# a single mesh
|
|
231
|
+
vertices = np.array(m.vertices, dtype=np.float32) * scaling
|
|
232
|
+
faces = np.array(m.faces.flatten(), dtype=np.int32)
|
|
233
|
+
mesh = Mesh(vertices, faces)
|
|
234
|
+
s = builder.add_shape_mesh(
|
|
235
|
+
body=link,
|
|
236
|
+
pos=wp.vec3(tf.p),
|
|
237
|
+
rot=wp.quat(tf.q),
|
|
238
|
+
mesh=mesh,
|
|
239
|
+
density=density,
|
|
240
|
+
is_visible=visible,
|
|
241
|
+
has_ground_collision=not just_visual,
|
|
242
|
+
has_shape_collision=not just_visual,
|
|
243
|
+
**contact_vars,
|
|
244
|
+
)
|
|
245
|
+
shapes.append(s)
|
|
246
|
+
|
|
247
|
+
return shapes
|
|
248
|
+
|
|
249
|
+
# maps from link name -> link index
|
|
250
|
+
link_index = {}
|
|
251
|
+
|
|
252
|
+
visual_shapes = []
|
|
253
|
+
|
|
254
|
+
builder.add_articulation()
|
|
255
|
+
|
|
256
|
+
start_shape_count = len(builder.shape_geo_type)
|
|
257
|
+
|
|
258
|
+
# add links
|
|
259
|
+
for _i, urdf_link in enumerate(root.findall("link")):
|
|
260
|
+
name = urdf_link.get("name")
|
|
261
|
+
link = builder.add_body(origin=wp.transform_identity(), armature=armature, name=name)
|
|
262
|
+
|
|
263
|
+
# add ourselves to the index
|
|
264
|
+
link_index[name] = link
|
|
265
|
+
|
|
266
|
+
visuals = urdf_link.findall("visual")
|
|
267
|
+
colliders = urdf_link.findall("collision")
|
|
268
|
+
|
|
269
|
+
if parse_visuals_as_colliders:
|
|
270
|
+
colliders = visuals
|
|
271
|
+
else:
|
|
272
|
+
s = parse_shapes(link, visuals, density=0.0, just_visual=True)
|
|
273
|
+
visual_shapes.extend(s)
|
|
274
|
+
|
|
275
|
+
show_colliders = force_show_colliders
|
|
276
|
+
if parse_visuals_as_colliders:
|
|
277
|
+
show_colliders = True
|
|
278
|
+
elif len(visuals) == 0:
|
|
279
|
+
# we need to show the collision shapes since there are no visual shapes
|
|
280
|
+
show_colliders = True
|
|
281
|
+
|
|
282
|
+
parse_shapes(link, colliders, density=density, visible=show_colliders)
|
|
283
|
+
m = builder.body_mass[link]
|
|
284
|
+
if not ignore_inertial_definitions and urdf_link.find("inertial") is not None:
|
|
285
|
+
# overwrite inertial parameters if defined
|
|
286
|
+
inertial = urdf_link.find("inertial")
|
|
287
|
+
inertial_frame = parse_transform(inertial)
|
|
288
|
+
com = inertial_frame.p
|
|
289
|
+
I_m = np.zeros((3, 3))
|
|
290
|
+
I_m[0, 0] = float(inertial.find("inertia").get("ixx") or "0") * scale**2
|
|
291
|
+
I_m[1, 1] = float(inertial.find("inertia").get("iyy") or "0") * scale**2
|
|
292
|
+
I_m[2, 2] = float(inertial.find("inertia").get("izz") or "0") * scale**2
|
|
293
|
+
I_m[0, 1] = float(inertial.find("inertia").get("ixy") or "0") * scale**2
|
|
294
|
+
I_m[0, 2] = float(inertial.find("inertia").get("ixz") or "0") * scale**2
|
|
295
|
+
I_m[1, 2] = float(inertial.find("inertia").get("iyz") or "0") * scale**2
|
|
296
|
+
I_m[1, 0] = I_m[0, 1]
|
|
297
|
+
I_m[2, 0] = I_m[0, 2]
|
|
298
|
+
I_m[2, 1] = I_m[1, 2]
|
|
299
|
+
rot = wp.quat_to_matrix(inertial_frame.q)
|
|
300
|
+
I_m = rot @ wp.mat33(I_m)
|
|
301
|
+
m = float(inertial.find("mass").get("value") or "0")
|
|
302
|
+
builder.body_mass[link] = m
|
|
303
|
+
builder.body_inv_mass[link] = 1.0 / m
|
|
304
|
+
builder.body_com[link] = com
|
|
305
|
+
builder.body_inertia[link] = I_m
|
|
306
|
+
builder.body_inv_inertia[link] = wp.inverse(I_m)
|
|
307
|
+
if m == 0.0 and ensure_nonstatic_links:
|
|
308
|
+
# set the mass to something nonzero to ensure the body is dynamic
|
|
309
|
+
m = static_link_mass
|
|
310
|
+
# cube with side length 0.5
|
|
311
|
+
I_m = wp.mat33(np.eye(3)) * m / 12.0 * (0.5 * scale) ** 2 * 2.0
|
|
312
|
+
I_m += wp.mat33(armature * np.eye(3))
|
|
313
|
+
builder.body_mass[link] = m
|
|
314
|
+
builder.body_inv_mass[link] = 1.0 / m
|
|
315
|
+
builder.body_inertia[link] = I_m
|
|
316
|
+
builder.body_inv_inertia[link] = wp.inverse(I_m)
|
|
317
|
+
|
|
318
|
+
end_shape_count = len(builder.shape_geo_type)
|
|
319
|
+
|
|
320
|
+
# find joints per body
|
|
321
|
+
body_children = {name: [] for name in link_index.keys()}
|
|
322
|
+
# mapping from parent, child link names to joint
|
|
323
|
+
parent_child_joint = {}
|
|
324
|
+
|
|
325
|
+
joints = []
|
|
326
|
+
for joint in root.findall("joint"):
|
|
327
|
+
parent = joint.find("parent").get("link")
|
|
328
|
+
child = joint.find("child").get("link")
|
|
329
|
+
body_children[parent].append(child)
|
|
330
|
+
joint_data = {
|
|
331
|
+
"name": joint.get("name"),
|
|
332
|
+
"parent": parent,
|
|
333
|
+
"child": child,
|
|
334
|
+
"type": joint.get("type"),
|
|
335
|
+
"origin": parse_transform(joint),
|
|
336
|
+
"damping": damping,
|
|
337
|
+
"friction": 0.0,
|
|
338
|
+
"limit_lower": joint_limit_lower,
|
|
339
|
+
"limit_upper": joint_limit_upper,
|
|
340
|
+
}
|
|
341
|
+
if joint.find("axis") is not None:
|
|
342
|
+
joint_data["axis"] = joint.find("axis").get("xyz")
|
|
343
|
+
joint_data["axis"] = np.array([float(x) for x in joint_data["axis"].split()])
|
|
344
|
+
if joint.find("dynamics") is not None:
|
|
345
|
+
dynamics = joint.find("dynamics")
|
|
346
|
+
joint_data["damping"] = float(dynamics.get("damping") or str(damping))
|
|
347
|
+
joint_data["friction"] = float(dynamics.get("friction") or "0")
|
|
348
|
+
if joint.find("limit") is not None:
|
|
349
|
+
limit = joint.find("limit")
|
|
350
|
+
joint_data["limit_lower"] = float(limit.get("lower") or "-1e6")
|
|
351
|
+
joint_data["limit_upper"] = float(limit.get("upper") or "1e6")
|
|
352
|
+
if joint.find("mimic") is not None:
|
|
353
|
+
mimic = joint.find("mimic")
|
|
354
|
+
joint_data["mimic_joint"] = mimic.get("joint")
|
|
355
|
+
joint_data["mimic_multiplier"] = float(mimic.get("multiplier") or "1")
|
|
356
|
+
joint_data["mimic_offset"] = float(mimic.get("offset") or "0")
|
|
357
|
+
|
|
358
|
+
parent_child_joint[(parent, child)] = joint_data
|
|
359
|
+
joints.append(joint_data)
|
|
360
|
+
|
|
361
|
+
# topological sorting of joints because the FK solver will resolve body transforms
|
|
362
|
+
# in joint order and needs the parent link transform to be resolved before the child
|
|
363
|
+
visited = {name: False for name in link_index.keys()}
|
|
364
|
+
sorted_joints = []
|
|
365
|
+
|
|
366
|
+
# depth-first search
|
|
367
|
+
def dfs(joint):
|
|
368
|
+
link = joint["child"]
|
|
369
|
+
if visited[link]:
|
|
370
|
+
return
|
|
371
|
+
visited[link] = True
|
|
372
|
+
|
|
373
|
+
for child in body_children[link]:
|
|
374
|
+
if not visited[child]:
|
|
375
|
+
dfs(parent_child_joint[(link, child)])
|
|
376
|
+
|
|
377
|
+
sorted_joints.insert(0, joint)
|
|
378
|
+
|
|
379
|
+
# start DFS from each unvisited joint
|
|
380
|
+
for joint in joints:
|
|
381
|
+
if not visited[joint["parent"]]:
|
|
382
|
+
dfs(joint)
|
|
383
|
+
|
|
384
|
+
# add base joint
|
|
385
|
+
if len(sorted_joints) > 0:
|
|
386
|
+
base_link_name = sorted_joints[0]["parent"]
|
|
387
|
+
else:
|
|
388
|
+
base_link_name = next(iter(link_index.keys()))
|
|
389
|
+
root = link_index[base_link_name]
|
|
390
|
+
if base_joint is not None:
|
|
391
|
+
# in case of a given base joint, the position is applied first, the rotation only
|
|
392
|
+
# after the base joint itself to not rotate its axis
|
|
393
|
+
base_parent_xform = wp.transform(xform.p, wp.quat_identity())
|
|
394
|
+
base_child_xform = wp.transform((0.0, 0.0, 0.0), wp.quat_inverse(xform.q))
|
|
395
|
+
if isinstance(base_joint, str):
|
|
396
|
+
axes = base_joint.lower().split(",")
|
|
397
|
+
axes = [ax.strip() for ax in axes]
|
|
398
|
+
linear_axes = [ax[-1] for ax in axes if ax[0] in {"l", "p"}]
|
|
399
|
+
angular_axes = [ax[-1] for ax in axes if ax[0] in {"a", "r"}]
|
|
400
|
+
axes = {
|
|
401
|
+
"x": [1.0, 0.0, 0.0],
|
|
402
|
+
"y": [0.0, 1.0, 0.0],
|
|
403
|
+
"z": [0.0, 0.0, 1.0],
|
|
404
|
+
}
|
|
405
|
+
builder.add_joint_d6(
|
|
406
|
+
linear_axes=[wp.sim.JointAxis(axes[a]) for a in linear_axes],
|
|
407
|
+
angular_axes=[wp.sim.JointAxis(axes[a]) for a in angular_axes],
|
|
408
|
+
parent_xform=base_parent_xform,
|
|
409
|
+
child_xform=base_child_xform,
|
|
410
|
+
parent=-1,
|
|
411
|
+
child=root,
|
|
412
|
+
name="base_joint",
|
|
413
|
+
)
|
|
414
|
+
elif isinstance(base_joint, dict):
|
|
415
|
+
base_joint["parent"] = -1
|
|
416
|
+
base_joint["child"] = root
|
|
417
|
+
base_joint["parent_xform"] = base_parent_xform
|
|
418
|
+
base_joint["child_xform"] = base_child_xform
|
|
419
|
+
base_joint["name"] = "base_joint"
|
|
420
|
+
builder.add_joint(**base_joint)
|
|
421
|
+
else:
|
|
422
|
+
raise ValueError(
|
|
423
|
+
"base_joint must be a comma-separated string of joint axes or a dict with joint parameters"
|
|
424
|
+
)
|
|
425
|
+
elif floating:
|
|
426
|
+
builder.add_joint_free(root, name="floating_base")
|
|
427
|
+
|
|
428
|
+
# set dofs to transform
|
|
429
|
+
start = builder.joint_q_start[root]
|
|
430
|
+
|
|
431
|
+
builder.joint_q[start + 0] = xform.p[0]
|
|
432
|
+
builder.joint_q[start + 1] = xform.p[1]
|
|
433
|
+
builder.joint_q[start + 2] = xform.p[2]
|
|
434
|
+
|
|
435
|
+
builder.joint_q[start + 3] = xform.q[0]
|
|
436
|
+
builder.joint_q[start + 4] = xform.q[1]
|
|
437
|
+
builder.joint_q[start + 5] = xform.q[2]
|
|
438
|
+
builder.joint_q[start + 6] = xform.q[3]
|
|
439
|
+
else:
|
|
440
|
+
builder.add_joint_fixed(-1, root, parent_xform=xform, name="fixed_base")
|
|
441
|
+
|
|
442
|
+
# add joints, in topological order starting from root body
|
|
443
|
+
for joint in sorted_joints:
|
|
444
|
+
parent = link_index[joint["parent"]]
|
|
445
|
+
child = link_index[joint["child"]]
|
|
446
|
+
if child == -1:
|
|
447
|
+
# we skipped the insertion of the child body
|
|
448
|
+
continue
|
|
449
|
+
|
|
450
|
+
lower = joint["limit_lower"]
|
|
451
|
+
upper = joint["limit_upper"]
|
|
452
|
+
joint_damping = joint["damping"]
|
|
453
|
+
|
|
454
|
+
parent_xform = joint["origin"]
|
|
455
|
+
child_xform = wp.transform_identity()
|
|
456
|
+
|
|
457
|
+
joint_mode = wp.sim.JOINT_MODE_FORCE
|
|
458
|
+
if stiffness > 0.0:
|
|
459
|
+
joint_mode = wp.sim.JOINT_MODE_TARGET_POSITION
|
|
460
|
+
|
|
461
|
+
joint_params = {
|
|
462
|
+
"parent": parent,
|
|
463
|
+
"child": child,
|
|
464
|
+
"parent_xform": parent_xform,
|
|
465
|
+
"child_xform": child_xform,
|
|
466
|
+
"name": joint["name"],
|
|
467
|
+
"armature": armature,
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if joint["type"] == "revolute" or joint["type"] == "continuous":
|
|
471
|
+
builder.add_joint_revolute(
|
|
472
|
+
axis=joint["axis"],
|
|
473
|
+
target_ke=stiffness,
|
|
474
|
+
target_kd=joint_damping,
|
|
475
|
+
limit_lower=lower,
|
|
476
|
+
limit_upper=upper,
|
|
477
|
+
limit_ke=limit_ke,
|
|
478
|
+
limit_kd=limit_kd,
|
|
479
|
+
mode=joint_mode,
|
|
480
|
+
**joint_params,
|
|
481
|
+
)
|
|
482
|
+
elif joint["type"] == "prismatic":
|
|
483
|
+
builder.add_joint_prismatic(
|
|
484
|
+
axis=joint["axis"],
|
|
485
|
+
target_ke=stiffness,
|
|
486
|
+
target_kd=joint_damping,
|
|
487
|
+
limit_lower=lower * scale,
|
|
488
|
+
limit_upper=upper * scale,
|
|
489
|
+
limit_ke=limit_ke,
|
|
490
|
+
limit_kd=limit_kd,
|
|
491
|
+
mode=joint_mode,
|
|
492
|
+
**joint_params,
|
|
493
|
+
)
|
|
494
|
+
elif joint["type"] == "fixed":
|
|
495
|
+
builder.add_joint_fixed(**joint_params)
|
|
496
|
+
elif joint["type"] == "floating":
|
|
497
|
+
builder.add_joint_free(**joint_params)
|
|
498
|
+
elif joint["type"] == "planar":
|
|
499
|
+
# find plane vectors perpendicular to axis
|
|
500
|
+
axis = np.array(joint["axis"])
|
|
501
|
+
axis /= np.linalg.norm(axis)
|
|
502
|
+
|
|
503
|
+
# create helper vector that is not parallel to the axis
|
|
504
|
+
helper = np.array([1, 0, 0]) if np.allclose(axis, [0, 1, 0]) else np.array([0, 1, 0])
|
|
505
|
+
|
|
506
|
+
u = np.cross(helper, axis)
|
|
507
|
+
u /= np.linalg.norm(u)
|
|
508
|
+
|
|
509
|
+
v = np.cross(axis, u)
|
|
510
|
+
v /= np.linalg.norm(v)
|
|
511
|
+
|
|
512
|
+
builder.add_joint_d6(
|
|
513
|
+
linear_axes=[
|
|
514
|
+
wp.sim.JointAxis(
|
|
515
|
+
u, limit_lower=lower * scale, limit_upper=upper * scale, limit_ke=limit_ke, limit_kd=limit_kd
|
|
516
|
+
),
|
|
517
|
+
wp.sim.JointAxis(
|
|
518
|
+
v, limit_lower=lower * scale, limit_upper=upper * scale, limit_ke=limit_ke, limit_kd=limit_kd
|
|
519
|
+
),
|
|
520
|
+
],
|
|
521
|
+
**joint_params,
|
|
522
|
+
)
|
|
523
|
+
else:
|
|
524
|
+
raise Exception("Unsupported joint type: " + joint["type"])
|
|
525
|
+
|
|
526
|
+
for i in range(start_shape_count, end_shape_count):
|
|
527
|
+
for j in visual_shapes:
|
|
528
|
+
builder.shape_collision_filter_pairs.add((i, j))
|
|
529
|
+
|
|
530
|
+
if not enable_self_collisions:
|
|
531
|
+
for i in range(start_shape_count, end_shape_count):
|
|
532
|
+
for j in range(i + 1, end_shape_count):
|
|
533
|
+
builder.shape_collision_filter_pairs.add((i, j))
|
|
534
|
+
|
|
535
|
+
if collapse_fixed_joints:
|
|
536
|
+
builder.collapse_fixed_joints()
|