|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
import argparse |
|
|
|
|
import random |
|
|
|
|
import unittest |
|
|
|
|
from parameterized import parameterized, parameterized_class |
|
|
|
|
from selfdrive.car.hyundai.values import CarControllerParams |
|
|
|
|
# from selfdrive.car.hyundai.values import CarControllerParams |
|
|
|
|
import importlib |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from cereal import car |
|
|
|
@ -25,17 +27,19 @@ jerks = defaultdict(dict) |
|
|
|
|
class TestLateralLimits(unittest.TestCase): |
|
|
|
|
@classmethod |
|
|
|
|
def setUpClass(cls): |
|
|
|
|
# TODO: remove these once it works with all platforms |
|
|
|
|
if not cls.car_model.startswith(('KIA', 'HYUNDAI', 'GENESIS')): |
|
|
|
|
raise unittest.SkipTest |
|
|
|
|
|
|
|
|
|
# if not cls.car_model.startswith('KIA EV6'): |
|
|
|
|
# raise unittest.SkipTest |
|
|
|
|
|
|
|
|
|
CarInterface, _, _ = interfaces[cls.car_model] |
|
|
|
|
CP = CarInterface.get_params(cls.car_model) |
|
|
|
|
# TODO: just make all CCPs take CarParams |
|
|
|
|
|
|
|
|
|
if CP.dashcamOnly: |
|
|
|
|
raise unittest.SkipTest("Platform is behind dashcamOnly") |
|
|
|
|
|
|
|
|
|
# TODO: test these |
|
|
|
|
if CP.carName in ("honda", "nissan", "body"): |
|
|
|
|
raise unittest.SkipTest("No steering safety") |
|
|
|
|
|
|
|
|
|
CarControllerParams = importlib.import_module(f'selfdrive.car.{CP.carName}.values').CarControllerParams |
|
|
|
|
cls.control_params = CarControllerParams(CP) |
|
|
|
|
|
|
|
|
|
cls.torque_params = get_torque_params(cls.car_model) |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
@ -47,19 +51,28 @@ class TestLateralLimits(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
def _calc_jerk(self): |
|
|
|
|
# TODO: some cars don't send at 100hz, put steer rate/step into CCP to calculate this properly |
|
|
|
|
time_to_max = self.control_params.STEER_MAX / self.control_params.STEER_DELTA_UP / 100. |
|
|
|
|
time_to_min = self.control_params.STEER_MAX / self.control_params.STEER_DELTA_DOWN / 100. |
|
|
|
|
# TODO: fix this |
|
|
|
|
max_lat_accel = (self.torque_params['LAT_ACCEL_FACTOR'] + self.torque_params['MAX_LAT_ACCEL_MEASURED']) / 2. |
|
|
|
|
steer_step = self.control_params.STEER_STEP |
|
|
|
|
time_to_max = self.control_params.STEER_MAX / self.control_params.STEER_DELTA_UP / 100. * steer_step |
|
|
|
|
time_to_min = self.control_params.STEER_MAX / self.control_params.STEER_DELTA_DOWN / 100. * steer_step |
|
|
|
|
max_lat_accel = self.torque_params['LAT_ACCEL_FACTOR'] |
|
|
|
|
|
|
|
|
|
return max_lat_accel / time_to_max, max_lat_accel / time_to_min |
|
|
|
|
|
|
|
|
|
def test_something(self): |
|
|
|
|
def test_jerk_limits(self): |
|
|
|
|
up_jerk, down_jerk = self._calc_jerk() |
|
|
|
|
jerks[self.car_model] = {"up_jerk": up_jerk, "down_jerk": down_jerk} |
|
|
|
|
# self.assertLess(up_jerk, 2.0) |
|
|
|
|
# self.assertLess(down_jerk, 2.5) |
|
|
|
|
self.assertLess(up_jerk, 2.5) |
|
|
|
|
# self.assertGreater(down_jerk, 2.0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
unittest.main() |
|
|
|
|
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
|
|
|
|
parser.add_argument("--print-jerks", action="store_true", help="Print theoretical max lateral jerk values for all platforms") |
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
if args.print_jerks: |
|
|
|
|
# TODO: would be nice to support this |
|
|
|
|
pass |
|
|
|
|
else: |
|
|
|
|
unittest.main() |
|
|
|
|