Update disturbance_controller.py

This commit is contained in:
infiniteCable
2025-04-07 18:49:24 +02:00
committed by GitHub
parent 3cda8e1676
commit 5bf4451692
@@ -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)