Skip to content

Commit

Permalink
Subaru Pre-Global: Reverse driver torque signal for certain platforms (
Browse files Browse the repository at this point in the history
…commaai#1648)

* Subaru Pre-Global: Reverse driver torque signal for certain platforms

* added flag

* fix tests

* use dbc instead

* duplicate

---------

Co-authored-by: Shane Smiskol <[email protected]>
Co-authored-by: Justin Newberry <[email protected]>
Co-authored-by: Justin Newberry <[email protected]>
  • Loading branch information
4 people authored Nov 8, 2023
1 parent 708303d commit 3f25cca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion board/safety/safety_subaru_preglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ AddrCheckStruct subaru_preglobal_addr_checks[] = {
#define SUBARU_PG_ADDR_CHECK_LEN (sizeof(subaru_preglobal_addr_checks) / sizeof(subaru_preglobal_addr_checks[0]))
addr_checks subaru_preglobal_rx_checks = {subaru_preglobal_addr_checks, SUBARU_PG_ADDR_CHECK_LEN};


const int SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 1;
bool subaru_pg_reversed_driver_torque = false;


static int subaru_preglobal_rx_hook(CANPacket_t *to_push) {

bool valid = addr_safety_check(to_push, &subaru_preglobal_rx_checks, NULL, NULL, NULL, NULL);
Expand All @@ -51,6 +56,7 @@ static int subaru_preglobal_rx_hook(CANPacket_t *to_push) {
int torque_driver_new;
torque_driver_new = (GET_BYTE(to_push, 3) >> 5) + (GET_BYTE(to_push, 4) << 3);
torque_driver_new = to_signed(torque_driver_new, 11);
torque_driver_new = subaru_pg_reversed_driver_torque ? -torque_driver_new : torque_driver_new;
update_sample(&torque_driver, torque_driver_new);
}

Expand Down Expand Up @@ -120,7 +126,7 @@ static int subaru_preglobal_fwd_hook(int bus_num, int addr) {
}

static const addr_checks* subaru_preglobal_init(uint16_t param) {
UNUSED(param);
subaru_pg_reversed_driver_torque = GET_FLAG(param, SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE);
return &subaru_preglobal_rx_checks;
}

Expand Down
2 changes: 2 additions & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class Panda:
FLAG_SUBARU_GEN2 = 1
FLAG_SUBARU_LONG = 2

FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 1

FLAG_NISSAN_ALT_EPS_BUS = 1

FLAG_GM_HW_CAM = 1
Expand Down
11 changes: 9 additions & 2 deletions tests/safety/test_subaru_preglobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@


class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest):
FLAGS = 0
DBC = "subaru_outback_2015_generated"
TX_MSGS = [[0x161, 0], [0x164, 0]]
STANDSTILL_THRESHOLD = 0 # kph
RELAY_MALFUNCTION_ADDRS = {0: (0x164,)}
Expand All @@ -24,9 +26,9 @@ class TestSubaruPreglobalSafety(common.PandaCarSafetyTest, common.DriverTorqueSt
DRIVER_TORQUE_FACTOR = 10

def setUp(self):
self.packer = CANPackerPanda("subaru_outback_2015_generated")
self.packer = CANPackerPanda(self.DBC)
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU_PREGLOBAL, 0)
self.safety.set_safety_hooks(Panda.SAFETY_SUBARU_PREGLOBAL, self.FLAGS)
self.safety.init_tests()

def _set_prev_torque(self, t):
Expand Down Expand Up @@ -59,5 +61,10 @@ def _pcm_status_msg(self, enable):
return self.packer.make_can_msg_panda("CruiseControl", 0, values)


class TestSubaruPreglobalReversedDriverTorqueSafety(TestSubaruPreglobalSafety):
FLAGS = Panda.FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE
DBC = "subaru_outback_2019_generated"


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

0 comments on commit 3f25cca

Please sign in to comment.