adapt to upstream

This commit is contained in:
infiniteCable2
2025-08-11 16:24:01 +02:00
parent af18e76252
commit 42ab8b14e4
2 changed files with 37 additions and 40 deletions

View File

@@ -14,17 +14,9 @@ DT_CTRL = 0.01 # car state and control loop timestep (s)
# kg of standard extra cargo to count for drive, gas, etc...
STD_CARGO_KG = 136.
ACCELERATION_DUE_TO_GRAVITY = 9.81 # m/s^2
ISO_LATERAL_ACCEL = 3.0 # ISO 11270
ISO_LATERAL_JERK = 5.0 # ISO 11270
ButtonType = structs.CarState.ButtonEvent.Type
@dataclass
class CurvatureSteeringLimits:
CURVATURE_MAX: float
def apply_hysteresis(val: float, val_steady: float, hyst_gap: float) -> float:
if val > val_steady + hyst_gap:
val_steady = val - hyst_gap
@@ -99,38 +91,6 @@ class Bus(StrEnum):
ap_party = auto()
def apply_std_curvature_limits(apply_curvature: float, apply_curvature_last: float, v_ego: float, roll: float, curvature: float,
steer_step: int, lat_active: bool, limits: CurvatureSteeringLimits) -> Tuple[float, bool]:
new_apply_curvature = apply_curvature
# ISO 11270
# Lateral jerk
ts_elapsed = steer_step * DT_CTRL
curvature_rate_limit = ISO_LATERAL_JERK / (max(v_ego, 1.0) ** 2)
curvature_up = apply_curvature_last + curvature_rate_limit * ts_elapsed
curvature_down = apply_curvature_last - curvature_rate_limit * ts_elapsed
new_apply_curvature = float(np.clip(new_apply_curvature, curvature_down, curvature_up))
# Lateral acceleration
# roll is passed to panda via custom Panda Data CAN message for internal usage only (not sent to car)
max_lat_accel = ISO_LATERAL_ACCEL - (roll * ACCELERATION_DUE_TO_GRAVITY)
min_lat_accel = -ISO_LATERAL_ACCEL - (roll * ACCELERATION_DUE_TO_GRAVITY)
max_curvature = max_lat_accel / (max(v_ego, 1.0) ** 2)
min_curvature = min_lat_accel / (max(v_ego, 1.0) ** 2)
new_apply_curvature = float(np.clip(new_apply_curvature, min_curvature, max_curvature))
# set output curvature as current curvature (if otherwise set to 0 in car controller)
if not lat_active:
new_apply_curvature = curvature
iso_limit_active = not (min_curvature <= new_apply_curvature <= max_curvature)
return float(np.clip(new_apply_curvature, -limits.CURVATURE_MAX, limits.CURVATURE_MAX)), iso_limit_active
def rate_limit(new_value, last_value, dw_step, up_step):
return float(np.clip(new_value, last_value + dw_step, last_value + up_step))