From dd53c5d65d5dc643b032ada8fc1ed3caba4cd729 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 21 Jan 2025 10:40:01 -0500 Subject: [PATCH] write to params for controls --- common/params.cc | 3 +++ selfdrive/car/card.py | 6 ++++++ selfdrive/controls/controlsd.py | 8 ++++++-- selfdrive/selfdrived/selfdrived.py | 11 +++++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/params.cc b/common/params.cc index 82bce27d0c..989c8e1a90 100644 --- a/common/params.cc +++ b/common/params.cc @@ -202,6 +202,9 @@ std::unordered_map keys = { // --- sunnypilot params --- // {"ApiCache_DriveStats", PERSISTENT}, + {"CarParamsSP", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION}, + {"CarParamsSPCache", CLEAR_ON_MANAGER_START}, + {"CarParamsSPPersistent", PERSISTENT}, {"EnableGithubRunner", PERSISTENT | BACKUP}, {"ModelRunnerTypeCache", CLEAR_ON_ONROAD_TRANSITION}, {"OffroadMode", CLEAR_ON_MANAGER_START}, diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 16ca81f39b..959ecc567d 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -169,6 +169,12 @@ class Car: self.params.put_nonblocking("CarParamsCache", cp_bytes) self.params.put_nonblocking("CarParamsPersistent", cp_bytes) + # Write CarParamsSP for controls + cp_sp_bytes = self.CP_SP.to_bytes() + self.params.put("CarParamsSP", cp_sp_bytes) + self.params.put_nonblocking("CarParamsSPCache", cp_sp_bytes) + self.params.put_nonblocking("CarParamsSPPersistent", cp_sp_bytes) + self.mock_carstate = MockCarState() self.v_cruise_helper = VCruiseHelper(self.CP) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index ba09841381..dea22fb3e7 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -2,7 +2,7 @@ import math from typing import SupportsFloat -from cereal import car, log +from cereal import car, log, custom import cereal.messaging as messaging from openpilot.common.conversions import Conversions as CV from openpilot.common.params import Params @@ -34,7 +34,11 @@ class Controls: self.CP = messaging.log_from_bytes(self.params.get("CarParams", block=True), car.CarParams) cloudlog.info("controlsd got CarParams") - self.CI = get_car_interface(self.CP) + cloudlog.info("controlsd is waiting for CarParamsSP") + self.CP_SP = messaging.log_from_bytes(self.params.get("CarParamsSP", block=True), custom.CarParamsSP) + cloudlog.info("controlsd got CarParamsSP") + + self.CI = get_car_interface(self.CP, self.CP_SP) self.sm = messaging.SubMaster(['liveParameters', 'liveTorqueParameters', 'modelV2', 'selfdriveState', 'liveCalibration', 'livePose', 'longitudinalPlan', 'carState', 'carOutput', diff --git a/selfdrive/selfdrived/selfdrived.py b/selfdrive/selfdrived/selfdrived.py index 1c669621af..9136d7b1bc 100755 --- a/selfdrive/selfdrived/selfdrived.py +++ b/selfdrive/selfdrived/selfdrived.py @@ -5,7 +5,7 @@ import threading import cereal.messaging as messaging -from cereal import car, log +from cereal import car, log, custom from msgq.visionipc import VisionIpcClient, VisionStreamType from panda import ALTERNATIVE_EXPERIENCE @@ -47,7 +47,7 @@ IGNORED_SAFETY_MODES = (SafetyModel.silent, SafetyModel.noOutput) class SelfdriveD(CruiseHelper): - def __init__(self, CP=None): + def __init__(self, CP=None, CP_SP=None): self.params = Params() # Ensure the current branch is cached, otherwise the first cycle lags @@ -60,6 +60,13 @@ class SelfdriveD(CruiseHelper): else: self.CP = CP + if CP_SP is None: + cloudlog.info("controlsd is waiting for CarParamsSP") + self.CP_SP = messaging.log_from_bytes(self.params.get("CarParamsSP", block=True), custom.CarParamsSP) + cloudlog.info("controlsd got CarParamsSP") + else: + self.CP_SP = CP_SP + self.car_events = CarSpecificEvents(self.CP) self.disengage_on_accelerator = not (self.CP.alternativeExperience & ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS)