mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-17 07:12:08 +08:00
GM: refactor steering control code (#27251)
* hopefully easier to understand? * space * no confusing elif, move comment to relevant part * better old-commit-hash: 5b9f2c3fcd09409211f518b9074afa046a1915d6
This commit is contained in:
@@ -49,25 +49,26 @@ class CarController:
|
||||
can_sends = []
|
||||
|
||||
# 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
|
||||
# Also send at 50Hz until we're in sync with camera so counters align when relay closes, preventing a fault
|
||||
# openpilot can subtly drift, so this is activated throughout a drive to stay synced
|
||||
out_of_sync = self.lka_steering_cmd_counter % 4 != (CS.camera_lka_steering_cmd_counter + 1) % 4
|
||||
sync_steer = (init_lka_counter or out_of_sync) and self.CP.networkLocation == NetworkLocation.fwdCamera
|
||||
steer_step = self.params.STEER_STEP if CC.latActive else self.params.INACTIVE_STEER_STEP
|
||||
|
||||
steer_step = self.params.INACTIVE_STEER_STEP
|
||||
if CC.latActive or sync_steer:
|
||||
steer_step = self.params.STEER_STEP
|
||||
if self.CP.networkLocation == NetworkLocation.fwdCamera:
|
||||
# Also send at 50Hz:
|
||||
# - on startup, first few msgs are blocked
|
||||
# - until we're in sync with camera so counters align when relay closes, preventing a fault.
|
||||
# openpilot can subtly drift, so this is activated throughout a drive to stay synced
|
||||
out_of_sync = self.lka_steering_cmd_counter % 4 != (CS.camera_lka_steering_cmd_counter + 1) % 4
|
||||
if not self.sent_lka_steering_cmd or out_of_sync:
|
||||
steer_step = self.params.STEER_STEP
|
||||
|
||||
# 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.
|
||||
if CS.loopback_lka_steering_cmd_updated:
|
||||
self.lka_steering_cmd_counter += 1
|
||||
self.sent_lka_steering_cmd = True
|
||||
elif (self.frame - self.last_steer_frame) >= steer_step:
|
||||
|
||||
# Avoid GM EPS faults when transmitting messages too close together: skip this transmit if we just
|
||||
# received the ASCMLKASteeringCmd loopback confirmation in the current CS frame
|
||||
if (self.frame - self.last_steer_frame) >= steer_step and not CS.loopback_lka_steering_cmd_updated:
|
||||
# Initialize ASCMLKASteeringCmd counter using the camera until we get a msg on the bus
|
||||
if init_lka_counter:
|
||||
if not self.sent_lka_steering_cmd:
|
||||
self.lka_steering_cmd_counter = CS.pt_lka_steering_cmd_counter + 1
|
||||
|
||||
if CC.latActive:
|
||||
|
||||
Reference in New Issue
Block a user