Files
NODEDC_MISSION_CORE/tests/test_nav2_configuration.py
T
DCCONSTRUCTIONS 6a89f809a4 fix(simulation): bound Nav2 heading discretization by rover geometry
Use pinned Smac Hybrid with a geometry-derived angular grid so rectangular starts are not rejected by coarse lattice headings. Keep the full padded footprint, unknown-space veto, TTLs, and native controller/behavior ownership.

Validated on the same archived costmap, five native pass/block scenarios, HTTP/PCL/Nav2 lifecycle and rear-obstacle checks, and 12 CPU tests. Original-route live check moved 20.13 m before its fixed wall budget; the 30 m integration criterion and full-route acceptance remain open.
2026-10-08 13:07:24 +03:00

61 lines
2.6 KiB
Python

"""Planner geometry is bounded by the rig and grid, independent of mission coordinates."""
import copy
import importlib.util
import json
import math
from pathlib import Path
import pytest
from k1link.simulation.ai_polygon.robots import select_robot
from k1link.simulation.ai_polygon.run_inputs import digest, legacy_run_inputs, mounted_run_inputs
@pytest.fixture
def configured(monkeypatch):
root = Path(__file__).parents[1] / "simulation/ai-polygon"
monkeypatch.syspath_prepend(str(root))
spec = importlib.util.spec_from_file_location(
"nav2_configuration", root / "nav2/configuration.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
robot = select_robot("dcd006-v020")
run = {"request": {}, "plan": None, "world": {"settings": {
"camera_height_m": 0.8, "max_speed_mps": 0.15, "route_xy": [[2., 0.]]}}}
inputs = mounted_run_inputs(legacy_run_inputs(run, robot), robot)
return module.configuration, inputs, robot
def test_heading_floor_moves_every_padded_corner_less_than_half_a_cell(configured):
configure, inputs, robot = configured
config = configure(inputs, robot)
grid = config["global_costmap"]["global_costmap"]["ros__parameters"]
planner = config["planner_server"]["ros__parameters"]["GridBased"]
bins = planner["angle_quantization_bins"]
step = 2 * math.pi / bins
assert bins % 4 == 0
# Evaluate actual rotated corner coordinates, including near-bin boundaries.
for x, y in json.loads(grid["footprint"]):
x += math.copysign(grid["footprint_padding"], x)
y += math.copysign(grid["footprint_padding"], y)
for index in range(bins):
for fraction in (0., .25, .5, .999999):
actual = (index + fraction) * step
snapped = index * step
def rotate(a, x=x, y=y):
return x * math.cos(a) - y * math.sin(a), x * math.sin(a) + y * math.cos(a)
assert math.dist(rotate(actual), rotate(snapped)) <= grid["resolution"] / 2
assert grid["footprint_padding"] == .05
assert not planner["allow_unknown"]
assert planner["tolerance"] == 0.
assert planner["max_planning_time"] == .5
def test_mission_translation_rotation_and_endpoint_do_not_change_navigation_config(configured):
configure, inputs, robot = configured
original = configure(inputs, robot)
changed = copy.deepcopy(inputs)
changed["mission"]["route_xy"] = [[-500., 700.], [-503., 702.]]
changed["sha256"] = digest({k: v for k, v in changed.items() if k != "sha256"})
assert configure(changed, robot) == original