mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-14 19:43:50 +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
71 lines
3.1 KiB
Python
71 lines
3.1 KiB
Python
import os
|
|
import hypothesis.strategies as st
|
|
from hypothesis import Phase, given, settings
|
|
from openpilot.common.parameterized import parameterized
|
|
|
|
from openpilot.cereal import custom
|
|
from opendbc.car.structs import car
|
|
from opendbc.car import DT_CTRL
|
|
from opendbc.car.structs import CarParams
|
|
from opendbc.car.tests.test_car_interfaces import get_fuzzy_car_interface
|
|
from opendbc.car.mock.values import CAR as MOCK
|
|
from opendbc.car.values import PLATFORMS
|
|
from openpilot.selfdrive.car.helpers import convert_carControlSP
|
|
from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle
|
|
from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID
|
|
from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque
|
|
from openpilot.selfdrive.controls.lib.longcontrol import LongControl
|
|
from openpilot.selfdrive.test.fuzzy_generation import FuzzyGenerator
|
|
|
|
from openpilot.sunnypilot.selfdrive.car import interfaces as sunnypilot_interfaces
|
|
|
|
MAX_EXAMPLES = int(os.environ.get('MAX_EXAMPLES', '60'))
|
|
|
|
|
|
class TestCarInterfaces:
|
|
# FIXME: Due to the lists used in carParams, Phase.target is very slow and will cause
|
|
# many generated examples to overrun when max_examples > ~20, don't use it
|
|
@parameterized.expand([(car,) for car in sorted(PLATFORMS)] + [MOCK.MOCK])
|
|
@settings(max_examples=MAX_EXAMPLES, deadline=None,
|
|
phases=(Phase.reuse, Phase.generate, Phase.shrink))
|
|
@given(data=st.data())
|
|
def test_car_interfaces(self, car_name, data):
|
|
car_interface = get_fuzzy_car_interface(car_name, data.draw)
|
|
car_params = car_interface.CP.as_reader()
|
|
car_params_sp = car_interface.CP_SP
|
|
sunnypilot_interfaces.setup_interfaces(car_interface)
|
|
|
|
cc_msg = FuzzyGenerator.get_random_msg(data.draw, car.CarControl, real_floats=True)
|
|
cc_sp_msg = FuzzyGenerator.get_random_msg(data.draw, custom.CarControlSP, real_floats=True)
|
|
# Run car interface
|
|
now_nanos = 0
|
|
CC = car.CarControl.new_message(**cc_msg)
|
|
CC = CC.as_reader()
|
|
CC_SP = custom.CarControlSP.new_message(**cc_sp_msg)
|
|
CC_SP = convert_carControlSP(CC_SP.as_reader())
|
|
for _ in range(10):
|
|
car_interface.update([])
|
|
car_interface.apply(CC, CC_SP, now_nanos)
|
|
now_nanos += DT_CTRL * 1e9 # 10 ms
|
|
|
|
CC = car.CarControl.new_message(**cc_msg)
|
|
CC.enabled = True
|
|
CC.latActive = True
|
|
CC.longActive = True
|
|
CC = CC.as_reader()
|
|
for _ in range(10):
|
|
car_interface.update([])
|
|
car_interface.apply(CC, CC_SP, now_nanos)
|
|
now_nanos += DT_CTRL * 1e9 # 10ms
|
|
|
|
# Test controller initialization
|
|
# TODO: wait until card refactor is merged to run controller a few times,
|
|
# hypothesis also slows down significantly with just one more message draw
|
|
LongControl(car_params, car_params_sp)
|
|
if car_params.steerControlType == CarParams.SteerControlType.angle:
|
|
LatControlAngle(car_params, car_params_sp, car_interface, DT_CTRL)
|
|
elif car_params.lateralTuning.which() == 'pid':
|
|
LatControlPID(car_params, car_params_sp, car_interface, DT_CTRL)
|
|
elif car_params.lateralTuning.which() == 'torque':
|
|
LatControlTorque(car_params, car_params_sp, car_interface, DT_CTRL)
|