From 94ed0608e6c62f33f7cf17aaa0498869e065324c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 24 Aug 2026 01:40:31 -0400 Subject: [PATCH] models: use less strict chestnut detection state (#1948) --- openpilot/sunnypilot/models/fetcher.py | 17 ++++++++--------- openpilot/sunnypilot/models/manager.py | 4 +++- .../sunnypilot/sunnylink/athena/sunnylinkd.py | 7 ++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/openpilot/sunnypilot/models/fetcher.py b/openpilot/sunnypilot/models/fetcher.py index b64e27b1ad..773eb5b95c 100644 --- a/openpilot/sunnypilot/models/fetcher.py +++ b/openpilot/sunnypilot/models/fetcher.py @@ -13,8 +13,6 @@ from openpilot.common.params import Params from openpilot.common.swaglog import cloudlog from openpilot.common.hardware.hw import Paths from openpilot.sunnypilot.models.helpers import is_bundle_version_compatible -from openpilot.selfdrive.modeld.helpers import usbgpu_present - from openpilot.cereal import custom @@ -149,11 +147,10 @@ class ModelFetcher: self._is_usbgpu: bool | None = None self.model_cache = ModelCache(params) self.model_url = self.MODEL_URL - self._update_model_source() - def _update_model_source(self) -> None: - """Updates what json to use based on usbgpu availability""" - is_usbgpu = usbgpu_present() + def _update_model_source(self, chestnut_present: bool) -> None: + """Updates what json to use based on chestnut hardware presence via deviceState""" + is_usbgpu = chestnut_present if is_usbgpu != self._is_usbgpu: self._is_usbgpu = is_usbgpu self.model_cache = ModelCache(self.params, suffix="_USBGPU" if is_usbgpu else "") @@ -191,9 +188,9 @@ class ModelFetcher: return None - def get_available_bundles(self) -> list[custom.ModelManagerSP.ModelBundle]: + def get_available_bundles(self, chestnut_present: bool = False) -> list[custom.ModelManagerSP.ModelBundle]: """Gets the list of available models, with smart cache handling""" - self._update_model_source() + self._update_model_source(chestnut_present) cached_data, is_expired = self.model_cache.get() if cached_data and not is_expired: @@ -210,10 +207,12 @@ class ModelFetcher: cloudlog.warning("Failed to fetch fresh data. Using expired cache as fallback") return self.model_parser.parse_models(cached_data) + if __name__ == "__main__": + from openpilot.selfdrive.modeld.helpers import usbgpu_present params = Params() model_fetcher = ModelFetcher(params) - bundles = model_fetcher.get_available_bundles() + bundles = model_fetcher.get_available_bundles(chestnut_present=usbgpu_present()) for bundle in bundles: for model in bundle.models: model_overrides = {override.key: override.value for override in bundle.overrides} diff --git a/openpilot/sunnypilot/models/manager.py b/openpilot/sunnypilot/models/manager.py index 8ca8775875..37bcb781cf 100644 --- a/openpilot/sunnypilot/models/manager.py +++ b/openpilot/sunnypilot/models/manager.py @@ -30,6 +30,7 @@ class ModelManagerSP: self.params = Params() self.model_fetcher = ModelFetcher(self.params) self.pm = messaging.PubMaster(["modelManagerSP"]) + self.sm = messaging.SubMaster(["deviceState"]) self.available_models: list[custom.ModelManagerSP.ModelBundle] = [] self.selected_bundle: custom.ModelManagerSP.ModelBundle = None self.active_bundle: custom.ModelManagerSP.ModelBundle = get_active_bundle(self.params) @@ -262,7 +263,8 @@ class ModelManagerSP: while True: try: - self.available_models = self.model_fetcher.get_available_bundles() + self.sm.update(0) + self.available_models = self.model_fetcher.get_available_bundles(self.sm['deviceState'].chestnutPresent) validate_active_bundle(self.params, self.available_models) self.active_bundle = get_active_bundle(self.params) diff --git a/openpilot/sunnypilot/sunnylink/athena/sunnylinkd.py b/openpilot/sunnypilot/sunnylink/athena/sunnylinkd.py index 3425a85624..1ab2f373ed 100755 --- a/openpilot/sunnypilot/sunnylink/athena/sunnylinkd.py +++ b/openpilot/sunnypilot/sunnylink/athena/sunnylinkd.py @@ -28,7 +28,6 @@ from websocket import (ABNF, WebSocket, WebSocketException, WebSocketTimeoutExce create_connection, WebSocketConnectionClosedException) import openpilot.cereal.messaging as messaging -from openpilot.selfdrive.modeld.helpers import usbgpu_present from openpilot.sunnypilot.models.model_name import DEFAULT_MODEL, DEFAULT_BIG_MODEL from openpilot.sunnypilot.selfdrive.car.sync_sunnylink_params import update_car_list_param from openpilot.sunnypilot.sunnylink.api import SunnylinkApi @@ -182,10 +181,8 @@ def getParamsMetadata() -> str: schema = generate_schema() schema["capabilities"] = generate_capabilities() schema["capability_labels"] = CAPABILITY_LABELS - # mirrors get_default_model() — ui_state unavailable in sunnylinkd process - show_big = (usbgpu_present() - and (params.get_bool("UsbGpuActive") or params.get_bool("UsbGpuLoading") or params.get_bool("IsOffroad"))) - schema["default_model"] = DEFAULT_BIG_MODEL if show_big else DEFAULT_MODEL + schema["default_model"] = DEFAULT_MODEL + schema["default_big_model"] = DEFAULT_BIG_MODEL schema["usbgpu_active"] = params.get_bool("UsbGpuActive") raw = json.dumps(schema, separators=(",", ":")).encode("utf-8") return base64.b64encode(gzip.compress(raw)).decode("utf-8")