|  |  |  | @ -2,6 +2,7 @@ import math | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | from cereal import log | 
			
		
	
		
			
				
					|  |  |  |  | from openpilot.common.numpy_fast import interp | 
			
		
	
		
			
				
					|  |  |  |  | from openpilot.selfdrive.car.interfaces import LatControlInputs | 
			
		
	
		
			
				
					|  |  |  |  | from openpilot.selfdrive.controls.lib.latcontrol import LatControl | 
			
		
	
		
			
				
					|  |  |  |  | from openpilot.selfdrive.controls.lib.pid import PIDController | 
			
		
	
		
			
				
					|  |  |  |  | from openpilot.selfdrive.controls.lib.vehicle_model import ACCELERATION_DUE_TO_GRAVITY | 
			
		
	
	
		
			
				
					|  |  |  | @ -38,16 +39,16 @@ class LatControlTorque(LatControl): | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   def update(self, active, CS, VM, params, steer_limited, desired_curvature, llk): | 
			
		
	
		
			
				
					|  |  |  |  |     pid_log = log.ControlsState.LateralTorqueState.new_message() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     if not active: | 
			
		
	
		
			
				
					|  |  |  |  |       output_torque = 0.0 | 
			
		
	
		
			
				
					|  |  |  |  |       pid_log.active = False | 
			
		
	
		
			
				
					|  |  |  |  |     else: | 
			
		
	
		
			
				
					|  |  |  |  |       actual_curvature_vm = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) | 
			
		
	
		
			
				
					|  |  |  |  |       roll_compensation = params.roll * ACCELERATION_DUE_TO_GRAVITY | 
			
		
	
		
			
				
					|  |  |  |  |       if self.use_steering_angle: | 
			
		
	
		
			
				
					|  |  |  |  |         actual_curvature = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) | 
			
		
	
		
			
				
					|  |  |  |  |         actual_curvature = actual_curvature_vm | 
			
		
	
		
			
				
					|  |  |  |  |         curvature_deadzone = abs(VM.calc_curvature(math.radians(self.steering_angle_deadzone_deg), CS.vEgo, 0.0)) | 
			
		
	
		
			
				
					|  |  |  |  |       else: | 
			
		
	
		
			
				
					|  |  |  |  |         actual_curvature_vm = -VM.calc_curvature(math.radians(CS.steeringAngleDeg - params.angleOffsetDeg), CS.vEgo, params.roll) | 
			
		
	
		
			
				
					|  |  |  |  |         actual_curvature_llk = llk.angularVelocityCalibrated.value[2] / CS.vEgo | 
			
		
	
		
			
				
					|  |  |  |  |         actual_curvature = interp(CS.vEgo, [2.0, 5.0], [actual_curvature_vm, actual_curvature_llk]) | 
			
		
	
		
			
				
					|  |  |  |  |         curvature_deadzone = 0.0 | 
			
		
	
	
		
			
				
					|  |  |  | @ -61,15 +62,15 @@ class LatControlTorque(LatControl): | 
			
		
	
		
			
				
					|  |  |  |  |       low_speed_factor = interp(CS.vEgo, LOW_SPEED_X, LOW_SPEED_Y)**2 | 
			
		
	
		
			
				
					|  |  |  |  |       setpoint = desired_lateral_accel + low_speed_factor * desired_curvature | 
			
		
	
		
			
				
					|  |  |  |  |       measurement = actual_lateral_accel + low_speed_factor * actual_curvature | 
			
		
	
		
			
				
					|  |  |  |  |       gravity_adjusted_lateral_accel = desired_lateral_accel - params.roll * ACCELERATION_DUE_TO_GRAVITY | 
			
		
	
		
			
				
					|  |  |  |  |       torque_from_setpoint = self.torque_from_lateral_accel(setpoint, self.torque_params, setpoint, | 
			
		
	
		
			
				
					|  |  |  |  |                                                      lateral_accel_deadzone, friction_compensation=False) | 
			
		
	
		
			
				
					|  |  |  |  |       torque_from_measurement = self.torque_from_lateral_accel(measurement, self.torque_params, measurement, | 
			
		
	
		
			
				
					|  |  |  |  |                                                      lateral_accel_deadzone, friction_compensation=False) | 
			
		
	
		
			
				
					|  |  |  |  |       gravity_adjusted_lateral_accel = desired_lateral_accel - roll_compensation | 
			
		
	
		
			
				
					|  |  |  |  |       torque_from_setpoint = self.torque_from_lateral_accel(LatControlInputs(setpoint, roll_compensation, CS.vEgo, CS.aEgo), self.torque_params, | 
			
		
	
		
			
				
					|  |  |  |  |                                                             setpoint, lateral_accel_deadzone, friction_compensation=False, gravity_adjusted=False) | 
			
		
	
		
			
				
					|  |  |  |  |       torque_from_measurement = self.torque_from_lateral_accel(LatControlInputs(measurement, roll_compensation, CS.vEgo, CS.aEgo), self.torque_params, | 
			
		
	
		
			
				
					|  |  |  |  |                                                                measurement, lateral_accel_deadzone, friction_compensation=False, gravity_adjusted=False) | 
			
		
	
		
			
				
					|  |  |  |  |       pid_log.error = torque_from_setpoint - torque_from_measurement | 
			
		
	
		
			
				
					|  |  |  |  |       ff = self.torque_from_lateral_accel(gravity_adjusted_lateral_accel, self.torque_params, | 
			
		
	
		
			
				
					|  |  |  |  |                                           desired_lateral_accel - actual_lateral_accel, | 
			
		
	
		
			
				
					|  |  |  |  |                                           lateral_accel_deadzone, friction_compensation=True) | 
			
		
	
		
			
				
					|  |  |  |  |       ff = self.torque_from_lateral_accel(LatControlInputs(gravity_adjusted_lateral_accel, roll_compensation, CS.vEgo, CS.aEgo), self.torque_params, | 
			
		
	
		
			
				
					|  |  |  |  |                                           desired_lateral_accel - actual_lateral_accel, lateral_accel_deadzone, friction_compensation=True, | 
			
		
	
		
			
				
					|  |  |  |  |                                           gravity_adjusted=True) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       freeze_integrator = steer_limited or CS.steeringPressed or CS.vEgo < 5 | 
			
		
	
		
			
				
					|  |  |  |  |       output_torque = self.pid.update(pid_log.error, | 
			
		
	
	
		
			
				
					|  |  |  | 
 |