5
5
6
6
import jaxsim .api as js
7
7
from jaxsim .api .kin_dyn_parameters import HwLinkMetadata , ScalingFactors
8
+ from jaxsim .rbda .contacts import SoftContactsParams
8
9
9
10
10
11
def test_update_hw_link_parameters (jaxsim_model_garpez : js .model .JaxSimModel ):
@@ -401,6 +402,18 @@ def test_hw_parameters_collision_scaling(
401
402
# Define the scaling factor for the model
402
403
scaling_factor = 5.0
403
404
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
+
404
417
# Define the nominal radius of the sphere
405
418
nominal_height = model .kin_dyn_parameters .hw_link_metadata .geometry [0 , 2 ]
406
419
@@ -413,6 +426,9 @@ def test_hw_parameters_collision_scaling(
413
426
# Update the model with the scaling parameters
414
427
updated_model = js .model .update_hw_parameters (model , scaling_parameters )
415
428
429
+ # Compute the expected height (nominal radius * scaling factor)
430
+ expected_height = nominal_height * scaling_factor / 2
431
+
416
432
# Simulate the box falling under gravity
417
433
data = js .data .JaxSimModelData .build (
418
434
model = updated_model ,
@@ -424,7 +440,7 @@ def test_hw_parameters_collision_scaling(
424
440
base_position = jnp .array (
425
441
[
426
442
* jax .random .uniform (subkey , shape = (2 ,)),
427
- nominal_height * scaling_factor + 0.01 ,
443
+ expected_height + 0.05 ,
428
444
]
429
445
),
430
446
)
@@ -440,9 +456,6 @@ def test_hw_parameters_collision_scaling(
440
456
# Get the final height of the box's base
441
457
updated_base_height = data .base_position [2 ]
442
458
443
- # Compute the expected height (nominal radius * scaling factor)
444
- expected_height = nominal_height * scaling_factor / 2
445
-
446
459
# Assert that the box settles at the expected height
447
460
assert jnp .isclose (
448
461
updated_base_height , expected_height , atol = 1e-3
0 commit comments