Compare commits

..

3 Commits

Author SHA1 Message Date
Jason Wen 717d416f07 bump opendbc 2026-12-01 17:30:32 -05:00
Jason Wen 80293608fa Merge master into esc-long-tune 2026-11-29 20:07:58 -05:00
discountchubbs d9ac2c89f7 Hyundai: ESC longitudinal tune 2026-11-23 10:58:27 -08:00
8 changed files with 20 additions and 66 deletions
+1 -1
View File
@@ -238,7 +238,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"BackupManager_RestoreVersion", {PERSISTENT, STRING}},
// sunnypilot car specific params
{"HyundaiLongitudinalTuning", {PERSISTENT | BACKUP, INT, "0"}},
{"HyundaiLongitudinalTuning", {PERSISTENT | BACKUP, BOOL, "0"}},
{"SubaruStopAndGo", {PERSISTENT | BACKUP, BOOL, "0"}},
{"SubaruStopAndGoManualParkingBrake", {PERSISTENT | BACKUP, BOOL, "0"}},
{"TeslaCoopSteering", {PERSISTENT | BACKUP, BOOL, "0"}},
@@ -7,7 +7,7 @@ See the LICENSE.md file in the root directory for more details.
from openpilot.selfdrive.ui.sunnypilot.layouts.settings.vehicle.brands.base import BrandSettings
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.sunnypilot.widgets.list_view import multiple_button_item_sp
from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp
from opendbc.car.hyundai.values import CAR, UNSUPPORTED_LONGITUDINAL_CAR
@@ -16,16 +16,9 @@ class HyundaiSettings(BrandSettings):
super().__init__()
self.alpha_long_available = False
tuning_texts = [tr("Off"), tr("Dynamic"), tr("Predictive")]
self.longitudinal_tuning_item = multiple_button_item_sp(tr("Custom Longitudinal Tuning"), "", tuning_texts,
button_width=300, callback=self._on_tuning_selected,
param="HyundaiLongitudinalTuning", inline=False)
self.longitudinal_tuning_item = toggle_item_sp(tr("Custom Longitudinal Tuning"), "", param="HyundaiLongitudinalTuning")
self.items = [self.longitudinal_tuning_item]
@staticmethod
def _on_tuning_selected(index):
ui_state.params.put("HyundaiLongitudinalTuning", index)
def update_settings(self):
self.alpha_long_available = False
bundle = ui_state.params.get("CarPlatformBundle")
@@ -35,25 +28,14 @@ class HyundaiSettings(BrandSettings):
elif ui_state.CP is not None:
self.alpha_long_available = ui_state.CP.alphaLongitudinalAvailable
tuning_param = int(ui_state.params.get("HyundaiLongitudinalTuning") or "0")
long_enabled = ui_state.has_longitudinal_control
desc = tr("Accelerates and brakes the way your car's own cruise control does.")
if not ui_state.is_offroad():
desc = tr("This feature is unavailable while the car is onroad.")
elif not long_enabled:
desc = tr("This feature is unavailable because sunnypilot Longitudinal Control (Alpha) is not enabled.")
long_tuning_descs = [
tr("Your vehicle will use the Default longitudinal tuning."),
tr("Your vehicle will use the Dynamic longitudinal tuning."),
tr("Your vehicle will use the Predictive longitudinal tuning."),
]
long_tuning_desc = long_tuning_descs[tuning_param] if tuning_param < len(long_tuning_descs) else long_tuning_descs[0]
longitudinal_tuning_disabled = not ui_state.is_offroad() or not long_enabled
if longitudinal_tuning_disabled:
if not ui_state.is_offroad():
long_tuning_desc = tr("This feature is unavailable while the car is onroad.")
elif not long_enabled:
long_tuning_desc = tr("This feature is unavailable because sunnypilot Longitudinal Control (Alpha) is not enabled.")
self.longitudinal_tuning_item.action_item.set_enabled(not longitudinal_tuning_disabled)
self.longitudinal_tuning_item.set_description(long_tuning_desc)
self.longitudinal_tuning_item.action_item.set_enabled(ui_state.is_offroad() and long_enabled)
self.longitudinal_tuning_item.set_description(desc)
self.longitudinal_tuning_item.show_description(True)
self.longitudinal_tuning_item.action_item.set_selected_button(tuning_param)
self.longitudinal_tuning_item.set_visible(self.alpha_long_available)
@@ -18,6 +18,7 @@ class LatControlTorqueExt(NeuralNetworkLateralControl, LatControlTorqueExtOverri
desired_lateral_accel, actual_lateral_accel, lateral_accel_deadzone, gravity_adjusted_lateral_accel,
desired_curvature, actual_curvature, steer_limited_by_safety, output_torque):
self._ff = ff
self._pid = pid
self._pid_log = pid_log
self._setpoint = setpoint
self._measurement = measurement
@@ -63,7 +63,7 @@ class LatControlTorqueExtBase:
self.torque_params = lac_torque.torque_params
self._ff = 0.0
self._pid = PIDController(KP, KI, pos_limit=lac_torque.steer_max, neg_limit=-lac_torque.steer_max, rate=1 / lac_torque.dt)
self._pid = PIDController(KP, KI)
self._pid_log = log.ControlsState.LateralTorqueState.new_message()
self._setpoint = 0.0
self._measurement = 0.0
@@ -4,7 +4,6 @@ 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 math
import numpy as np
from openpilot.cereal import log, messaging
@@ -60,9 +59,9 @@ def _make_model_v2():
return model
def _run_update(controller, VM, v_ego=30, desired_curvature=0.5):
def _run_update(controller, VM):
CS = car.CarState.new_message()
CS.vEgo = v_ego
CS.vEgo = 30
CS.steeringPressed = False
lp = generate_deviceMotion()
pose = Pose.from_device_motion(lp.deviceMotion)
@@ -70,7 +69,7 @@ def _run_update(controller, VM, v_ego=30, desired_curvature=0.5):
model_v2 = _make_model_v2().modelV2
controller.extension.update_model_v2(model_v2)
controller.extension.update_lateral_lag(0.2)
return controller.update(True, CS, VM, params, False, desired_curvature, pose, False, 0.2)
return controller.update(True, CS, VM, params, False, 0.5, pose, False, 0.2)
class TestLatControlTorqueExt(OpenpilotTestCase):
@@ -108,12 +107,3 @@ class TestLatControlTorqueExt(OpenpilotTestCase):
controller, VM, _ = _make_controller(enhanced=True, nnlc=True)
output_torque, _, pid_log = _run_update(controller, VM)
assert pid_log.active
def test_low_speed_gain_bounded(self):
for kwargs in ({"nnlc": True}, {"enhanced": True}):
controller, VM, _ = _make_controller(**kwargs)
one_degree = -VM.calc_curvature(math.radians(1.0), 2.0, 0.0)
output_torque, _, _ = _run_update(controller, VM, v_ego=2.0, desired_curvature=one_degree)
assert controller.extension._nnlc_enabled or controller.extension._jerk_aware_enabled
assert controller.extension._pid is not controller.pid
assert abs(output_torque) < 0.3, kwargs
@@ -2186,22 +2186,9 @@
"items": [
{
"key": "HyundaiLongitudinalTuning",
"widget": "multiple_button",
"widget": "toggle",
"title": "Custom Longitudinal Tuning",
"options": [
{
"value": 0,
"label": "Off"
},
{
"value": 1,
"label": "Dynamic"
},
{
"value": 2,
"label": "Predictive"
}
],
"description": "Accelerates and brakes the way your car's own cruise control does.",
"visibility": [
{
"type": "capability",
@@ -11,15 +11,9 @@ sections:
description: ''
items:
- key: HyundaiLongitudinalTuning
widget: multiple_button
widget: toggle
title: Custom Longitudinal Tuning
options:
- value: 0
label: 'Off'
- value: 1
label: Dynamic
- value: 2
label: Predictive
description: Accelerates and brakes the way your car's own cruise control does.
visibility:
- type: capability
field: hyundai_alpha_long_available