From f646a64ccea31fe2dafa505156a5f15e329c7a09 Mon Sep 17 00:00:00 2001 From: Greg Hogan Date: Tue, 21 Jul 2020 08:41:45 -0700 Subject: [PATCH] Honda CRV BSM alert from B-CAN (#1867) old-commit-hash: 825821f010db63c3498d3730069f3eac08ace789 --- release/files_common | 1 + selfdrive/car/__init__.py | 4 ++-- selfdrive/car/honda/carstate.py | 22 +++++++++++++++++++++- selfdrive/car/honda/interface.py | 8 +++++--- selfdrive/car/honda/values.py | 2 +- selfdrive/car/interfaces.py | 5 +++++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/release/files_common b/release/files_common index a457994112..f06e6db317 100644 --- a/release/files_common +++ b/release/files_common @@ -510,6 +510,7 @@ opendbc/honda_civic_hatchback_ex_2017_can_generated.dbc opendbc/honda_civic_sedan_16_diesel_2019_can_generated.dbc opendbc/honda_crv_touring_2016_can_generated.dbc opendbc/honda_crv_ex_2017_can_generated.dbc +opendbc/honda_crv_ex_2017_body_generated.dbc opendbc/honda_crv_executive_2016_can_generated.dbc opendbc/honda_crv_hybrid_2019_can_generated.dbc opendbc/honda_fit_ex_2018_can_generated.dbc diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index 09edb03156..7701f90a6d 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -40,8 +40,8 @@ def scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor return tire_stiffness_front, tire_stiffness_rear -def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None): - return {'pt': pt_dbc, 'radar': radar_dbc, 'chassis': chassis_dbc} +def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None, body_dbc=None): + return {'pt': pt_dbc, 'radar': radar_dbc, 'chassis': chassis_dbc, 'body': body_dbc} def apply_std_steer_torque_limits(apply_torque, apply_torque_last, driver_torque, LIMITS): diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 4845e482f8..4aaa98aa66 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -172,7 +172,7 @@ class CarState(CarStateBase): self.v_cruise_pcm_prev = 0 self.cruise_mode = 0 - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, cp_body): ret = car.CarState.new_message() # car params @@ -322,6 +322,12 @@ class CarState(CarStateBase): self.stock_hud = cp_cam.vl["ACC_HUD"] self.stock_brake = cp_cam.vl["BRAKE_COMMAND"] + if self.CP.carFingerprint in (CAR.CRV_5G, ): + # BSM messages are on B-CAN, requires a panda forwarding B-CAN messages to CAN 0 + # more info here: https://github.com/commaai/openpilot/pull/1867 + ret.leftBlindspot = cp_body.vl["BSM_STATUS_LEFT"]['BSM_ALERT'] == 1 + ret.rightBlindspot = cp_body.vl["BSM_STATUS_RIGHT"]['BSM_ALERT'] == 1 + return ret @staticmethod @@ -354,3 +360,17 @@ class CarState(CarStateBase): bus_cam = 1 if CP.carFingerprint in HONDA_BOSCH and not CP.isPandaBlack else 2 return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, bus_cam) + + @staticmethod + def get_body_can_parser(CP): + signals = [] + checks = [] + + if CP.carFingerprint == CAR.CRV_5G: + signals += [("BSM_ALERT", "BSM_STATUS_RIGHT", 0), + ("BSM_ALERT", "BSM_STATUS_LEFT", 0)] + + bus_body = 0 # B-CAN is forwarded to ACC-CAN radar side (CAN 0 on fake ethernet port) + return CANParser(DBC[CP.carFingerprint]['body'], signals, checks, bus_body) + + return None diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 7468e06353..ac8bfe3b9f 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -83,7 +83,7 @@ class CarInterface(CarInterfaceBase): self.compute_gb = compute_gb_honda @staticmethod - def compute_gb(accel, speed): + def compute_gb(accel, speed): # pylint: disable=method-hidden raise NotImplementedError @staticmethod @@ -426,10 +426,12 @@ class CarInterface(CarInterfaceBase): # ******************* do can recv ******************* self.cp.update_strings(can_strings) self.cp_cam.update_strings(can_strings) + if self.cp_body: + self.cp_body.update_strings(can_strings) - ret = self.CS.update(self.cp, self.cp_cam) + ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) - ret.canValid = self.cp.can_valid and self.cp_cam.can_valid + ret.canValid = self.cp.can_valid and self.cp_cam.can_valid and (self.cp_body is None or self.cp_body.can_valid) ret.yawRate = self.VM.yaw_rate(ret.steeringAngle * CV.DEG_TO_RAD, ret.vEgo) # FIXME: read sendcan for brakelights brakelights_threshold = 0.02 if self.CS.CP.carFingerprint == CAR.CIVIC else 0.1 diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index 803ded8a06..c2aca11a21 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -922,7 +922,7 @@ DBC = { CAR.CIVIC_BOSCH: dbc_dict('honda_civic_hatchback_ex_2017_can_generated', None), CAR.CIVIC_BOSCH_DIESEL: dbc_dict('honda_civic_sedan_16_diesel_2019_can_generated', None), CAR.CRV: dbc_dict('honda_crv_touring_2016_can_generated', 'acura_ilx_2016_nidec'), - CAR.CRV_5G: dbc_dict('honda_crv_ex_2017_can_generated', None), + CAR.CRV_5G: dbc_dict('honda_crv_ex_2017_can_generated', None, body_dbc='honda_crv_ex_2017_body_generated'), CAR.CRV_EU: dbc_dict('honda_crv_executive_2016_can_generated', 'acura_ilx_2016_nidec'), CAR.CRV_HYBRID: dbc_dict('honda_crv_hybrid_2019_can_generated', None), CAR.FIT: dbc_dict('honda_fit_ex_2018_can_generated', 'acura_ilx_2016_nidec'), diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index c73aa93847..287dc979bf 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -27,6 +27,7 @@ class CarInterfaceBase(): self.CS = CarState(CP) self.cp = self.CS.get_can_parser(CP) self.cp_cam = self.CS.get_cam_can_parser(CP) + self.cp_body = self.CS.get_body_can_parser(CP) self.CC = None if CarController is not None: @@ -175,3 +176,7 @@ class CarStateBase: @staticmethod def get_cam_can_parser(CP): return None + + @staticmethod + def get_body_can_parser(CP): + return None