mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-23 17:33:55 +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>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import numpy as np
|
|
from abc import abstractmethod, ABC
|
|
|
|
from openpilot.common.realtime import DT_CTRL
|
|
|
|
MIN_LATERAL_CONTROL_SPEED = 0.3 # m/s
|
|
|
|
|
|
class LatControl(ABC):
|
|
def __init__(self, CP, CP_SP, CI):
|
|
self.sat_count_rate = 1.0 * DT_CTRL
|
|
self.sat_limit = CP.steerLimitTimer
|
|
self.sat_count = 0.
|
|
self.sat_check_min_speed = 10.
|
|
|
|
# we define the steer torque scale as [-1.0...1.0]
|
|
self.steer_max = 1.0
|
|
|
|
@abstractmethod
|
|
def update(self, active, CS, VM, params, steer_limited_by_controls, desired_curvature, calibrated_pose, curvature_limited):
|
|
pass
|
|
|
|
def reset(self):
|
|
self.sat_count = 0.
|
|
|
|
def _check_saturation(self, saturated, CS, steer_limited_by_controls, curvature_limited):
|
|
# Saturated only if control output is not being limited by car torque/angle rate limits
|
|
if (saturated or curvature_limited) and CS.vEgo > self.sat_check_min_speed and not steer_limited_by_controls and not CS.steeringPressed:
|
|
self.sat_count += self.sat_count_rate
|
|
else:
|
|
self.sat_count -= self.sat_count_rate
|
|
self.sat_count = np.clip(self.sat_count, 0.0, self.sat_limit)
|
|
return self.sat_count > (self.sat_limit - 1e-3)
|