84 lines
3.7 KiB
Python
84 lines
3.7 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
|
|
|
|
|
|
def test_clearance_potential_spans_the_local_intent_horizon(configured):
|
|
configure, inputs, robot = configured
|
|
config = configure(inputs, robot)
|
|
for name in ('global_costmap', 'local_costmap'):
|
|
grid = config[name][name]['ros__parameters']
|
|
layer = grid['inflation_layer']
|
|
assert layer['inflation_radius'] >= 3.5
|
|
# The native exponential must still distinguish the middle of a
|
|
# passage from its edge well outside the hard collision reserve.
|
|
cost = lambda d: 252*math.exp(-layer['cost_scaling_factor']*d)
|
|
assert cost(1.) > cost(2.) > cost(3.) > 1.
|
|
assert grid['footprint_padding'] == .05 and grid['track_unknown_space']
|
|
|
|
|
|
def test_simulation_clock_reaches_every_native_node_and_costmap(configured):
|
|
configure, inputs, robot = configured
|
|
config = configure(inputs, robot, use_sim_time=True)
|
|
for name in ('planner_server', 'controller_server', 'behavior_server'):
|
|
assert config[name]['ros__parameters']['use_sim_time'] is True
|
|
for name in ('global_costmap', 'local_costmap'):
|
|
assert config[name][name]['ros__parameters']['use_sim_time'] is True
|