mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-03 06:33:50 +08:00
38 lines
1.3 KiB
Python
38 lines
1.3 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, 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_safety, desired_curvature, curvature_limited, llk, model_data, frogpilot_toggles):
|
|
pass
|
|
|
|
def reset(self):
|
|
self.sat_count = 0.
|
|
|
|
def _check_saturation(self, saturated, CS, steer_limited_by_safety, curvature_limited):
|
|
# Treat either controller saturation, curvature limiting, or the safety layer
|
|
# clamping the request as a saturation event. The additional safety check
|
|
# catches cases where the torque request is being clipped
|
|
saturated = saturated or curvature_limited or steer_limited_by_safety
|
|
|
|
if saturated and CS.vEgo > self.sat_check_min_speed 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)
|