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.
This commit is contained in:
@@ -46,10 +46,15 @@ def configuration(inputs, robot):
|
||||
inflation_layer=dict(plugin='nav2_costmap_2d::InflationLayer',
|
||||
cost_scaling_factor=3.0, inflation_radius=math.hypot(x, y) + 0.15),
|
||||
)
|
||||
# The upstream differential primitives include pure rotation. They are
|
||||
# geometrical candidates; the drive/support/freshness gates remain required.
|
||||
lattice = ('/opt/ndc_nav2/install/nav2_smac_planner/share/nav2_smac_planner/'
|
||||
'sample_primitives/5cm_resolution/0.5m_turning_radius/diff/output.json')
|
||||
# Bound the corner displacement from a full angular bin to half a map
|
||||
# cell. Humble floors the start heading; a coarse primitive lattice can
|
||||
# classify an actually clear rectangular start as colliding. Hybrid-A*
|
||||
# exposes angular resolution without generating custom motion primitives.
|
||||
# Round to quarter-turn symmetry, independent of world coordinates.
|
||||
radius = math.hypot(x + costmap['footprint_padding'],
|
||||
y + costmap['footprint_padding'])
|
||||
angle_step = 2 * math.asin(min(1.0, costmap['resolution'] / (4 * radius)))
|
||||
heading_bins = max(8, 4 * math.ceil((2 * math.pi / angle_step) / 4))
|
||||
return {
|
||||
'behavior_server': {'ros__parameters': dict(
|
||||
use_sim_time=False, global_frame='map', robot_base_frame='base_link',
|
||||
@@ -65,11 +70,15 @@ def configuration(inputs, robot):
|
||||
)},
|
||||
'planner_server': {'ros__parameters': dict(
|
||||
use_sim_time=False, expected_planner_frequency=5.0, planner_plugins=['GridBased'],
|
||||
GridBased=dict(plugin='nav2_smac_planner/SmacPlannerLattice',
|
||||
lattice_filepath=lattice, allow_unknown=False,
|
||||
GridBased=dict(plugin='nav2_smac_planner/SmacPlannerHybrid',
|
||||
motion_model_for_search='DUBIN',
|
||||
# Retain the former differential lattice's 0.5 m
|
||||
# minimum arc radius; explicit Spin/BackUp stay
|
||||
# separate native behaviors behind unchanged gates.
|
||||
minimum_turning_radius=0.5,
|
||||
angle_quantization_bins=heading_bins, allow_unknown=False,
|
||||
tolerance=0.0, max_planning_time=0.5,
|
||||
allow_reverse_expansion=False, cache_obstacle_heuristic=False,
|
||||
smooth_path=False),
|
||||
cache_obstacle_heuristic=False, smooth_path=False),
|
||||
)},
|
||||
'controller_server': {'ros__parameters': dict(
|
||||
use_sim_time=False, controller_frequency=20.0, odom_topic='/odom',
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user