diff --git a/selfdrive/controls/lib/latcontrol_craycray.py b/selfdrive/controls/lib/latcontrol_craycray.py index 09b9d455f..f438205c4 100644 --- a/selfdrive/controls/lib/latcontrol_craycray.py +++ b/selfdrive/controls/lib/latcontrol_craycray.py @@ -2,6 +2,8 @@ from selfdrive.controls.lib.pid import PIController from selfdrive.controls.lib.latcontrol import LatControl, MIN_STEER_SPEED from cereal import log +CURVATURE_SCALE = 200 + class LatControlCrayCray(LatControl): def __init__(self, CP, CI): @@ -13,6 +15,7 @@ class LatControlCrayCray(LatControl): self.steer_max = 1.0 self.pid.pos_limit = self.steer_max self.pid.neg_limit = -self.steer_max + self.use_steering_angle = False def reset(self): super().reset() @@ -31,13 +34,18 @@ class LatControlCrayCray(LatControl): self.pid.reset() else: # TODO lateral acceleration works great at high speed, not so much at low speed - lateral_accel_desired = desired_curvature * CS.vEgo**2 - lateral_accel_actual = llk.angularVelocityCalibrated.value[2] * CS.vEgo + if self.use_steering_angle: + actual_curvature = VM.calc_curvature(-(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) + else: + actual_curvature = llk.angularVelocityCalibrated.value[2] / CS.vEgo + desired_lateral_accel = desired_curvature * CS.vEgo**2 + actual_lateral_accel = actual_curvature * CS.vEgo**2 - deadzone = 0.0 + setpoint = desired_lateral_accel + CURVATURE_SCALE * desired_curvature + measurement = actual_lateral_accel + CURVATURE_SCALE * actual_curvature - output_torque = self.pid.update(lateral_accel_desired, lateral_accel_actual, override=CS.steeringPressed, - feedforward=lateral_accel_desired, speed=CS.vEgo, deadzone=deadzone) + output_torque = self.pid.update(setpoint, measurement, override=CS.steeringPressed, + feedforward=desired_lateral_accel, speed=CS.vEgo) pid_log.active = True pid_log.p = self.pid.p pid_log.i = self.pid.i