  
      # Gas/Brake PID loop
      actuators.gas, actuators.brake = self.LoC.update(self.active, CS, v_acc_sol, long_plan.vTargetFuture, a_acc_sol, self.CP)
      # Steering PID loop and lateral MPC
      actuators.steer, actuators.steeringAngleDeg, lac_log = self.LaC.update(self.active, CS, self.CP, lat_plan)
  
      # Check for difference between desired angle and angle for angle based control
      angle_control_saturated = self.CP.steerControlType == car.CarParams.SteerControlType.angle and \
        abs(actuators.steeringAngleDeg - CS.steeringAngleDeg) > STEER_ANGLE_SATURATION_THRESHOLD
  
 
</s> remove       # Check if we deviated from the path
      left_deviation = actuators.steer > 0 and lat_plan.dPathPoints[0] < -0.1
      right_deviation = actuators.steer < 0 and lat_plan.dPathPoints[0] > 0.1
 </s> add  </s> remove     # reset to current steer angle if not active or overriding
    if active:
      curvature_desired = next_curvature
      desired_curvature_rate = next_curvature_rate
    else:
      curvature_desired = measured_curvature
      desired_curvature_rate = 0.0

    # negative sign, controls uses different convention
    self.desired_steering_wheel_angle_deg = -float(math.degrees(curvature_desired * VM.sR)/curvature_factor) + steering_wheel_angle_offset_deg
    self.desired_steering_wheel_angle_rate_deg = -float(math.degrees(desired_curvature_rate * VM.sR)/curvature_factor)
 </s> add     self.desired_curvature = next_curvature
    self.desired_curvature_rate = next_curvature_rate </s> remove         error = self.angle_steers_des - angle_steers_k
 </s> add         error = desired_angle - angle_steers_k </s> remove     curvature_diff_from_psi = psi/(max(v_ego, 1e-1) * delay) - current_curvature
    next_curvature = current_curvature + 2*curvature_diff_from_psi
 </s> add     curvature_diff_from_psi = psi / (max(v_ego, 1e-1) * delay) - current_curvature
    next_curvature = current_curvature + 2 * curvature_diff_from_psi </s> remove       self.angle_steers_des = lat_plan.steeringAngleDeg # get from MPC/LateralPlanner

 </s> add 
    actuators.steer, actuators.steeringAngleDeg, lac_log = self.LaC.update(self.active, CS, self.CP, self.VM, params, lat_plan)
  
      # Gas/Brake PID loop
      actuators.gas, actuators.brake = self.LoC.update(self.active, CS, v_acc_sol, long_plan.vTargetFuture, a_acc_sol, self.CP)
      # Steering PID loop and lateral MPC
    actuators.steer, actuators.steeringAngleDeg, lac_log = self.LaC.update(self.active, CS, self.CP, self.VM, params, lat_plan)
  
      # Check for difference between desired angle and angle for angle based control
      angle_control_saturated = self.CP.steerControlType == car.CarParams.SteerControlType.angle and \
        abs(actuators.steeringAngleDeg - CS.steeringAngleDeg) > STEER_ANGLE_SATURATION_THRESHOLD
  
keep keep keep keep replace keep keep keep keep keep
 LateralPlanner should only compute curvature (#20289)

* get curvature from planner

* no need to check active

* remove that

* remove self

* liveParams not needed

* cast

* fix test bug

* fixes

* fix ui.py

* fix radians

* update refs

* update refs

* bump cereal

* bump cereal

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> 
selfdrive/controls/controlsd.py