import importlib import math from pathlib import Path import pytest @pytest.fixture def rig(monkeypatch): monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon")) return importlib.import_module("control_qualification") def test_arrival_reference_point_does_not_guarantee_full_body_support(rig): g = dict(length_m=1.163, width_m=0.905) lane = [-2, -0.5, 2, 0.5] assert rig.goal_body_supported([0, 0], 0, [0, 0], g, lane) assert not rig.goal_body_supported([0, 0], math.pi / 2, [0, 0], g, lane) assert not rig.goal_body_supported([0.2, 0], 0, [0, 0], g, [-0.6, -0.5, 0.6, 0.5]) assert not rig.goal_body_supported([0.401, 0], 0, [0, 0], g, [-2, -2, 2, 2]) assert rig.goal_body_supported([0.399, 0], math.pi / 3, [0, 0], g, [-2, -2, 2, 2]) def test_matrix_is_bounded_and_covers_speed_load_and_friction(rig): cases = rig.specifications() assert len(cases) == len({c["id"] for c in cases}) == 12 assert {c["speed_mps"] for c in cases} == {0.1, 0.2, 0.3} assert {c["payload_kg"] for c in cases} == {0, 30} assert {c["dynamic_friction"] for c in cases} == {0.35, 0.8} assert sum(p[1] for p in rig.PHASES) < 70 def test_stationary_motor_targets_cannot_pass_a_sliding_body(rig): rows = [ dict( phase="stop", phase_seconds=(i + 1) / 60, dt=1 / 60, request=[0, 0], nominal=[0, 0], distance_step_m=0.1 / 60, turn_step_rad=0, position=[i * 0.1 / 60, 0], velocity=[0.1, 0, 0], forward_mps=0.1, yaw_rps=0, acceleration_mps2=0, held_sides=[True, True], ) for i in range(180) ] m = rig.phase_metrics(rows) assert not m["passed"] and not m["checks"]["hold_speed"] assert m["stopping_time_s"] is None and m["stopping_distance_m"] is None def test_pivot_position_uses_excursion_not_accumulated_path(rig): rows = [ dict( phase="pivot", phase_seconds=(i + 1) / 60, dt=1 / 60, request=[0, 0.35], nominal=[0, 0.35], distance_step_m=0.002, turn_step_rad=0.35 / 60, position=[0.1 * math.sin(i * 0.04), 0.1 * (1 - math.cos(i * 0.04))], phase_origin=[0, 0], velocity=[0.1, 0, 0], forward_mps=0, yaw_rps=0.35, acceleration_mps2=0, held_sides=[False, False], ) for i in range(360) ] result = rig.phase_metrics(rows) assert result["distance_m"] > 0.3 assert result["maximum_displacement_m"] < 0.21 and result["checks"]["pivot_position"]