@ -9,7 +9,6 @@ class CarController:
self . CP = CP
self . CP = CP
self . frame = 0
self . frame = 0
self . last_angle = 0
self . last_angle = 0
self . long_control_counter = 0
self . packer = CANPacker ( dbc_name )
self . packer = CANPacker ( dbc_name )
self . pt_packer = CANPacker ( DBC [ CP . carFingerprint ] [ ' pt ' ] )
self . pt_packer = CANPacker ( DBC [ CP . carFingerprint ] [ ' pt ' ] )
self . tesla_can = TeslaCAN ( self . packer , self . pt_packer )
self . tesla_can = TeslaCAN ( self . packer , self . pt_packer )
@ -41,15 +40,15 @@ class CarController:
self . last_angle = apply_angle
self . last_angle = apply_angle
can_sends . append ( self . tesla_can . create_steering_control ( apply_angle , lkas_enabled , self . frame ) )
can_sends . append ( self . tesla_can . create_steering_control ( apply_angle , lkas_enabled , self . frame ) )
# Longitudinal control (40Hz)
# Longitudinal control (in sync with stock message, about 40Hz)
if self . CP . openpilotLongitudinalControl and self . frame % 5 in ( 0 , 2 ) :
if self . CP . openpilotLongitudinalControl :
target_accel = actuators . accel
target_accel = actuators . accel
target_speed = max ( CS . out . vEgo + ( target_accel * CarControllerParams . ACCEL_TO_SPEED_MULTIPLIER ) , 0 )
target_speed = max ( CS . out . vEgo + ( target_accel * CarControllerParams . ACCEL_TO_SPEED_MULTIPLIER ) , 0 )
max_accel = 0 if target_accel < 0 else target_accel
max_accel = 0 if target_accel < 0 else target_accel
min_accel = 0 if target_accel > 0 else target_accel
min_accel = 0 if target_accel > 0 else target_accel
can_sends . extend ( self . tesla_can . create_longitudinal_commands ( CS . acc_state , target_speed , min_accel , max_accel , self . long_control_counter ) )
while len ( CS . das_control_counters ) > 0 :
self . long_control_counter + = 1
can_sends . extend ( self . tesla_can . create_longitudinal_commands ( CS . acc_state , target_speed , min_accel , max_accel , CS . das_control_counters . popleft ( ) ) )
# Cancel on user steering override, since there is no steering torque blending
# Cancel on user steering override, since there is no steering torque blending
if hands_on_fault :
if hands_on_fault :