@ -10,6 +10,12 @@ from selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerPar 
			
		
	
		
		
			
				
					
					VisualAlert  =  car . CarControl . HUDControl . VisualAlert VisualAlert  =  car . CarControl . HUDControl . VisualAlert  
			
		
	
		
		
			
				
					
					LongCtrlState  =  car . CarControl . Actuators . LongControlState LongCtrlState  =  car . CarControl . Actuators . LongControlState  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					# EPS faults if you apply torque while the steering angle is above 90 degrees for more than 1 second  
			
		
	
		
		
			
				
					
					# All slightly below EPS thresholds to avoid fault  
			
		
	
		
		
			
				
					
					MAX_ANGLE  =  85  
			
		
	
		
		
			
				
					
					MAX_ANGLE_FRAMES  =  89  
			
		
	
		
		
			
				
					
					MAX_ANGLE_CONSECUTIVE_FRAMES  =  2  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					def  process_hud_alert ( enabled ,  fingerprint ,  hud_control ) : def  process_hud_alert ( enabled ,  fingerprint ,  hud_control ) :  
			
		
	
		
		
			
				
					
					  sys_warning  =  ( hud_control . visualAlert  in  ( VisualAlert . steerRequired ,  VisualAlert . ldw ) )    sys_warning  =  ( hud_control . visualAlert  in  ( VisualAlert . steerRequired ,  VisualAlert . ldw ) )   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -40,6 +46,7 @@ class CarController: 
			
		
	
		
		
			
				
					
					    self . CP  =  CP      self . CP  =  CP   
			
		
	
		
		
			
				
					
					    self . params  =  CarControllerParams ( CP )      self . params  =  CarControllerParams ( CP )   
			
		
	
		
		
			
				
					
					    self . packer  =  CANPacker ( dbc_name )      self . packer  =  CANPacker ( dbc_name )   
			
		
	
		
		
			
				
					
					    self . angle_limit_counter  =  0   
			
		
	
		
		
			
				
					
					    self . frame  =  0      self . frame  =  0   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    self . apply_steer_last  =  0      self . apply_steer_last  =  0   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -107,8 +114,21 @@ class CarController: 
			
		
	
		
		
			
				
					
					        if  self . frame  %  100  ==  0 :          if  self . frame  %  100  ==  0 :   
			
		
	
		
		
			
				
					
					          can_sends . append ( [ 0x7D0 ,  0 ,  b " \x02 \x3E \x80 \x00 \x00 \x00 \x00 \x00 " ,  0 ] )            can_sends . append ( [ 0x7D0 ,  0 ,  b " \x02 \x3E \x80 \x00 \x00 \x00 \x00 \x00 " ,  0 ] )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      can_sends . append ( hyundaican . create_lkas11 ( self . packer ,  self . frame ,  self . car_fingerprint ,  apply_steer ,  CC . latActive ,        # Count up to MAX_ANGLE_FRAMES, at which point we need to cut torque to avoid a steering fault   
			
				
				
			
		
	
		
		
			
				
					
					                                     CS . lkas11 ,  sys_warning ,  sys_state ,  CC . enabled ,        if  CC . latActive  and  abs ( CS . out . steeringAngleDeg )  > =  MAX_ANGLE :   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					        self . angle_limit_counter  + =  1   
			
		
	
		
		
			
				
					
					      else :   
			
		
	
		
		
			
				
					
					        self . angle_limit_counter  =  0   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      # Cut steer actuation bit for two frames and hold torque with induced temporary fault   
			
		
	
		
		
			
				
					
					      torque_fault  =  CC . latActive  and  self . angle_limit_counter  >  MAX_ANGLE_FRAMES   
			
		
	
		
		
			
				
					
					      lat_active  =  CC . latActive  and  not  torque_fault   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      if  self . angle_limit_counter  > =  MAX_ANGLE_FRAMES  +  MAX_ANGLE_CONSECUTIVE_FRAMES :   
			
		
	
		
		
			
				
					
					        self . angle_limit_counter  =  0   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      can_sends . append ( hyundaican . create_lkas11 ( self . packer ,  self . frame ,  self . car_fingerprint ,  apply_steer ,  lat_active ,   
			
		
	
		
		
			
				
					
					                                                torque_fault ,  CS . lkas11 ,  sys_warning ,  sys_state ,  CC . enabled ,   
			
		
	
		
		
			
				
					
					                                                hud_control . leftLaneVisible ,  hud_control . rightLaneVisible ,                                                  hud_control . leftLaneVisible ,  hud_control . rightLaneVisible ,   
			
		
	
		
		
			
				
					
					                                                left_lane_warning ,  right_lane_warning ) )                                                  left_lane_warning ,  right_lane_warning ) )