Files
StarPilot/sunnypilot/selfdrive/controls/lib/latcontrol_torque_ext_override.py
Jason Wen de64b99740 Torque Lateral Control: customized settings (#1314)
* init

* use internal frame

* exit early if toggle not enabled

* ui init

* ui: replace `static_cast<int>` with `std::nearbyint` for precise rounding

* revert

* update title

* handle live relaxed

* fix

* tweak ui

* toggle behaviors

* lint

* Update torqued_ext.py

* always update

* make sure it's updated properly with offroad states

* fix

* make sure to initialize

---------

Co-authored-by: nayan <nayan8teen@gmail.com>
2025-10-05 23:41:31 -04:00

35 lines
1.2 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.
"""
from openpilot.common.params import Params
class LatControlTorqueExtOverride:
def __init__(self, CP):
self.CP = CP
self.params = Params()
self.enforce_torque_control_toggle = self.params.get_bool("EnforceTorqueControl") # only during init
self.torque_override_enabled = self.params.get_bool("TorqueParamsOverrideEnabled")
self.frame = -1
def update_override_torque_params(self, torque_params) -> bool:
if not self.enforce_torque_control_toggle:
return False
self.frame += 1
if self.frame % 300 == 0:
self.torque_override_enabled = self.params.get_bool("TorqueParamsOverrideEnabled")
if not self.torque_override_enabled:
return False
torque_params.latAccelFactor = float(self.params.get("TorqueParamsOverrideLatAccelFactor", return_default=True))
torque_params.friction = float(self.params.get("TorqueParamsOverrideFriction", return_default=True))
return True
return False