Skip to content

Commit b426c1c

Browse files
authored
Rivian: cancel command (#1910)
* add candidate cancel command and test * fixes * this was correct * try spacing out the messages * try adas status to acm to cancel * try a bunch of stuff * send the entire range * try faulted * try two faults * try faster * 50hz * Revert "50hz" This reverts commit babcbdf. * no fault on dash * 50hz * see if "unavailable" also works * try sending just 1 * 100 Hz * Revert "100 Hz" This reverts commit 29ae625. * Revert "try sending just 1" This reverts commit 64908eb. * revert other stuff - forgot counter! * Revert "revert other stuff - forgot counter!" This reverts commit 5ce09b7. * try counter * final thing * 100 hz * Revert "100 hz" (faults) This reverts commit bea3977. * nvm we can't do this since the state management to know when openpilot stops sending cancel is too complex * Revert "nvm we can't do this since the state management to know when openpilot stops sending cancel is too complex" This reverts commit 19fb385. * forward through openpilot * try these two * let's also try this * are we doing this right? * temp fault? * ? * try oscillating?! * that works?! * maybe ACM needs to see VDM status rise before VDM can request cancel with a falling edge * try to cancel immediately (1 frame of available) * no counter * cmts * 3 frames * comments * clean up safety * clean up * cc clean up * typo * comments * clean this up too * and this too
1 parent c9c4972 commit b426c1c

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

opendbc/car/rivian/carcontroller.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from opendbc.can.packer import CANPacker
22
from opendbc.car import Bus, apply_driver_steer_torque_limits
33
from opendbc.car.interfaces import CarControllerBase
4-
from opendbc.car.rivian.riviancan import create_lka_steering, create_longitudinal, create_wheel_touch
4+
from opendbc.car.rivian.riviancan import create_lka_steering, create_longitudinal, create_wheel_touch, create_adas_status
55
from opendbc.car.rivian.values import CarControllerParams
66

77

@@ -11,6 +11,8 @@ def __init__(self, dbc_names, CP):
1111
self.apply_torque_last = 0
1212
self.packer = CANPacker(dbc_names[Bus.pt])
1313

14+
self.cancel_frames = 0
15+
1416
def update(self, CC, CS, now_nanos):
1517
actuators = CC.actuators
1618
can_sends = []
@@ -31,6 +33,17 @@ def update(self, CC, CS, now_nanos):
3133
# Longitudinal control
3234
if self.CP.openpilotLongitudinalControl:
3335
can_sends.append(create_longitudinal(self.packer, self.frame % 15, actuators.accel, CC.enabled))
36+
else:
37+
interface_status = None
38+
if CC.cruiseControl.cancel:
39+
# if there is a noEntry, we need to send a status of "available" before the ACM will accept "unavailable"
40+
# send "available" right away as the VDM itself takes a few frames to acknowledge
41+
interface_status = 1 if self.cancel_frames < 5 else 0
42+
self.cancel_frames += 1
43+
else:
44+
self.cancel_frames = 0
45+
46+
can_sends.append(create_adas_status(self.packer, CS.vdm_adas_status, interface_status))
3447

3548
new_actuators = actuators.as_builder()
3649
new_actuators.torque = apply_torque / CarControllerParams.STEER_MAX

opendbc/car/rivian/carstate.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, CP):
1313

1414
self.acm_lka_hba_cmd = None
1515
self.sccm_wheel_touch = None
16+
self.vdm_adas_status = None
1617

1718
def update(self, can_parsers) -> structs.CarState:
1819
cp = can_parsers[Bus.pt]
@@ -86,6 +87,7 @@ def update(self, can_parsers) -> structs.CarState:
8687
# Messages needed by carcontroller
8788
self.acm_lka_hba_cmd = copy.copy(cp_cam.vl["ACM_lkaHbaCmd"])
8889
self.sccm_wheel_touch = copy.copy(cp.vl["SCCM_WheelTouch"])
90+
self.vdm_adas_status = copy.copy(cp.vl["VDM_AdasSts"])
8991

9092
return ret
9193

opendbc/car/rivian/riviancan.py

