mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-24 09:52:05 +08:00
14318d2f09
# Conflicts: # .github/labeler.yaml # .github/workflows/auto_pr_review.yaml # .github/workflows/docs.yaml # .github/workflows/release.yaml # .github/workflows/repo-maintenance.yaml # .github/workflows/tests.yaml # .github/workflows/ui_preview.yaml # README.md # SConstruct # conftest.py # docs/CARS.md # msgq_repo # opendbc_repo # openpilot/cereal/messaging/tests/validate_sp_cereal_upstream.py # openpilot/common/api.py # openpilot/common/hardware/hw.py # openpilot/common/version.py # openpilot/selfdrive/assets/fonts/Audiowide-Regular.ttf # openpilot/selfdrive/assets/sounds/prompt_single_high.wav # openpilot/selfdrive/assets/sounds/prompt_single_low.wav # openpilot/selfdrive/car/card.py # openpilot/selfdrive/car/helpers.py # openpilot/selfdrive/car/tests/test_car_interfaces.py # openpilot/selfdrive/car/tests/test_cruise_speed.py # openpilot/selfdrive/controls/lib/desire_helper.py # openpilot/selfdrive/controls/lib/longcontrol.py # openpilot/selfdrive/controls/plannerd.py # openpilot/selfdrive/controls/radard.py # openpilot/selfdrive/controls/tests/test_longcontrol.py # openpilot/selfdrive/modeld/compile_warp.py # openpilot/selfdrive/modeld/modeld.py # openpilot/selfdrive/monitoring/policy.py # openpilot/selfdrive/monitoring/test_monitoring.py # openpilot/selfdrive/selfdrived/events.py # openpilot/selfdrive/selfdrived/selfdrived.py # openpilot/selfdrive/ui/layouts/onboarding.py # openpilot/selfdrive/ui/mici/layouts/onboarding.py # openpilot/selfdrive/ui/soundd.py # openpilot/selfdrive/ui/tests/diff/replay.py # openpilot/selfdrive/ui/translations/app.pot # openpilot/system/athena/athenad.py # openpilot/system/athena/manage_athenad.py # openpilot/system/hardware/hardwared.py # openpilot/system/loggerd/config.py # openpilot/system/manager/github_runner.sh # openpilot/system/manager/manager.py # openpilot/system/updated/updated.py # panda # pyproject.toml # scripts/lint/lint.sh # system/manager/process_config.py # system/statsd.py # tinygrad_repo # tools/release/build_release.sh # tools/release/build_stripped.sh # uv.lock
38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
import math
|
|
|
|
from openpilot.cereal import log
|
|
from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
|
|
|
# TODO This is speed dependent
|
|
STEER_ANGLE_SATURATION_THRESHOLD = 2.5 # Degrees
|
|
|
|
|
|
class LatControlAngle(LatControl):
|
|
def __init__(self, CP, CP_SP, CI, dt):
|
|
super().__init__(CP, CP_SP, CI, dt)
|
|
self.sat_check_min_speed = 5.
|
|
self.use_steer_limited_by_safety = CP.brand in ("tesla", "hyundai")
|
|
|
|
def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, calibrated_pose, curvature_limited, lat_delay):
|
|
angle_log = log.ControlsState.LateralAngleState.new_message()
|
|
|
|
if not active:
|
|
angle_log.active = False
|
|
angle_steers_des = float(CS.steeringAngleDeg)
|
|
else:
|
|
angle_log.active = True
|
|
angle_steers_des = math.degrees(VM.get_steer_from_curvature(-desired_curvature, CS.vEgo, params.roll))
|
|
angle_steers_des += params.angleOffsetDeg
|
|
|
|
if self.use_steer_limited_by_safety:
|
|
# these cars' carcontrollers calculate max lateral accel and jerk, so we can rely on carOutput for saturation
|
|
angle_control_saturated = steer_limited_by_safety
|
|
else:
|
|
# for cars which use a method of limiting torque such as a torque signal (Nissan and Toyota)
|
|
# or relying on EPS (Ford Q3), carOutput does not capture maxing out torque # TODO: this can be improved
|
|
angle_control_saturated = abs(angle_steers_des - CS.steeringAngleDeg) > STEER_ANGLE_SATURATION_THRESHOLD
|
|
angle_log.saturated = bool(self._check_saturation(angle_control_saturated, CS, False, curvature_limited))
|
|
angle_log.steeringAngleDeg = float(CS.steeringAngleDeg)
|
|
angle_log.steeringAngleDesiredDeg = angle_steers_des
|
|
return 0, float(angle_steers_des), angle_log
|