Files
openpilot-evo/sunnypilot/selfdrive/controls/controlsd_ext.py
T
Jason Wen 0c506c868d Controls: Pause lateral control based on blinker state and vehicle speed (#983)
* Controls: Pause lateral control based on blinker state and vehicle speed

* in its own module

* tests

* cleanup tests

* ui

* always refresh on show panel

* remove default

* change to 20 default

* need to update params live

* shorter

* off by default

* lol lint

* use ExpandableToggleRow

* not needed

* shorter

* ci ui preview delay for all offroad

* more

* Revert "more"

This reverts commit 809cfd99dac4183e318f3f7dff8e7c14f8223d62.

* Revert "ci ui preview delay for all offroad"

This reverts commit ab38292fa84165081e32fcfc7b44f7f7afdfe791.

---------

Co-authored-by: nayan8teen <nayan8teen@gmail.com>
2025-06-05 00:21:58 -04:00

68 lines
2.3 KiB
Python

"""
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
import cereal.messaging as messaging
from cereal import custom
from opendbc.car import structs
from openpilot.common.params import Params
from openpilot.common.swaglog import cloudlog
from openpilot.sunnypilot.selfdrive.controls.lib.param_store import ParamStore
from openpilot.sunnypilot.selfdrive.controls.lib.blinker_pause_lateral import BlinkerPauseLateral
class ControlsExt:
def __init__(self, CP: structs.CarParams, params: Params):
self.CP = CP
self.params = params
self.blinker_pause_lateral = BlinkerPauseLateral()
self.param_store = ParamStore(self.CP)
self.get_params_sp()
cloudlog.info("controlsd_ext is waiting for CarParamsSP")
self.CP_SP = messaging.log_from_bytes(params.get("CarParamsSP", block=True), custom.CarParamsSP)
cloudlog.info("controlsd_ext got CarParamsSP")
self.sm_services_ext = ['selfdriveStateSP']
self.pm_services_ext = ['carControlSP']
def get_params_sp(self) -> None:
self.param_store.update(self.params)
self.blinker_pause_lateral.get_params()
def get_lat_active(self, sm: messaging.SubMaster) -> bool:
if self.blinker_pause_lateral.update(sm['carState']):
return False
ss_sp = sm['selfdriveStateSP']
if ss_sp.mads.available:
return bool(ss_sp.mads.active)
# MADS not available, use stock state to engage
return bool(sm['selfdriveState'].active)
def state_control_ext(self, sm: messaging.SubMaster) -> custom.CarControlSP:
CC_SP = custom.CarControlSP.new_message()
# MADS state
CC_SP.mads = sm['selfdriveStateSP'].mads
CC_SP.params = self.param_store.publish()
return CC_SP
@staticmethod
def publish_ext(CC_SP: custom.CarControlSP, sm: messaging.SubMaster, pm: messaging.PubMaster) -> None:
cc_sp_send = messaging.new_message('carControlSP')
cc_sp_send.valid = sm['carState'].canValid
cc_sp_send.carControlSP = CC_SP
pm.send('carControlSP', cc_sp_send)
def run_ext(self, sm: messaging.SubMaster, pm: messaging.PubMaster) -> None:
CC_SP = self.state_control_ext(sm)
self.publish_ext(CC_SP, sm, pm)