mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-21 22:23:53 +08:00
* init * more init * keep it alive * fixes * more fixes * more fix * new submodule for nn data * bump submodule * update path to submodule * spacing??? * update submodule path * update submodule path * bump * dump * bump * introduce params * Add Neural Network Lateral Control toggle to developer panel This introduces a new toggle for enabling Neural Network Lateral Control (NNLC), providing detailed descriptions of its functionality and compatibility. It includes UI integration, car compatibility checks, and feedback links for unsupported vehicles. * decouple even more * static * codespell * remove debug * in structs * fix import * convert to capnp * fixes * debug * only initialize if NNLC is enabled or allow to enable * oops * fix initialization * only allow engage if nnlc is off * fix toggle param * fix tests * lint * fix more test * capnp test * try this out * validate if it's not None * make it 33 to match * align * share the same friction input calculation * return stock values if not enabled * unused * split base and child * space * rename * NeuralNetworkFeedForwardModel * less * just use file name * try this * more explicit * rename * move it * child class for additional controllers * rename * time to split out custom lateral acceleration * move around * space * fix * TODO-SP * TODO-SP * split nnlc and custom lat accel * more * not yet * comment * fix --------- Co-authored-by: DevTekVE <devtekve@gmail.com>
49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
import math
|
|
|
|
from cereal import log
|
|
from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
|
from openpilot.common.pid import PIDController
|
|
|
|
|
|
class LatControlPID(LatControl):
|
|
def __init__(self, CP, CP_SP, CI):
|
|
super().__init__(CP, CP_SP, CI)
|
|
self.pid = PIDController((CP.lateralTuning.pid.kpBP, CP.lateralTuning.pid.kpV),
|
|
(CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV),
|
|
k_f=CP.lateralTuning.pid.kf, pos_limit=self.steer_max, neg_limit=-self.steer_max)
|
|
self.get_steer_feedforward = CI.get_steer_feedforward_function()
|
|
|
|
def reset(self):
|
|
super().reset()
|
|
self.pid.reset()
|
|
|
|
def update(self, active, CS, VM, params, steer_limited_by_controls, desired_curvature, calibrated_pose, curvature_limited):
|
|
pid_log = log.ControlsState.LateralPIDState.new_message()
|
|
pid_log.steeringAngleDeg = float(CS.steeringAngleDeg)
|
|
pid_log.steeringRateDeg = float(CS.steeringRateDeg)
|
|
|
|
angle_steers_des_no_offset = math.degrees(VM.get_steer_from_curvature(-desired_curvature, CS.vEgo, params.roll))
|
|
angle_steers_des = angle_steers_des_no_offset + params.angleOffsetDeg
|
|
error = angle_steers_des - CS.steeringAngleDeg
|
|
|
|
pid_log.steeringAngleDesiredDeg = angle_steers_des
|
|
pid_log.angleError = error
|
|
if not active:
|
|
output_steer = 0.0
|
|
pid_log.active = False
|
|
self.pid.reset()
|
|
else:
|
|
# offset does not contribute to resistive torque
|
|
steer_feedforward = self.get_steer_feedforward(angle_steers_des_no_offset, CS.vEgo)
|
|
|
|
output_steer = self.pid.update(error, override=CS.steeringPressed,
|
|
feedforward=steer_feedforward, speed=CS.vEgo)
|
|
pid_log.active = True
|
|
pid_log.p = float(self.pid.p)
|
|
pid_log.i = float(self.pid.i)
|
|
pid_log.f = float(self.pid.f)
|
|
pid_log.output = float(output_steer)
|
|
pid_log.saturated = bool(self._check_saturation(self.steer_max - abs(output_steer) < 1e-3, CS, steer_limited_by_controls, curvature_limited))
|
|
|
|
return output_steer, angle_steers_des, pid_log
|