Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nissan/carcontroller: add max steering angle safeguard for nissan #33020

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion selfdrive/car/nissan/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cereal import car
from opendbc.can.packer import CANPacker
from openpilot.common.numpy_fast import clip
from openpilot.selfdrive.car import apply_std_steer_angle_limits
from openpilot.selfdrive.car.interfaces import CarControllerBase
from openpilot.selfdrive.car.nissan import nissancan
Expand Down Expand Up @@ -49,7 +50,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))
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
Loading