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 #1258

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions opendbc/car/nissan/carcontroller.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -48,6 +49,7 @@ def update(self, CC, CS, now_nanos):
apply_angle = CS.out.steeringAngleDeg
self.lkas_max_torque = 0

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:
Expand Down
6 changes: 5 additions & 1 deletion opendbc/car/nissan/nissancan.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import crcmod
from opendbc.car.nissan.values import CAR
import warnings
from opendbc.car.nissan.values import CAR, CarControllerParams
adeebshihadeh marked this conversation as resolved.
Show resolved Hide resolved

# 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)

adeebshihadeh marked this conversation as resolved.
Show resolved Hide resolved
values = {
"COUNTER": frame % 0x10,
"DESIRED_ANGLE": apply_steer,
Expand Down
4 changes: 4 additions & 0 deletions opendbc/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