From 8201f3edf450f9871e46f2c9db7b4d8483aac767 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 19 May 2025 16:55:43 -0400 Subject: [PATCH] MADS: Rivian support (#936) * MADS: Tesla and Rivian support * request lateral if acc is engaged * try this out * fix * make sure we keep the toggle off for tesla * namedtuple * disallow steering past 90 degrees for rivian * whoops * Revert "Revert "MADS: Steering Mode on Brake Pedal Press (#687)" (#789)" This reverts commit 8dec4ea5 * both rivian and tesla * enforce disengage on brake steering mode for Rivian and Tesla * wrong one * MADS: Steering Mode on Brake Pedal Press * bump * bump * descriptions * bump * bump * no tesla or rivian yet * codecov v5 * Revert "codecov v5" This reverts commit a347e3fb27c0fbf2510b69fe8148b254fa93b8de. * cleanup * refactor description * sync name * fix * make sure we don't allow if brake was already being pressed * no longer needed * proper ui! * allow LKAS tx at all times with MADS * extra * this ain't right * try this * test only * bring them back * some dynamic checks * dynamic description for mads toggle * one place for limited platforms * just rivian * not here * Revert "not here" This reverts commit 53271b942839feb706e393254a3516097cc72890. * get them out * get them out * no longer needed * Revert "get them out" This reverts commit 532b671bfb8bf76d5b4ef6349e5a1e3cd760dc3e. * bump * bump * less * Revert "bump" This reverts commit 05ee4be04f190aaaa61bf18b0884b09accd74522. --- opendbc_repo | 2 +- sunnypilot/mads/helpers.py | 18 +++++++++++++----- sunnypilot/mads/mads.py | 7 +++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/opendbc_repo b/opendbc_repo index a05175477..748a84787 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit a051754777785cc93eb0be35b081d19f7fbce595 +Subproject commit 748a84787ad8b55125cf3953fd08de7f90da10c6 diff --git a/sunnypilot/mads/helpers.py b/sunnypilot/mads/helpers.py index 5c7b575d1..806f8edbe 100644 --- a/sunnypilot/mads/helpers.py +++ b/sunnypilot/mads/helpers.py @@ -17,7 +17,14 @@ class MadsSteeringModeOnBrake: DISENGAGE = 2 -def read_steering_mode_param(params: Params): +def get_mads_limited_brands(CP: structs.CarParams) -> bool: + return CP.brand in ("rivian", ) + + +def read_steering_mode_param(CP: structs.CarParams, params: Params): + if get_mads_limited_brands(CP): + return MadsSteeringModeOnBrake.DISENGAGE + try: return int(params.get("MadsSteeringMode")) except (ValueError, TypeError): @@ -26,7 +33,7 @@ def read_steering_mode_param(params: Params): def set_alternative_experience(CP: structs.CarParams, params: Params): enabled = params.get_bool("Mads") - steering_mode = read_steering_mode_param(params) + steering_mode = read_steering_mode_param(CP, params) if enabled: CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.ENABLE_MADS @@ -49,7 +56,8 @@ def set_car_specific_params(CP: structs.CarParams, CP_SP: structs.CarParamsSP, p # MADS Partial Support # MADS is currently partially supported for these platforms due to lack of consistent states to engage controls # Only MadsSteeringModeOnBrake.DISENGAGE is supported for these platforms - mads_partial_support = False + # TODO-SP: To enable MADS full support for Rivian, identify consistent signals for MADS toggling + mads_partial_support = get_mads_limited_brands(CP) if mads_partial_support: params.put("MadsSteeringMode", "2") params.put_bool("MadsUnifiedEngagementMode", True) @@ -57,6 +65,6 @@ def set_car_specific_params(CP: structs.CarParams, CP_SP: structs.CarParamsSP, p # MADS Disabled - No Support # MADS is currently not supported for these platforms due to lack of consistent states to engage controls - # TODO-SP: To enable MADS full support for Rivian/Tesla, identify consistent signals for MADS toggling - if CP.brand in ("rivian", "tesla"): + # TODO-SP: To enable MADS full support for Tesla, identify consistent signals for MADS toggling + if CP.brand in ("tesla", ): params.remove("Mads") diff --git a/sunnypilot/mads/mads.py b/sunnypilot/mads/mads.py index ffe6e6efe..3b0629056 100644 --- a/sunnypilot/mads/mads.py +++ b/sunnypilot/mads/mads.py @@ -10,7 +10,7 @@ from cereal import log, custom from opendbc.car import structs from opendbc.car.hyundai.values import HyundaiFlags from opendbc.safety import ALTERNATIVE_EXPERIENCE -from openpilot.sunnypilot.mads.helpers import MadsSteeringModeOnBrake, read_steering_mode_param +from openpilot.sunnypilot.mads.helpers import MadsSteeringModeOnBrake, read_steering_mode_param, get_mads_limited_brands from openpilot.sunnypilot.mads.state import StateMachine, GEARS_ALLOW_PAUSED_SILENT State = custom.ModularAssistiveDrivingSystem.ModularAssistiveDrivingSystemState @@ -45,10 +45,13 @@ class ModularAssistiveDrivingSystem: if self.CP.flags & (HyundaiFlags.HAS_LDA_BUTTON | HyundaiFlags.CANFD): self.allow_always = True + if get_mads_limited_brands(self.CP): + self.no_main_cruise = True + # read params on init self.enabled_toggle = self.params.get_bool("Mads") self.main_enabled_toggle = self.params.get_bool("MadsMainCruiseAllowed") - self.steering_mode_on_brake = read_steering_mode_param(self.params) + self.steering_mode_on_brake = read_steering_mode_param(self.CP, self.params) self.unified_engagement_mode = self.params.get_bool("MadsUnifiedEngagementMode") def read_params(self):