Skip to content

Commit 04744ac

Browse files
committed
Tune contact params for collision scaling test
1 parent 9c24869 commit 04744ac

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/test_api_model_hw_parametrization.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import jaxsim.api as js
77
from jaxsim.api.kin_dyn_parameters import HwLinkMetadata, ScalingFactors
8+
from jaxsim.rbda.contacts import SoftContactsParams
89

910

1011
def test_update_hw_link_parameters(jaxsim_model_garpez: js.model.JaxSimModel):
@@ -401,6 +402,18 @@ def test_hw_parameters_collision_scaling(
401402
# Define the scaling factor for the model
402403
scaling_factor = 5.0
403404

405+
# Recompute K and D, since the mass is scaled by scaling_factor^3
406+
# and the expected static compression of the terrain is approximately
407+
# proportional to mass/K and divided by the 4 contact points.
408+
K = model.contact_params.K * (scaling_factor**3) / 4
409+
410+
# Strongly overdamped, to avoid oscillations due to the high mass
411+
# and the low penetration allowed.
412+
D = 8 * jnp.sqrt(K)
413+
414+
with model.editable(validate=False) as model:
415+
model.contact_params = SoftContactsParams(K=K, D=D)
416+
404417
# Define the nominal radius of the sphere
405418
nominal_height = model.kin_dyn_parameters.hw_link_metadata.geometry[0, 2]
406419

@@ -413,6 +426,9 @@ def test_hw_parameters_collision_scaling(
413426
# Update the model with the scaling parameters
414427
updated_model = js.model.update_hw_parameters(model, scaling_parameters)
415428

429+
# Compute the expected height (nominal radius * scaling factor)
430+
expected_height = nominal_height * scaling_factor / 2
431+
416432
# Simulate the box falling under gravity
417433
data = js.data.JaxSimModelData.build(
418434
model=updated_model,
@@ -424,7 +440,7 @@ def test_hw_parameters_collision_scaling(
424440
base_position=jnp.array(
425441
[
426442
*jax.random.uniform(subkey, shape=(2,)),
427-
nominal_height * scaling_factor + 0.01,
443+
expected_height + 0.05,
428444
]
429445
),
430446
)
@@ -440,9 +456,6 @@ def test_hw_parameters_collision_scaling(
440456
# Get the final height of the box's base
441457
updated_base_height = data.base_position[2]
442458

443-
# Compute the expected height (nominal radius * scaling factor)
444-
expected_height = nominal_height * scaling_factor / 2
445-
446459
# Assert that the box settles at the expected height
447460
assert jnp.isclose(
448461
updated_base_height, expected_height, atol=1e-3

0 commit comments

Comments
 (0)