warp-lang 1.9.1__py3-none-manylinux_2_34_aarch64.whl → 1.10.0rc2__py3-none-manylinux_2_34_aarch64.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.

Files changed (346) hide show
  1. warp/__init__.py +301 -287
  2. warp/__init__.pyi +794 -305
  3. warp/_src/__init__.py +14 -0
  4. warp/_src/autograd.py +1075 -0
  5. warp/_src/build.py +618 -0
  6. warp/_src/build_dll.py +640 -0
  7. warp/{builtins.py → _src/builtins.py} +1382 -377
  8. warp/_src/codegen.py +4359 -0
  9. warp/{config.py → _src/config.py} +178 -169
  10. warp/_src/constants.py +57 -0
  11. warp/_src/context.py +8294 -0
  12. warp/_src/dlpack.py +462 -0
  13. warp/_src/fabric.py +355 -0
  14. warp/_src/fem/__init__.py +14 -0
  15. warp/_src/fem/adaptivity.py +508 -0
  16. warp/_src/fem/cache.py +687 -0
  17. warp/_src/fem/dirichlet.py +188 -0
  18. warp/{fem → _src/fem}/domain.py +40 -30
  19. warp/_src/fem/field/__init__.py +131 -0
  20. warp/_src/fem/field/field.py +701 -0
  21. warp/{fem → _src/fem}/field/nodal_field.py +30 -15
  22. warp/{fem → _src/fem}/field/restriction.py +1 -1
  23. warp/{fem → _src/fem}/field/virtual.py +53 -27
  24. warp/_src/fem/geometry/__init__.py +32 -0
  25. warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +77 -163
  26. warp/_src/fem/geometry/closest_point.py +97 -0
  27. warp/{fem → _src/fem}/geometry/deformed_geometry.py +14 -22
  28. warp/{fem → _src/fem}/geometry/element.py +32 -10
  29. warp/{fem → _src/fem}/geometry/geometry.py +48 -20
  30. warp/{fem → _src/fem}/geometry/grid_2d.py +12 -23
  31. warp/{fem → _src/fem}/geometry/grid_3d.py +12 -23
  32. warp/{fem → _src/fem}/geometry/hexmesh.py +40 -63
  33. warp/{fem → _src/fem}/geometry/nanogrid.py +255 -248
  34. warp/{fem → _src/fem}/geometry/partition.py +121 -63
  35. warp/{fem → _src/fem}/geometry/quadmesh.py +26 -45
  36. warp/{fem → _src/fem}/geometry/tetmesh.py +40 -63
  37. warp/{fem → _src/fem}/geometry/trimesh.py +26 -45
  38. warp/{fem → _src/fem}/integrate.py +164 -158
  39. warp/_src/fem/linalg.py +383 -0
  40. warp/_src/fem/operator.py +396 -0
  41. warp/_src/fem/polynomial.py +229 -0
  42. warp/{fem → _src/fem}/quadrature/pic_quadrature.py +15 -20
  43. warp/{fem → _src/fem}/quadrature/quadrature.py +95 -47
  44. warp/_src/fem/space/__init__.py +248 -0
  45. warp/{fem → _src/fem}/space/basis_function_space.py +20 -11
  46. warp/_src/fem/space/basis_space.py +679 -0
  47. warp/{fem → _src/fem}/space/dof_mapper.py +3 -3
  48. warp/{fem → _src/fem}/space/function_space.py +14 -13
  49. warp/{fem → _src/fem}/space/grid_2d_function_space.py +4 -7
  50. warp/{fem → _src/fem}/space/grid_3d_function_space.py +4 -4
  51. warp/{fem → _src/fem}/space/hexmesh_function_space.py +4 -10
  52. warp/{fem → _src/fem}/space/nanogrid_function_space.py +3 -9
  53. warp/{fem → _src/fem}/space/partition.py +117 -60
  54. warp/{fem → _src/fem}/space/quadmesh_function_space.py +4 -10
  55. warp/{fem → _src/fem}/space/restriction.py +66 -33
  56. warp/_src/fem/space/shape/__init__.py +152 -0
  57. warp/{fem → _src/fem}/space/shape/cube_shape_function.py +9 -9
  58. warp/{fem → _src/fem}/space/shape/shape_function.py +8 -9
  59. warp/{fem → _src/fem}/space/shape/square_shape_function.py +6 -6
  60. warp/{fem → _src/fem}/space/shape/tet_shape_function.py +3 -3
  61. warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +3 -3
  62. warp/{fem → _src/fem}/space/tetmesh_function_space.py +3 -9
  63. warp/_src/fem/space/topology.py +459 -0
  64. warp/{fem → _src/fem}/space/trimesh_function_space.py +3 -9
  65. warp/_src/fem/types.py +112 -0
  66. warp/_src/fem/utils.py +486 -0
  67. warp/_src/jax.py +186 -0
  68. warp/_src/jax_experimental/__init__.py +14 -0
  69. warp/_src/jax_experimental/custom_call.py +387 -0
  70. warp/_src/jax_experimental/ffi.py +1284 -0
  71. warp/_src/jax_experimental/xla_ffi.py +656 -0
  72. warp/_src/marching_cubes.py +708 -0
  73. warp/_src/math.py +414 -0
  74. warp/_src/optim/__init__.py +14 -0
  75. warp/_src/optim/adam.py +163 -0
  76. warp/_src/optim/linear.py +1606 -0
  77. warp/_src/optim/sgd.py +112 -0
  78. warp/_src/paddle.py +406 -0
  79. warp/_src/render/__init__.py +14 -0
  80. warp/_src/render/imgui_manager.py +289 -0
  81. warp/_src/render/render_opengl.py +3636 -0
  82. warp/_src/render/render_usd.py +937 -0
  83. warp/_src/render/utils.py +160 -0
  84. warp/_src/sparse.py +2716 -0
  85. warp/_src/tape.py +1206 -0
  86. warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
  87. warp/_src/torch.py +391 -0
  88. warp/_src/types.py +5870 -0
  89. warp/_src/utils.py +1693 -0
  90. warp/autograd.py +12 -1054
  91. warp/bin/warp-clang.so +0 -0
  92. warp/bin/warp.so +0 -0
  93. warp/build.py +8 -588
  94. warp/build_dll.py +6 -721
  95. warp/codegen.py +6 -4251
  96. warp/constants.py +6 -39
  97. warp/context.py +12 -8062
  98. warp/dlpack.py +6 -444
  99. warp/examples/distributed/example_jacobi_mpi.py +4 -5
  100. warp/examples/fem/example_adaptive_grid.py +1 -1
  101. warp/examples/fem/example_apic_fluid.py +1 -1
  102. warp/examples/fem/example_burgers.py +8 -8
  103. warp/examples/fem/example_diffusion.py +1 -1
  104. warp/examples/fem/example_distortion_energy.py +1 -1
  105. warp/examples/fem/example_mixed_elasticity.py +2 -2
  106. warp/examples/fem/example_navier_stokes.py +1 -1
  107. warp/examples/fem/example_nonconforming_contact.py +7 -7
  108. warp/examples/fem/example_stokes.py +1 -1
  109. warp/examples/fem/example_stokes_transfer.py +1 -1
  110. warp/examples/fem/utils.py +2 -2
  111. warp/examples/interop/example_jax_callable.py +1 -1
  112. warp/examples/interop/example_jax_ffi_callback.py +1 -1
  113. warp/examples/interop/example_jax_kernel.py +1 -1
  114. warp/examples/tile/example_tile_mcgp.py +191 -0
  115. warp/fabric.py +6 -337
  116. warp/fem/__init__.py +159 -97
  117. warp/fem/adaptivity.py +7 -489
  118. warp/fem/cache.py +9 -648
  119. warp/fem/dirichlet.py +6 -184
  120. warp/fem/field/__init__.py +8 -109
  121. warp/fem/field/field.py +7 -652
  122. warp/fem/geometry/__init__.py +7 -18
  123. warp/fem/geometry/closest_point.py +11 -77
  124. warp/fem/linalg.py +18 -366
  125. warp/fem/operator.py +11 -369
  126. warp/fem/polynomial.py +9 -209
  127. warp/fem/space/__init__.py +5 -211
  128. warp/fem/space/basis_space.py +6 -662
  129. warp/fem/space/shape/__init__.py +41 -118
  130. warp/fem/space/topology.py +6 -437
  131. warp/fem/types.py +6 -81
  132. warp/fem/utils.py +11 -444
  133. warp/jax.py +8 -165
  134. warp/jax_experimental/__init__.py +14 -1
  135. warp/jax_experimental/custom_call.py +8 -365
  136. warp/jax_experimental/ffi.py +17 -873
  137. warp/jax_experimental/xla_ffi.py +5 -605
  138. warp/marching_cubes.py +5 -689
  139. warp/math.py +16 -393
  140. warp/native/array.h +385 -37
  141. warp/native/builtin.h +314 -37
  142. warp/native/bvh.cpp +43 -9
  143. warp/native/bvh.cu +62 -27
  144. warp/native/bvh.h +310 -309
  145. warp/native/clang/clang.cpp +102 -97
  146. warp/native/coloring.cpp +0 -1
  147. warp/native/crt.h +208 -0
  148. warp/native/exports.h +156 -0
  149. warp/native/hashgrid.cu +2 -0
  150. warp/native/intersect.h +24 -1
  151. warp/native/intersect_tri.h +44 -35
  152. warp/native/mat.h +1456 -276
  153. warp/native/mesh.cpp +4 -4
  154. warp/native/mesh.cu +4 -2
  155. warp/native/mesh.h +176 -61
  156. warp/native/quat.h +0 -52
  157. warp/native/scan.cu +2 -0
  158. warp/native/sparse.cu +7 -3
  159. warp/native/spatial.h +12 -0
  160. warp/native/tile.h +681 -89
  161. warp/native/tile_radix_sort.h +1 -1
  162. warp/native/tile_reduce.h +394 -46
  163. warp/native/tile_scan.h +4 -4
  164. warp/native/vec.h +469 -0
  165. warp/native/version.h +23 -0
  166. warp/native/volume.cpp +1 -1
  167. warp/native/volume.cu +1 -0
  168. warp/native/volume.h +1 -1
  169. warp/native/volume_builder.cu +2 -0
  170. warp/native/warp.cpp +57 -29
  171. warp/native/warp.cu +253 -171
  172. warp/native/warp.h +11 -8
  173. warp/optim/__init__.py +6 -3
  174. warp/optim/adam.py +6 -145
  175. warp/optim/linear.py +14 -1585
  176. warp/optim/sgd.py +6 -94
  177. warp/paddle.py +6 -388
  178. warp/render/__init__.py +8 -4
  179. warp/render/imgui_manager.py +7 -267
  180. warp/render/render_opengl.py +6 -3618
  181. warp/render/render_usd.py +6 -919
  182. warp/render/utils.py +6 -142
  183. warp/sparse.py +37 -2563
  184. warp/tape.py +6 -1188
  185. warp/tests/__main__.py +1 -1
  186. warp/tests/cuda/test_async.py +4 -4
  187. warp/tests/cuda/test_conditional_captures.py +1 -1
  188. warp/tests/cuda/test_multigpu.py +1 -1
  189. warp/tests/cuda/test_streams.py +58 -1
  190. warp/tests/geometry/test_bvh.py +157 -22
  191. warp/tests/geometry/test_marching_cubes.py +0 -1
  192. warp/tests/geometry/test_mesh.py +5 -3
  193. warp/tests/geometry/test_mesh_query_aabb.py +5 -12
  194. warp/tests/geometry/test_mesh_query_point.py +5 -2
  195. warp/tests/geometry/test_mesh_query_ray.py +15 -3
  196. warp/tests/geometry/test_volume_write.py +5 -5
  197. warp/tests/interop/test_dlpack.py +14 -14
  198. warp/tests/interop/test_jax.py +772 -49
  199. warp/tests/interop/test_paddle.py +1 -1
  200. warp/tests/test_adam.py +0 -1
  201. warp/tests/test_arithmetic.py +9 -9
  202. warp/tests/test_array.py +527 -100
  203. warp/tests/test_array_reduce.py +3 -3
  204. warp/tests/test_atomic.py +12 -8
  205. warp/tests/test_atomic_bitwise.py +209 -0
  206. warp/tests/test_atomic_cas.py +4 -4
  207. warp/tests/test_bool.py +2 -2
  208. warp/tests/test_builtins_resolution.py +5 -571
  209. warp/tests/test_codegen.py +33 -14
  210. warp/tests/test_conditional.py +1 -1
  211. warp/tests/test_context.py +6 -6
  212. warp/tests/test_copy.py +242 -161
  213. warp/tests/test_ctypes.py +3 -3
  214. warp/tests/test_devices.py +24 -2
  215. warp/tests/test_examples.py +16 -84
  216. warp/tests/test_fabricarray.py +35 -35
  217. warp/tests/test_fast_math.py +0 -2
  218. warp/tests/test_fem.py +56 -10
  219. warp/tests/test_fixedarray.py +3 -3
  220. warp/tests/test_func.py +8 -5
  221. warp/tests/test_generics.py +1 -1
  222. warp/tests/test_indexedarray.py +24 -24
  223. warp/tests/test_intersect.py +39 -9
  224. warp/tests/test_large.py +1 -1
  225. warp/tests/test_lerp.py +3 -1
  226. warp/tests/test_linear_solvers.py +1 -1
  227. warp/tests/test_map.py +35 -4
  228. warp/tests/test_mat.py +52 -62
  229. warp/tests/test_mat_constructors.py +4 -5
  230. warp/tests/test_mat_lite.py +1 -1
  231. warp/tests/test_mat_scalar_ops.py +121 -121
  232. warp/tests/test_math.py +34 -0
  233. warp/tests/test_module_aot.py +4 -4
  234. warp/tests/test_modules_lite.py +28 -2
  235. warp/tests/test_print.py +11 -11
  236. warp/tests/test_quat.py +93 -58
  237. warp/tests/test_runlength_encode.py +1 -1
  238. warp/tests/test_scalar_ops.py +38 -10
  239. warp/tests/test_smoothstep.py +1 -1
  240. warp/tests/test_sparse.py +126 -15
  241. warp/tests/test_spatial.py +105 -87
  242. warp/tests/test_special_values.py +6 -6
  243. warp/tests/test_static.py +7 -7
  244. warp/tests/test_struct.py +13 -2
  245. warp/tests/test_triangle_closest_point.py +48 -1
  246. warp/tests/test_types.py +27 -15
  247. warp/tests/test_utils.py +52 -52
  248. warp/tests/test_vec.py +29 -29
  249. warp/tests/test_vec_constructors.py +5 -5
  250. warp/tests/test_vec_scalar_ops.py +97 -97
  251. warp/tests/test_version.py +75 -0
  252. warp/tests/tile/test_tile.py +178 -0
  253. warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
  254. warp/tests/tile/test_tile_cholesky.py +7 -4
  255. warp/tests/tile/test_tile_load.py +26 -2
  256. warp/tests/tile/test_tile_mathdx.py +3 -3
  257. warp/tests/tile/test_tile_matmul.py +1 -1
  258. warp/tests/tile/test_tile_mlp.py +2 -4
  259. warp/tests/tile/test_tile_reduce.py +214 -13
  260. warp/tests/unittest_suites.py +6 -14
  261. warp/tests/unittest_utils.py +10 -9
  262. warp/tests/walkthrough_debug.py +3 -1
  263. warp/torch.py +6 -373
  264. warp/types.py +29 -5764
  265. warp/utils.py +10 -1659
  266. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/METADATA +46 -99
  267. warp_lang-1.10.0rc2.dist-info/RECORD +468 -0
  268. warp_lang-1.10.0rc2.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
  269. warp_lang-1.10.0rc2.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
  270. warp_lang-1.10.0rc2.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
  271. warp_lang-1.10.0rc2.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
  272. warp_lang-1.10.0rc2.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
  273. warp_lang-1.10.0rc2.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
  274. warp_lang-1.10.0rc2.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
  275. warp_lang-1.10.0rc2.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
  276. warp_lang-1.10.0rc2.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
  277. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
  278. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
  279. warp_lang-1.10.0rc2.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
  280. warp_lang-1.10.0rc2.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
  281. warp_lang-1.10.0rc2.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
  282. warp_lang-1.10.0rc2.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
  283. warp/examples/assets/cartpole.urdf +0 -110
  284. warp/examples/assets/crazyflie.usd +0 -0
  285. warp/examples/assets/nv_ant.xml +0 -92
  286. warp/examples/assets/nv_humanoid.xml +0 -183
  287. warp/examples/assets/quadruped.urdf +0 -268
  288. warp/examples/optim/example_bounce.py +0 -266
  289. warp/examples/optim/example_cloth_throw.py +0 -228
  290. warp/examples/optim/example_drone.py +0 -870
  291. warp/examples/optim/example_inverse_kinematics.py +0 -182
  292. warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
  293. warp/examples/optim/example_softbody_properties.py +0 -400
  294. warp/examples/optim/example_spring_cage.py +0 -245
  295. warp/examples/optim/example_trajectory.py +0 -227
  296. warp/examples/sim/example_cartpole.py +0 -143
  297. warp/examples/sim/example_cloth.py +0 -225
  298. warp/examples/sim/example_cloth_self_contact.py +0 -316
  299. warp/examples/sim/example_granular.py +0 -130
  300. warp/examples/sim/example_granular_collision_sdf.py +0 -202
  301. warp/examples/sim/example_jacobian_ik.py +0 -244
  302. warp/examples/sim/example_particle_chain.py +0 -124
  303. warp/examples/sim/example_quadruped.py +0 -203
  304. warp/examples/sim/example_rigid_chain.py +0 -203
  305. warp/examples/sim/example_rigid_contact.py +0 -195
  306. warp/examples/sim/example_rigid_force.py +0 -133
  307. warp/examples/sim/example_rigid_gyroscopic.py +0 -115
  308. warp/examples/sim/example_rigid_soft_contact.py +0 -140
  309. warp/examples/sim/example_soft_body.py +0 -196
  310. warp/examples/tile/example_tile_walker.py +0 -327
  311. warp/sim/__init__.py +0 -74
  312. warp/sim/articulation.py +0 -793
  313. warp/sim/collide.py +0 -2570
  314. warp/sim/graph_coloring.py +0 -307
  315. warp/sim/import_mjcf.py +0 -791
  316. warp/sim/import_snu.py +0 -227
  317. warp/sim/import_urdf.py +0 -579
  318. warp/sim/import_usd.py +0 -898
  319. warp/sim/inertia.py +0 -357
  320. warp/sim/integrator.py +0 -245
  321. warp/sim/integrator_euler.py +0 -2000
  322. warp/sim/integrator_featherstone.py +0 -2101
  323. warp/sim/integrator_vbd.py +0 -2487
  324. warp/sim/integrator_xpbd.py +0 -3295
  325. warp/sim/model.py +0 -4821
  326. warp/sim/particles.py +0 -121
  327. warp/sim/render.py +0 -431
  328. warp/sim/utils.py +0 -431
  329. warp/tests/sim/disabled_kinematics.py +0 -244
  330. warp/tests/sim/test_cloth.py +0 -863
  331. warp/tests/sim/test_collision.py +0 -743
  332. warp/tests/sim/test_coloring.py +0 -347
  333. warp/tests/sim/test_inertia.py +0 -161
  334. warp/tests/sim/test_model.py +0 -226
  335. warp/tests/sim/test_sim_grad.py +0 -287
  336. warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
  337. warp/tests/sim/test_sim_kinematics.py +0 -98
  338. warp/thirdparty/__init__.py +0 -0
  339. warp_lang-1.9.1.dist-info/RECORD +0 -456
  340. /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
  341. /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
  342. /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
  343. /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
  344. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/WHEEL +0 -0
  345. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/licenses/LICENSE.md +0 -0
  346. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/top_level.txt +0 -0