+23
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,26 @@ def create_longitudinal(packer, frame, accel, enabled):
8383
data = packer.make_can_msg("ACM_longitudinalRequest", 0, values)[1]
8484
values["ACM_longitudinalRequest_Checksum"] = checksum(data[1:], 0x1D, 0x12)
8585
return packer.make_can_msg("ACM_longitudinalRequest", 0, values)
86+
87+
88+
def create_adas_status(packer, vdm_adas_status, interface_status):
89+
values = {s: vdm_adas_status[s] for s in (
90+
"VDM_AdasStatus_Checksum",
91+
"VDM_AdasStatus_Counter",
92+
"VDM_AdasDecelLimit",
93+
"VDM_AdasDriverAccelPriorityStatus",
94+
"VDM_AdasFaultStatus",
95+
"VDM_AdasAccelLimit",
96+
"VDM_AdasDriverModeStatus",
97+
"VDM_AdasAccelRequest",
98+
"VDM_AdasInterfaceStatus",
99+
"VDM_AdasAccelRequestAcknowledged",
100+
"VDM_AdasVehicleHoldStatus",
101+
)}
102+
103+
if interface_status is not None:
104+
values["VDM_AdasInterfaceStatus"] = interface_status
105+
106+
data = packer.make_can_msg("VDM_AdasSts", 2, values)[1]
107+
values["VDM_AdasStatus_Checksum"] = checksum(data[1:], 0x1D, 0xD1)
108+
return packer.make_can_msg("VDM_AdasSts", 2, values)

opendbc/dbc/rivian_primary_actuator.dbc

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ BO_ 354 VDM_AdasSts: 8 VDM
185185
SG_ VDM_AdasStatus_Checksum : 7|8@0+ (1,0) [0|0] "" ACM
186186
SG_ VDM_AdasStatus_Counter : 11|4@0+ (1,0) [0|0] "" ACM
187187
SG_ VDM_AdasDecelLimit : 17|10@0+ (0.01,0) [0|10.23] "m/s^2" ACM
188-
SG_ VDM_AdasDriverAccelPriorityStatu : 19|2@0+ (1,0) [0|3] "" ACM
188+
SG_ VDM_AdasDriverAccelPriorityStatus : 19|2@0+ (1,0) [0|3] "" ACM
189189
SG_ VDM_AdasFaultStatus : 23|4@0+ (1,0) [0|15] "" ACM
190190
SG_ VDM_AdasAccelLimit : 33|10@0+ (0.01,0) [0|10.23] "m/s^2" ACM
191191
SG_ VDM_AdasDriverModeStatus : 36|3@0+ (1,0) [0|7] "" ACM
@@ -874,7 +874,7 @@ VAL_ 352 ACM_VehicleHoldRequired 0 "ACM_VEHICLEHOLDREQ_NO_REQUEST" 1 "ACM_VEHICL
874874
VAL_ 352 ACM_PrndRequired 0 "ACM_PRNDREQ_PARK" 1 "ACM_PRNDREQ_REVERSE" 2 "ACM_PRNDREQ_NEUTRAL" 3 "ACM_PRNDREQ_DRIVE" 4 "ACM_PRNDREQ_NOT_USED";
875875
VAL_ 352 ACM_longInterfaceEnable 0 "ACM_LONGIFEN_INIT" 1 "ACM_LONGIFEN_LONGITUDINAL_INTERFACE_ENABLE" 2 "ACM_LONGIFEN_LONGITUDINAL_INTERFACE_DISABLE" 3 "ACM_LONGIFEN_SNA";
876876
VAL_ 352 ACM_AccelerationRequestType 0 "ACM_ACCELREQTYPE_INIT" 1 "ACM_ACCELREQTYPE_ACCEL_NEGATIVE" 2 "ACM_ACCELREQTYPE_ACCEL_POSITIVE" 3 "ACM_ACCELREQTYPE_SNA";
877-
VAL_ 354 VDM_AdasDriverAccelPriorityStatu 0 "VDM_AdasDriverAccelPriorityStatus_Driver" 1 "VDM_AdasDriverAccelPriorityStatus_Adas";
877+
VAL_ 354 VDM_AdasDriverAccelPriorityStatus 0 "VDM_AdasDriverAccelPriorityStatus_Driver" 1 "VDM_AdasDriverAccelPriorityStatus_Adas";
878878
VAL_ 354 VDM_AdasFaultStatus 0 "VDM_AdasFlaultStatus_No_Fault" 1 "VDM_AdasFaultStatus_Brk_Intv" 2 "VDM_AdasFlaultStatus_Cntr_Fault" 3 "VDM_AdasFlaultStatus_Imps_Cmd" 15 "VDM_AdasFlaultStatus_Sna";
879879
VAL_ 354 VDM_AdasDriverModeStatus 0 "VDM_AdasDriverModeStatus_Human" 1 "VDM_AdasDriverModeStatus_Adas" 2 "VDM_AdasDriverModeStatus_Reserved" 3 "VDM_AdasDriverModeStatus_Sna";
880880
VAL_ 354 VDM_AdasInterfaceStatus 0 "VDM_AdasInterfaceStatus_Unavailable" 1 "VDM_AdasInterfaceStatus_Available" 2 "VDM_AdasInterfaceStatus_Enabled" 3 "VDM_AdasInterfaceStatus_Faulted";

