diff --git a/simulations/response/mbd/four_post/four_post_eval_sim.py b/simulations/response/mbd/four_post/four_post_eval_sim.py index 73862685..c070e5a8 100644 --- a/simulations/response/mbd/four_post/four_post_eval_sim.py +++ b/simulations/response/mbd/four_post/four_post_eval_sim.py @@ -906,12 +906,11 @@ def build_model_setup_overrides(self) -> dict[str, float]: overrides: dict[str, float] = { "pVehicle.pFrAxleDW.springFreeLength": float(setup["front_spring_free_length"]), "pVehicle.pRrAxleDW.springFreeLength": float(setup["rear_spring_free_length"]), - "pVehicle.pFrStabar.barRate": front_stabar_rate, - "pVehicle.pRrStabar.barRate": rear_stabar_rate, - # Templates zero the bars for pure K&C. Set them for the load-transfer pass. - "pFrStabar.barRate": front_stabar_rate, - "pRrStabar.barRate": rear_stabar_rate, } + # The rig binds p{Fr,Rr}Stabar, not pVehicle.p{Fr,Rr}Stabar. Its templates zero the bars for pure K&C. + for tag, axle_name, bar_rate in (("Fr", "front", front_stabar_rate), ("Rr", "rear", rear_stabar_rate)): + if _side_has_stabar(setup[f"{axle_name}_side"]): + overrides[f"p{tag}Stabar.barRate"] = bar_rate overrides.update( _indexed_table_overrides( "pVehicle.pFrAxleDW.springTable", diff --git a/tests/test_kinematics.py b/tests/test_kinematics.py index 8b4b9476..afdc8a29 100644 --- a/tests/test_kinematics.py +++ b/tests/test_kinematics.py @@ -1146,3 +1146,20 @@ def test_four_post_preserves_vehicle_spring_curves_without_rate_overrides( }) np.testing.assert_array_equal(overridden["front_spring_table"][:, 1], np.asarray(tables["front"])[:, 0] * 10000.0) np.testing.assert_array_equal(overridden["rear_spring_table"], tables["rear"]) + + +def test_four_post_sends_bar_rates_only_to_the_rig_bars_that_exist( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + vehicle = _four_post_unit_vehicle() + front = vehicle["front"] + assert isinstance(front, dict) + front["actuation"].pop("stabar") + monkeypatch.setattr(four_post_eval, "_load_active_vehicle_yaml", lambda: vehicle) + + overrides = four_post_eval.FourPostEvalSim(_four_post_unit_config(tmp_path)).build_model_setup_overrides() + + assert not [key for key in overrides if key.startswith("pVehicle.") and "Stabar" in key] + assert "pFrStabar.barRate" not in overrides + assert overrides["pRrStabar.barRate"] == 0.0