mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-09 00:43:43 +08:00
7461f70fdb
# Conflicts: # README.md # SConstruct # conftest.py # docs/CARS.md # msgq_repo # opendbc_repo # openpilot/common/params_keys.h # openpilot/common/params_pyx.pyx # openpilot/common/tests/test_swaglog.cc # openpilot/selfdrive/car/card.py # openpilot/selfdrive/car/tests/test_car_interfaces.py # openpilot/selfdrive/car/tests/test_cruise_speed.py # openpilot/selfdrive/car/tests/test_models.py # openpilot/selfdrive/controls/controlsd.py # openpilot/selfdrive/controls/lib/latcontrol_torque.py # openpilot/selfdrive/controls/lib/longitudinal_planner.py # openpilot/selfdrive/controls/plannerd.py # openpilot/selfdrive/controls/radard.py # openpilot/selfdrive/controls/tests/test_longcontrol.py # openpilot/selfdrive/locationd/torqued.py # openpilot/selfdrive/modeld/modeld.py # openpilot/selfdrive/monitoring/dmonitoringd.py # openpilot/selfdrive/monitoring/test_monitoring.py # openpilot/selfdrive/selfdrived/selfdrived.py # openpilot/selfdrive/selfdrived/tests/test_alertmanager.py # openpilot/selfdrive/test/longitudinal_maneuvers/plant.py # openpilot/selfdrive/test/process_replay/migration.py # openpilot/selfdrive/test/process_replay/process_replay.py # openpilot/selfdrive/ui/feedback/feedbackd.py # openpilot/selfdrive/ui/layouts/settings/device.py # openpilot/selfdrive/ui/layouts/settings/toggles.py # openpilot/selfdrive/ui/mici/layouts/onboarding.py # openpilot/selfdrive/ui/onroad/augmented_road_view.py # openpilot/selfdrive/ui/tests/test_soundd.py # openpilot/selfdrive/ui/translations/app.pot # openpilot/selfdrive/ui/translations/app_de.po # openpilot/selfdrive/ui/translations/app_en.po # openpilot/selfdrive/ui/translations/app_es.po # openpilot/selfdrive/ui/translations/app_fr.po # openpilot/selfdrive/ui/translations/app_ja.po # openpilot/selfdrive/ui/translations/app_ko.po # openpilot/selfdrive/ui/translations/app_pt-BR.po # openpilot/selfdrive/ui/translations/app_th.po # openpilot/selfdrive/ui/translations/app_tr.po # openpilot/selfdrive/ui/translations/app_uk.po # openpilot/selfdrive/ui/translations/app_zh-CHS.po # openpilot/selfdrive/ui/translations/app_zh-CHT.po # openpilot/system/athena/athenad.py # openpilot/system/hardware/hardwared.py # openpilot/system/loggerd/deleter.py # openpilot/system/manager/process_config.py # openpilot/system/ui/lib/application.py # panda # pyproject.toml # tinygrad_repo # uv.lock
85 lines
3.9 KiB
Python
85 lines
3.9 KiB
Python
import os
|
|
|
|
from openpilot.common.test import OpenpilotTestCase
|
|
from openpilot.common.parameterized import parameterized
|
|
from openpilot.common.fuzzy import capnp_random_dict, fuzzy_test
|
|
|
|
from openpilot.cereal import custom
|
|
from opendbc.car.structs import car
|
|
from opendbc.car import DT_CTRL
|
|
from opendbc.car.car_helpers import interfaces
|
|
from opendbc.car.fingerprints import FW_VERSIONS
|
|
from opendbc.car.fw_versions import FW_QUERY_CONFIGS
|
|
from opendbc.car.structs import CarParams
|
|
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.sunnypilot.selfdrive.car import interfaces as sunnypilot_interfaces
|
|
|
|
MAX_EXAMPLES = int(os.environ.get('MAX_EXAMPLES', '60'))
|
|
ALL_ECUS = tuple(sorted({ecu for ecus in FW_VERSIONS.values() for ecu in ecus} |
|
|
{ecu for config in FW_QUERY_CONFIGS.values() for ecu in config.extra_ecus}))
|
|
ALL_REQUESTS = tuple(sorted({tuple(request.request) for config in FW_QUERY_CONFIGS.values() for request in config.requests}))
|
|
DLC_TO_LEN = (0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64)
|
|
|
|
|
|
class TestCarInterfaces(OpenpilotTestCase):
|
|
@parameterized.expand([(car,) for car in sorted(PLATFORMS)] + [MOCK.MOCK], ids=lambda car_name: car_name)
|
|
@fuzzy_test(max_examples=60)
|
|
def test_car_interfaces(self, car_name, fuzzy):
|
|
fingerprint = dict(fuzzy.list(lambda: (fuzzy.integer(0, 0x800), fuzzy.choice(DLC_TO_LEN))))
|
|
fingerprints = dict.fromkeys(range(7), fingerprint)
|
|
|
|
def generate_car_fw():
|
|
ecu, address, sub_address = fuzzy.choice(ALL_ECUS)
|
|
return CarParams.CarFw(ecu=ecu, address=address, subAddress=sub_address or 0, request=fuzzy.choice(ALL_REQUESTS))
|
|
|
|
CarInterface = interfaces[car_name]
|
|
car_fw = fuzzy.list(generate_car_fw)
|
|
alpha_long = fuzzy.boolean()
|
|
car_params = CarInterface.get_params(car_name, fingerprints, car_fw,
|
|
alpha_long=alpha_long, is_release=False, docs=False)
|
|
car_params_sp = CarInterface.get_params_sp(car_params, car_name, fingerprints, car_fw,
|
|
alpha_long=alpha_long, is_release_sp=False, docs=False)
|
|
car_interface = CarInterface(car_params, car_params_sp)
|
|
car_params = car_interface.CP.as_reader()
|
|
car_params_sp = car_interface.CP_SP
|
|
sunnypilot_interfaces.setup_interfaces(car_interface)
|
|
|
|
cc_msg = capnp_random_dict(fuzzy, car.CarControl.schema, real_floats=True)
|
|
cc_sp_msg = capnp_random_dict(fuzzy, custom.CarControlSP.schema, 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
|
|
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)
|