Skip to content

Commit

Permalink
warning in nissancan
Browse files Browse the repository at this point in the history
  • Loading branch information
bongbui321 committed Jul 27, 2024
1 parent 72993c4 commit 35df91d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 1 addition & 5 deletions selfdrive/car/nissan/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

VisualAlert = car.CarControl.HUDControl.VisualAlert

# When output steering Angle not within range -1311 and 1310,
# CANPacker packs wrong angle output to be decoded by panda
MAX_STEER_ANGLE = 1310


class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
Expand Down Expand Up @@ -54,7 +50,7 @@ def update(self, CC, CS, now_nanos):
apply_angle = CS.out.steeringAngleDeg
self.lkas_max_torque = 0

self.apply_angle_last = clip(apply_angle, -MAX_STEER_ANGLE, MAX_STEER_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))
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/car/nissan/nissancan.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import crcmod
from openpilot.selfdrive.car.nissan.values import CAR
import warnings
from openpilot.selfdrive.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,
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/car/nissan/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 35df91d

Please sign in to comment.