Files
MoreTore/selfdrive/controls/tests/test_following_distance.py
T
HaraldSchafer 0b87a4ddb1 More conservative lead policy in e2e long mode (#25684)
* Add params for lead and danger

* fix long params

* E2e passes simple maneuver tests

* Make tests run with e2e long mode

* Slightly more error allowed in e2e mode

* FCW back and populate long source field

* Fix planner name

* FCW still doesnt work

* Slightly less aggressive

* Doesn't need to simulate from stop
old-commit-hash: 7899fb79c1
2022-09-06 21:52:34 -07:00

42 lines
1.2 KiB
Python

#!/usr/bin/env python3
import unittest
import numpy as np
from common.params import Params
from selfdrive.controls.lib.longitudinal_mpc_lib.long_mpc import desired_follow_distance
from selfdrive.test.longitudinal_maneuvers.maneuver import Maneuver
def run_following_distance_simulation(v_lead, t_end=100.0, e2e=False):
man = Maneuver(
'',
duration=t_end,
initial_speed=float(v_lead),
lead_relevancy=True,
initial_distance_lead=100,
speed_lead_values=[v_lead],
breakpoints=[0.],
e2e=e2e
)
valid, output = man.evaluate()
assert valid
return output[-1,2] - output[-1,1]
class TestFollowingDistance(unittest.TestCase):
def test_following_distance(self):
params = Params()
for e2e in [False, True]:
params.put_bool("EndToEndLong", e2e)
for speed in np.arange(0, 40, 5):
print(f'Testing {speed} m/s')
v_lead = float(speed)
simulation_steady_state = run_following_distance_simulation(v_lead)
correct_steady_state = desired_follow_distance(v_lead, v_lead)
err_ratio = 0.2 if e2e else 0.1
self.assertAlmostEqual(simulation_steady_state, correct_steady_state, delta=(err_ratio * correct_steady_state + .5))
if __name__ == "__main__":
unittest.main()