Compare commits

...

4 Commits

Author SHA1 Message Date
Jason Wen 80293608fa Merge master into esc-long-tune 2026-11-29 20:07:58 -05:00
James Vecellio-Grant 1d8788e9d5 bug: camera offset migration from old branches (#2127) 2026-11-29 15:57:23 -05:00
Jason Wen 5966b94504 pandad: wait for non-empty CarParams (#2126) 2026-11-29 10:51:59 -05:00
discountchubbs d9ac2c89f7 Hyundai: ESC longitudinal tune 2026-11-23 10:58:27 -08:00
9 changed files with 44 additions and 54 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 -1
View File
@@ -52,7 +52,13 @@ std::vector<std::string> PandaSafety::fetchCarParams() {
if (!params_.getBool("ControlsReady")) {
return {};
}
return {params_.get("CarParams"), params_.get("CarParamsSP")};
std::string car_params = params_.get("CarParams");
std::string car_params_sp = params_.get("CarParamsSP");
if (car_params.empty() || car_params_sp.empty()) {
return {};
}
return {car_params, car_params_sp};
}
// TODO-SP: Use structs instead of vector
@@ -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)
@@ -8,6 +8,8 @@ import numpy as np
from openpilot.common.transformations.camera import DEVICE_CAMERAS
MAX_CAMERA_OFFSET = 0.35 # m, the settings' range
class CameraOffsetHelper:
def __init__(self):
@@ -34,6 +36,13 @@ class CameraOffsetHelper:
def set_offset(self, offset):
self.camera_offset = offset
def load_offset(self, params):
offset = params.get("CameraOffset", return_default=True)
if offset is None or not np.isfinite(offset) or abs(offset) > MAX_CAMERA_OFFSET + 1e-6: # older sunnypilot stored whole centimeters
offset = 0.0
params.put("CameraOffset", offset)
self.set_offset(offset)
def update(self, model_transform_main, model_transform_extra, sm, main_wide_camera):
self.actual_camera_offset = (0.9 * self.actual_camera_offset) + (0.1 * self.camera_offset)
dc = DEVICE_CAMERAS[(str(sm['deviceState'].deviceType), str(sm['narrowRoadCameraState'].sensor))]
+1 -1
View File
@@ -424,7 +424,7 @@ def main(demo=False):
if sm.frame % 60 == 0:
model.lat_delay = get_lat_delay(params, sm["lateralDelay"].lateralDelay)
model.PLANPLUS_CONTROL = params.get("PlanplusControl", return_default=True)
camera_offset_helper.set_offset(params.get("CameraOffset", return_default=True))
camera_offset_helper.load_offset(params)
blendful_enabled = params.get_bool("Blendful")
lat_delay = model.lat_delay + model.LAT_SMOOTH_SECONDS
if sm.updated["extrinsicsCalibration"] and sm.seen['narrowRoadCameraState'] and sm.seen['deviceState']:
@@ -27,6 +27,18 @@ class TestCameraOffset(OpenpilotTestCase):
self.camera_offset = CameraOffsetHelper()
self.dc = DEVICE_CAMERAS[('mici', 'os04c10')]
def test_load_offset_resets_out_of_range(self):
class Params:
def __init__(self, v): self.v = v
def get(self, key, return_default=False): return self.v
def put(self, key, v): self.v = v
for stored, used in ((0.2, 0.2), (-0.35, -0.35), (4.0, 0.0), (-35.0, 0.0), (float('nan'), 0.0), (None, 0.0)):
params = Params(stored)
self.camera_offset.load_offset(params)
assert self.camera_offset.camera_offset == used
assert params.v == (stored if used == stored else 0.0)
def test_smoothing(self):
self.camera_offset.set_offset(0.2)
@@ -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