From 4e1abddbc34509c6eea6a1469915e8d9bd6ac950 Mon Sep 17 00:00:00 2001 From: bongbui321 Date: Thu, 19 Sep 2024 19:49:56 -0400 Subject: [PATCH 1/4] Nissan/carcontroller: add max steering angle safeguard for nissan --- opendbc/car/nissan/carcontroller.py | 3 ++- opendbc/car/nissan/nissancan.py | 5 ++++- opendbc/car/nissan/values.py | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/opendbc/car/nissan/carcontroller.py b/opendbc/car/nissan/carcontroller.py index 9e38312550..b4626b3b75 100644 --- a/opendbc/car/nissan/carcontroller.py +++ b/opendbc/car/nissan/carcontroller.py @@ -1,5 +1,6 @@ import copy from opendbc.can.packer import CANPacker +from opendbc.car.common.numpy_fast import clip from opendbc.car import apply_std_steer_angle_limits, structs from opendbc.car.interfaces import CarControllerBase from opendbc.car.nissan import nissancan @@ -48,7 +49,7 @@ def update(self, CC, CS, now_nanos): apply_angle = CS.out.steeringAngleDeg self.lkas_max_torque = 0 - self.apply_angle_last = apply_angle + self.apply_angle_last = clip(apply_angle, -CarControllerParams.MAX_STEER_ANGLE, CarControllerParams.MAX_STEER_ANGLE) if self.CP.carFingerprint in (CAR.NISSAN_ROGUE, CAR.NISSAN_XTRAIL, CAR.NISSAN_ALTIMA) and pcm_cancel_cmd: can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg)) diff --git a/opendbc/car/nissan/nissancan.py b/opendbc/car/nissan/nissancan.py index 555020d858..14a26c0b34 100644 --- a/opendbc/car/nissan/nissancan.py +++ b/opendbc/car/nissan/nissancan.py @@ -1,11 +1,14 @@ import crcmod -from opendbc.car.nissan.values import CAR +import warnings +from opendbc.car.nissan.values import CAR, CarControllerParams # TODO: add this checksum to the CANPacker nissan_checksum = crcmod.mkCrcFun(0x11d, initCrc=0x00, rev=False, xorOut=0xff) def create_steering_control(packer, apply_steer, frame, steer_on, lkas_max_torque): + if not (-CarControllerParams.MAX_STEER_ANGLE <= apply_steer <= CarControllerParams.MAX_STEER_ANGLE): + warnings.warn(f"Nissan apply steering angle is out of bound: {apply_steer}", RuntimeWarning, stacklevel=1) values = { "COUNTER": frame % 0x10, "DESIRED_ANGLE": apply_steer, diff --git a/opendbc/car/nissan/values.py b/opendbc/car/nissan/values.py index da396e655e..a8755e52cf 100644 --- a/opendbc/car/nissan/values.py +++ b/opendbc/car/nissan/values.py @@ -15,6 +15,10 @@ class CarControllerParams: LKAS_MAX_TORQUE = 1 # A value of 1 is easy to overpower STEER_THRESHOLD = 1.0 + # When output steering Angle not within range -1311 and 1310, + # CANPacker packs wrong angle output to be decoded by panda + MAX_STEER_ANGLE = 1310 + def __init__(self, CP): pass From c1f81f6ea86d5261ba8391ce765e1637f0601f5b Mon Sep 17 00:00:00 2001 From: bongbui321 Date: Sun, 22 Sep 2024 05:54:16 +0700 Subject: [PATCH 2/4] minor fixes --- opendbc/car/nissan/carcontroller.py | 3 ++- opendbc/car/nissan/nissancan.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/opendbc/car/nissan/carcontroller.py b/opendbc/car/nissan/carcontroller.py index b4626b3b75..94b220ca7a 100644 --- a/opendbc/car/nissan/carcontroller.py +++ b/opendbc/car/nissan/carcontroller.py @@ -49,7 +49,8 @@ def update(self, CC, CS, now_nanos): apply_angle = CS.out.steeringAngleDeg self.lkas_max_torque = 0 - self.apply_angle_last = clip(apply_angle, -CarControllerParams.MAX_STEER_ANGLE, CarControllerParams.MAX_STEER_ANGLE) + apply_angle = clip(apply_angle, -CarControllerParams.MAX_STEER_ANGLE, CarControllerParams.MAX_STEER_ANGLE) + self.apply_angle_last = apply_angle if self.CP.carFingerprint in (CAR.NISSAN_ROGUE, CAR.NISSAN_XTRAIL, CAR.NISSAN_ALTIMA) and pcm_cancel_cmd: can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg)) diff --git a/opendbc/car/nissan/nissancan.py b/opendbc/car/nissan/nissancan.py index 14a26c0b34..3b53e343e8 100644 --- a/opendbc/car/nissan/nissancan.py +++ b/opendbc/car/nissan/nissancan.py @@ -9,6 +9,7 @@ def create_steering_control(packer, apply_steer, frame, steer_on, lkas_max_torque): if not (-CarControllerParams.MAX_STEER_ANGLE <= apply_steer <= CarControllerParams.MAX_STEER_ANGLE): warnings.warn(f"Nissan apply steering angle is out of bound: {apply_steer}", RuntimeWarning, stacklevel=1) + values = { "COUNTER": frame % 0x10, "DESIRED_ANGLE": apply_steer, From b4820e931f0237d7638084889eeb937e80e3c95b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 1 Oct 2024 13:58:36 -0700 Subject: [PATCH 3/4] Update opendbc/car/nissan/nissancan.py --- opendbc/car/nissan/nissancan.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opendbc/car/nissan/nissancan.py b/opendbc/car/nissan/nissancan.py index 3b53e343e8..b5ce1b4145 100644 --- a/opendbc/car/nissan/nissancan.py +++ b/opendbc/car/nissan/nissancan.py @@ -1,6 +1,5 @@ import crcmod -import warnings -from opendbc.car.nissan.values import CAR, CarControllerParams +from opendbc.car.nissan.values import CAR # TODO: add this checksum to the CANPacker nissan_checksum = crcmod.mkCrcFun(0x11d, initCrc=0x00, rev=False, xorOut=0xff) From c6b374dba43fa6ca5705419ccbf01e43048f6dd1 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 1 Oct 2024 13:58:41 -0700 Subject: [PATCH 4/4] Update opendbc/car/nissan/nissancan.py --- opendbc/car/nissan/nissancan.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/opendbc/car/nissan/nissancan.py b/opendbc/car/nissan/nissancan.py index b5ce1b4145..555020d858 100644 --- a/opendbc/car/nissan/nissancan.py +++ b/opendbc/car/nissan/nissancan.py @@ -6,9 +6,6 @@ def create_steering_control(packer, apply_steer, frame, steer_on, lkas_max_torque): - if not (-CarControllerParams.MAX_STEER_ANGLE <= apply_steer <= CarControllerParams.MAX_STEER_ANGLE): - warnings.warn(f"Nissan apply steering angle is out of bound: {apply_steer}", RuntimeWarning, stacklevel=1) - values = { "COUNTER": frame % 0x10, "DESIRED_ANGLE": apply_steer,