Compare commits

...

3 Commits

Author SHA1 Message Date
discountchubbs 89881bd50b 6d42b5fc5ac6292796a204ff2288fe04/6000 2026-12-02 08:06:07 -08: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
5 changed files with 31 additions and 4 deletions
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:962396e7909556af6a9c7bfb7ad6db01a8d2c8da0760379eb71efda004cb3548
size 69699272
oid sha256:546ae4ccc03b1ef7cf08c971eb78a8ae46976d79078e5296e49a466736ed3773
size 89833676
+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
@@ -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)