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

Rivian: fix temp steering faults #1894

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions opendbc/car/rivian/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
from opendbc.can.packer import CANPacker
from opendbc.car import Bus, apply_driver_steer_torque_limits
from opendbc.car import Bus, apply_driver_steer_torque_limits, common_fault_avoidance
from opendbc.car.interfaces import CarControllerBase
from opendbc.car.rivian.riviancan import create_lka_steering, create_longitudinal, create_wheel_touch, create_adas_status
from opendbc.car.rivian.values import CarControllerParams

MAX_STEER_RATE = 90 # deg/s
MAX_STEER_RATE_FRAMES = 4 # tx control frames needed before torque can be cut


class CarController(CarControllerBase):
def __init__(self, dbc_names, CP):
super().__init__(dbc_names, CP)
self.apply_torque_last = 0
self.packer = CANPacker(dbc_names[Bus.pt])

self.steer_rate_counter = 0
self.cancel_frames = 0

def update(self, CC, CS, now_nanos):
actuators = CC.actuators
can_sends = []

# >100 degree/sec steering fault prevention
self.steer_rate_counter, apply_steer_req = common_fault_avoidance(abs(CS.out.steeringRateDeg) >= MAX_STEER_RATE, CC.latActive,
self.steer_rate_counter, MAX_STEER_RATE_FRAMES)
torque_fault = CC.latActive and not apply_steer_req

apply_torque = 0
if CC.latActive:
new_torque = int(round(CC.actuators.torque * CarControllerParams.STEER_MAX))
Expand All @@ -25,7 +34,7 @@ def update(self, CC, CS, now_nanos):

# send steering command
self.apply_torque_last = apply_torque
can_sends.append(create_lka_steering(self.packer, CS.acm_lka_hba_cmd, apply_torque, CC.latActive))
can_sends.append(create_lka_steering(self.packer, CS.acm_lka_hba_cmd, apply_torque, CC.enabled, apply_steer_req, torque_fault))

if self.frame % 5 == 0:
can_sends.append(create_wheel_touch(self.packer, CS.sccm_wheel_touch, CC.enabled))
Expand Down
12 changes: 7 additions & 5 deletions opendbc/car/rivian/riviancan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def checksum(data, poly, xor_output):
return crc ^ xor_output


def create_lka_steering(packer, acm_lka_hba_cmd, apply_torque, enabled):
def create_lka_steering(packer, acm_lka_hba_cmd, apply_torque, enabled, apply_steer_req, torque_fault):
values = {s: acm_lka_hba_cmd[s] for s in [
"ACM_lkaHbaCmd_Counter",
"ACM_lkaHbaCmd_Checksum",
"ACM_HapticRequest",
"ACM_lkaStrToqReq",
# "ACM_lkaStrToqReq",
"ACM_lkaSymbolState",
"ACM_lkaToiFlt",
"ACM_lkaActToi",
# "ACM_lkaActToi",
"ACM_hbaSysState",
"ACM_FailinfoAeb",
"ACM_lkaRHWarning",
Expand All @@ -36,11 +36,13 @@ def create_lka_steering(packer, acm_lka_hba_cmd, apply_torque, enabled):
"ACM_unkown6",
]}

values["ACM_lkaStrToqReq"] = apply_torque
values["ACM_lkaActToi"] = apply_steer_req
values["ACM_lkaToiFlt"] = torque_fault

if enabled:
values["ACM_lkaActToi"] = 1
values["ACM_lkaSymbolState"] = 3
values["ACM_lkaLaneRecogState"] = 3
values["ACM_lkaStrToqReq"] = apply_torque
values["ACM_unkown2"] = 1
values["ACM_unkown3"] = 4
values["ACM_unkown4"] = 160
Expand Down
7 changes: 7 additions & 0 deletions opendbc/safety/safety/safety_rivian.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ static bool rivian_tx_hook(const CANPacket_t *to_send) {
.driver_torque_multiplier = 2,
.driver_torque_allowance = 100,
.type = TorqueDriverLimited,

// the EPS faults when the steering angle rate is above a certain threshold for too long. to prevent this,
// we allow setting STEER_REQUEST bit to 0 while maintaining the requested torque value for a single frame
.min_valid_request_frames = 4,
.max_invalid_request_frames = 1,
.min_valid_request_rt_interval = 36000, // 170ms; a ~10% buffer on cutting every 19 frames
.has_steer_req_tolerance = true,
};

const LongitudinalLimits RIVIAN_LONG_LIMITS = {
Expand Down