jaxsim 0.4.3.dev143__py3-none-any.whl → 0.4.3.dev159__py3-none-any.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.
@@ -10,10 +10,11 @@ import jax_dataclasses
10
10
  import jaxsim.api as js
11
11
  import jaxsim.math
12
12
  import jaxsim.typing as jtp
13
+ from jaxsim import logging
13
14
  from jaxsim.math import StandardGravity
14
15
  from jaxsim.terrain import FlatTerrain, Terrain
15
16
 
16
- from .common import ContactModel, ContactsParams, ContactsState
17
+ from .common import ContactModel, ContactsParams
17
18
 
18
19
  try:
19
20
  from typing import Self
@@ -192,13 +193,67 @@ class SoftContacts(ContactModel):
192
193
  """Soft contacts model."""
193
194
 
194
195
  parameters: SoftContactsParams = dataclasses.field(
195
- default_factory=SoftContactsParams
196
+ default_factory=SoftContactsParams.build
196
197
  )
197
198
 
198
199
  terrain: jax_dataclasses.Static[Terrain] = dataclasses.field(
199
- default_factory=FlatTerrain
200
+ default_factory=FlatTerrain.build
200
201
  )
201
202
 
203
+ @classmethod
204
+ def build(
205
+ cls: type[Self],
206
+ parameters: SoftContactsParams | None = None,
207
+ terrain: Terrain | None = None,
208
+ model: js.model.JaxSimModel | None = None,
209
+ **kwargs,
210
+ ) -> Self:
211
+ """
212
+ Create a `SoftContacts` instance with specified parameters.
213
+
214
+ Args:
215
+ parameters: The parameters of the soft contacts model.
216
+ terrain: The considered terrain.
217
+ model:
218
+ The robot model considered by the contact model.
219
+ If passed, it is used to estimate good default parameters.
220
+
221
+ Returns:
222
+ The `SoftContacts` instance.
223
+ """
224
+
225
+ if len(kwargs) != 0:
226
+ logging.debug(msg=f"Ignoring extra arguments: {kwargs}")
227
+
228
+ # Build the contact parameters if not provided. Use the model to estimate
229
+ # good default parameters, if passed. Users can later override these default
230
+ # parameters with their own values -- possibly tuned better.
231
+ if parameters is None:
232
+ parameters = (
233
+ SoftContactsParams.build_default_from_jaxsim_model(model=model)
234
+ if model is not None
235
+ else cls.__dataclass_fields__["parameters"].default_factory()
236
+ )
237
+
238
+ return SoftContacts(
239
+ parameters=parameters,
240
+ terrain=terrain or cls.__dataclass_fields__["terrain"].default_factory(),
241
+ )
242
+
243
+ @classmethod
244
+ def zero_state_variables(cls, model: js.model.JaxSimModel) -> dict[str, jtp.Array]:
245
+ """
246
+ Build zero state variables of the contact model.
247
+ """
248
+
249
+ # Initialize the material deformation to zero.
250
+ tangential_deformation = jnp.zeros(
251
+ shape=(len(model.kin_dyn_parameters.contact_parameters.body), 3),
252
+ dtype=float,
253
+ )
254
+
255
+ return {"tangential_deformation": tangential_deformation}
256
+
202
257
  @staticmethod
203
258
  @functools.partial(jax.jit, static_argnames=("terrain",))
