@ -22,6 +22,7 @@ class CarController:
self . apply_gas = 0
self . apply_gas = 0
self . apply_brake = 0
self . apply_brake = 0
self . frame = 0
self . frame = 0
self . last_steer_frame = 0
self . last_button_frame = 0
self . last_button_frame = 0
self . cancel_counter = 0
self . cancel_counter = 0
@ -46,15 +47,21 @@ class CarController:
# Send CAN commands.
# Send CAN commands.
can_sends = [ ]
can_sends = [ ]
# Steering (50Hz)
# Steering (Active: 50Hz, inactive: 10Hz)
# Attempt to sync with camera on startup at 50Hz, first few msgs are blocked
init_lka_counter = not self . sent_lka_steering_cmd and self . CP . networkLocation == NetworkLocation . fwdCamera
steer_step = self . params . INACTIVE_STEER_STEP
if CC . latActive or init_lka_counter :
steer_step = self . params . ACTIVE_STEER_STEP
# Avoid GM EPS faults when transmitting messages too close together: skip this transmit if we just received the
# Avoid GM EPS faults when transmitting messages too close together: skip this transmit if we just received the
# next Panda loopback confirmation in the current CS frame.
# next Panda loopback confirmation in the current CS frame.
if CS . loopback_lka_steering_cmd_updated :
if CS . loopback_lka_steering_cmd_updated :
self . lka_steering_cmd_counter + = 1
self . lka_steering_cmd_counter + = 1
self . sent_lka_steering_cmd = True
self . sent_lka_steering_cmd = True
elif ( self . frame % self . params . STEER_STEP ) == 0 :
elif ( self . frame - self . last_steer_frame ) > = steer_step :
# Initialize ASCMLKASteeringCmd counter using the camera
# Initialize ASCMLKASteeringCmd counter using the camera until we get a msg on the bus
if not self . sent_lka_steering_cmd and self . CP . networkLocation == NetworkLocation . fwdCamera :
if init_lka_counter :
self . lka_steering_cmd_counter = CS . camera_lka_steering_cmd_counter + 1
self . lka_steering_cmd_counter = CS . camera_lka_steering_cmd_counter + 1
if CC . latActive :
if CC . latActive :
@ -63,6 +70,7 @@ class CarController:
else :
else :
apply_steer = 0
apply_steer = 0
self . last_steer_frame = self . frame
self . apply_steer_last = apply_steer
self . apply_steer_last = apply_steer
idx = self . lka_steering_cmd_counter % 4
idx = self . lka_steering_cmd_counter % 4
can_sends . append ( gmcan . create_steering_control ( self . packer_pt , CanBus . POWERTRAIN , apply_steer , idx , CC . latActive ) )
can_sends . append ( gmcan . create_steering_control ( self . packer_pt , CanBus . POWERTRAIN , apply_steer , idx , CC . latActive ) )