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

Subaru: Global gen1 longitudinal safety #1500

Merged
merged 170 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
5e97fc7
Add subaru long TX and RX messages
martinl May 27, 2020
76676b7
misra c2012 fix
martinl Jun 3, 2020
64919ad
fix tests
martinl Jun 3, 2020
aba9ad2
Reorder signals
martinl Jun 3, 2020
185d420
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Apr 3, 2021
152b087
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl May 21, 2021
324a552
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Jun 12, 2021
eb2993c
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Jul 8, 2021
3eb4aa7
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Aug 15, 2021
09bd99b
merge upstream
martinl Sep 29, 2021
1b2e129
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Oct 2, 2021
8647423
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Oct 18, 2021
beb6d0a
Merge commit '0cc5ec33e437d4ecf0ec29a3e05113bdddc5d260' into feature-…
martinl Nov 7, 2021
c8916c3
merge upstream
martinl Dec 31, 2021
308af7e
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Jan 8, 2022
4f73c77
Merge commit 'f56ebf5b776b677bf12ec772b0223274dd798999' into feature-…
martinl Feb 19, 2022
3ed3139
increase max steering torque
martinl Feb 23, 2022
3fac438
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Apr 12, 2022
dcf8516
Merge commit '7dd9493eb102ba8b96362c7265b06851ec1d4bac' into feature-…
martinl Apr 24, 2022
b7a6ecb
Merge commit 'eb662e4e5014a3fc3c04512d708f61080c7707c1' into feature-…
martinl May 4, 2022
5d0f77f
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl May 4, 2022
606b360
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Aug 14, 2022
90847c9
merge fix
martinl Aug 14, 2022
5c0b301
merge fix, remove cnt from test
martinl Aug 14, 2022
cbb8056
Move subaru logitudinal behind flag, add safety test
martinl Aug 19, 2022
17cc58a
Merge commit '0ca23b67786d0fa2a3162371aadeca52d24a8958' into feature-…
martinl Sep 7, 2022
1697d0b
update subaru_longitudinal checks
martinl Sep 8, 2022
8702eb8
Merge branch 'master' of github.com:commaai/panda into feature-subaru…
adeebshihadeh Sep 17, 2022
61178a1
cleanup
adeebshihadeh Sep 17, 2022
2e2783d
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Oct 2, 2022
1211f9e
Add subaru longitudinal checks
martinl Oct 2, 2022
577e45d
misra fix
martinl Oct 2, 2022
03cdfba
Add subaru rpm and throttle rate limit checks
martinl Oct 2, 2022
d2925e7
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Oct 16, 2022
2b90cc9
temporary disable cruise throttle and cruise rpm checks
martinl Oct 16, 2022
4d68f7c
Merge commit '9147cba1af0a8d72379242eb1ce0bfd42ab8075e' into feature-…
martinl Nov 3, 2022
2a28770
Merge commit 'd57311126860c9a87edf5b7b9f81a2a038866a26' into feature-…
martinl Nov 12, 2022
3d56b64
Merge commit 'c0632cd32b78279dfbb3ce28c7a10ded8090d40f' into feature-…
martinl Nov 15, 2022
2cfc910
Merge commit '5dc5cd8e20668dfb15d35b175fccbfd3f7b63b09' into feature-…
martinl Nov 19, 2022
611a828
Merge remote-tracking branch 'upstream/master' into feature-subaru-long
martinl Dec 7, 2022
98249dc
update subaru long test
martinl Dec 7, 2022
e53c847
update longitudinal safety and add tests
martinl Dec 10, 2022
2e3f5e3
fix tests
martinl Dec 10, 2022
cf23e8d
fix misra
martinl Dec 10, 2022
63c3475
subaru long signals limits checks
martinl Dec 11, 2022
b9cfddf
Add controls_allowed to long tests
martinl Dec 11, 2022
b13a453
remove unused variables
martinl Dec 11, 2022
d1eff3e
Add AEB passthru and tests
martinl Dec 12, 2022
0de5ee1
Add bus
martinl Dec 12, 2022
aef8ab1
Update AEB logic
martinl Dec 12, 2022
660b258
Add GEN2 AEB support
martinl Dec 12, 2022
5fd7c69
syntax fix
martinl Dec 12, 2022
0575d7a
Update AEB tests
martinl Dec 12, 2022
fd6dfd0
Merge commit '1923b1418933e464ff7460a3e0a05d63aad0d53b' into feature-…
martinl Mar 2, 2023
77ddd7f
Add comment for subaru_aeb
martinl Mar 5, 2023
c1d84c5
Do not check cruise_throttle and cruise_rpm limits when gas pressed
martinl Mar 20, 2023
b5b19d2
Merge commit 'e4cc97d8826dc95a7833b859c36948302445a499' into feature-…
martinl Mar 20, 2023
d818184
Merge branch 'master' into feature-subaru-long
adeebshihadeh Apr 9, 2023
128178b
Merge branch 'master' of github.com:commaai/panda into feature-subaru…
adeebshihadeh Apr 15, 2023
4cd4a12
use long limits struct
adeebshihadeh Apr 15, 2023
c0847a6
Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_S…
martinl Apr 19, 2023
7166dd5
fix misra, set controls_allowed for es_brake test
martinl Apr 19, 2023
adf234c
fix misra
martinl Apr 23, 2023
3de6861
Fix es_brake violation check
martinl Apr 27, 2023
b01faef
Merge commit 'b342c2d724125b3d12b88a53c2f87ba01c8043d0' into feature-…
martinl Apr 27, 2023
e260a04
Add 0x323 to longitudinal test
martinl Apr 27, 2023
63da689
Remove stock fcw from aeb signals
martinl Apr 28, 2023
73fde1c
merge 0.9.2
martinl May 25, 2023
222f1b9
Merge branch 'feature-subaru-long' of github.com:martinl/panda into f…
martinl May 25, 2023
0a559fc
Use GET_BYTES
martinl May 25, 2023
86e8d32
Revert "export FW_PATH"
martinl Jun 4, 2023
5aae671
Revert "cleanup fw filename conventions (#1434)"
martinl Jun 4, 2023
0da8fdf
Merge commit 'b2cf1976796dbd9f700a76543466c8c9c9665827' into feature-…
martinl Jun 25, 2023
60e6847
Revert "Revert "export FW_PATH""
martinl Jun 25, 2023
4d1f681
Revert "Revert "cleanup fw filename conventions (#1434)""
martinl Jun 25, 2023
6efbe4f
Merge commit '5285eec35ae290ad711f8a7fc7fc5af38c204d25' into feature-…
martinl Jul 2, 2023
d7e9727
merge
jnewb1 Jul 10, 2023
b86bba4
cleaned up safety
jnewb1 Jul 10, 2023
d0a5abd
cleanup subaru long safety
jnewb1 Jul 10, 2023
3705973
subaru_aeb -> stock_aeb for other platforms
jnewb1 Jul 10, 2023
0841625
fix unittests
jnewb1 Jul 10, 2023
52b7367
pretty
jnewb1 Jul 11, 2023
78f6d34
need to upload this route
jnewb1 Jul 11, 2023
8e64805
remove AEB stuff for now
jnewb1 Jul 11, 2023
4110eac
remove unrequired rpm checks
jnewb1 Jul 12, 2023
4849837
add comment
jnewb1 Jul 12, 2023
21fc764
added comment about acceleration and use throttle limit for rpm too
jnewb1 Jul 13, 2023
f52659b
inactive_throttle_fix
jnewb1 Jul 14, 2023
93d6abb
Update board/safety/safety_subaru.h
jnewb1 Jul 14, 2023
eede344
added comments about long limits
jnewb1 Jul 14, 2023
dc9cf4e
increase max brake
jnewb1 Jul 14, 2023
56638ad
merge with master
jnewb1 Jul 15, 2023
2c7e0fd
revert that
jnewb1 Jul 15, 2023
5006eb2
cleanup
jnewb1 Jul 15, 2023
706fd78
rename throttle to gas
jnewb1 Jul 15, 2023
41e4a4b
add safety replay
jnewb1 Jul 15, 2023
209c66e
Merge branch 'master' into feature-subaru-long
jnewb1 Jul 15, 2023
0397443
remove todo
jnewb1 Jul 15, 2023
3429b8d
rename throttle to gas
jnewb1 Jul 17, 2023
e5dc258
Merge branch 'feature-subaru-long' of https://github.com/commaai/pand…
jnewb1 Jul 17, 2023
de43707
move subaru stuff out of common test
jnewb1 Jul 17, 2023
6d8f714
merge
jnewb1 Jul 20, 2023
3492c5e
Merge branch 'master' into feature-subaru-long
jnewb1 Jul 26, 2023
3a73b60
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Jul 26, 2023
339c343
PR cleanup
jnewb1 Jul 31, 2023
ef909e8
added min gas
jnewb1 Jul 31, 2023
1b2886b
reduce initial complexity by not intercepting cruisecontrol or brake_…
jnewb1 Aug 1, 2023
1fd7429
create common gas brake safety test
jnewb1 Aug 1, 2023
2c2b95e
remove unrelated subaru reference
jnewb1 Aug 1, 2023
c9bcbc5
also test below min_value
jnewb1 Aug 1, 2023
d760723
fix fwd hook test
jnewb1 Aug 1, 2023
5156dac
better name and hardcoded
jnewb1 Aug 1, 2023
c1aa976
use same as acceleration limits
jnewb1 Aug 1, 2023
dd3ea6b
revert gm
jnewb1 Aug 1, 2023
b1dc602
remove callable
jnewb1 Aug 1, 2023
38cbce1
also limit rpm
jnewb1 Aug 7, 2023
11d2c55
remove safety replay for now
jnewb1 Aug 7, 2023
5b43b01
Merge branch 'master' into feature-subaru-long
jnewb1 Aug 7, 2023
3c4ac7a
revert unrelated changes
jnewb1 Aug 7, 2023
d2dd787
pr cleanup
jnewb1 Aug 7, 2023
b604cef
remove unused gasbrake safety test
jnewb1 Aug 7, 2023
3e6010e
fix ruff linter
jnewb1 Aug 7, 2023
5a83f32
PR cleanup
jnewb1 Aug 8, 2023
b174f8a
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Aug 8, 2023
08621fa
pr cleanup?
jnewb1 Aug 8, 2023
59734b7
added common brake test and moved generic test to base safety class
jnewb1 Aug 9, 2023
d9e88ae
Merge branch 'common-gas-brake-test-2' into common-gas-brake-test
jnewb1 Aug 9, 2023
1ac5e9d
remove duplicate test
jnewb1 Aug 9, 2023
9360a9e
wip
jnewb1 Aug 9, 2023
20338da
wip
jnewb1 Aug 9, 2023
fa49064
rename longitudinalaccelsafety
jnewb1 Aug 9, 2023
f8d4914
revert limits correct test
jnewb1 Aug 9, 2023
353207b
fix controls allowed test
jnewb1 Aug 9, 2023
f13b2b6
move gm over to long gas brake test
jnewb1 Aug 10, 2023
e5c7a35
assert that limits are reasonable
jnewb1 Aug 10, 2023
1697759
fix typing
jnewb1 Aug 11, 2023
db1be0c
fix linter again
jnewb1 Aug 11, 2023
2b20d28
fix linter again
jnewb1 Aug 11, 2023
29c4bde
fix linter again
jnewb1 Aug 11, 2023
e51103c
Merge remote-tracking branch 'upstream/master' into common-gas-brake-…
sshane Aug 11, 2023
d8812de
Merge remote-tracking branch 'upstream/master' into common-gas-brake-…
sshane Aug 11, 2023
3168233
like to make it clear
sshane Aug 11, 2023
27dd7b5
typo
sshane Aug 11, 2023
49081e3
fix from merge
sshane Aug 11, 2023
c9ddf64
clearer names
sshane Aug 11, 2023
c0367c1
dont need thesemore
jnewb1 Aug 11, 2023
b73659b
Merge branch 'common-gas-brake-test' into feature-subaru-long
jnewb1 Aug 11, 2023
1c4b49d
subaru: use common test
jnewb1 Aug 11, 2023
8113cf0
just add test for now
jnewb1 Aug 12, 2023
7e39d36
Merge branch 'common-gas-brake-test' into feature-subaru-long
jnewb1 Aug 12, 2023
1890601
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Aug 12, 2023
ae2f1b0
Merge branch 'master' into feature-subaru-long
jnewb1 Aug 13, 2023
3e3b383
fix merge issue
jnewb1 Aug 13, 2023
79f70e1
inactive gas from long limits
jnewb1 Aug 13, 2023
0f482d4
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Aug 13, 2023
442d95a
fix tests
jnewb1 Aug 13, 2023
b36ae94
linter
jnewb1 Aug 13, 2023
815452c
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Aug 15, 2023
8b0146c
fix gen2
jnewb1 Aug 15, 2023
8f4c7d7
fix linter
jnewb1 Aug 15, 2023
ac7d178
also test torque when doing long control
jnewb1 Aug 15, 2023
495426a
renamre transmision rpm
jnewb1 Aug 15, 2023
34e9163
consistent whitespace
jnewb1 Aug 15, 2023
676020f
Merge branch 'rename-alt-transmission-rpm' into feature-subaru-long
jnewb1 Aug 15, 2023
0b1f0ad
rename declarations too
jnewb1 Aug 15, 2023
0bded87
Merge branch 'rename-alt-transmission-rpm' into feature-subaru-long
jnewb1 Aug 15, 2023
0ecc177
rename transmission rpm
jnewb1 Aug 15, 2023
301579e
Merge remote-tracking branch 'origin/master' into feature-subaru-long
jnewb1 Aug 16, 2023
3fba020
same line
jnewb1 Aug 16, 2023
9e1312e
actually is transmission rpm
jnewb1 Aug 16, 2023
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
67 changes: 61 additions & 6 deletions board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const SteeringLimits SUBARU_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(2
const SteeringLimits SUBARU_GEN2_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(1000, 40, 40);


const LongitudinalLimits SUBARU_LONG_LIMITS = {
.min_gas = 808, // appears to be engine braking
.max_gas = 3400, // approx 2 m/s^2 when maxing cruise_rpm and cruise_throttle
.inactive_gas = 1818, // this is zero acceleration
jnewb1 marked this conversation as resolved.
Show resolved Hide resolved
.max_brake = 600, // approx -3.5 m/s^2

.min_alt = 0, // Transmission RPM limits
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this alt name is confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal was to make it generic in case any other brands have a similar "alternative" gas or brake signal that needs limiting. "rpm" is also weird, because it's actually the transmission rpm not the engine rpm

Copy link
Contributor

@adeebshihadeh adeebshihadeh Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's incredibly important that this particular code is as simple and readable as possible; we are not optimizing for line count. in this case, the variable should probably be called min_transmission_rpm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to transmission_rpm

.max_alt = 2400,
};

#define MSG_SUBARU_Brake_Status 0x13c
#define MSG_SUBARU_CruiseControl 0x240
#define MSG_SUBARU_Throttle 0x40
Expand All @@ -39,6 +49,10 @@ const SteeringLimits SUBARU_GEN2_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERA
{MSG_SUBARU_ES_LKAS_State, SUBARU_MAIN_BUS, 8}, \
{MSG_SUBARU_ES_Infotainment, SUBARU_MAIN_BUS, 8}, \

#define SUBARU_COMMON_LONG_TX_MSGS(alt_bus) \
{MSG_SUBARU_ES_Brake, SUBARU_MAIN_BUS, 8}, \
{MSG_SUBARU_ES_Status, SUBARU_MAIN_BUS, 8}, \

#define SUBARU_COMMON_ADDR_CHECKS(alt_bus) \
{.msg = {{MSG_SUBARU_Throttle, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, \
{.msg = {{MSG_SUBARU_Steering_Torque, SUBARU_MAIN_BUS, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, \
Expand All @@ -51,6 +65,12 @@ const CanMsg SUBARU_TX_MSGS[] = {
};
#define SUBARU_TX_MSGS_LEN (sizeof(SUBARU_TX_MSGS) / sizeof(SUBARU_TX_MSGS[0]))

const CanMsg SUBARU_LONG_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS)
SUBARU_COMMON_LONG_TX_MSGS(SUBARU_MAIN_BUS)
};
#define SUBARU_LONG_TX_MSGS_LEN (sizeof(SUBARU_LONG_TX_MSGS) / sizeof(SUBARU_LONG_TX_MSGS[0]))

const CanMsg SUBARU_GEN2_TX_MSGS[] = {
SUBARU_COMMON_TX_MSGS(SUBARU_ALT_BUS)
};
Expand All @@ -70,7 +90,10 @@ addr_checks subaru_gen2_rx_checks = {subaru_gen2_addr_checks, SUBARU_GEN2_ADDR_C


const uint16_t SUBARU_PARAM_GEN2 = 1;
const uint16_t SUBARU_PARAM_LONGITUDINAL = 2;

bool subaru_gen2 = false;
bool subaru_longitudinal = false;


static uint32_t subaru_get_checksum(CANPacket_t *to_push) {
Expand Down Expand Up @@ -153,6 +176,8 @@ static int subaru_tx_hook(CANPacket_t *to_send) {

if (subaru_gen2) {
tx = msg_allowed(to_send, SUBARU_GEN2_TX_MSGS, SUBARU_GEN2_TX_MSGS_LEN);
} else if (subaru_longitudinal) {
tx = msg_allowed(to_send, SUBARU_LONG_TX_MSGS, SUBARU_LONG_TX_MSGS_LEN);
} else {
tx = msg_allowed(to_send, SUBARU_TX_MSGS, SUBARU_TX_MSGS_LEN);
}
Expand All @@ -166,12 +191,32 @@ static int subaru_tx_hook(CANPacket_t *to_send) {
violation |= steer_torque_cmd_checks(desired_torque, -1, limits);
}

// Only allow ES_Distance when Cruise_Cancel is true, and Cruise_Throttle is "inactive" (1818)
if (addr == MSG_SUBARU_ES_Distance){
// check es_brake brake_pressure limits
if (addr == MSG_SUBARU_ES_Brake) {
int es_brake_pressure = GET_BYTES(to_send, 2, 2);
violation |= longitudinal_brake_checks(es_brake_pressure, SUBARU_LONG_LIMITS);
}

// check es_distance cruise_throttle limits
if (addr == MSG_SUBARU_ES_Distance) {
int cruise_throttle = (GET_BYTES(to_send, 2, 2) & 0xFFFU);
bool cruise_cancel = GET_BIT(to_send, 56U) != 0U;
violation |= (cruise_throttle != 1818);
violation |= (!cruise_cancel);

if (subaru_longitudinal) {
violation |= longitudinal_gas_checks(cruise_throttle, SUBARU_LONG_LIMITS);
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// If openpilot is not controlling long, only allow ES_Distance for cruise cancel requests,
// (when Cruise_Cancel is true, and Cruise_Throttle is inactive)
violation |= (cruise_throttle != SUBARU_LONG_LIMITS.inactive_gas);
violation |= (!cruise_cancel);
}
}

// check es_status cruise_rpm limits
if (addr == MSG_SUBARU_ES_Status) {
int cruise_rpm = (GET_BYTES(to_send, 2, 2) & 0xFFFU);
violation |= longitudinal_alt_checks(cruise_rpm, SUBARU_LONG_LIMITS);
}

if (violation){
Expand All @@ -184,7 +229,7 @@ static int subaru_fwd_hook(int bus_num, int addr) {
int bus_fwd = -1;

if (bus_num == SUBARU_MAIN_BUS) {
bus_fwd = SUBARU_CAM_BUS; // forward to camera
bus_fwd = SUBARU_CAM_BUS; // to the eyesight camera
}

if (bus_num == SUBARU_CAM_BUS) {
Expand All @@ -193,7 +238,13 @@ static int subaru_fwd_hook(int bus_num, int addr) {
(addr == MSG_SUBARU_ES_DashStatus) ||
(addr == MSG_SUBARU_ES_LKAS_State) ||
(addr == MSG_SUBARU_ES_Infotainment));
if (!block_lkas) {

bool block_long = ((addr == MSG_SUBARU_ES_Brake) ||
(addr == MSG_SUBARU_ES_Distance) ||
(addr == MSG_SUBARU_ES_Status));
jnewb1 marked this conversation as resolved.
Show resolved Hide resolved

bool block_msg = block_lkas || (subaru_longitudinal && block_long);
if (!block_msg) {
bus_fwd = SUBARU_MAIN_BUS; // Main CAN
}
}
Expand All @@ -204,6 +255,10 @@ static int subaru_fwd_hook(int bus_num, int addr) {
static const addr_checks* subaru_init(uint16_t param) {
subaru_gen2 = GET_FLAG(param, SUBARU_PARAM_GEN2);

#ifdef ALLOW_DEBUG
subaru_longitudinal = GET_FLAG(param, SUBARU_PARAM_LONGITUDINAL) && !subaru_gen2;
#endif

if (subaru_gen2) {
subaru_rx_checks = (addr_checks){subaru_gen2_addr_checks, SUBARU_GEN2_ADDR_CHECK_LEN};
} else {
Expand Down
1 change: 1 addition & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class Panda:
FLAG_CHRYSLER_RAM_HD = 2

FLAG_SUBARU_GEN2 = 1
FLAG_SUBARU_LONG = 2

FLAG_GM_HW_CAM = 1
FLAG_GM_HW_CAM_LONG = 2
Expand Down
3 changes: 2 additions & 1 deletion tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ def test_tx_hook_on_wrong_safety_mode(self):
continue
if attr.startswith('TestToyota') and current_test.startswith('TestToyota'):
continue
if {attr, current_test}.issubset({'TestSubaruGen1TorqueStockLongitudinalSafety', 'TestSubaruGen2TorqueStockLongitudinalSafety'}):
if {attr, current_test}.issubset({'TestSubaruGen1TorqueStockLongitudinalSafety', 'TestSubaruGen2TorqueStockLongitudinalSafety',
'TestSubaruGen1LongitudinalSafety'}):
continue
if {attr, current_test}.issubset({'TestVolkswagenPqSafety', 'TestVolkswagenPqStockSafety', 'TestVolkswagenPqLongSafety'}):
continue
Expand Down
42 changes: 42 additions & 0 deletions tests/safety/test_subaru.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def lkas_tx_msgs(alt_bus):
[MSG_SUBARU_ES_LKAS_State, SUBARU_MAIN_BUS],
[MSG_SUBARU_ES_Infotainment, SUBARU_MAIN_BUS]]

def long_tx_msgs():
return [[MSG_SUBARU_ES_Brake, SUBARU_MAIN_BUS],
[MSG_SUBARU_ES_Status, SUBARU_MAIN_BUS]]

class TestSubaruSafetyBase(common.PandaSafetyTest, MeasurementSafetyTest):
FLAGS = 0
Expand Down Expand Up @@ -100,6 +103,40 @@ def test_cancel_message(self):
self._generic_limit_safety_check(partial(self._cancel_msg, cancel), self.INACTIVE_GAS, self.INACTIVE_GAS, 0, 2**12, 1, self.INACTIVE_GAS, cancel)


class TestSubaruLongitudinalSafetyBase(TestSubaruSafetyBase, common.LongitudinalGasBrakeSafetyTest):
MIN_GAS = 808
MAX_GAS = 3400
INACTIVE_GAS = 1818
MAX_POSSIBLE_GAS = 2**12

MIN_BRAKE = 0
MAX_BRAKE = 600
MAX_POSSIBLE_BRAKE = 2**16

MIN_RPM = 0
MAX_RPM = 2400
MAX_POSSIBLE_RPM = 2**12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we get this from the DBC

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really have a way to parse the DBC and get all the messages/ signals / sizes from python directly that I've seen. I could look at adding something like that in a separate pr

Copy link
Contributor

@sshane sshane Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can add to CANDefine (right now it just gives you the value map, but we can expand to give general signal info)


FWD_BLACKLISTED_ADDRS = {2: [MSG_SUBARU_ES_LKAS, MSG_SUBARU_ES_Brake, MSG_SUBARU_ES_Distance,
MSG_SUBARU_ES_Status, MSG_SUBARU_ES_DashStatus,
MSG_SUBARU_ES_LKAS_State, MSG_SUBARU_ES_Infotainment]}

def test_rpm_safety_check(self):
self._generic_limit_safety_check(self._send_rpm_msg, self.MIN_RPM, self.MAX_RPM, 0, self.MAX_POSSIBLE_RPM, 1)

def _send_brake_msg(self, brake):
values = {"Brake_Pressure": brake}
return self.packer.make_can_msg_panda("ES_Brake", self.ALT_BUS, values)

def _send_gas_msg(self, gas):
values = {"Cruise_Throttle": gas}
return self.packer.make_can_msg_panda("ES_Distance", self.ALT_BUS, values)

def _send_rpm_msg(self, rpm):
values = {"Cruise_RPM": rpm}
return self.packer.make_can_msg_panda("ES_Status", self.ALT_BUS, values)


class TestSubaruTorqueSafetyBase(TestSubaruSafetyBase, common.DriverTorqueSteeringSafetyTest):
MAX_RATE_UP = 50
MAX_RATE_DOWN = 70
Expand All @@ -126,5 +163,10 @@ class TestSubaruGen2TorqueStockLongitudinalSafety(TestSubaruStockLongitudinalSaf
TX_MSGS = lkas_tx_msgs(SUBARU_ALT_BUS)


class TestSubaruGen1LongitudinalSafety(TestSubaruLongitudinalSafetyBase, TestSubaruTorqueSafetyBase):
FLAGS = Panda.FLAG_SUBARU_LONG
TX_MSGS = lkas_tx_msgs(SUBARU_MAIN_BUS) + long_tx_msgs()


if __name__ == "__main__":
unittest.main()
Loading