204
259
  def hunt_crossley_contact_model(
@@ -380,8 +435,7 @@ class SoftContacts(ContactModel):
380
435
  W_p_C, W_ṗ_C = js.contact.collidable_point_kinematics(model=model, data=data)
381
436
 
382
437
  # Extract the material deformation corresponding to the collidable points.
383
- assert isinstance(data.state.contact, SoftContactsState)
384
- m = data.state.contact.tangential_deformation
438
+ m = data.state.extended["tangential_deformation"]
385
439
 
386
440
  # Compute the contact forces for all collidable points.
387
441
  # Since we treat them as independent, we can vmap the computation.
@@ -423,131 +477,3 @@ class SoftContacts(ContactModel):
423
477
  δ̇ = jnp.where(δ > 0, δ̇, 0.0)
424
478
 
425
479
  return δ, δ̇, n̂
426
-
427
-
428
- @jax_dataclasses.pytree_dataclass
429
- class SoftContactsState(ContactsState):
430
- """
431
- Class storing the state of the soft contacts model.
432
-
433
- Attributes:
434
- tangential_deformation:
435
- The matrix of 3D tangential material deformations corresponding to
436
- each collidable point.
437
- """
438
-
439
- tangential_deformation: jtp.Matrix
440
-
441
- def __hash__(self) -> int:
442
-
443
- return hash(
444
- tuple(jnp.atleast_1d(self.tangential_deformation.flatten()).tolist())
445
- )
446
-
447
- def __eq__(self: Self, other: Self) -> bool:
448
-
449
- if not isinstance(other, type(self)):
450
- return False
451
-
452
- return hash(self) == hash(other)
453
-
454
- @classmethod
455
- def build_from_jaxsim_model(
456
- cls: type[Self],
457
- model: js.model.JaxSimModel | None = None,
458
- tangential_deformation: jtp.MatrixLike | None = None,
459
- ) -> Self:
460
- """
461
- Build a `SoftContactsState` from a `JaxSimModel`.
462
-
463
- Args:
464
- model: The `JaxSimModel` associated with the soft contacts state.
465
- tangential_deformation: The matrix of 3D tangential material deformations.
466
-
467
- Returns:
468
- The `SoftContactsState` built from the `JaxSimModel`.
469
-
470
- Note:
471
- If any of the state components are not provided, they are built from the
472
- `JaxSimModel` and initialized to zero.
473
- """
474
-
475
- return cls.build(
476
- tangential_deformation=tangential_deformation,
477
- number_of_collidable_points=len(
478
- model.kin_dyn_parameters.contact_parameters.body
479
- ),
480
- )
481
-
482
- @classmethod
483
- def build(
484
- cls: type[Self],
485
- *,
486
- tangential_deformation: jtp.MatrixLike | None = None,
487
- number_of_collidable_points: int | None = None,
488
- ) -> Self:
489
- """
490
- Create a `SoftContactsState`.
491
-
492
- Args:
493
- tangential_deformation:
494
- The matrix of 3D tangential material deformations corresponding to
495
- each collidable point.
496
- number_of_collidable_points: The number of collidable points.
497
-
498
- Returns:
499
- A `SoftContactsState` instance.
500
- """
501
-
502
- tangential_deformation = (
503
- jnp.atleast_2d(tangential_deformation)
504
- if tangential_deformation is not None
505
- else jnp.zeros(shape=(number_of_collidable_points, 3))
506
- ).astype(float)
507
-
508
- if tangential_deformation.shape[1] != 3:
509
- raise RuntimeError("The tangential deformation matrix must have 3 columns.")
510
-
511
- if (
512
- number_of_collidable_points is not None
513
- and tangential_deformation.shape[0] != number_of_collidable_points
514
- ):
515
- msg = "The number of collidable points must match the number of rows "
516
- msg += "in the tangential deformation matrix."
517
- raise RuntimeError(msg)
518
-
519
- return cls(tangential_deformation=tangential_deformation)
520
-
521
- @classmethod
522
- def zero(cls: type[Self], *, model: js.model.JaxSimModel) -> Self:
523
- """
524
- Build a zero `SoftContactsState` from a `JaxSimModel`.
525
-
526
- Args:
527
- model: The `JaxSimModel` associated with the soft contacts state.
528
-
529
- Returns:
530
- A zero `SoftContactsState` instance.
531
- """
532
-
533
- return cls.build_from_jaxsim_model(model=model)
534
-
535
- def valid(self, *, model: js.model.JaxSimModel) -> jtp.BoolLike:
536
- """
537
- Check if the `SoftContactsState` is valid for a given `JaxSimModel`.
538
-
539
- Args:
540
- model: The `JaxSimModel` to validate the `SoftContactsState` against.
541
-
542
- Returns:
543
- `True` if the soft contacts state is valid for the given `JaxSimModel`,
544
- `False` otherwise.
545
- """
546
-
547
- shape = self.tangential_deformation.shape
548
- expected = (len(model.kin_dyn_parameters.contact_parameters.body), 3)
549
-
550
- if shape != expected:
551
- return False
552
-
553
- return True
jaxsim/terrain/terrain.py CHANGED
@@ -49,7 +49,7 @@ class FlatTerrain(Terrain):
49
49
  _height: float = dataclasses.field(default=0.0, kw_only=True)
50
50
 
51
51
  @staticmethod
52
- def build(height: jtp.FloatLike) -> FlatTerrain:
52
+ def build(height: jtp.FloatLike = 0.0) -> FlatTerrain:
53
53
 
54
54
  return FlatTerrain(_height=float(height))
55
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jaxsim
3
- Version: 0.4.3.dev143
3
+ Version: 0.4.3.dev159
4
4
  Summary: A differentiable physics engine and multibody dynamics library for control and robot learning.
5
5
  Author-email: Diego Ferigo <dgferigo@gmail.com>
6
6
  Maintainer-email: Diego Ferigo <dgferigo@gmail.com>, Filippo Luca Ferretti <filippo.ferretti@iit.it>
@@ -1,20 +1,20 @@
1
1
  jaxsim/__init__.py,sha256=bSbpggIz5aG6QuGZLa0V2EfHjAOeucMxi-vIYxzLmN8,2788
2
- jaxsim/_version.py,sha256=AUMtPwp-9k4PBssfGUg1S2TuNzVQkbYfnNIjR31wCZY,428
2
+ jaxsim/_version.py,sha256=p1_cPvBnSIuAbg5RWked461etxKJN-ANdqjllGN6J4s,428
3
3
  jaxsim/exceptions.py,sha256=8_h8iqL8DgNR754dR8SZiQ7361GR5V1sUk3ZuZCHw1Q,2069
4
4
  jaxsim/logging.py,sha256=STI-D_upXZYX-ZezLrlJJ0UlD5YspST0vZ_DcIwkzO4,1553
5
5
  jaxsim/typing.py,sha256=2HXy9hgazPXjofi1vLQ09ZubPtgVmg80U9NKmZ6NYiI,761
6
6
  jaxsim/api/__init__.py,sha256=8eV22t2S3UwNyCg8karPetG1dmX1VDBXkyv28_FwNQA,210
7
7
  jaxsim/api/com.py,sha256=m-p3EJDhpnMTlXKplfbZE_aH9NqX_VyLlAE3vUhc6l4,13642
8
8
  jaxsim/api/common.py,sha256=SNgxq42r6eF_-aPszvOjUYkGwXOzz4hKmhDwEUkscFQ,6650
9
- jaxsim/api/contact.py,sha256=ktol-c2UHDqt3Hd6NpMhK86NlyadIyB5eY7chA5GhkY,22568
10
- jaxsim/api/data.py,sha256=bSuBVKKksYtANLnxCkMQ3u2JGbn5mud7g8G5aLZawls,28988
9
+ jaxsim/api/contact.py,sha256=RYIaVqDMizxfretC72Ye5vfr8208UsFyzqGE-C1oxxA,22204
10
+ jaxsim/api/data.py,sha256=kDP1s5mm8F-LpIqKrdaCmHhJEMyigFDyuaAXdMukhWY,29588
11
11
  jaxsim/api/frame.py,sha256=KS8A5wRfjxhe9NgcVo2QA516iP5zky7UVnWxG7nTa7c,12911
12
12
  jaxsim/api/joint.py,sha256=lksT1Doxz2jknHyhb4ls20z6f6dofpZSzBJtVacZXAE,7129
13
13
  jaxsim/api/kin_dyn_parameters.py,sha256=ElahFk_RCcLvjTidH2qDOsY-m1gN1hXitCv4SvfgGYY,29260
14
14
  jaxsim/api/link.py,sha256=LAA6ZMQXkWomXeptURBtc7z3_xDZ2BBnBMhVrohh0bE,18621
15
- jaxsim/api/model.py,sha256=Y0A9p7uKpfBdZLC9o_pTw7WQrmAaNJJBK1G97YkDRjQ,68260
16
- jaxsim/api/ode.py,sha256=B9CANQGLbrKAkmTxvWvkb0UGKC__r1nlHf-bGw963q0,13999
17
- jaxsim/api/ode_data.py,sha256=6q3IECaA351hLSGRovrOSKLo_P8IhJrW-p2-ZDlzGG8,20436
15
+ jaxsim/api/model.py,sha256=IcJhFdVjswSncurVpQXoa7uXVqSsvAuZVs-DXDsXi08,69021
16
+ jaxsim/api/ode.py,sha256=_rTgDVNLQWbZ-E8ApKbq4JQ6ctCcQeDvCzAf6d35hY8,14061
17
+ jaxsim/api/ode_data.py,sha256=1SD-x-lYk_YSEnVpxTLd69uOKC0mFUj44ZqpSmEDOxw,20190
18
18
  jaxsim/api/references.py,sha256=fW77LitZ8DYgT6ZmUInJfm5luBV1mTcqcNRiC_i79og,20862
19
19
  jaxsim/integrators/__init__.py,sha256=hxvOD-VK_mmd6v31wtC-nb28AYve1gLuZCNLV9wS-Kg,103
20
20
  jaxsim/integrators/common.py,sha256=78MBs89GxsL0wU2yAexjvBZt3HEtfZoGVIN9f0a8yTc,20305
@@ -52,19 +52,19 @@ jaxsim/rbda/forward_kinematics.py,sha256=2GmEoWsrioVl_SAbKRKfhOLz57pY4aR81PKRdul
52
52
  jaxsim/rbda/jacobian.py,sha256=p0EV_8cLzLVV-93VKznT7VPuRj8W7h7rQWkPlWJXfCA,11023
53
53
  jaxsim/rbda/rnea.py,sha256=CLfqs9XFVaD-hvkLABshDAfdw5bm_AMV3UVAQ_IvURQ,7542
54
54
  jaxsim/rbda/utils.py,sha256=eeT21Y4DiiyhrdF0lUE_VvRuwru5-rR7yOlOlWzCCWE,5381
55
- jaxsim/rbda/contacts/__init__.py,sha256=0UnO9ZR3BwdjQa276jOFbPi90pporr32LSc0qa9UUm4,369
56
- jaxsim/rbda/contacts/common.py,sha256=-eM8d1kvJ2E_2_kAgZJk4s3x8vDZHNSyOAinwPmRmEk,3469
57
- jaxsim/rbda/contacts/relaxed_rigid.py,sha256=G3NoFrIGqzr_hrScLtsbmliTSqcVxDxheA1w2HRcU7A,15794
58
- jaxsim/rbda/contacts/rigid.py,sha256=WzPPo_UACOo_7olv_R1PelRjdjGqdWHkQ6hkSSfdBZk,15689
59
- jaxsim/rbda/contacts/soft.py,sha256=NzzCYw5rvK8Fx_qH3fiMzPgey-KoxmRe9xkF3fluidE,18866
55
+ jaxsim/rbda/contacts/__init__.py,sha256=Vqtk2GeSAXh6YxiqadY-fe4PY__IUYiOwnLgSdpLqW0,271
56
+ jaxsim/rbda/contacts/common.py,sha256=_yrxTM16Je9ck5aM95ndk8Kwu_oijxG9Jaf1jEjHEYw,4332
57
+ jaxsim/rbda/contacts/relaxed_rigid.py,sha256=Ob5LdKe3D7tGlIdT4LamJ6_F0j5pzUmWNYoWqy8Di98,17169
58
+ jaxsim/rbda/contacts/rigid.py,sha256=1TTiGXSOipO8l5FDTtxqRNo1ArCNtDg-Yr3olPgBLGs,17588
59
+ jaxsim/rbda/contacts/soft.py,sha256=TMCUDtFmNIae04LCla57iXMjdt9F5qTFjYEnP5NdLFg,16809
60
60
  jaxsim/terrain/__init__.py,sha256=f7lVX-iNpH_wkkjef9Qpjh19TTAUOQw76EiLYJDVizc,78
61
- jaxsim/terrain/terrain.py,sha256=Y0TGnUAGPuaeeSN8vbaSFjMXP5GYy3nxMCETjpUIMSA,5009
61
+ jaxsim/terrain/terrain.py,sha256=K91HEzPqTSyNrc_j1KfAAEF_5oDeuk_-jnnZGrcMEcY,5015
62
62
  jaxsim/utils/__init__.py,sha256=Y5zyoRevl3EMVQadhZ4EtSwTEkDt2vcnFoRhPJjKTZ0,215
63
63
  jaxsim/utils/jaxsim_dataclass.py,sha256=TGmTQV2Lq7Q-2nLoAEaeNtkPa_qj0IKkdBm4COj46Os,11312
64
64
  jaxsim/utils/tracing.py,sha256=KDMoyVPlu2NJvFkhtZwq5AkqMMgajt3munvJom-vEjQ,650
65
65
  jaxsim/utils/wrappers.py,sha256=Fh82ZcaFi5fUnByyFLnmumaobsu1hJIvFdopUVzJ1ps,4052
66
- jaxsim-0.4.3.dev143.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
67
- jaxsim-0.4.3.dev143.dist-info/METADATA,sha256=jZMIz7kCovjDtiHxhrp18oWpaYUhdX8t056wtbTv1us,17276
68
- jaxsim-0.4.3.dev143.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
69
- jaxsim-0.4.3.dev143.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
70
- jaxsim-0.4.3.dev143.dist-info/RECORD,,
66
+ jaxsim-0.4.3.dev159.dist-info/LICENSE,sha256=eaYdFmdeMbiIoIiPzEK0MjP1S9wtFXjXNR5er49uLR0,1546
67
+ jaxsim-0.4.3.dev159.dist-info/METADATA,sha256=3AP-0_JvmN0Co6aNIBawlZVlTfi1nMi4V-XSchb91lM,17276
68
+ jaxsim-0.4.3.dev159.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
69
+ jaxsim-0.4.3.dev159.dist-info/top_level.txt,sha256=LxGMA8FLtXjQ6oI7N5gd_R_oSUHxpXxUEOfT1xS_ni0,7
70
+ jaxsim-0.4.3.dev159.dist-info/RECORD,,