@ -21,8 +21,8 @@ MAX_USER_TORQUE = 500 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					# LTA limits  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					# EPS ignores commands above this angle and causes PCS to fault  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					MAX_STEER _ANGLE  =  94.9461   # deg  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					MAX_DRIVER_TORQUE_ALLOWANCE  =  150   # slightly above steering pressed allows some resistance when changing lanes  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					MAX_LTA _ANGLE  =  94.9461   # deg  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					MAX_LTA_ DRIVER_TORQUE_ALLOWANCE  =  150   # slightly above steering pressed allows some resistance when changing lanes  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					class  CarController :  
				
			 
			
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
				 
				 
				
					@ -71,25 +71,32 @@ class CarController: 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        apply_angle  =  actuators . steeringAngleDeg  +  CS . out . steeringAngleOffsetDeg   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        # Angular rate limit based on speed   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        apply_angle  =  apply_std_steer_angle_limits ( apply_angle ,  self . last_angle ,  CS . out . vEgo ,  self . params )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        apply_angle  =  apply_std_steer_angle_limits ( apply_angle ,  self . last_angle ,  CS . out . vEgoRaw  ,  self . params )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        if  not  lat_active :   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					          apply_angle  =  CS . out . steeringAngleDeg  +  CS . out . steeringAngleOffsetDeg   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        self . last_angle  =  clip ( apply_angle ,  - MAX_STEER_ANGLE ,  MAX_STEER _ANGLE )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					        self . last_angle  =  clip ( apply_angle ,  - MAX_LTA_ANGLE ,  MAX_LTA _ANGLE )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    self . last_steer  =  apply_steer   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # toyota can trace shows this message  at 42Hz, with counter adding alternatively 1 and 2;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # toyota can trace shows STEERING_LKA  at 42Hz, with counter adding alternatively 1 and 2;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # sending it at 100Hz seem to allow a higher rate limit, as the rate limit seems imposed   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # on consecutive messages   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    can_sends . append ( toyotacan . create_steer_command ( self . packer ,  apply_steer ,  apply_steer_req ) )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # STEERING_LTA does not seem to allow more rate by sending faster, and may wind up easier   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    if  self . frame  %  2  ==  0  and  self . CP . carFingerprint  in  TSS2_CAR :   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      lta_active  =  lat_active  and  self . CP . steerControlType  ==  SteerControlType . angle   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      # cut steering torque with SETME_X64 when either EPS torque or driver torque is above   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      # the threshold, to limit max lateral acceleration and for driver torque blending respectively.   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      full_torque_condition  =  ( abs ( CS . out . steeringTorqueEps )  <  self . params . STEER_MAX  and   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                               abs ( CS . out . steeringTorque )  <  MAX_DRIVER_TORQUE_ALLOWANCE )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                               abs ( CS . out . steeringTorque )  <  MAX_LTA_DRIVER_TORQUE_ALLOWANCE )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      # SETME_X64 at 0 ramps down torque at roughly the max down rate of 1500 units/sec   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      setme_x64  =  100  if  lta_active  and  full_torque_condition  else  0   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      can_sends . append ( toyotacan . create_lta_steer_command ( self . packer ,  self . last_angle ,  lta_active ,  self . frame  / /  2 ,  setme_x64 ) )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					      can_sends . append ( toyotacan . create_lta_steer_command ( self . packer ,  self . CP . steerControlType ,  self . last_angle ,   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					                                                          lta_active ,  self . frame  / /  2 ,  setme_x64 ) )   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    # *** gas and brake ***   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					    if  self . CP . enableGasInterceptor  and  CC . longActive :