|
|
|
@ -5,16 +5,22 @@ import math |
|
|
|
|
from cereal import car |
|
|
|
|
from opendbc.can.parser import CANParser |
|
|
|
|
from opendbc.can.can_define import CANDefine |
|
|
|
|
from openpilot.selfdrive.car import create_button_events |
|
|
|
|
from openpilot.selfdrive.car.conversions import Conversions as CV |
|
|
|
|
from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus |
|
|
|
|
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CAN_GEARS, CAMERA_SCC_CAR, \ |
|
|
|
|
CANFD_CAR, Buttons, CarControllerParams |
|
|
|
|
from openpilot.selfdrive.car.interfaces import CarStateBase |
|
|
|
|
|
|
|
|
|
ButtonType = car.CarState.ButtonEvent.Type |
|
|
|
|
|
|
|
|
|
PREV_BUTTON_SAMPLES = 8 |
|
|
|
|
CLUSTER_SAMPLE_RATE = 20 # frames |
|
|
|
|
STANDSTILL_THRESHOLD = 12 * 0.03125 * CV.KPH_TO_MS |
|
|
|
|
|
|
|
|
|
BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: ButtonType.decelCruise, |
|
|
|
|
Buttons.GAP_DIST: ButtonType.gapAdjustCruise, Buttons.CANCEL: ButtonType.cancel} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CarState(CarStateBase): |
|
|
|
|
def __init__(self, CP): |
|
|
|
@ -162,10 +168,13 @@ class CarState(CarStateBase): |
|
|
|
|
self.lkas11 = copy.copy(cp_cam.vl["LKAS11"]) |
|
|
|
|
self.clu11 = copy.copy(cp.vl["CLU11"]) |
|
|
|
|
self.steer_state = cp.vl["MDPS12"]["CF_Mdps_ToiActive"] # 0 NOT ACTIVE, 1 ACTIVE |
|
|
|
|
self.prev_cruise_buttons = self.cruise_buttons[-1] |
|
|
|
|
prev_cruise_buttons = self.cruise_buttons[-1] |
|
|
|
|
self.cruise_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwState"]) |
|
|
|
|
self.main_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwMain"]) |
|
|
|
|
|
|
|
|
|
if self.CP.openpilotLongitudinalControl: |
|
|
|
|
ret.buttonEvents = create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT) |
|
|
|
|
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
def update_canfd(self, cp, cp_cam): |
|
|
|
@ -238,7 +247,7 @@ class CarState(CarStateBase): |
|
|
|
|
if self.CP.flags & HyundaiFlags.EV: |
|
|
|
|
ret.cruiseState.nonAdaptive = cp.vl["MANUAL_SPEED_LIMIT_ASSIST"]["MSLA_ENABLED"] == 1 |
|
|
|
|
|
|
|
|
|
self.prev_cruise_buttons = self.cruise_buttons[-1] |
|
|
|
|
prev_cruise_buttons = self.cruise_buttons[-1] |
|
|
|
|
self.cruise_buttons.extend(cp.vl_all[self.cruise_btns_msg_canfd]["CRUISE_BUTTONS"]) |
|
|
|
|
self.main_buttons.extend(cp.vl_all[self.cruise_btns_msg_canfd]["ADAPTIVE_CRUISE_MAIN_BTN"]) |
|
|
|
|
self.buttons_counter = cp.vl[self.cruise_btns_msg_canfd]["COUNTER"] |
|
|
|
@ -248,6 +257,9 @@ class CarState(CarStateBase): |
|
|
|
|
self.hda2_lfa_block_msg = copy.copy(cp_cam.vl["CAM_0x362"] if self.CP.flags & HyundaiFlags.CANFD_HDA2_ALT_STEERING |
|
|
|
|
else cp_cam.vl["CAM_0x2a4"]) |
|
|
|
|
|
|
|
|
|
if self.CP.openpilotLongitudinalControl: |
|
|
|
|
ret.buttonEvents = create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT) |
|
|
|
|
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
def get_can_parser(self, CP): |
|
|
|
|