From 8cb3ded338c0332fa44c43d2706071f78bb4b4a0 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 6 Feb 2026 01:35:46 -0600 Subject: [PATCH] Integrator Smooth On Handoff --- selfdrive/controls/lib/latcontrol_pid.py | 8 ++++++++ selfdrive/controls/lib/latcontrol_torque.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/selfdrive/controls/lib/latcontrol_pid.py b/selfdrive/controls/lib/latcontrol_pid.py index 2dd7e2167..ea51462e5 100644 --- a/selfdrive/controls/lib/latcontrol_pid.py +++ b/selfdrive/controls/lib/latcontrol_pid.py @@ -8,6 +8,8 @@ from openpilot.selfdrive.controls.lib.pid import PIDController class LatControlPID(LatControl): def __init__(self, CP, CI, dt): super().__init__(CP, CI, dt) + self.steer_release_i_decay = 0.8 + self.prev_steering_pressed = False self.pid = PIDController((CP.lateralTuning.pid.kpBP, CP.lateralTuning.pid.kpV), (CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV), pos_limit=self.steer_max, neg_limit=-self.steer_max) @@ -29,8 +31,12 @@ class LatControlPID(LatControl): if not active: output_torque = 0.0 pid_log.active = False + self.pid.reset() else: + if self.prev_steering_pressed and not CS.steeringPressed: + self.pid.i *= self.steer_release_i_decay + # offset does not contribute to resistive torque ff = self.ff_factor * self.get_steer_feedforward(angle_steers_des_no_offset, CS.vEgo) if CS.vEgo < self.low_speed_reset_threshold: @@ -49,4 +55,6 @@ class LatControlPID(LatControl): pid_log.output = float(output_torque) pid_log.saturated = bool(self._check_saturation(self.steer_max - abs(output_torque) < 1e-3, CS, steer_limited_by_safety, curvature_limited)) + self.prev_steering_pressed = CS.steeringPressed + return output_torque, angle_steers_des, pid_log diff --git a/selfdrive/controls/lib/latcontrol_torque.py b/selfdrive/controls/lib/latcontrol_torque.py index ee918b166..d30732f9c 100644 --- a/selfdrive/controls/lib/latcontrol_torque.py +++ b/selfdrive/controls/lib/latcontrol_torque.py @@ -40,6 +40,8 @@ VERSION = 2 class LatControlTorque(LatControl): def __init__(self, CP, CI, dt): super().__init__(CP, CI, dt) + self.steer_release_i_decay = 0.8 + self.prev_steering_pressed = False self.torque_params = CP.lateralTuning.torque self.torque_from_lateral_accel = CI.torque_from_lateral_accel() self.lateral_accel_from_torque = CI.lateral_accel_from_torque() @@ -75,6 +77,9 @@ class LatControlTorque(LatControl): self.measurement_rate_filter.x = 0.0 self.lat_accel_request_buffer = deque([0.] * self.lat_accel_request_buffer_len , maxlen=self.lat_accel_request_buffer_len) else: + if self.prev_steering_pressed and not CS.steeringPressed: + self.pid.i *= self.steer_release_i_decay + measured_curvature = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) roll_compensation = params.roll * ACCELERATION_DUE_TO_GRAVITY curvature_deadzone = abs(VM.calc_curvature(math.radians(self.steering_angle_deadzone_deg), CS.vEgo, 0.0)) @@ -124,5 +129,7 @@ class LatControlTorque(LatControl): pid_log.desiredLateralJerk = float(desired_lateral_jerk) pid_log.saturated = bool(self._check_saturation(self.steer_max - abs(output_torque) < 1e-3, CS, steer_limited_by_safety, curvature_limited)) + self.prev_steering_pressed = CS.steeringPressed + # TODO left is positive in this convention return -output_torque, 0.0, pid_log