warp/sim/articulation.py DELETED
@@ -1,793 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
- # SPDX-License-Identifier: Apache-2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- import warp as wp
17
-
18
- from .utils import quat_decompose, quat_twist
19
-
20
-
21
- @wp.func
22
- def compute_2d_rotational_dofs(
23
- axis_0: wp.vec3,
24
- axis_1: wp.vec3,
25
- q0: float,
26
- q1: float,
27
- qd0: float,
28
- qd1: float,
29
- ):
30
- """
31
- Computes the rotation quaternion and 3D angular velocity given the joint axes, coordinates and velocities.
32
- """
33
- q_off = wp.quat_from_matrix(wp.matrix_from_cols(axis_0, axis_1, wp.cross(axis_0, axis_1)))
34
-
35
- # body local axes
36
- local_0 = wp.quat_rotate(q_off, wp.vec3(1.0, 0.0, 0.0))
37
- local_1 = wp.quat_rotate(q_off, wp.vec3(0.0, 1.0, 0.0))
38
-
39
- axis_0 = local_0
40
- q_0 = wp.quat_from_axis_angle(axis_0, q0)
41
-
42
- axis_1 = wp.quat_rotate(q_0, local_1)
43
- q_1 = wp.quat_from_axis_angle(axis_1, q1)
44
-
45
- rot = q_1 * q_0
46
-
47
- vel = axis_0 * qd0 + axis_1 * qd1
48
-
49
- return rot, vel
50
-
51
-
52
- @wp.func
53
- def invert_2d_rotational_dofs(
54
- axis_0: wp.vec3,
55
- axis_1: wp.vec3,
56
- q_p: wp.quat,
57
- q_c: wp.quat,
58
- w_err: wp.vec3,
59
- ):
60
- """
61
- Computes generalized joint position and velocity coordinates for a 2D rotational joint given the joint axes, relative orientations and angular velocity differences between the two bodies the joint connects.
62
- """
63
- q_off = wp.quat_from_matrix(wp.matrix_from_cols(axis_0, axis_1, wp.cross(axis_0, axis_1)))
64
- q_pc = wp.quat_inverse(q_off) * wp.quat_inverse(q_p) * q_c * q_off
65
-
66
- # decompose to a compound rotation each axis
67
- angles = quat_decompose(q_pc)
68
-
69
- # find rotation axes
70
- local_0 = wp.quat_rotate(q_off, wp.vec3(1.0, 0.0, 0.0))
71
- local_1 = wp.quat_rotate(q_off, wp.vec3(0.0, 1.0, 0.0))
72
- local_2 = wp.quat_rotate(q_off, wp.vec3(0.0, 0.0, 1.0))
73
-
74
- axis_0 = local_0
75
- q_0 = wp.quat_from_axis_angle(axis_0, angles[0])
76
-
77
- axis_1 = wp.quat_rotate(q_0, local_1)
78
- q_1 = wp.quat_from_axis_angle(axis_1, angles[1])
79
-
80
- axis_2 = wp.quat_rotate(q_1 * q_0, local_2)
81
-
82
- # convert angular velocity to local space
83
- w_err_p = wp.quat_rotate_inv(q_p, w_err)
84
-
85
- # given joint axes and angular velocity error, solve for joint velocities
86
- c12 = wp.cross(axis_1, axis_2)
87
- c02 = wp.cross(axis_0, axis_2)
88
-
89
- vel = wp.vec2(wp.dot(w_err_p, c12) / wp.dot(axis_0, c12), wp.dot(w_err_p, c02) / wp.dot(axis_1, c02))
90
-
91
- return wp.vec2(angles[0], angles[1]), vel
92
-
93
-
94
- @wp.func
95
- def compute_3d_rotational_dofs(
96
- axis_0: wp.vec3,
97
- axis_1: wp.vec3,
98
- axis_2: wp.vec3,
99
- q0: float,
100
- q1: float,
101
- q2: float,
102
- qd0: float,
103
- qd1: float,
104
- qd2: float,
105
- ):
106
- """
107
- Computes the rotation quaternion and 3D angular velocity given the joint axes, coordinates and velocities.
108
- """
109
- q_off = wp.quat_from_matrix(wp.matrix_from_cols(axis_0, axis_1, axis_2))
110
-
111
- # body local axes
112
- local_0 = wp.quat_rotate(q_off, wp.vec3(1.0, 0.0, 0.0))
113
- local_1 = wp.quat_rotate(q_off, wp.vec3(0.0, 1.0, 0.0))
114
- local_2 = wp.quat_rotate(q_off, wp.vec3(0.0, 0.0, 1.0))
115
-
116
- # reconstruct rotation axes
117
- axis_0 = local_0
118
- q_0 = wp.quat_from_axis_angle(axis_0, q0)
119
-
120
- axis_1 = wp.quat_rotate(q_0, local_1)
121
- q_1 = wp.quat_from_axis_angle(axis_1, q1)
122
-
123
- axis_2 = wp.quat_rotate(q_1 * q_0, local_2)
124
- q_2 = wp.quat_from_axis_angle(axis_2, q2)
125
-
126
- rot = q_2 * q_1 * q_0
127
- vel = axis_0 * qd0 + axis_1 * qd1 + axis_2 * qd2
128
-
129
- return rot, vel
130
-
131
-
132
- @wp.func
133
- def invert_3d_rotational_dofs(
134
- axis_0: wp.vec3, axis_1: wp.vec3, axis_2: wp.vec3, q_p: wp.quat, q_c: wp.quat, w_err: wp.vec3
135
- ):
136
- """
137
- Computes generalized joint position and velocity coordinates for a 3D rotational joint given the joint axes, relative orientations and angular velocity differences between the two bodies the joint connects.
138
- """
139
- q_off = wp.quat_from_matrix(wp.matrix_from_cols(axis_0, axis_1, axis_2))
140
- q_pc = wp.quat_inverse(q_off) * wp.quat_inverse(q_p) * q_c * q_off
141
-
142
- # decompose to a compound rotation each axis
143
- angles = quat_decompose(q_pc)
144
-
145
- # find rotation axes
146
- local_0 = wp.quat_rotate(q_off, wp.vec3(1.0, 0.0, 0.0))
147
- local_1 = wp.quat_rotate(q_off, wp.vec3(0.0, 1.0, 0.0))
148
- local_2 = wp.quat_rotate(q_off, wp.vec3(0.0, 0.0, 1.0))
149
-
150
- axis_0 = local_0
151
- q_0 = wp.quat_from_axis_angle(axis_0, angles[0])
152
-
153
- axis_1 = wp.quat_rotate(q_0, local_1)
154
- q_1 = wp.quat_from_axis_angle(axis_1, angles[1])
155
-
156
- axis_2 = wp.quat_rotate(q_1 * q_0, local_2)
157
-
158
- # convert angular velocity to local space
159
- w_err_p = wp.quat_rotate_inv(q_p, w_err)
160
-
161
- # given joint axes and angular velocity error, solve for joint velocities
162
- c12 = wp.cross(axis_1, axis_2)
163
- c02 = wp.cross(axis_0, axis_2)
164
- c01 = wp.cross(axis_0, axis_1)
165
-
166
- velocities = wp.vec3(
167
- wp.dot(w_err_p, c12) / wp.dot(axis_0, c12),
168
- wp.dot(w_err_p, c02) / wp.dot(axis_1, c02),
169
- wp.dot(w_err_p, c01) / wp.dot(axis_2, c01),
170
- )
171
-
172
- return angles, velocities
173
-
174
-
175
- @wp.func
176
- def eval_single_articulation_fk(
177
- joint_start: int,
178
- joint_end: int,
179
- joint_q: wp.array(dtype=float),
180
- joint_qd: wp.array(dtype=float),
181
- joint_q_start: wp.array(dtype=int),
182
- joint_qd_start: wp.array(dtype=int),
183
- joint_type: wp.array(dtype=int),
184
- joint_parent: wp.array(dtype=int),
185
- joint_child: wp.array(dtype=int),
186
- joint_X_p: wp.array(dtype=wp.transform),
187
- joint_X_c: wp.array(dtype=wp.transform),
188
- joint_axis: wp.array(dtype=wp.vec3),
189
- joint_axis_start: wp.array(dtype=int),
190
- joint_axis_dim: wp.array(dtype=int, ndim=2),
191
- body_com: wp.array(dtype=wp.vec3),
192
- # outputs
193
- body_q: wp.array(dtype=wp.transform),
194
- body_qd: wp.array(dtype=wp.spatial_vector),
195
- ):
196
- for i in range(joint_start, joint_end):
197
- parent = joint_parent[i]
198
- child = joint_child[i]
199
-
200
- # compute transform across the joint
201
- type = joint_type[i]
202
-
203
- X_pj = joint_X_p[i]
204
- X_cj = joint_X_c[i]
205
-
206
- # parent anchor frame in world space
207
- X_wpj = X_pj
208
- # velocity of parent anchor point in world space
209
- v_wpj = wp.spatial_vector()
210
- if parent >= 0:
211
- X_wp = body_q[parent]
212
- X_wpj = X_wp * X_wpj
213
- r_p = wp.transform_get_translation(X_wpj) - wp.transform_point(X_wp, body_com[parent])
214
-
215
- v_wp = body_qd[parent]
216
- w_p = wp.spatial_top(v_wp)
217
- v_p = wp.spatial_bottom(v_wp) + wp.cross(w_p, r_p)
218
- v_wpj = wp.spatial_vector(w_p, v_p)
219
-
220
- q_start = joint_q_start[i]
221
- qd_start = joint_qd_start[i]
222
- axis_start = joint_axis_start[i]
223
- lin_axis_count = joint_axis_dim[i, 0]
224
- ang_axis_count = joint_axis_dim[i, 1]
225
-
226
- X_j = wp.transform_identity()
227
- v_j = wp.spatial_vector(wp.vec3(), wp.vec3())
228
-
229
- if type == wp.sim.JOINT_PRISMATIC:
230
- axis = joint_axis[axis_start]
231
-
232
- q = joint_q[q_start]
233
- qd = joint_qd[qd_start]
234
-
235
- X_j = wp.transform(axis * q, wp.quat_identity())
236
- v_j = wp.spatial_vector(wp.vec3(), axis * qd)
237
-
238
- if type == wp.sim.JOINT_REVOLUTE:
239
- axis = joint_axis[axis_start]
240
-
241
- q = joint_q[q_start]
242
- qd = joint_qd[qd_start]
243
-
244
- X_j = wp.transform(wp.vec3(), wp.quat_from_axis_angle(axis, q))
245
- v_j = wp.spatial_vector(axis * qd, wp.vec3())
246
-
247
- if type == wp.sim.JOINT_BALL:
248
- r = wp.quat(joint_q[q_start + 0], joint_q[q_start + 1], joint_q[q_start + 2], joint_q[q_start + 3])
249
-
250
- w = wp.vec3(joint_qd[qd_start + 0], joint_qd[qd_start + 1], joint_qd[qd_start + 2])
251
-
252
- X_j = wp.transform(wp.vec3(), r)
253
- v_j = wp.spatial_vector(w, wp.vec3())
254
-
255
- if type == wp.sim.JOINT_FREE or type == wp.sim.JOINT_DISTANCE:
256
- t = wp.transform(
257
- wp.vec3(joint_q[q_start + 0], joint_q[q_start + 1], joint_q[q_start + 2]),
258
- wp.quat(joint_q[q_start + 3], joint_q[q_start + 4], joint_q[q_start + 5], joint_q[q_start + 6]),
259
- )
260
-
261
- v = wp.spatial_vector(
262
- wp.vec3(joint_qd[qd_start + 0], joint_qd[qd_start + 1], joint_qd[qd_start + 2]),
263
- wp.vec3(joint_qd[qd_start + 3], joint_qd[qd_start + 4], joint_qd[qd_start + 5]),
264
- )
265
-
266
- X_j = t
267
- v_j = v
268
-
269
- if type == wp.sim.JOINT_COMPOUND:
270
- rot, vel_w = compute_3d_rotational_dofs(
271
- joint_axis[axis_start],
272
- joint_axis[axis_start + 1],
273
- joint_axis[axis_start + 2],
274
- joint_q[q_start + 0],
275
- joint_q[q_start + 1],
276
- joint_q[q_start + 2],
277
- joint_qd[qd_start + 0],
278
- joint_qd[qd_start + 1],
279
- joint_qd[qd_start + 2],
280
- )
281
-
282
- t = wp.transform(wp.vec3(0.0, 0.0, 0.0), rot)
283
- v = wp.spatial_vector(vel_w, wp.vec3(0.0, 0.0, 0.0))
284
-
285
- X_j = t
286
- v_j = v
287
-
288
- if type == wp.sim.JOINT_UNIVERSAL:
289
- rot, vel_w = compute_2d_rotational_dofs(
290
- joint_axis[axis_start],
291
- joint_axis[axis_start + 1],
292
- joint_q[q_start + 0],
293
- joint_q[q_start + 1],
294
- joint_qd[qd_start + 0],
295
- joint_qd[qd_start + 1],
296
- )
297
-
298
- t = wp.transform(wp.vec3(0.0, 0.0, 0.0), rot)
299
- v = wp.spatial_vector(vel_w, wp.vec3(0.0, 0.0, 0.0))
300
-
301
- X_j = t
302
- v_j = v
303
-
304
- if type == wp.sim.JOINT_D6:
305
- pos = wp.vec3(0.0)
306
- rot = wp.quat_identity()
307
- vel_v = wp.vec3(0.0)
308
- vel_w = wp.vec3(0.0)
309
-
310
- # unroll for loop to ensure joint actions remain differentiable
311
- # (since differentiating through a for loop that updates a local variable is not supported)
312
-
313
- if lin_axis_count > 0:
314
- axis = joint_axis[axis_start + 0]
315
- pos += axis * joint_q[q_start + 0]
316
- vel_v += axis * joint_qd[qd_start + 0]
317
- if lin_axis_count > 1:
318
- axis = joint_axis[axis_start + 1]
319
- pos += axis * joint_q[q_start + 1]
320
- vel_v += axis * joint_qd[qd_start + 1]
321
- if lin_axis_count > 2:
322
- axis = joint_axis[axis_start + 2]
323
- pos += axis * joint_q[q_start + 2]
324
- vel_v += axis * joint_qd[qd_start + 2]
325
-
326
- ia = axis_start + lin_axis_count
327
- iq = q_start + lin_axis_count
328
- iqd = qd_start + lin_axis_count
329
- if ang_axis_count == 1:
330
- axis = joint_axis[ia]
331
- rot = wp.quat_from_axis_angle(axis, joint_q[iq])
332
- vel_w = joint_qd[iqd] * axis
333
- if ang_axis_count == 2:
334
- rot, vel_w = compute_2d_rotational_dofs(
335
- joint_axis[ia + 0],
336
- joint_axis[ia + 1],
337
- joint_q[iq + 0],
338
- joint_q[iq + 1],
339
- joint_qd[iqd + 0],
340
- joint_qd[iqd + 1],
341
- )
342
- if ang_axis_count == 3:
343
- rot, vel_w = compute_3d_rotational_dofs(
344
- joint_axis[ia + 0],
345
- joint_axis[ia + 1],
346
- joint_axis[ia + 2],
347
- joint_q[iq + 0],
348
- joint_q[iq + 1],
349
- joint_q[iq + 2],
350
- joint_qd[iqd + 0],
351
- joint_qd[iqd + 1],
352
- joint_qd[iqd + 2],
353
- )
354
-
355
- X_j = wp.transform(pos, rot)
356
- v_j = wp.spatial_vector(vel_w, vel_v)
357
-
358
- # transform from world to joint anchor frame at child body
359
- X_wcj = X_wpj * X_j
360
- # transform from world to child body frame
361
- X_wc = X_wcj * wp.transform_inverse(X_cj)
362
-
363
- # transform velocity across the joint to world space
364
- angular_vel = wp.transform_vector(X_wpj, wp.spatial_top(v_j))
365
- linear_vel = wp.transform_vector(X_wpj, wp.spatial_bottom(v_j))
366
-
367
- v_wc = v_wpj + wp.spatial_vector(angular_vel, linear_vel)
368
-
369
- body_q[child] = X_wc
370
- body_qd[child] = v_wc
371
-
372
-
373
- # implementation where mask is an integer array
374
- @wp.kernel
375
- def eval_articulation_fk(
376
- articulation_start: wp.array(dtype=int),
377
- articulation_mask: wp.array(
378
- dtype=int
379
- ), # used to enable / disable FK for an articulation, if None then treat all as enabled
380
- joint_q: wp.array(dtype=float),
381
- joint_qd: wp.array(dtype=float),
382
- joint_q_start: wp.array(dtype=int),
383
- joint_qd_start: wp.array(dtype=int),
384
- joint_type: wp.array(dtype=int),
385
- joint_parent: wp.array(dtype=int),
386
- joint_child: wp.array(dtype=int),
387
- joint_X_p: wp.array(dtype=wp.transform),
388
- joint_X_c: wp.array(dtype=wp.transform),
389
- joint_axis: wp.array(dtype=wp.vec3),
390
- joint_axis_start: wp.array(dtype=int),
391
- joint_axis_dim: wp.array(dtype=int, ndim=2),
392
- body_com: wp.array(dtype=wp.vec3),
393
- # outputs
394
- body_q: wp.array(dtype=wp.transform),
395
- body_qd: wp.array(dtype=wp.spatial_vector),
396
- ):
397
- tid = wp.tid()
398
-
399
- # early out if disabling FK for this articulation
400
- if articulation_mask:
401
- if articulation_mask[tid] == 0:
402
- return
403
-
404
- joint_start = articulation_start[tid]
405
- joint_end = articulation_start[tid + 1]
406
-
407
- eval_single_articulation_fk(
408
- joint_start,
409
- joint_end,
410
- joint_q,
411
- joint_qd,
412
- joint_q_start,
413
- joint_qd_start,
414
- joint_type,
415
- joint_parent,
416
- joint_child,
417
- joint_X_p,
418
- joint_X_c,
419
- joint_axis,
420
- joint_axis_start,
421
- joint_axis_dim,
422
- body_com,
423
- # outputs
424
- body_q,
425
- body_qd,
426
- )
427
-
428
-
429
- # overload where mask is a bool array
430
- @wp.kernel
431
- def eval_articulation_fk(
432
- articulation_start: wp.array(dtype=int),
433
- articulation_mask: wp.array(
434
- dtype=bool
435
- ), # used to enable / disable FK for an articulation, if None then treat all as enabled
436
- joint_q: wp.array(dtype=float),
437
- joint_qd: wp.array(dtype=float),
438
- joint_q_start: wp.array(dtype=int),
439
- joint_qd_start: wp.array(dtype=int),
440
- joint_type: wp.array(dtype=int),
441
- joint_parent: wp.array(dtype=int),
442
- joint_child: wp.array(dtype=int),
443
- joint_X_p: wp.array(dtype=wp.transform),
444
- joint_X_c: wp.array(dtype=wp.transform),
445
- joint_axis: wp.array(dtype=wp.vec3),
446
- joint_axis_start: wp.array(dtype=int),
447
- joint_axis_dim: wp.array(dtype=int, ndim=2),
448
- body_com: wp.array(dtype=wp.vec3),
449
- # outputs
450
- body_q: wp.array(dtype=wp.transform),
451
- body_qd: wp.array(dtype=wp.spatial_vector),
452
- ):
453
- tid = wp.tid()
454
-
455
- # early out if disabling FK for this articulation
456
- if articulation_mask:
457
- if not articulation_mask[tid]:
458
- return
459
-
460
- joint_start = articulation_start[tid]
461
- joint_end = articulation_start[tid + 1]
462
-
463
- eval_single_articulation_fk(
464
- joint_start,
465
- joint_end,
466
- joint_q,
467
- joint_qd,
468
- joint_q_start,
469
- joint_qd_start,
470
- joint_type,
471
- joint_parent,
472
- joint_child,
473
- joint_X_p,
474
- joint_X_c,
475
- joint_axis,
476
- joint_axis_start,
477
- joint_axis_dim,
478
- body_com,
479
- # outputs
480
- body_q,
481
- body_qd,
482
- )
483
-
484
-
485
- # updates state body information based on joint coordinates
486
- def eval_fk(model, joint_q, joint_qd, mask, state):
487
- """
488
- Evaluates the model's forward kinematics given the joint coordinates and updates the state's body information (:attr:`State.body_q` and :attr:`State.body_qd`).
489
-
490
- Args:
491
- model (Model): The model to evaluate.
492
- joint_q (array): Generalized joint position coordinates, shape [joint_coord_count], float
493
- joint_qd (array): Generalized joint velocity coordinates, shape [joint_dof_count], float
494
- mask (array): The mask to use to enable / disable FK for an articulation. If None then treat all as enabled, shape [articulation_count], int/bool
495
- state (State): The state to update.
496
- """
497
- wp.launch(
498
- kernel=eval_articulation_fk,
499
- dim=model.articulation_count,
500
- inputs=[
501
- model.articulation_start,
502
- mask,
503
- joint_q,
504
- joint_qd,
505
- model.joint_q_start,
506
- model.joint_qd_start,
507
- model.joint_type,
508
- model.joint_parent,
509
- model.joint_child,
510
- model.joint_X_p,
511
- model.joint_X_c,
512
- model.joint_axis,
513
- model.joint_axis_start,
514
- model.joint_axis_dim,
515
- model.body_com,
516
- ],
517
- outputs=[
518
- state.body_q,
519
- state.body_qd,
520
- ],
521
- device=model.device,
522
- )
523
-
524
-
525
- @wp.func
526
- def reconstruct_angular_q_qd(q_pc: wp.quat, w_err: wp.vec3, X_wp: wp.transform, axis: wp.vec3):
527
- """
528
- Reconstructs the angular joint coordinates and velocities given the relative rotation and angular velocity
529
- between a parent and child body.
530
-
531
- Args:
532
- q_pc (quat): The relative rotation between the parent and child body.
533
- w_err (vec3): The angular velocity between the parent and child body.
534
- X_wp (transform): The parent body's transform in world space.
535
- axis (vec3): The joint axis in the frame of the parent body.
536
-
537
- Returns:
538
- q (float): The joint position coordinate.
539
- qd (float): The joint velocity coordinate.
540
- """
541
- axis_p = wp.transform_vector(X_wp, axis)
542
- twist = quat_twist(axis, q_pc)
543
- q = wp.acos(twist[3]) * 2.0 * wp.sign(wp.dot(axis, wp.vec3(twist[0], twist[1], twist[2])))
544
- qd = wp.dot(w_err, axis_p)
545
- return q, qd
546
-
547
-
548
- @wp.kernel
549
- def eval_articulation_ik(
550
- body_q: wp.array(dtype=wp.transform),
551
- body_qd: wp.array(dtype=wp.spatial_vector),
552
- body_com: wp.array(dtype=wp.vec3),
553
- joint_type: wp.array(dtype=int),
554
- joint_parent: wp.array(dtype=int),
555
- joint_child: wp.array(dtype=int),
556
- joint_X_p: wp.array(dtype=wp.transform),
557
- joint_X_c: wp.array(dtype=wp.transform),
558
- joint_axis: wp.array(dtype=wp.vec3),
559
- joint_axis_start: wp.array(dtype=int),
560
- joint_axis_dim: wp.array(dtype=int, ndim=2),
561
- joint_q_start: wp.array(dtype=int),
562
- joint_qd_start: wp.array(dtype=int),
563
- joint_q: wp.array(dtype=float),
564
- joint_qd: wp.array(dtype=float),
565
- ):
566
- tid = wp.tid()
567
-
568
- parent = joint_parent[tid]
569
- child = joint_child[tid]
570
-
571
- X_pj = joint_X_p[tid]
572
- X_cj = joint_X_c[tid]
573
-
574
- w_p = wp.vec3()
575
- v_p = wp.vec3()
576
- v_wp = wp.spatial_vector()
577
-
578
- # parent anchor frame in world space
579
- X_wpj = X_pj
580
- if parent >= 0:
581
- X_wp = body_q[parent]
582
- X_wpj = X_wp * X_pj
583
- r_p = wp.transform_get_translation(X_wpj) - wp.transform_point(X_wp, body_com[parent])
584
-
585
- v_wp = body_qd[parent]
586
- w_p = wp.spatial_top(v_wp)
587
- v_p = wp.spatial_bottom(v_wp) + wp.cross(w_p, r_p)
588
-
589
- # child transform and moment arm
590
- X_wc = body_q[child]
591
- X_wcj = X_wc * X_cj
592
-
593
- v_wc = body_qd[child]
594
-
595
- w_c = wp.spatial_top(v_wc)
596
- v_c = wp.spatial_bottom(v_wc)
597
-
598
- # joint properties
599
- type = joint_type[tid]
600
-
601
- # compute position and orientation differences between anchor frames
602
- x_p = wp.transform_get_translation(X_wpj)
603
- x_c = wp.transform_get_translation(X_wcj)
604
-
605
- q_p = wp.transform_get_rotation(X_wpj)
606
- q_c = wp.transform_get_rotation(X_wcj)
607
-
608
- x_err = x_c - x_p
609
- v_err = v_c - v_p
610
- w_err = w_c - w_p
611
-
612
- q_start = joint_q_start[tid]
613
- qd_start = joint_qd_start[tid]
614
- axis_start = joint_axis_start[tid]
615
- lin_axis_count = joint_axis_dim[tid, 0]
616
- ang_axis_count = joint_axis_dim[tid, 1]
617
-
618
- if type == wp.sim.JOINT_PRISMATIC:
619
- axis = joint_axis[axis_start]
620
-
621
- # world space joint axis
622
- axis_p = wp.quat_rotate(q_p, axis)
623
-
624
- # evaluate joint coordinates
625
- q = wp.dot(x_err, axis_p)
626
- qd = wp.dot(v_err, axis_p)
627
-
628
- joint_q[q_start] = q
629
- joint_qd[qd_start] = qd
630
-
631
- return
632
-
633
- if type == wp.sim.JOINT_REVOLUTE:
634
- axis = joint_axis[axis_start]
635
- q_pc = wp.quat_inverse(q_p) * q_c
636
-
637
- q, qd = reconstruct_angular_q_qd(q_pc, w_err, X_wpj, axis)
638
-
639
- joint_q[q_start] = q
640
- joint_qd[qd_start] = qd
641
-
642
- return
643
-
644
- if type == wp.sim.JOINT_BALL:
645
- q_pc = wp.quat_inverse(q_p) * q_c
646
-
647
- joint_q[q_start + 0] = q_pc[0]
648
- joint_q[q_start + 1] = q_pc[1]
649
- joint_q[q_start + 2] = q_pc[2]
650
- joint_q[q_start + 3] = q_pc[3]
651
-
652
- ang_vel = wp.transform_vector(wp.transform_inverse(X_wpj), w_err)
653
- joint_qd[qd_start + 0] = ang_vel[0]
654
- joint_qd[qd_start + 1] = ang_vel[1]
655
- joint_qd[qd_start + 2] = ang_vel[2]
656
-
657
- return
658
-
659
- if type == wp.sim.JOINT_FIXED:
660
- return
661
-
662
- if type == wp.sim.JOINT_FREE or type == wp.sim.JOINT_DISTANCE:
663
- q_pc = wp.quat_inverse(q_p) * q_c
664
-
665
- x_err_c = wp.quat_rotate_inv(q_p, x_err)
666
- v_err_c = wp.quat_rotate_inv(q_p, v_err)
667
- w_err_c = wp.quat_rotate_inv(q_p, w_err)
668
-
669
- joint_q[q_start + 0] = x_err_c[0]
670
- joint_q[q_start + 1] = x_err_c[1]
671
- joint_q[q_start + 2] = x_err_c[2]
672
-
673
- joint_q[q_start + 3] = q_pc[0]
674
- joint_q[q_start + 4] = q_pc[1]
675
- joint_q[q_start + 5] = q_pc[2]
676
- joint_q[q_start + 6] = q_pc[3]
677
-
678
- joint_qd[qd_start + 0] = w_err_c[0]
679
- joint_qd[qd_start + 1] = w_err_c[1]
680
- joint_qd[qd_start + 2] = w_err_c[2]
681
-
682
- joint_qd[qd_start + 3] = v_err_c[0]
683
- joint_qd[qd_start + 4] = v_err_c[1]
684
- joint_qd[qd_start + 5] = v_err_c[2]
685
-
686
- return
687
-
688
- if type == wp.sim.JOINT_COMPOUND:
689
- axis_0 = joint_axis[axis_start + 0]
690
- axis_1 = joint_axis[axis_start + 1]
691
- axis_2 = joint_axis[axis_start + 2]
692
- qs, qds = invert_3d_rotational_dofs(axis_0, axis_1, axis_2, q_p, q_c, w_err)
693
- joint_q[q_start + 0] = qs[0]
694
- joint_q[q_start + 1] = qs[1]
695
- joint_q[q_start + 2] = qs[2]
696
- joint_qd[qd_start + 0] = qds[0]
697
- joint_qd[qd_start + 1] = qds[1]
698
- joint_qd[qd_start + 2] = qds[2]
699
-
700
- return
701
-
702
- if type == wp.sim.JOINT_UNIVERSAL:
703
- axis_0 = joint_axis[axis_start + 0]
704
- axis_1 = joint_axis[axis_start + 1]
705
- qs2, qds2 = invert_2d_rotational_dofs(axis_0, axis_1, q_p, q_c, w_err)
706
- joint_q[q_start + 0] = qs2[0]
707
- joint_q[q_start + 1] = qs2[1]
708
- joint_qd[qd_start + 0] = qds2[0]
709
- joint_qd[qd_start + 1] = qds2[1]
710
-
711
- return
712
-
713
- if type == wp.sim.JOINT_D6:
714
- x_err_c = wp.quat_rotate_inv(q_p, x_err)
715
- v_err_c = wp.quat_rotate_inv(q_p, v_err)
716
- if lin_axis_count > 0:
717
- axis = joint_axis[axis_start + 0]
718
- joint_q[q_start + 0] = wp.dot(x_err_c, axis)
719
- joint_qd[qd_start + 0] = wp.dot(v_err_c, axis)
720
-
721
- if lin_axis_count > 1:
722
- axis = joint_axis[axis_start + 1]
723
- joint_q[q_start + 1] = wp.dot(x_err_c, axis)
724
- joint_qd[qd_start + 1] = wp.dot(v_err_c, axis)
725
-
726
- if lin_axis_count > 2:
727
- axis = joint_axis[axis_start + 2]
728
- joint_q[q_start + 2] = wp.dot(x_err_c, axis)
729
- joint_qd[qd_start + 2] = wp.dot(v_err_c, axis)
730
-
731
- if ang_axis_count == 1:
732
- axis = joint_axis[axis_start]
733
- q_pc = wp.quat_inverse(q_p) * q_c
734
- q, qd = reconstruct_angular_q_qd(q_pc, w_err, X_wpj, joint_axis[axis_start + lin_axis_count])
735
- joint_q[q_start + lin_axis_count] = q
736
- joint_qd[qd_start + lin_axis_count] = qd
737
-
738
- if ang_axis_count == 2:
739
- axis_0 = joint_axis[axis_start + lin_axis_count + 0]
740
- axis_1 = joint_axis[axis_start + lin_axis_count + 1]
741
- qs2, qds2 = invert_2d_rotational_dofs(axis_0, axis_1, q_p, q_c, w_err)
742
- joint_q[q_start + lin_axis_count + 0] = qs2[0]
743
- joint_q[q_start + lin_axis_count + 1] = qs2[1]
744
- joint_qd[qd_start + lin_axis_count + 0] = qds2[0]
745
- joint_qd[qd_start + lin_axis_count + 1] = qds2[1]
746
-
747
- if ang_axis_count == 3:
748
- axis_0 = joint_axis[axis_start + lin_axis_count + 0]
749
- axis_1 = joint_axis[axis_start + lin_axis_count + 1]
750
- axis_2 = joint_axis[axis_start + lin_axis_count + 2]
751
- qs3, qds3 = invert_3d_rotational_dofs(axis_0, axis_1, axis_2, q_p, q_c, w_err)
752
- joint_q[q_start + lin_axis_count + 0] = qs3[0]
753
- joint_q[q_start + lin_axis_count + 1] = qs3[1]
754
- joint_q[q_start + lin_axis_count + 2] = qs3[2]
755
- joint_qd[qd_start + lin_axis_count + 0] = qds3[0]
756
- joint_qd[qd_start + lin_axis_count + 1] = qds3[1]
757
- joint_qd[qd_start + lin_axis_count + 2] = qds3[2]
758
-
759
- return
760
-
761
-
762
- # given maximal coordinate model computes ik (closest point projection)
763
- def eval_ik(model, state, joint_q, joint_qd):
764
- """
765
- Evaluates the model's inverse kinematics given the state's body information (:attr:`State.body_q` and :attr:`State.body_qd`) and updates the generalized joint coordinates `joint_q` and `joint_qd`.
766
-
767
- Args:
768
- model (Model): The model to evaluate.
769
- state (State): The state with the body's maximal coordinates (positions :attr:`State.body_q` and velocities :attr:`State.body_qd`) to use.
770
- joint_q (array): Generalized joint position coordinates, shape [joint_coord_count], float
771
- joint_qd (array): Generalized joint velocity coordinates, shape [joint_dof_count], float
772
- """
773
- wp.launch(
774
- kernel=eval_articulation_ik,
775
- dim=model.joint_count,
776
- inputs=[
777
- state.body_q,
778
- state.body_qd,
779
- model.body_com,
780
- model.joint_type,
781
- model.joint_parent,
782
- model.joint_child,
783
- model.joint_X_p,
784
- model.joint_X_c,
785
- model.joint_axis,
786
- model.joint_axis_start,
787
- model.joint_axis_dim,
788
- model.joint_q_start,
789
- model.joint_qd_start,
790
- ],
791
- outputs=[joint_q, joint_qd],
792
- device=model.device,
793
- )