feat(simulation): add Worker AI polygon runtime and terrain navigation
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""The actuator may soften acceleration but must never prolong a safety command."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"motion_control", Path(__file__).parents[1] / "simulation/ai-polygon/motion_control.py"
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
|
||||
def test_slow_perception_keeps_continuous_physics_command():
|
||||
drive = module.DriveEnvelope()
|
||||
rows = [drive.step(0.15, 0, 1 / 60)[0] for _ in range(180)]
|
||||
assert rows[0] == pytest.approx(0.2 / 60)
|
||||
assert all(0 <= b - a <= 0.2 / 60 + 1e-9 for a, b in zip(rows, rows[1:], strict=False))
|
||||
assert rows[44:] == pytest.approx([0.15] * 136)
|
||||
|
||||
|
||||
def test_braking_and_deadman_bypass_ramp():
|
||||
drive = module.DriveEnvelope()
|
||||
for _ in range(60):
|
||||
drive.step(0.15, 0, 1 / 60)
|
||||
assert drive.step(0.03, 0, 1 / 60) == (0.03, 0)
|
||||
assert drive.step(0.15, 0.2, 1 / 60, stop=True) == (0, 0)
|
||||
assert drive.wheels == (0, 0)
|
||||
assert drive.step(0.15, 0, 1 / 60)[0] == pytest.approx(0.2 / 60)
|
||||
|
||||
|
||||
def test_curvature_and_direction_change():
|
||||
drive = module.DriveEnvelope()
|
||||
for _ in range(60):
|
||||
speed, yaw = drive.step(0.15, 0.2, 1 / 60)
|
||||
assert yaw / speed == pytest.approx(0.2 / 0.15)
|
||||
speed, yaw = drive.step(-0.15, -0.2, 1 / 60)
|
||||
assert speed < 0 and yaw < 0
|
||||
assert max(map(abs, drive.wheels)) <= 0.2 / 60 + 1e-9
|
||||
Reference in New Issue
Block a user