|
|
|
@ -4,7 +4,7 @@ from common.numpy_fast import interp |
|
|
|
|
from selfdrive.config import Conversions as CV |
|
|
|
|
from selfdrive.car import apply_std_steer_torque_limits |
|
|
|
|
from selfdrive.car.gm import gmcan |
|
|
|
|
from selfdrive.car.gm.values import DBC, SUPERCRUISE_CARS |
|
|
|
|
from selfdrive.car.gm.values import DBC, SUPERCRUISE_CARS, CanBus |
|
|
|
|
from opendbc.can.packer import CANPacker |
|
|
|
|
|
|
|
|
|
VisualAlert = car.CarControl.HUDControl.VisualAlert |
|
|
|
@ -69,22 +69,18 @@ def process_hud_alert(hud_alert): |
|
|
|
|
return steer |
|
|
|
|
|
|
|
|
|
class CarController(): |
|
|
|
|
def __init__(self, canbus, car_fingerprint): |
|
|
|
|
def __init__(self, dbc_name, CP, VM): |
|
|
|
|
self.pedal_steady = 0. |
|
|
|
|
self.start_time = 0. |
|
|
|
|
self.steer_idx = 0 |
|
|
|
|
self.apply_steer_last = 0 |
|
|
|
|
self.car_fingerprint = car_fingerprint |
|
|
|
|
self.car_fingerprint = CP.carFingerprint |
|
|
|
|
self.lka_icon_status_last = (False, False) |
|
|
|
|
self.steer_rate_limited = False |
|
|
|
|
|
|
|
|
|
# Setup detection helper. Routes commands to |
|
|
|
|
# an appropriate CAN bus number. |
|
|
|
|
self.canbus = canbus |
|
|
|
|
self.params = CarControllerParams(car_fingerprint) |
|
|
|
|
self.params = CarControllerParams(CP.carFingerprint) |
|
|
|
|
|
|
|
|
|
self.packer_pt = CANPacker(DBC[car_fingerprint]['pt']) |
|
|
|
|
self.packer_ch = CANPacker(DBC[car_fingerprint]['chassis']) |
|
|
|
|
self.packer_pt = CANPacker(DBC[CP.carFingerprint]['pt']) |
|
|
|
|
self.packer_ch = CANPacker(DBC[CP.carFingerprint]['chassis']) |
|
|
|
|
|
|
|
|
|
def update(self, enabled, CS, frame, actuators, \ |
|
|
|
|
hud_v_cruise, hud_show_lanes, hud_show_car, hud_alert): |
|
|
|
@ -93,7 +89,6 @@ class CarController(): |
|
|
|
|
|
|
|
|
|
# Send CAN commands. |
|
|
|
|
can_sends = [] |
|
|
|
|
canbus = self.canbus |
|
|
|
|
|
|
|
|
|
alert_out = process_hud_alert(hud_alert) |
|
|
|
|
steer = alert_out |
|
|
|
@ -114,10 +109,10 @@ class CarController(): |
|
|
|
|
|
|
|
|
|
if self.car_fingerprint in SUPERCRUISE_CARS: |
|
|
|
|
can_sends += gmcan.create_steering_control_ct6(self.packer_pt, |
|
|
|
|
canbus, apply_steer, CS.out.vEgo, idx, lkas_enabled) |
|
|
|
|
CanBus, apply_steer, CS.out.vEgo, idx, lkas_enabled) |
|
|
|
|
else: |
|
|
|
|
can_sends.append(gmcan.create_steering_control(self.packer_pt, |
|
|
|
|
canbus.powertrain, apply_steer, idx, lkas_enabled)) |
|
|
|
|
CanBus.POWERTRAIN, apply_steer, idx, lkas_enabled)) |
|
|
|
|
|
|
|
|
|
### GAS/BRAKE ### |
|
|
|
|
|
|
|
|
@ -144,14 +139,14 @@ class CarController(): |
|
|
|
|
|
|
|
|
|
at_full_stop = enabled and CS.out.standstill |
|
|
|
|
near_stop = enabled and (CS.out.vEgo < P.NEAR_STOP_BRAKE_PHASE) |
|
|
|
|
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, canbus.chassis, apply_brake, idx, near_stop, at_full_stop)) |
|
|
|
|
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, CanBus.CHASSIS, apply_brake, idx, near_stop, at_full_stop)) |
|
|
|
|
|
|
|
|
|
at_full_stop = enabled and CS.out.standstill |
|
|
|
|
can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, canbus.powertrain, apply_gas, idx, enabled, at_full_stop)) |
|
|
|
|
can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, CanBus.POWERTRAIN, apply_gas, idx, enabled, at_full_stop)) |
|
|
|
|
|
|
|
|
|
# Send dashboard UI commands (ACC status), 25hz |
|
|
|
|
if (frame % 4) == 0: |
|
|
|
|
can_sends.append(gmcan.create_acc_dashboard_command(self.packer_pt, canbus.powertrain, enabled, hud_v_cruise * CV.MS_TO_KPH, hud_show_car)) |
|
|
|
|
can_sends.append(gmcan.create_acc_dashboard_command(self.packer_pt, CanBus.POWERTRAIN, enabled, hud_v_cruise * CV.MS_TO_KPH, hud_show_car)) |
|
|
|
|
|
|
|
|
|
# Radar needs to know current speed and yaw rate (50hz), |
|
|
|
|
# and that ADAS is alive (10hz) |
|
|
|
@ -160,17 +155,17 @@ class CarController(): |
|
|
|
|
|
|
|
|
|
if frame % time_and_headlights_step == 0: |
|
|
|
|
idx = (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(canbus.obstacle)) |
|
|
|
|
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(CanBus.OBSTACLE)) |
|
|
|
|
|
|
|
|
|
speed_and_accelerometer_step = 2 |
|
|
|
|
if frame % speed_and_accelerometer_step == 0: |
|
|
|
|
idx = (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)) |
|
|
|
|
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 frame % P.ADAS_KEEPALIVE_STEP == 0: |
|
|
|
|
can_sends += gmcan.create_adas_keepalive(canbus.powertrain) |
|
|
|
|
can_sends += gmcan.create_adas_keepalive(CanBus.POWERTRAIN) |
|
|
|
|
|
|
|
|
|
# Show green icon when LKA torque is applied, and |
|
|
|
|
# alarming orange icon when approaching torque limit. |
|
|
|
@ -181,7 +176,7 @@ class CarController(): |
|
|
|
|
lka_icon_status = (lka_active, lka_critical) |
|
|
|
|
if frame % P.CAMERA_KEEPALIVE_STEP == 0 \ |
|
|
|
|
or lka_icon_status != self.lka_icon_status_last: |
|
|
|
|
can_sends.append(gmcan.create_lka_icon_command(canbus.sw_gmlan, lka_active, lka_critical, steer)) |
|
|
|
|
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer)) |
|
|
|
|
self.lka_icon_status_last = lka_icon_status |
|
|
|
|
|
|
|
|
|
return can_sends |
|
|
|
|