diff --git a/openpilot/starpilot/lateral/palisade_policy.py b/openpilot/starpilot/lateral/palisade_policy.py index 6d0c933304..93d616461d 100644 --- a/openpilot/starpilot/lateral/palisade_policy.py +++ b/openpilot/starpilot/lateral/palisade_policy.py @@ -22,11 +22,11 @@ class PalisadeTorquePolicy(HKGShapedTorquePolicy): self.hda2 = cp.carFingerprint == CAR.HYUNDAI_PALISADE_2023 and bool(cp.flags & HyundaiFlags.CANFD_LKA_STEER_MSG) self.center_output_taper = 0.27 if self.hda2 else shaping.PALISADE_CENTER_OUTPUT_TAPER_MAX self.feedforward_demand = 0.0 - self.feedforward_filter = FirstOrderFilter(0.0, 0.20, self.dt, initialized=False) if self.hda2 else None + self.feedforward_filter = FirstOrderFilter(0.0, 0.27, self.dt, initialized=False) if self.hda2 else None def update(self, active, cs, vm, params, safety_limited, curvature, curvature_limited, delay): if self.feedforward_filter is not None: - if not active or cs.steeringPressed or self.previous_pressed or cs.vEgo <= 15.0: + if not active or cs.steeringPressed or self.previous_pressed or cs.vEgo <= 10.5: self.feedforward_filter.initialized = False self.feedforward_demand = curvature * cs.vEgo**2 if active: @@ -34,8 +34,13 @@ class PalisadeTorquePolicy(HKGShapedTorquePolicy): return super().update(active, cs, vm, params, safety_limited, curvature, curvature_limited, delay) def feedforward(self, value, setpoint, jerk, speed): - if self.feedforward_filter is not None and speed > 15.0: - weight = min((speed - 15.0) / 7.0, 1.0) + if self.feedforward_filter is not None and speed > 10.5: + weight = min(max((speed - 15.0) / 7.0, 0.0), 1.0) + if speed < 22.0: + mid_speed = min((speed - 10.5) / 5.5, 1.0) + shallow = min(max((1.25 - abs(self.feedforward_demand)) / 0.7, 0.0), 1.0) + transient = min(abs(jerk) / 0.35, 1.0) + weight = max(weight, mid_speed * shallow * transient) correction = max(-0.28, min(self.feedforward_filter.x - self.feedforward_demand, 0.28)) value += weight * correction return value * shaping.get_palisade_ff_scale(setpoint, jerk, speed) * shaping.get_palisade_center_taper_scale(setpoint, speed) diff --git a/openpilot/starpilot/lateral/tests/test_palisade_policy.py b/openpilot/starpilot/lateral/tests/test_palisade_policy.py index 846cbf53d6..5db6381987 100644 --- a/openpilot/starpilot/lateral/tests/test_palisade_policy.py +++ b/openpilot/starpilot/lateral/tests/test_palisade_policy.py @@ -147,7 +147,7 @@ def test_exit_feedforward_damps_hda2_and_reseeds_after_driver_override(topology, assert tick(0.) == pytest.approx(1.) assert tick(.8) == pytest.approx(expected) - for _ in range(200): + for _ in range(250): steady = tick(.8) assert steady == pytest.approx(1., abs=.0001) state.steeringPressed = True @@ -158,3 +158,26 @@ def test_exit_feedforward_damps_hda2_and_reseeds_after_driver_override(topology, assert tick(-.8) == pytest.approx(1.) state.vEgo = 14.0 assert tick(.8) == pytest.approx(1.) + + +@pytest.mark.parametrize('alpha', (False, True)) +def test_palisade_damps_shallow_mid_speed_corrections_without_softening_deeper_turns(alpha): + cp = topology_params('hdaii') + cp.openpilotLongitudinalControl, cp.pcmCruise = alpha, not alpha + controller = LatControlTorque(cp.as_reader(), interfaces[cp.carFingerprint](cp), .01) + policy = controller.starpilot_extension.policy + vm = VehicleModel(cp) + parameters = SimpleNamespace(angleOffsetDeg=0., roll=0.) + state = SimpleNamespace(vEgo=14., steeringAngleDeg=0., steeringPressed=False) + setpoint, jerk = .4, .5 + raw = shaping.get_palisade_ff_scale(setpoint, jerk, state.vEgo) * shaping.get_palisade_center_taper_scale(setpoint, state.vEgo) + + def tick(target): + controller.update(True, state, vm, parameters, False, target / state.vEgo**2, False, .22) + return policy.feedforward(1.0, setpoint, jerk, state.vEgo) / raw + + assert tick(0.) == pytest.approx(1.0) + assert tick(.4) == pytest.approx(1.0 - .28 * 3.5 / 5.5) + assert tick(1.3) == pytest.approx(1.0) + state.steeringPressed = True + assert tick(.4) == pytest.approx(1.0) diff --git a/prebuilt.json b/prebuilt.json index 4cca552460..e7f41dbcd4 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "b304f4a33df8b0236fa72c39c165b0292ccde40f8a14ad5764631d4b942e7647", "schema_version": 1} +{"protected_inventory_sha256": "f5203c88c2cc06d8e7e38ab50532a2b99ba28bb3dc520cf32186f438022131c0", "schema_version": 1}