@ -10,6 +10,9 @@ from selfdrive.car.gm.values import DBC, CanBus, CarControllerParams, CruiseButt
VisualAlert = car . CarControl . HUDControl . VisualAlert
VisualAlert = car . CarControl . HUDControl . VisualAlert
NetworkLocation = car . CarParams . NetworkLocation
NetworkLocation = car . CarParams . NetworkLocation
# Camera cancels up to 0.1s after brake is pressed, ECM allows 0.5s
CAMERA_CANCEL_DELAY_FRAMES = 10
class CarController :
class CarController :
def __init__ ( self , dbc_name , CP , VM ) :
def __init__ ( self , dbc_name , CP , VM ) :
@ -20,6 +23,7 @@ class CarController:
self . apply_brake = 0
self . apply_brake = 0
self . frame = 0
self . frame = 0
self . last_button_frame = 0
self . last_button_frame = 0
self . cancel_counter = 0
self . lka_steering_cmd_counter = 0
self . lka_steering_cmd_counter = 0
self . sent_lka_steering_cmd = False
self . sent_lka_steering_cmd = False
@ -111,9 +115,13 @@ class CarController:
can_sends + = gmcan . create_adas_keepalive ( CanBus . POWERTRAIN )
can_sends + = gmcan . create_adas_keepalive ( CanBus . POWERTRAIN )
else :
else :
# While car is braking, cancel button causes ECM to enter a soft disable state with a fault status.
# A delayed cancellation allows camera to cancel and avoids a fault when user depresses brake quickly
self . cancel_counter = self . cancel_counter + 1 if CC . cruiseControl . cancel else 0
# Stock longitudinal, integrated at camera
# Stock longitudinal, integrated at camera
if ( self . frame - self . last_button_frame ) * DT_CTRL > 0.04 :
if ( self . frame - self . last_button_frame ) * DT_CTRL > 0.04 :
if CC . cruiseControl . cancel :
if self . cancel_counter > CAMERA_CANCEL_DELAY_FRAMES :
self . last_button_frame = self . frame
self . last_button_frame = self . frame
can_sends . append ( gmcan . create_buttons ( self . packer_pt , CanBus . CAMERA , CS . buttons_counter , CruiseButtons . CANCEL ) )
can_sends . append ( gmcan . create_buttons ( self . packer_pt , CanBus . CAMERA , CS . buttons_counter , CruiseButtons . CANCEL ) )