From 41e9610ff841e4cf62051c6df09c1870f5d12477 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Wed, 6 Mar 2024 21:13:13 +0100 Subject: [PATCH 1/3] Tesla Raven (#1886) * raven uses a different steering angle sensor * add raven flag * raven test * bump opendbc ref --- Dockerfile | 2 +- board/safety/safety_tesla.h | 31 +++++++++++++++++++++++-------- python/__init__.py | 1 + tests/safety/test_tesla.py | 11 +++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b2c2073297..99bedcf08d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,7 @@ ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}" ENV PANDA_PATH=/tmp/openpilot/panda ENV OPENPILOT_REF="5690386d8d731c9bebda536a5c71c890f6dfe98c" -ENV OPENDBC_REF="40d9c723d48496229fecc436046538a53af19c11" +ENV OPENDBC_REF="1745ab51825055cd18748013c4a5e3377319e390" COPY requirements.txt /tmp/ RUN pyenv install 3.11.4 && \ diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index 4fa0df84aa..652161ff2c 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -19,6 +19,7 @@ const LongitudinalLimits TESLA_LONG_LIMITS = { const int TESLA_FLAG_POWERTRAIN = 1; const int TESLA_FLAG_LONGITUDINAL_CONTROL = 2; +const int TESLA_FLAG_RAVEN = 4; const CanMsg TESLA_TX_MSGS[] = { {0x488, 0, 4}, // DAS_steeringControl @@ -41,6 +42,16 @@ RxCheck tesla_rx_checks[] = { {.msg = {{0x318, 0, 8, .frequency = 10U}, { 0 }, { 0 }}}, // GTW_carState }; +RxCheck tesla_raven_rx_checks[] = { + {.msg = {{0x2b9, 2, 8, .frequency = 25U}, { 0 }, { 0 }}}, // DAS_control + {.msg = {{0x131, 2, 8, .frequency = 100U}, { 0 }, { 0 }}}, // EPAS3P_sysStatus + {.msg = {{0x108, 0, 8, .frequency = 100U}, { 0 }, { 0 }}}, // DI_torque1 + {.msg = {{0x118, 0, 6, .frequency = 100U}, { 0 }, { 0 }}}, // DI_torque2 + {.msg = {{0x20a, 0, 8, .frequency = 50U}, { 0 }, { 0 }}}, // BrakeMessage + {.msg = {{0x368, 0, 8, .frequency = 10U}, { 0 }, { 0 }}}, // DI_state + {.msg = {{0x318, 0, 8, .frequency = 10U}, { 0 }, { 0 }}}, // GTW_carState +}; + RxCheck tesla_pt_rx_checks[] = { {.msg = {{0x106, 0, 8, .frequency = 100U}, { 0 }, { 0 }}}, // DI_torque1 {.msg = {{0x116, 0, 6, .frequency = 100U}, { 0 }, { 0 }}}, // DI_torque2 @@ -51,6 +62,7 @@ RxCheck tesla_pt_rx_checks[] = { bool tesla_longitudinal = false; bool tesla_powertrain = false; // Are we the second panda intercepting the powertrain bus? +bool tesla_raven = false; bool tesla_stock_aeb = false; @@ -58,16 +70,16 @@ static void tesla_rx_hook(const CANPacket_t *to_push) { int bus = GET_BUS(to_push); int addr = GET_ADDR(to_push); - if(bus == 0) { - if (!tesla_powertrain) { - if(addr == 0x370) { - // Steering angle: (0.1 * val) - 819.2 in deg. - // Store it 1/10 deg to match steering request - int angle_meas_new = (((GET_BYTE(to_push, 4) & 0x3FU) << 8) | GET_BYTE(to_push, 5)) - 8192U; - update_sample(&angle_meas, angle_meas_new); - } + if (!tesla_powertrain) { + if((!tesla_raven && (addr == 0x370) && (bus == 0)) || (tesla_raven && (addr == 0x131) && (bus == 2))) { + // Steering angle: (0.1 * val) - 819.2 in deg. + // Store it 1/10 deg to match steering request + int angle_meas_new = (((GET_BYTE(to_push, 4) & 0x3FU) << 8) | GET_BYTE(to_push, 5)) - 8192U; + update_sample(&angle_meas, angle_meas_new); } + } + if(bus == 0) { if(addr == (tesla_powertrain ? 0x116 : 0x118)) { // Vehicle speed: ((0.05 * val) - 25) * MPH_TO_MPS float speed = (((((GET_BYTE(to_push, 3) & 0x0FU) << 8) | (GET_BYTE(to_push, 2))) * 0.05) - 25) * 0.447; @@ -206,12 +218,15 @@ static int tesla_fwd_hook(int bus_num, int addr) { static safety_config tesla_init(uint16_t param) { tesla_powertrain = GET_FLAG(param, TESLA_FLAG_POWERTRAIN); tesla_longitudinal = GET_FLAG(param, TESLA_FLAG_LONGITUDINAL_CONTROL); + tesla_raven = GET_FLAG(param, TESLA_FLAG_RAVEN); tesla_stock_aeb = false; safety_config ret; if (tesla_powertrain) { ret = BUILD_SAFETY_CFG(tesla_pt_rx_checks, TESLA_PT_TX_MSGS); + } else if (tesla_raven) { + ret = BUILD_SAFETY_CFG(tesla_raven_rx_checks, TESLA_TX_MSGS); } else { ret = BUILD_SAFETY_CFG(tesla_rx_checks, TESLA_TX_MSGS); } diff --git a/python/__init__.py b/python/__init__.py index 6e614775d9..304aa13528 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -214,6 +214,7 @@ class Panda: FLAG_TESLA_POWERTRAIN = 1 FLAG_TESLA_LONG_CONTROL = 2 + FLAG_TESLA_RAVEN = 4 FLAG_VOLKSWAGEN_LONG_CONTROL = 1 diff --git a/tests/safety/test_tesla.py b/tests/safety/test_tesla.py index 0b425ae19a..9461ff68f9 100755 --- a/tests/safety/test_tesla.py +++ b/tests/safety/test_tesla.py @@ -108,6 +108,17 @@ def test_acc_buttons(self): self.assertEqual(tx, should_tx) +class TestTeslaRavenSteeringSafety(TestTeslaSteeringSafety): + def setUp(self): + self.packer = CANPackerPanda("tesla_can") + self.safety = libpanda_py.libpanda + self.safety.set_safety_hooks(Panda.SAFETY_TESLA, Panda.FLAG_TESLA_RAVEN) + self.safety.init_tests() + + def _angle_meas_msg(self, angle: float): + values = {"EPAS_internalSAS": angle} + return self.packer.make_can_msg_panda("EPAS3P_sysStatus", 2, values) + class TestTeslaLongitudinalSafety(TestTeslaSafety): def setUp(self): raise unittest.SkipTest From 01984e5b443ce9a8d77a3e92431fdf9f39a4aac3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 7 Mar 2024 13:57:02 -0800 Subject: [PATCH 2/3] pre-commit: autoupdate hooks (#1892) Update pre-commit hook versions Co-authored-by: adeebshihadeh --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f978433e2..402bdc3a1f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,6 @@ repos: additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', 'types-pycurl'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.3.0 hooks: - id: ruff From 4b6f6ac1629d001ced6e86f43579d399230af614 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 8 Mar 2024 14:57:33 -0800 Subject: [PATCH 3/3] 723 power init (#1891) LDO only This reverts commit ea156f7c628a371bea9a15a29f9068d5392534ba. Co-authored-by: Comma Device --- board/stm32h7/clock.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/board/stm32h7/clock.h b/board/stm32h7/clock.h index a0ac01d0d9..94e08ca600 100644 --- a/board/stm32h7/clock.h +++ b/board/stm32h7/clock.h @@ -21,11 +21,13 @@ void clock_init(void) { // Set power mode to direct SMPS power supply(depends on the board layout) #ifndef STM32H723 register_set(&(PWR->CR3), PWR_CR3_SMPSEN, 0xFU); // powered only by SMPS +#else + register_set(&(PWR->CR3), PWR_CR3_LDOEN, 0xFU); +#endif // Set VOS level (VOS3 to 170Mhz, VOS2 to 300Mhz, VOS1 to 400Mhz, VOS0 to 550Mhz) register_set(&(PWR->D3CR), PWR_D3CR_VOS_1 | PWR_D3CR_VOS_0, 0xC000U); //VOS1, needed for 80Mhz CAN FD while ((PWR->CSR1 & PWR_CSR1_ACTVOSRDY) == 0); while ((PWR->CSR1 & PWR_CSR1_ACTVOS) != (PWR->D3CR & PWR_D3CR_VOS)); // check that VOS level was actually set -#endif // Configure Flash ACR register LATENCY and WRHIGHFREQ (VOS0 range!) register_set(&(FLASH->ACR), FLASH_ACR_LATENCY_2WS | 0x20U, 0x3FU); // VOS2, AXI 100MHz-150MHz