opendbc/safety/safety/safety_rivian.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ static int rivian_fwd_hook(int bus, int addr) {
100100
block_msg = true;
101101
}
102102

103+
// VDM_AdasSts: for canceling stock ACC
104+
if ((addr == 0x162) && !rivian_longitudinal) {
105+
block_msg = true;
106+
}
107+
103108
if (!block_msg) {
104109
bus_fwd = 2;
105110
}
@@ -125,8 +130,8 @@ static int rivian_fwd_hook(int bus, int addr) {
125130
}
126131

127132
static safety_config rivian_init(uint16_t param) {
128-
// 0x120 = ACM_lkaHbaCmd, 0x321 = SCCM_WheelTouch
129-
static const CanMsg RIVIAN_TX_MSGS[] = {{0x120, 0, 8}, {0x321, 2, 7}};
133+
// 0x120 = ACM_lkaHbaCmd, 0x321 = SCCM_WheelTouch, 0x162 = VDM_AdasSts
134+
static const CanMsg RIVIAN_TX_MSGS[] = {{0x120, 0, 8}, {0x321, 2, 7}, {0x162, 2, 8}};
130135
// 0x160 = ACM_longitudinalRequest
131136
static const CanMsg RIVIAN_LONG_TX_MSGS[] = {{0x120, 0, 8}, {0x321, 2, 7}, {0x160, 0, 5}};
132137

opendbc/safety/tests/test_rivian.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
class TestRivianSafetyBase(common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest, common.LongitudinalAccelSafetyTest):
1212

13-
TX_MSGS = [[0x120, 0], [0x321, 2]]
13+
TX_MSGS = [[0x120, 0], [0x321, 2], [0x162, 2]]
1414
STANDSTILL_THRESHOLD = 0
1515
RELAY_MALFUNCTION_ADDRS = {0: (0x120,)}
16-
FWD_BLACKLISTED_ADDRS = {0: [0x321], 2: [0x120]}
16+
FWD_BLACKLISTED_ADDRS = {0: [0x321, 0x162], 2: [0x120]}
1717
FWD_BUS_LOOKUP = {0: 2, 2: 0}
1818

1919
MAX_TORQUE = 250
@@ -64,7 +64,7 @@ def _accel_msg(self, accel: float):
6464
return self.packer.make_can_msg_panda("ACM_longitudinalRequest", 0, values)
6565

6666
def test_wheel_touch(self):
67-
self.safety.set_controls_allowed(True)
67+
# For hiding hold wheel alert on engage
6868
for controls_allowed in (True, False):
6969
self.safety.set_controls_allowed(controls_allowed)
7070
values = {
@@ -85,6 +85,14 @@ def setUp(self):
8585
self.safety.set_safety_hooks(CarParams.SafetyModel.rivian, 0)
8686
self.safety.init_tests()
8787

88+
def test_adas_status(self):
89+
# For canceling stock ACC
90+
for controls_allowed in (True, False):
91+
self.safety.set_controls_allowed(controls_allowed)
92+
for interface_status in range(4):
93+
values = {"VDM_AdasInterfaceStatus": interface_status}
94+
self.assertTrue(self._tx(self.packer.make_can_msg_panda("VDM_AdasSts", 2, values)))
95+
8896

8997
class TestRivianLongitudinalSafety(TestRivianSafetyBase):
9098

0 commit comments

Comments
 (0)