Ease Elantra cruise corrections near set speed

This commit is contained in:
firestar5683
2026-11-27 15:01:10 -06:00
parent 4bf630534f
commit 26e0f927bd
3 changed files with 71 additions and 3 deletions
@@ -82,7 +82,7 @@ def get_cruise_accel(e2e, v_cruise, v_ego, a_cruise_prev, angle_steers, CP, dt,
profile: AppliedProfile | None = None,
base_brake_floor: float = A_CRUISE_MIN, selected_acceleration_max: float | None = None, faster_takeoffs: bool = False,
*, a_target_prev: float | None = None, ease_slc_braking: bool = False,
speed_step: bool = False, downhill_error: float | None = None):
speed_step: bool = False, downhill_error: float | None = None, gentle_settle: bool = False):
ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX
max_accel = ceiling if e2e else get_max_accel(v_ego, faster_takeoffs)
if selected_acceleration_max is not None and not e2e:
@@ -110,6 +110,9 @@ def get_cruise_accel(e2e, v_cruise, v_ego, a_cruise_prev, angle_steers, CP, dt,
max_accel = min(max_accel, 0.)
if not e2e and not faster_takeoffs and v_ego >= MIN_ALLOW_THROTTLE_SPEED and speed_error > 0.:
speed_error /= CRUISE_ACCEL_RESPONSE_TIME
elif gentle_settle and speed_error > 0.:
# The Elantra's delayed response can overshoot when Fast Takeoffs doubles a small speed correction.
speed_error /= np.interp(speed_error, [.5, 1.5], [CRUISE_ACCEL_RESPONSE_TIME, 1.0])
elif ease_slc_braking and speed_error < 0.:
speed_error /= CRUISE_ACCEL_RESPONSE_TIME # correct an SLC overshoot as gradually as an approach
target_accel = np.clip(speed_error, cruise_min, max_accel)
@@ -513,13 +516,26 @@ class LongitudinalPlanner:
else:
self.previous_manual_cruise_kph = None
self.manual_cruise_step_until_ns = 0
cs = sm['carState']
gentle_settle = (
self.CP.carFingerprint == 'HYUNDAI_ELANTRA_2021' and faster_takeoffs and
profile_eligible and not reset_state and v_ego >= 10. and self.allow_throttle and
cs.canValid and not (cs.canTimeout or cs.gasPressed or cs.brakePressed or cs.standstill) and
not sm['selfdriveState'].experimentalMode and not sm['controlsState'].forceDecel and traffic_mode is not True and
not any(lead.present for lead in (sm['radarState'].leadOne, sm['radarState'].leadTwo)) and
not (self.fcw or self.force_stop_plan.forcing or self.force_stop_plan.should_stop or self.force_stop_plan.approach_distance_m or
output_should_stop_mpc or output_should_stop_e2e) and self.mpc.solution_status == 0 and
ceiling.effective_mps is None and curve.effective_mps is None and navigation_target is None and downhill_error is None and
(coast_plan is None or not (coast_plan.force_decel or coast_plan.pulse_coasting or coast_plan.brake_floor is not None)) and
v_cruise == v_cruise_kph * CV.KPH_TO_MS
)
self.a_cruise = get_cruise_accel(sm['selfdriveState'].experimentalMode, v_cruise, v_ego,
cruise_seed, steer_angle_without_offset, self.CP, self.dt,
accel_coast, self.allow_throttle, cruise_profile,
base_brake_floor=global_floor, selected_acceleration_max=selected_acceleration, faster_takeoffs=faster_takeoffs,
a_target_prev=self.output_a_target,
ease_slc_braking=v_cruise == ceiling.effective_mps and not relevant_lead, speed_step=speed_step,
downhill_error=downhill_error)
downhill_error=downhill_error, gentle_settle=gentle_settle)
if self.button_cruise is not None:
button_target = self.button_cruise.sample(
sm, now_ns=sample_now_ns, drive_id=drive_id, target_speed=v_cruise,
@@ -63,3 +63,55 @@ def test_repeated_imperial_cruise_taps_do_not_build_a_sharp_acceleration_peak():
speed += previous * .05
assert max(acceleration) <= .36
assert speed > 28. + 3 * CV.MPH_TO_MS
@pytest.mark.parametrize('case', ('settling', 'large deficit', 'above set', 'lead one', 'lead two', 'experimental',
'stop', 'driver pedal', 'low speed', 'speed ceiling', 'faster disabled', 'other car'))
def test_elantra_fast_takeoffs_settle_only_during_clear_cruise(case, monkeypatch):
from opendbc.car.hyundai.interface import CarInterface as HyundaiInterface
from opendbc.car.hyundai.values import CAR as HYUNDAI
from openpilot.selfdrive.controls.lib import longitudinal_planner as lp
from openpilot.starpilot.longitudinal.cruise_ceiling import CruiseCeiling
from openpilot.starpilot.longitudinal.tests.test_conditional_handoff import Frame, NOW, DRIVE
from openpilot.starpilot.longitudinal.tests.test_cruise_ceiling import ACTIVE
identity = HYUNDAI.HYUNDAI_SONATA if case == 'other car' else HYUNDAI.HYUNDAI_ELANTRA_2021
cp = HyundaiInterface.get_params(identity, {0: {}, 1: {}, 2: {}}, [], True, False, False)
assert cp.openpilotLongitudinalControl and not cp.pcmCruise
speed = {'large deficit': 18., 'above set': 20.3, 'low speed': 4.}.get(case, 19.7)
candidate, original = (lp.LongitudinalPlanner(cp, init_v=speed) for _ in range(2))
cruise_accel = lp.get_cruise_accel
def previous(*args, **kw):
kw['gentle_settle'] = False
return cruise_accel(*args, **kw)
for tick in range(24):
now = NOW + tick * 50_000_000
sm = Frame()
sm.logMonoTime = dict.fromkeys(sm, now - 5_000_000)
sm.recv_time = dict.fromkeys(sm, (now - 5_000_000) / 1e9)
sm['selfdriveState'].experimentalMode = case == 'experimental'
sm['carState'].vEgo = speed
sm['carState'].vCruise = 72.
sm['carState'].canValid = True
sm['carState'].gasPressed = case == 'driver pedal'
sm['modelV2'].action.shouldStop = case == 'stop'
sm['modelV2'].action.desiredAcceleration = 1.
sm['radarState'].leadOne.present = case == 'lead one'
sm['radarState'].leadTwo.present = case == 'lead two'
kwargs = {'faster_lead_takeoff': case != 'faster disabled', 'now_ns': now, 'drive_id': DRIVE,
'cruise_ceiling': CruiseCeiling(19.9, ACTIVE) if case == 'speed ceiling' else None}
candidate.update(sm, **kwargs)
with monkeypatch.context() as restore:
restore.setattr(lp, 'get_cruise_accel', previous)
original.update(sm, **kwargs)
assert candidate.mpc.solution_status == original.mpc.solution_status == 0
assert candidate.output_should_stop == original.output_should_stop
if case != 'settling':
assert candidate.a_cruise == original.a_cruise
assert candidate.output_a_target == original.output_a_target
if case == 'settling':
error = 20. - sm['carState'].vEgo
assert candidate.output_a_target == pytest.approx(error / 2.)
assert original.output_a_target == pytest.approx(error)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "6af946ff5a45a4837f1b3aac33c389977a8b7c9a4436dbdf5023a34f1a7f3e1f", "schema_version": 1}
{"protected_inventory_sha256": "42c0ceaa618fe3882427db01e93da4424b7bee2e877a9be2d0fa0e5b13ad0863", "schema_version": 1}