mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-12-02 05:23:43 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41e044d654 | |||
| 7fde95c2e4 |
+1
-1
Submodule opendbc_repo updated: 5e123e2af5...07fb3ab9bc
@@ -238,7 +238,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"BackupManager_RestoreVersion", {PERSISTENT, STRING}},
|
||||
|
||||
// sunnypilot car specific params
|
||||
{"HyundaiLongitudinalTuning", {PERSISTENT | BACKUP, BOOL, "0"}},
|
||||
{"HyundaiLongitudinalTuning", {PERSISTENT | BACKUP, INT, "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 toggle_item_sp
|
||||
from openpilot.system.ui.sunnypilot.widgets.list_view import multiple_button_item_sp
|
||||
from opendbc.car.hyundai.values import CAR, UNSUPPORTED_LONGITUDINAL_CAR
|
||||
|
||||
|
||||
@@ -16,9 +16,16 @@ class HyundaiSettings(BrandSettings):
|
||||
super().__init__()
|
||||
self.alpha_long_available = False
|
||||
|
||||
self.longitudinal_tuning_item = toggle_item_sp(tr("Custom Longitudinal Tuning"), "", param="HyundaiLongitudinalTuning")
|
||||
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.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")
|
||||
@@ -28,14 +35,25 @@ 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.")
|
||||
|
||||
self.longitudinal_tuning_item.action_item.set_enabled(ui_state.is_offroad() and long_enabled)
|
||||
self.longitudinal_tuning_item.set_description(desc)
|
||||
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.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,7 +18,6 @@ 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)
|
||||
self._pid = PIDController(KP, KI, pos_limit=lac_torque.steer_max, neg_limit=-lac_torque.steer_max, rate=1 / lac_torque.dt)
|
||||
self._pid_log = log.ControlsState.LateralTorqueState.new_message()
|
||||
self._setpoint = 0.0
|
||||
self._measurement = 0.0
|
||||
|
||||
@@ -4,6 +4,7 @@ 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
|
||||
@@ -59,9 +60,9 @@ def _make_model_v2():
|
||||
return model
|
||||
|
||||
|
||||
def _run_update(controller, VM):
|
||||
def _run_update(controller, VM, v_ego=30, desired_curvature=0.5):
|
||||
CS = car.CarState.new_message()
|
||||
CS.vEgo = 30
|
||||
CS.vEgo = v_ego
|
||||
CS.steeringPressed = False
|
||||
lp = generate_deviceMotion()
|
||||
pose = Pose.from_device_motion(lp.deviceMotion)
|
||||
@@ -69,7 +70,7 @@ def _run_update(controller, VM):
|
||||
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, 0.5, pose, False, 0.2)
|
||||
return controller.update(True, CS, VM, params, False, desired_curvature, pose, False, 0.2)
|
||||
|
||||
|
||||
class TestLatControlTorqueExt(OpenpilotTestCase):
|
||||
@@ -107,3 +108,12 @@ 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,9 +2186,22 @@
|
||||
"items": [
|
||||
{
|
||||
"key": "HyundaiLongitudinalTuning",
|
||||
"widget": "toggle",
|
||||
"widget": "multiple_button",
|
||||
"title": "Custom Longitudinal Tuning",
|
||||
"description": "Accelerates and brakes the way your car's own cruise control does.",
|
||||
"options": [
|
||||
{
|
||||
"value": 0,
|
||||
"label": "Off"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"label": "Dynamic"
|
||||
},
|
||||
{
|
||||
"value": 2,
|
||||
"label": "Predictive"
|
||||
}
|
||||
],
|
||||
"visibility": [
|
||||
{
|
||||
"type": "capability",
|
||||
|
||||
@@ -11,9 +11,15 @@ sections:
|
||||
description: ''
|
||||
items:
|
||||
- key: HyundaiLongitudinalTuning
|
||||
widget: toggle
|
||||
widget: multiple_button
|
||||
title: Custom Longitudinal Tuning
|
||||
description: Accelerates and brakes the way your car's own cruise control does.
|
||||
options:
|
||||
- value: 0
|
||||
label: 'Off'
|
||||
- value: 1
|
||||
label: Dynamic
|
||||
- value: 2
|
||||
label: Predictive
|
||||
visibility:
|
||||
- type: capability
|
||||
field: hyundai_alpha_long_available
|
||||
|
||||
Reference in New Issue
Block a user