HKG CAN-FD: set cruise state available with car signal (#26812)

* HKG CAN-FD: set cruise state available with car signal

* Whoops

* Check this signal

* No should be in SCC_CONTROL

* use TCS

* add back

* match CAN

* think these are missing

Co-authored-by: Shane Smiskol <shane@smiskol.com>
old-commit-hash: ccb4327197
beeps
Jason Wen 2 years ago committed by GitHub
parent d5655ac4e3
commit e6f3cfd7f9
  1. 21
      selfdrive/car/hyundai/carstate.py

@ -156,6 +156,9 @@ class CarState(CarStateBase):
def update_canfd(self, cp, cp_cam): def update_canfd(self, cp, cp_cam):
ret = car.CarState.new_message() ret = car.CarState.new_message()
self.is_metric = cp.vl["CRUISE_BUTTONS_ALT"]["DISTANCE_UNIT"] != 1
speed_factor = CV.KPH_TO_MS if self.is_metric else CV.MPH_TO_MS
if self.CP.carFingerprint in (EV_CAR | HYBRID_CAR): if self.CP.carFingerprint in (EV_CAR | HYBRID_CAR):
if self.CP.carFingerprint in EV_CAR: if self.CP.carFingerprint in EV_CAR:
ret.gas = cp.vl["ACCELERATOR"]["ACCELERATOR_PEDAL"] / 255. ret.gas = cp.vl["ACCELERATOR"]["ACCELERATOR_PEDAL"] / 255.
@ -197,14 +200,18 @@ class CarState(CarStateBase):
ret.leftBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FL_INDICATOR"] != 0 ret.leftBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FL_INDICATOR"] != 0
ret.rightBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FR_INDICATOR"] != 0 ret.rightBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FR_INDICATOR"] != 0
ret.cruiseState.available = True # cruise state
self.is_metric = cp.vl["CRUISE_BUTTONS_ALT"]["DISTANCE_UNIT"] != 1 if self.CP.openpilotLongitudinalControl:
if not self.CP.openpilotLongitudinalControl: # These are not used for engage/disengage since openpilot keeps track of state using the buttons
speed_factor = CV.KPH_TO_MS if self.is_metric else CV.MPH_TO_MS ret.cruiseState.available = cp.vl["TCS"]["ACCEnable"] == 0
ret.cruiseState.enabled = cp.vl["TCS"]["ACC_REQ"] == 1
ret.cruiseState.standstill = False
else:
cp_cruise_info = cp_cam if self.CP.flags & HyundaiFlags.CANFD_CAMERA_SCC else cp cp_cruise_info = cp_cam if self.CP.flags & HyundaiFlags.CANFD_CAMERA_SCC else cp
ret.cruiseState.speed = cp_cruise_info.vl["SCC_CONTROL"]["VSetDis"] * speed_factor ret.cruiseState.available = cp_cruise_info.vl["SCC_CONTROL"]["MainMode_ACC"] == 1
ret.cruiseState.standstill = cp_cruise_info.vl["SCC_CONTROL"]["CRUISE_STANDSTILL"] == 1
ret.cruiseState.enabled = cp_cruise_info.vl["SCC_CONTROL"]["ACCMode"] in (1, 2) ret.cruiseState.enabled = cp_cruise_info.vl["SCC_CONTROL"]["ACCMode"] in (1, 2)
ret.cruiseState.standstill = cp_cruise_info.vl["SCC_CONTROL"]["CRUISE_STANDSTILL"] == 1
ret.cruiseState.speed = cp_cruise_info.vl["SCC_CONTROL"]["VSetDis"] * speed_factor
self.cruise_info = copy.copy(cp_cruise_info.vl["SCC_CONTROL"]) self.cruise_info = copy.copy(cp_cruise_info.vl["SCC_CONTROL"])
cruise_btn_msg = "CRUISE_BUTTONS_ALT" if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS else "CRUISE_BUTTONS" cruise_btn_msg = "CRUISE_BUTTONS_ALT" if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS else "CRUISE_BUTTONS"
@ -435,6 +442,7 @@ class CarState(CarStateBase):
("DriverBraking", "TCS"), ("DriverBraking", "TCS"),
("ACCEnable", "TCS"), ("ACCEnable", "TCS"),
("ACC_REQ", "TCS"),
("COUNTER", cruise_btn_msg), ("COUNTER", cruise_btn_msg),
("CRUISE_BUTTONS", cruise_btn_msg), ("CRUISE_BUTTONS", cruise_btn_msg),
@ -476,6 +484,7 @@ class CarState(CarStateBase):
("ACCMode", "SCC_CONTROL"), ("ACCMode", "SCC_CONTROL"),
("VSetDis", "SCC_CONTROL"), ("VSetDis", "SCC_CONTROL"),
("CRUISE_STANDSTILL", "SCC_CONTROL"), ("CRUISE_STANDSTILL", "SCC_CONTROL"),
("MainMode_ACC", "SCC_CONTROL"),
] ]
checks += [ checks += [
("SCC_CONTROL", 50), ("SCC_CONTROL", 50),

Loading…
Cancel
Save