From 5bf4451692414ccd2c45364f10c77716be115fb6 Mon Sep 17 00:00:00 2001 From: infiniteCable <75014343+infiniteCable@users.noreply.github.com> Date: Mon, 7 Apr 2025 18:49:24 +0200 Subject: [PATCH] Update disturbance_controller.py --- .../controls/lib/disturbance_controller.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/selfdrive/controls/lib/disturbance_controller.py b/selfdrive/controls/lib/disturbance_controller.py index fbe13dcbf..1a519de72 100644 --- a/selfdrive/controls/lib/disturbance_controller.py +++ b/selfdrive/controls/lib/disturbance_controller.py @@ -40,20 +40,21 @@ class DisturbanceController: def highpass_filter(self, current_value, lowpass_value): return current_value - lowpass_value - def compensate(self, CS, VM, params, calibrated_pose, desired_curvature): + def get_correction(self, CS, VM, params, calibrated_pose, desired_curvature): if calibrated_pose is None: return desired_curvature - - actual_curvature_vm = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, 0.) - actual_curvature_3dof = -VM.calc_curvature_3dof(calibrated_pose.acceleration.y, calibrated_pose.acceleration.x, calibrated_pose.angular_velocity.yaw, - CS.vEgo, math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), 0.) + + steering_angle_without_offset = math.radians(CS.steeringAngleDeg - params.angleOffsetDeg) + actual_curvature_vm = -VM.calc_curvature(steering_angle_without_offset, CS.vEgo, 0.) + actual_curvature_3dof = -VM.calc_curvature_3dof(calibrated_pose.acceleration.y, calibrated_pose.acceleration.x, + calibrated_pose.angular_velocity.yaw, CS.vEgo, steering_angle_without_offset, 0.) actual_curvature = np.interp(CS.vEgo, [2.0, 5.0], [actual_curvature_vm, actual_curvature_3dof]) alpha = self.compute_dynamic_alpha(desired_curvature) reaction = self.lowpass_filter(actual_curvature, alpha) disturbance = self.highpass_filter(actual_curvature, reaction) - error = desired_curvature - disturbance - output_curvature = self.pid.update(error, feedforward=desired_curvature, speed=CS.vEgo) + error = -disturbance + correction = self.pid.update(error, feedforward=0.0, speed=CS.vEgo) - return float(output_curvature) + return float(correction)