Compare commits

..

2 Commits

Author SHA1 Message Date
Jason Wen 41e044d654 Merge branch 'master' into nnlc-own-pid 2026-11-29 22:04:19 -05:00
Jason Wen 7fde95c2e4 NNLC: keep own PID in torque extension 2026-11-29 01:27:31 -05:00
4 changed files with 16 additions and 7 deletions
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:546ae4ccc03b1ef7cf08c971eb78a8ae46976d79078e5296e49a466736ed3773
size 89833676
oid sha256:962396e7909556af6a9c7bfb7ad6db01a8d2c8da0760379eb71efda004cb3548
size 69699272
@@ -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