From cce337f07907d614a1be6e0dfac29acb3ddd63ff Mon Sep 17 00:00:00 2001 From: CarlottaSartore Date: Mon, 22 Sep 2025 11:29:15 +0200 Subject: [PATCH 1/5] updated default contact model --- src/jaxsim/api/model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jaxsim/api/model.py b/src/jaxsim/api/model.py index c3ac2fbc5..a07ca11e2 100644 --- a/src/jaxsim/api/model.py +++ b/src/jaxsim/api/model.py @@ -247,7 +247,7 @@ def build( The optional name of the model overriding the physics model name. contact_model: The contact model to consider. - If not specified, a relaxed-constraints rigid contacts model is used. + If not specified, a soft contact model is used. contact_params: The parameters of the contact model. actuation_params: The parameters of the actuation model. integrator: The integrator to use for the simulation. @@ -282,7 +282,7 @@ def build( contact_model = ( contact_model if contact_model is not None - else jaxsim.rbda.contacts.RelaxedRigidContacts.build() + else jaxsim.rbda.contacts.SoftContacts.build() ) if contact_params is None: From 4b695aa11a1fa4341b6d17bf403dbdb7bc588da5 Mon Sep 17 00:00:00 2001 From: CarlottaSartore Date: Mon, 22 Sep 2025 11:30:43 +0200 Subject: [PATCH 2/5] remove deprecated note --- src/jaxsim/api/model.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/jaxsim/api/model.py b/src/jaxsim/api/model.py index a07ca11e2..09e4fc50f 100644 --- a/src/jaxsim/api/model.py +++ b/src/jaxsim/api/model.py @@ -2344,9 +2344,6 @@ def update_hw_parameters( Returns: The updated JaxSimModel object with modified hardware parameters. - - Note: - This function can be used only with models using Relax-Rigid contact model. """ kin_dyn_params: KinDynParameters = model.kin_dyn_parameters From 5be3141bf336fd14f896bcc86fb0edbc99167d48 Mon Sep 17 00:00:00 2001 From: Filippo Luca Ferretti Date: Wed, 1 Oct 2025 15:26:06 +0200 Subject: [PATCH 3/5] Remove deprecated docstring --- src/jaxsim/rbda/contacts/soft.py | 4 ---- tests/test_automatic_differentiation.py | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/jaxsim/rbda/contacts/soft.py b/src/jaxsim/rbda/contacts/soft.py index 961133b9c..4a2f37f53 100644 --- a/src/jaxsim/rbda/contacts/soft.py +++ b/src/jaxsim/rbda/contacts/soft.py @@ -130,16 +130,12 @@ class SoftContacts(common.ContactModel): @classmethod def build( cls: type[Self], - model: js.model.JaxSimModel | None = None, **kwargs, ) -> Self: """ Create a `SoftContacts` instance with specified parameters. Args: - model: - The robot model considered by the contact model. - If passed, it is used to estimate good default parameters. **kwargs: Additional parameters to pass to the contact model. Returns: diff --git a/tests/test_automatic_differentiation.py b/tests/test_automatic_differentiation.py index 3ed956f67..6704aa7fc 100644 --- a/tests/test_automatic_differentiation.py +++ b/tests/test_automatic_differentiation.py @@ -297,7 +297,7 @@ def test_ad_soft_contacts( model = jaxsim_models_types with model.editable(validate=False) as model: - model.contact_model = jaxsim.rbda.contacts.SoftContacts.build(model=model) + model.contact_model = jaxsim.rbda.contacts.SoftContacts.build() _, subkey1, subkey2, subkey3 = jax.random.split(prng_key, num=4) p = jax.random.uniform(subkey1, shape=(3,), minval=-1) From 92fcd7ec83cff7429a42d6af21a0fb45646c9332 Mon Sep 17 00:00:00 2001 From: Filippo Luca Ferretti Date: Wed, 1 Oct 2025 18:48:48 +0200 Subject: [PATCH 4/5] Tune contact params for collision scaling test --- tests/test_api_model_hw_parametrization.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_api_model_hw_parametrization.py b/tests/test_api_model_hw_parametrization.py index 9d389710a..b00439db9 100644 --- a/tests/test_api_model_hw_parametrization.py +++ b/tests/test_api_model_hw_parametrization.py @@ -5,6 +5,7 @@ import jaxsim.api as js from jaxsim.api.kin_dyn_parameters import HwLinkMetadata, ScalingFactors +from jaxsim.rbda.contacts import SoftContactsParams def test_update_hw_link_parameters(jaxsim_model_garpez: js.model.JaxSimModel): @@ -401,6 +402,18 @@ def test_hw_parameters_collision_scaling( # Define the scaling factor for the model scaling_factor = 5.0 + # Recompute K and D, since the mass is scaled by scaling_factor^3 + # and the expected static compression of the terrain is approximately + # proportional to mass/K and divided by the 4 contact points. + K = model.contact_params.K * (scaling_factor**2) + + # Strongly overdamped, to avoid oscillations due to the high mass + # and the low penetration allowed. + D = 8 * jnp.sqrt(K) + + with model.editable(validate=False) as model: + model.contact_params = SoftContactsParams(K=K, D=D) + # Define the nominal radius of the sphere nominal_height = model.kin_dyn_parameters.hw_link_metadata.geometry[0, 2] @@ -413,6 +426,9 @@ def test_hw_parameters_collision_scaling( # Update the model with the scaling parameters updated_model = js.model.update_hw_parameters(model, scaling_parameters) + # Compute the expected height (nominal radius * scaling factor) + expected_height = nominal_height * scaling_factor / 2 + # Simulate the box falling under gravity data = js.data.JaxSimModelData.build( model=updated_model, @@ -424,7 +440,7 @@ def test_hw_parameters_collision_scaling( base_position=jnp.array( [ *jax.random.uniform(subkey, shape=(2,)), - nominal_height * scaling_factor + 0.01, + expected_height + 0.05, ] ), ) @@ -440,9 +456,6 @@ def test_hw_parameters_collision_scaling( # Get the final height of the box's base updated_base_height = data.base_position[2] - # Compute the expected height (nominal radius * scaling factor) - expected_height = nominal_height * scaling_factor / 2 - # Assert that the box settles at the expected height assert jnp.isclose( updated_base_height, expected_height, atol=1e-3 From 49e36024b1ad11d8a380e67fdf978c20263b2809 Mon Sep 17 00:00:00 2001 From: Filippo Luca Ferretti Date: Fri, 3 Oct 2025 12:51:23 +0200 Subject: [PATCH 5/5] Increase base height of 4bar linkage and tolerance --- tests/test_simulations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_simulations.py b/tests/test_simulations.py index 79ef1eed2..a98347a1d 100644 --- a/tests/test_simulations.py +++ b/tests/test_simulations.py @@ -579,6 +579,7 @@ def test_simulation_with_kinematic_constraints_4_bar_linkage( data_t0 = js.data.JaxSimModelData.build( model=model, velocity_representation=VelRepr.Inertial, + base_position=jnp.array([0.0, 0.0, 0.10]), ) # ==== @@ -607,7 +608,7 @@ def test_simulation_with_kinematic_constraints_4_bar_linkage( pos1 = H_frame1[:3, 3] pos2 = H_frame2[:3, 3] assert pos1 == pytest.approx( - pos2, abs=1e-6 + pos2, abs=1e-5 ), f"Frame position mismatch. pos1={pos1}, pos2={pos2}, diff={pos1 - pos2}" # Orientation check