|  |  | @ -5,35 +5,18 @@ from selfdrive.car.toyota.toyotacan import create_steer_command, create_ui_comma | 
			
		
	
		
		
			
				
					
					|  |  |  |                                            create_accel_command, create_acc_cancel_command, \ |  |  |  |                                            create_accel_command, create_acc_cancel_command, \ | 
			
		
	
		
		
			
				
					
					|  |  |  |                                            create_fcw_command, create_lta_steer_command |  |  |  |                                            create_fcw_command, create_lta_steer_command | 
			
		
	
		
		
			
				
					
					|  |  |  | from selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_TIMER_CAR, TSS2_CAR, \ |  |  |  | from selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_TIMER_CAR, TSS2_CAR, \ | 
			
		
	
		
		
			
				
					
					|  |  |  |                                         MIN_ACC_SPEED, PEDAL_HYST_GAP, PEDAL_SCALE, CarControllerParams |  |  |  |                                         MIN_ACC_SPEED, PEDAL_TRANSITION, CarControllerParams | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | from opendbc.can.packer import CANPacker |  |  |  | from opendbc.can.packer import CANPacker | 
			
		
	
		
		
			
				
					
					|  |  |  | VisualAlert = car.CarControl.HUDControl.VisualAlert |  |  |  | VisualAlert = car.CarControl.HUDControl.VisualAlert | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | def accel_hysteresis(accel, accel_steady, enabled): |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   # for small accel oscillations within ACCEL_HYST_GAP, don't change the accel command |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   if not enabled: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     # send 0 when disabled, otherwise acc faults |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     accel_steady = 0. |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   elif accel > accel_steady + CarControllerParams.ACCEL_HYST_GAP: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     accel_steady = accel - CarControllerParams.ACCEL_HYST_GAP |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   elif accel < accel_steady - CarControllerParams.ACCEL_HYST_GAP: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     accel_steady = accel + CarControllerParams.ACCEL_HYST_GAP |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   accel = accel_steady |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   return accel, accel_steady |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | class CarController(): |  |  |  | class CarController(): | 
			
		
	
		
		
			
				
					
					|  |  |  |   def __init__(self, dbc_name, CP, VM): |  |  |  |   def __init__(self, dbc_name, CP, VM): | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.last_steer = 0 |  |  |  |     self.last_steer = 0 | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.accel_steady = 0. |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.alert_active = False |  |  |  |     self.alert_active = False | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.last_standstill = False |  |  |  |     self.last_standstill = False | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.standstill_req = False |  |  |  |     self.standstill_req = False | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.steer_rate_limited = False |  |  |  |     self.steer_rate_limited = False | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.use_interceptor = False |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.packer = CANPacker(dbc_name) |  |  |  |     self.packer = CANPacker(dbc_name) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -43,25 +26,22 @@ class CarController(): | 
			
		
	
		
		
			
				
					
					|  |  |  |     # *** compute control surfaces *** |  |  |  |     # *** compute control surfaces *** | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     # gas and brake |  |  |  |     # gas and brake | 
			
		
	
		
		
			
				
					
					|  |  |  |     interceptor_gas_cmd = 0. |  |  |  |     if CS.CP.enableGasInterceptor and enabled: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     pcm_accel_cmd = actuators.accel |  |  |  |       MAX_INTERCEPTOR_GAS = 0.5 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |       # RAV4 has very sensitive has pedal | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     if CS.CP.enableGasInterceptor: |  |  |  |       if CS.CP.carFingerprint in [CAR.RAV4, CAR.RAV4H, CAR.HIGHLANDER, CAR.HIGHLANDERH]: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       # handle hysteresis when around the minimum acc speed |  |  |  |         PEDAL_SCALE = interp(CS.out.vEgo, [0.0, MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_TRANSITION], [0.15, 0.3, 0.0]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       if CS.out.vEgo < MIN_ACC_SPEED: |  |  |  |       elif CS.CP.carFingerprint in [CAR.COROLLA]: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         self.use_interceptor = True |  |  |  |         PEDAL_SCALE = interp(CS.out.vEgo, [0.0, MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_TRANSITION], [0.3, 0.4, 0.0]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       elif CS.out.vEgo > MIN_ACC_SPEED + PEDAL_HYST_GAP: |  |  |  |       else: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         self.use_interceptor = False |  |  |  |         PEDAL_SCALE = interp(CS.out.vEgo, [0.0, MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_TRANSITION], [0.4, 0.5, 0.0]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |       # offset for creep and windbrake | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       if self.use_interceptor and active: |  |  |  |       pedal_offset = interp(CS.out.vEgo, [0.0, 2.3, MIN_ACC_SPEED + PEDAL_TRANSITION], [-.4, 0.0, 0.2]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         # only send negative accel when using interceptor. gas handles acceleration |  |  |  |       pedal_command = PEDAL_SCALE * (actuators.accel + pedal_offset) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         # +0.18 m/s^2 offset to reduce ABS pump usage when OP is engaged |  |  |  |       interceptor_gas_cmd = clip(pedal_command, 0., MAX_INTERCEPTOR_GAS) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         MAX_INTERCEPTOR_GAS = interp(CS.out.vEgo, [0.0, MIN_ACC_SPEED], [0.2, 0.5]) |  |  |  |     else: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         interceptor_gas_cmd = clip(actuators.accel / PEDAL_SCALE, 0., MAX_INTERCEPTOR_GAS) |  |  |  |       interceptor_gas_cmd = 0. | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         pcm_accel_cmd = 0.18 - max(0, -actuators.accel) |  |  |  |     pcm_accel_cmd = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     pcm_accel_cmd, self.accel_steady = accel_hysteresis(pcm_accel_cmd, self.accel_steady, enabled) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     pcm_accel_cmd = clip(pcm_accel_cmd, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     # steer torque |  |  |  |     # steer torque | 
			
		
	
		
		
			
				
					
					|  |  |  |     new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX)) |  |  |  |     new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX)) | 
			
		
	
	
		
		
			
				
					|  |  | @ -88,7 +68,6 @@ class CarController(): | 
			
		
	
		
		
			
				
					
					|  |  |  |       self.standstill_req = False |  |  |  |       self.standstill_req = False | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.last_steer = apply_steer |  |  |  |     self.last_steer = apply_steer | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.last_accel = pcm_accel_cmd |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.last_standstill = CS.out.standstill |  |  |  |     self.last_standstill = CS.out.standstill | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     can_sends = [] |  |  |  |     can_sends = [] | 
			
		
	
	
		
		
			
				
					|  |  | 
 |