From 5def2110d661d3171f6396cfdca517d5cce34149 Mon Sep 17 00:00:00 2001 From: whoisdomi Date: Wed, 8 Jul 2026 17:29:08 -0500 Subject: [PATCH] Lane change tweak --- selfdrive/controls/controlsd.py | 13 ++++++------- starpilot/common/starpilot_variables.py | 7 +++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index daa9a0657..1e1ad5d3d 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -216,15 +216,15 @@ class Controls: new_desired_curvature = model_v2.action.desiredCurvature if CC.latActive else self.curvature jerk_factor = 1.0 - lat_accel_factor = 1.0 if self.starpilot_toggles.lane_change_pace < 10: set_jerk = self.starpilot_toggles.lane_change_jerk_factor - set_accel = self.starpilot_toggles.lane_change_lat_accel_factor in_lane_change = model_v2.meta.laneChangeState in (LaneChangeState.laneChangeStarting, LaneChangeState.laneChangeFinishing) \ and CS.vEgo >= self.starpilot_toggles.minimum_lane_change_speed - # Hold the tight limits for the whole maneuver (factors carry 1.3x headroom over the - # target-duration profile), then taper back to stock so the model's recenter step and - # mid-change corrections stay shaped instead of passing through a mostly-relaxed clamp. + # Hold the tight jerk limit for the whole maneuver, then taper back to stock so the + # model's recenter step and mid-change corrections stay shaped instead of passing + # through a mostly-relaxed clamp. Only the jerk (curvature rate) is tightened: capping + # lat accel strangles the end-of-maneuver arrest and lets the car glide past the new + # lane center before it can build enough counter-curvature. if in_lane_change: self.lc_smooth_release = LANE_CHANGE_SMOOTH_RELEASE_T else: @@ -232,10 +232,9 @@ class Controls: if self.lc_smooth_release > 0.0: release = 1.0 - self.lc_smooth_release / LANE_CHANGE_SMOOTH_RELEASE_T # 0 in maneuver → 1 after jerk_factor = set_jerk + (1.0 - set_jerk) * release - lat_accel_factor = set_accel + (1.0 - set_accel) * release self.desired_curvature, curvature_limited = clip_curvature(CS.vEgo, self.desired_curvature, new_desired_curvature, lp.roll, - jerk_factor, lat_accel_factor) + jerk_factor) lat_delay = self.sm["liveDelay"].lateralDelay + LAT_SMOOTH_SECONDS actuators.curvature = self.desired_curvature diff --git a/starpilot/common/starpilot_variables.py b/starpilot/common/starpilot_variables.py index 8733153cf..14107b420 100644 --- a/starpilot/common/starpilot_variables.py +++ b/starpilot/common/starpilot_variables.py @@ -1000,16 +1000,15 @@ class StarPilotVariables: toggle.one_lane_change = self.get_value("OneLaneChange", condition=toggle.lane_changes) # Lane change pace: 1 = smoothest (~8 s target), 10 = stock (no clamp applied) - # Factors are derived from a sinusoidal lane-change profile: a = pi^2 * W / T^2, j = pi^3 * W / T^3. - # 1.3x headroom keeps the controller off the ceiling mid-maneuver. + # The jerk factor is derived from a sinusoidal lane-change profile: j = pi^3 * W / T^3, + # with 1.3x headroom. Only jerk (curvature rate) is shaped; lateral accel stays at the + # stock envelope so the end-of-maneuver arrest is never starved of authority. pace = self.get_value("LaneChangeSmoothing", cast=int, condition=toggle.lane_changes) or 10 pace = max(1, min(10, pace)) lane_w = 3.5 t_target = 3.0 + (10 - pace) * 5.0 / 9.0 - a_req = (math.pi ** 2) * lane_w / (t_target ** 2) j_req = (math.pi ** 3) * lane_w / (t_target ** 3) toggle.lane_change_pace = pace - toggle.lane_change_lat_accel_factor = min(1.0, a_req * 1.3 / 3.0) toggle.lane_change_jerk_factor = min(1.0, j_req * 1.3 / 5.0) toggle.lane_change_time_max = 10.0 + (10 - pace) * 2.0 / 9.0