Skip to content

Commit

Permalink
Make build_default_from_jaxsim_model compatible with all models
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed Feb 10, 2025
1 parent 21ba99e commit 62adf79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/jaxsim/rbda/contacts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def build_default_from_jaxsim_model(
damping_ratio: jtp.FloatLike = 1.0,
p: jtp.FloatLike = 0.5,
q: jtp.FloatLike = 0.5,
**kwargs,
) -> Self:
"""
Create a `ContactsParams` instance with default parameters.
Expand All @@ -111,6 +112,7 @@ def build_default_from_jaxsim_model(
damping_ratio: The damping ratio.
p: The first parameter of the contact model.
q: The second parameter of the contact model.
**kwargs: Optional additional arguments.
Returns:
The `ContactsParams` instance.
Expand Down Expand Up @@ -157,6 +159,7 @@ def build_default_from_jaxsim_model(
mu=μc,
p=p,
q=q,
**kwargs,
)

@abc.abstractmethod
Expand Down
25 changes: 12 additions & 13 deletions src/jaxsim/rbda/contacts/relaxed_rigid.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class RelaxedRigidContactsParams(common.ContactsParams):
)

# Stiffness
stiffness: jtp.Float = dataclasses.field(
K: jtp.Float = dataclasses.field(
default_factory=lambda: jnp.array(0.0, dtype=float)
)

# Damping
damping: jtp.Float = dataclasses.field(
D: jtp.Float = dataclasses.field(
default_factory=lambda: jnp.array(0.0, dtype=float)
)

Expand All @@ -90,8 +90,8 @@ def __hash__(self) -> int:
HashedNumpyArray(self.width),
HashedNumpyArray(self.midpoint),
HashedNumpyArray(self.power),
HashedNumpyArray(self.stiffness),
HashedNumpyArray(self.damping),
HashedNumpyArray(self.K),
HashedNumpyArray(self.D),
HashedNumpyArray(self.mu),
)
)
Expand All @@ -110,9 +110,10 @@ def build(
width: jtp.FloatLike | None = None,
midpoint: jtp.FloatLike | None = None,
power: jtp.FloatLike | None = None,
stiffness: jtp.FloatLike | None = None,
damping: jtp.FloatLike | None = None,
K: jtp.FloatLike | None = None,
D: jtp.FloatLike | None = None,
mu: jtp.FloatLike | None = None,
**kwargs,
) -> Self:
"""Create a `RelaxedRigidContactsParams` instance."""

Expand Down Expand Up @@ -151,13 +152,11 @@ def default(name: str):
power=jnp.array(
power if power is not None else default("power"), dtype=float
),
stiffness=jnp.array(
stiffness if stiffness is not None else default("stiffness"),
K=jnp.array(
K if K is not None else default("K"),
dtype=float,
),
damping=jnp.array(
damping if damping is not None else default("damping"), dtype=float
),
D=jnp.array(D if D is not None else default("D"), dtype=float),
mu=jnp.array(mu if mu is not None else default("mu"), dtype=float),
)

Expand Down Expand Up @@ -505,8 +504,8 @@ def _regularizers(
"width",
"midpoint",
"power",
"stiffness",
"damping",
"K",
"D",
"mu",
)
)
Expand Down
2 changes: 2 additions & 0 deletions src/jaxsim/rbda/contacts/soft.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def build(
mu: jtp.FloatLike = 0.5,
p: jtp.FloatLike = 0.5,
q: jtp.FloatLike = 0.5,
**kwargs,
) -> Self:
"""
Create a SoftContactsParams instance with specified parameters.
Expand All @@ -90,6 +91,7 @@ def build(
q:
The exponent q corresponding to the spring-related non-linearity
of the Hunt/Crossley model
**kwargs: Additional parameters to pass to the contact model.
Returns:
A SoftContactsParams instance with the specified parameters.
Expand Down

0 comments on commit 62adf79

Please sign in to comment.