|
|
|
@ -8,7 +8,9 @@ from selfdrive.car.gm import gmcan |
|
|
|
|
from selfdrive.car.gm.values import DBC, CanBus, CarControllerParams |
|
|
|
|
|
|
|
|
|
VisualAlert = car.CarControl.HUDControl.VisualAlert |
|
|
|
|
|
|
|
|
|
GearShifter = car.CarState.GearShifter |
|
|
|
|
TransmissionType = car.CarParams.TransmissionType |
|
|
|
|
NetworkLocation = car.CarParams.NetworkLocation |
|
|
|
|
|
|
|
|
|
class CarController: |
|
|
|
|
def __init__(self, dbc_name, CP, VM): |
|
|
|
@ -61,7 +63,7 @@ class CarController: |
|
|
|
|
can_sends.append(gmcan.create_steering_control(self.packer_pt, CanBus.POWERTRAIN, apply_steer, idx, lkas_enabled)) |
|
|
|
|
|
|
|
|
|
# Gas/regen and brakes - all at 25Hz |
|
|
|
|
if (self.frame % 4) == 0: |
|
|
|
|
if CS.CP.openpilotLongitudinalControl and (self.frame % 4) == 0: |
|
|
|
|
if not CC.longActive: |
|
|
|
|
# Stock ECU sends max regen when not enabled |
|
|
|
|
self.apply_gas = self.params.MAX_ACC_REGEN |
|
|
|
@ -79,7 +81,7 @@ class CarController: |
|
|
|
|
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, CanBus.CHASSIS, self.apply_brake, idx, near_stop, at_full_stop)) |
|
|
|
|
|
|
|
|
|
# Send dashboard UI commands (ACC status), 25hz |
|
|
|
|
if (self.frame % 4) == 0: |
|
|
|
|
if CS.CP.openpilotLongitudinalControl and (self.frame % 4) == 0: |
|
|
|
|
send_fcw = hud_alert == VisualAlert.fcw |
|
|
|
|
can_sends.append(gmcan.create_acc_dashboard_command(self.packer_pt, CanBus.POWERTRAIN, CC.enabled, |
|
|
|
|
hud_v_cruise * CV.MS_TO_KPH, hud_control.leadVisible, send_fcw)) |
|
|
|
@ -89,18 +91,18 @@ class CarController: |
|
|
|
|
time_and_headlights_step = 10 |
|
|
|
|
tt = self.frame * DT_CTRL |
|
|
|
|
|
|
|
|
|
if self.frame % time_and_headlights_step == 0: |
|
|
|
|
if CS.CP.openpilotLongitudinalControl and (not CS.CP.radarOffCan) and (self.frame % time_and_headlights_step) == 0: |
|
|
|
|
idx = (self.frame // time_and_headlights_step) % 4 |
|
|
|
|
can_sends.append(gmcan.create_adas_time_status(CanBus.OBSTACLE, int((tt - self.start_time) * 60), idx)) |
|
|
|
|
can_sends.append(gmcan.create_adas_headlights_status(self.packer_obj, CanBus.OBSTACLE)) |
|
|
|
|
|
|
|
|
|
speed_and_accelerometer_step = 2 |
|
|
|
|
if self.frame % speed_and_accelerometer_step == 0: |
|
|
|
|
if CS.CP.openpilotLongitudinalControl and (not CS.CP.radarOffCan) and self.frame % speed_and_accelerometer_step == 0: |
|
|
|
|
idx = (self.frame // speed_and_accelerometer_step) % 4 |
|
|
|
|
can_sends.append(gmcan.create_adas_steering_status(CanBus.OBSTACLE, idx)) |
|
|
|
|
can_sends.append(gmcan.create_adas_accelerometer_speed_status(CanBus.OBSTACLE, CS.out.vEgo, idx)) |
|
|
|
|
|
|
|
|
|
if self.frame % self.params.ADAS_KEEPALIVE_STEP == 0: |
|
|
|
|
if CS.CP.openpilotLongitudinalControl and CS.CP.networkLocation == NetworkLocation.gateway and (self.frame % self.params.ADAS_KEEPALIVE_STEP) == 0: |
|
|
|
|
can_sends += gmcan.create_adas_keepalive(CanBus.POWERTRAIN) |
|
|
|
|
|
|
|
|
|
# Show green icon when LKA torque is applied, and |
|
|
|
@ -110,7 +112,8 @@ class CarController: |
|
|
|
|
lka_active = CS.lkas_status == 1 |
|
|
|
|
lka_critical = lka_active and abs(actuators.steer) > 0.9 |
|
|
|
|
lka_icon_status = (lka_active, lka_critical) |
|
|
|
|
if self.frame % self.params.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last: |
|
|
|
|
# SW_GMLAN is not yet available on Cam Harness |
|
|
|
|
if CS.CP.networkLocation != NetworkLocation.fwdCamera and self.frame % self.params.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last: |
|
|
|
|
steer_alert = hud_alert in (VisualAlert.steerRequired, VisualAlert.ldw) |
|
|
|
|
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer_alert)) |
|
|
|
|
self.lka_icon_status_last = lka_icon_status |
|
|
|
|