Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
32eb04e
Autonomous: add rules-compliant autocross course generation
tanushchauhan Nov 3, 2026
835aa75
Autonomous: add fixed extreme autocross scenarios
tanushchauhan Nov 3, 2026
80c716c
Autonomous: import audited AMZ competition cone layouts
tanushchauhan Nov 7, 2026
a5a2f73
Merge main into competition layout imports
tanushchauhan Nov 12, 2026
142eb3a
Audit imported gate geometry before smoothing
tanushchauhan Nov 12, 2026
ae6399e
Merge main into extreme autocross scenarios
tanushchauhan Nov 12, 2026
2edc1e7
Keep extreme gate rows on the current sensor stack
tanushchauhan Nov 12, 2026
ac251be
Merge remote-tracking branch 'origin/main' into tanush/competition-la…
tanushchauhan Nov 16, 2026
ff35ee3
Fix imported-course campaign planning and noisy geometry audits
tanushchauhan Nov 16, 2026
343c3f2
Integrate competition layouts and pin extreme-course review regressions
tanushchauhan Nov 16, 2026
c1bf194
Test the narrow-course road clearance instead of cone-pair separation
tanushchauhan Nov 16, 2026
dea7f99
Space extreme-course cones by boundary arc and preserve complete appr…
tanushchauhan Nov 16, 2026
80f4bbd
Merge main into competition track layouts
tanushchauhan Nov 20, 2026
9e76ef6
Update the extreme autocross base branch
tanushchauhan Nov 20, 2026
3a9e68e
Pin extreme course widths and cone density
tanushchauhan Nov 20, 2026
93f23ea
Reconcile extreme autocross with merged competition tracks
tanushchauhan Nov 20, 2026
a5379ae
Assign distinct IMU seeds to fixed-course gate runs
tanushchauhan Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions autonomy/ros2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ launch lists what it takes:
./scripts/run_gazebo_demo.sh perception:=lidar estimator:=ekf safety:=true # trip the mission on stack faults (lhr_safety)
```

The `track_style` argument selects a generator (`oval`, `autocross`, `rules_autocross`, `acceleration` or `simple`) or a fixed imported layout (`amz_fsg`, `amz_fsi`). Imports use seed 1 and require acknowledgement of their envelope flags; see [competition layouts](src/lhr_gazebo/worlds/competition/README.md). The world SDF is auto-resolved from `track_style` + `seed` (e.g. `oval_seed1.sdf`). Pre-generated worlds are installed by colcon from `worlds/*.sdf`: `autocross_seed1` to `seed5` (the MVP gate's seeds), `oval_seed1` and `acceleration_seed1`. The acceleration layout ignores the seed and always runs the acceleration mission; `mission:=acceleration` on any other track is an error. A missing world is an error that names the generate command, never a substitute world. `simple` has no pre-generated world, so run `./scripts/generate_gazebo_world.sh --style simple --seed 1` and rebuild first. Acceleration is Gazebo-only for now: `mvs_demo.launch.py` neither forces the mission nor gives the track builder the course's pairing width ([lhr_demo](src/lhr_demo/README.md)).
The `track_style` argument selects a generator (`oval`, `autocross`, `rules_autocross`, `acceleration` or `simple`) or a fixed layout. The seven [extreme courses](src/lhr_gazebo/worlds/README.md#extreme-autocross-set) are `extreme_narrow`, `extreme_hairpin`, `extreme_decreasing`, `extreme_slalom_chicane`, `extreme_doubleback`, `extreme_500m` and `extreme_combined`. They use seed 1, as do `amz_fsg` and `amz_fsi`. Imports use seed 1 and require acknowledgement of their envelope flags; see [competition layouts](src/lhr_gazebo/worlds/competition/README.md). The world SDF is auto-resolved from `track_style` + `seed` (e.g. `oval_seed1.sdf`). Pre-generated worlds are installed by colcon from `worlds/*.sdf`: `autocross_seed1` to `seed5` (the MVP gate's seeds), `oval_seed1`, `acceleration_seed1` and one world per extreme and imported layout. The acceleration layout ignores the seed and always runs the acceleration mission; `mission:=acceleration` on any other track is an error. A missing world is an error that names the generate command, never a substitute world. `simple` has no pre-generated world, so run `./scripts/generate_gazebo_world.sh --style simple --seed 1` and rebuild first. Acceleration is Gazebo-only for now: `mvs_demo.launch.py` neither forces the mission nor gives the track builder the course's pairing width ([lhr_demo](src/lhr_demo/README.md)).

The track builder's eight chaining parameters are also launch arguments in
both `perception:=sim` and `perception:=lidar`: `chaining_alg`, `min_step_m`,
Expand Down Expand Up @@ -624,7 +624,7 @@ With `enable_stereo_camera:=true`, Gazebo adds static transforms from
| `seed` | `1` | Random seed for track generation |
| `frame_id` | `"map"` | TF frame |
| `publish_hz` | `5.0` | Publishing rate (Hz) |
| `track_style` | `"autocross"` | Generator or fixed import: `rules_autocross`, `amz_fsg`, `amz_fsi`, `autocross` (Catmull-Rom spline), `simple` (original oval), `oval` (dedicated oval generator), or `acceleration` (fixed rules layout: 75 m start to finish, 4.9 m clear between cone bases, large orange cones flanking both lines, a 75 m small-orange exit lane; only `cone_spacing_m` applies) |
| `track_style` | `"autocross"` | Generator or fixed layout: the seven `extreme_*` styles listed above, `rules_autocross`, `amz_fsg`, `amz_fsi`, `autocross` (Catmull-Rom spline), `simple` (original oval), `oval` (dedicated oval generator), or `acceleration` (fixed rules layout: 75 m start to finish, 4.9 m clear between cone bases, large orange cones flanking both lines, a 75 m small-orange exit lane; only `cone_spacing_m` applies) |
| `num_waypoints` | `10` | Number of waypoints around the loop (autocross only) |
| `radius_m` | `25.0` | Base radius of the track (autocross only) |
| `jitter_m` | `10.0` | Radial jitter per waypoint (autocross only) |
Expand Down
12 changes: 12 additions & 0 deletions autonomy/ros2/src/lhr_gazebo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ Metrics scores the actual world's paired centerline without a style-specific
route shortcut. These courses can expose failures in perception and planning;
passing the geometry checks does not imply the autonomy gate passes.

## Fixed extreme worlds

The [world catalog](worlds/README.md#extreme-autocross-set) provides seven
committed, rules-checked `extreme_*_seed1.sdf` scenes for #212. Select their
style directly through `track_style`; both perception branches retain the
same fixed scene and pairing width, and metrics uses that saved reference.
`generate_world.py --style <name>` regenerates each scene with ten-decimal
XY coordinates and validates its serialized geometry. Other styles retain
their prior precision. Rebuild after regeneration; freshness and geometry
checks run in `lhr_gazebo`'s tests. The catalog lists usage and the intended
failure modes; a valid scene is not a successful autonomy gate run.

## Imported competition worlds

`track_style:=amz_fsg` and `track_style:=amz_fsi` select fixed source layouts
Expand Down
18 changes: 16 additions & 2 deletions autonomy/ros2/src/lhr_gazebo/scripts/generate_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
sys.path.insert(0, _trackgen_pkg)

from lhr_trackgen.cone_geometry import CONE_SPECS # noqa: E402
from lhr_trackgen.extreme_autocross import extreme_spawn, SCENARIOS # noqa: E402
from lhr_trackgen.publish_cones import ( # noqa: E402
ACCEL_STAGING_M, cone_kinds, GENERATORS)
from lhr_trackgen.rules_autocross import check_envelope # noqa: E402

# Gazebo model for each lhr_trackgen cone kind (the CONE_SPECS keys).
CONE_MODELS = {
Expand All @@ -53,7 +55,7 @@ def _vehicle_nose_m() -> float:


def _cone_include(model_name: str, instance_name: str,
x: float, y: float, z: float, precision=4) -> str:
x: float, y: float, z: float, precision: int = 4) -> str:
"""Return an SDF <include> block for a cone."""
return textwrap.dedent(f"""\
<include>
Expand Down Expand Up @@ -107,7 +109,7 @@ def generate_world_sdf(
model_dir: str = '',
left_kinds=None,
right_kinds=None,
coordinate_precision=4,
coordinate_precision: int = 4,
) -> str:
"""Build a complete Gazebo world SDF string."""
# Auto-compute spawn from track geometry if not explicitly set
Expand Down Expand Up @@ -281,14 +283,26 @@ def main():
vy = 0.0 if vy is None else vy
vyaw = 0.0 if vyaw is None else vyaw

precision = 10 if args.style in SCENARIOS else 4
if args.style in SCENARIOS:
sx, sy, syaw = extreme_spawn(args.style)
vx = sx if vx is None else vx
vy = sy if vy is None else vy
vyaw = syaw if vyaw is None else vyaw
saved = [[[round(v, precision) for v in p] for p in side] for side in (left, right)]
print(f'Rules envelope: {check_envelope(*saved)}')

sdf = generate_world_sdf(
left, right,
vehicle_x=vx,
vehicle_y=vy,
vehicle_yaw=vyaw,
left_kinds=left_kinds,
right_kinds=right_kinds,
coordinate_precision=precision,
)
if args.style in SCENARIOS:
sdf = sdf.replace('-0.0000000000', '0.0000000000')

if args.output is None:
# Default output path relative to this script's parent (lhr_gazebo/)
Expand Down
190 changes: 190 additions & 0 deletions autonomy/ros2/src/lhr_gazebo/test/test_extreme_courses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
"""Keep saved edge-case worlds, launch branches and gate coverage consistent."""

import csv
import math
import os
from pathlib import Path
import subprocess
import xml.etree.ElementTree as ET

from launch import LaunchContext
from lhr_metrics.course import CourseEnvelope
from lhr_metrics.reference import (
CircuitProgress, paired_centerline, ReferenceTrack, world_geometry)
from lhr_track_builder.track_builder_node import TrackBuilder
from lhr_trackgen.extreme_autocross import generate_extreme_track, SCENARIOS
from lhr_trackgen.publish_cones import ConePublisher, GENERATORS, pairing_width_m
from lhr_trackgen.rules_autocross import check_envelope
from lhr_vehicle import load_vehicle
import pytest
from test_acceleration_event import _launch, _params
from test_gate_runner import gate_stack, runner_prefix
from test_launch_param_types import _start
from test_rules_autocross import load

PACKAGE = Path(__file__).parents[1]
TOOLS = Path(__file__).parents[4]/'testing/tools/gate'


@pytest.mark.parametrize('name', SCENARIOS)
def test_saved_world_is_current_legal_and_has_a_complete_reference(name, tmp_path):
committed = PACKAGE/f'worlds/{name}_seed1.sdf'
left, right, cones = world_geometry(committed)
report = check_envelope(left, right)
assert len(cones) == len(left)+len(right)
for side in (left, right):
gaps = [math.dist(a, b) for a, b in zip(side, side[1:]+side[:1])]
assert min(gaps) >= .5, f'{name}: overlapping or wall-like cone placement'
assert max(gaps) <= 2.01
expected = generate_extreme_track(name)
for actual_side, expected_side in zip((left, right), expected):
assert len(actual_side) == len(expected_side)
assert max(math.dist(a, b) for a, b in zip(actual_side, expected_side)) < 1e-8
if name in ('extreme_narrow', 'extreme_combined'):
assert 3 <= report['minimum_clear_width_m'] < 3.01
if name in ('extreme_hairpin', 'extreme_combined'):
assert report['longest_straight_m'] == pytest.approx(80., abs=1e-8)
assert report['minimum_radius_m'] == pytest.approx(4.5, abs=1e-8)
if name == 'extreme_500m':
assert 499.9999 < report['lap_length_m'] <= 500
# Regenerate through the public CLI, not just the in-memory helper.
output = tmp_path/'regenerated.sdf'
subprocess.run(['python3', str(PACKAGE/'scripts/generate_world.py'),
'--style', name, '--output', str(output)], check=True, capture_output=True)
regenerated = world_geometry(output)
assert output.read_text() == committed.read_text() # Include the saved vehicle spawn.
for actual_side, expected_side in zip(regenerated[:2], (left, right)):
assert len(actual_side) == len(expected_side)
assert max(math.dist(a, b) for a, b in zip(actual_side, expected_side)) < 1e-8
track = ReferenceTrack(paired_centerline(left, right))
progress = CircuitProgress(track)
completed = False
for i, (x, y) in enumerate(track.points+track.points[:2]):
completed |= progress.observe(x, y, i*.4, 5.)
assert completed
assert not progress.invalid_reason


@pytest.mark.parametrize('name', SCENARIOS)
@pytest.mark.parametrize('perception', ['sim', 'lidar'])
@pytest.mark.parametrize('estimator', ['truth', 'ekf'])
def test_fixed_style_reaches_both_perception_branches(monkeypatch, name, perception, estimator):
assert GENERATORS[name]() == generate_extreme_track(name)
context, nodes = _launch(monkeypatch, track_style=name, perception=perception,
estimator=estimator)
builder = _params(context, nodes, 'track_builder')
width = pairing_width_m(name)
assert builder['track_width'] == width
assert _start(TrackBuilder, builder, ['track_width'])['track_width'] == width
assert _params(context, nodes, 'metrics_node')['track_style'] == name
if perception == 'sim':
params = _params(context, nodes, 'publish_cones')
assert _start(ConePublisher, params, ['track_style'])['track_style'] == name
module = load('extreme_launch', PACKAGE/'launch/gazebo_demo.launch.py')
launch_context = LaunchContext()
launch_context.launch_configurations.update(track_style=name, seed='1')
assert Path(module._find_world(launch_context)).name == f'{name}_seed1.sdf'


def plan(tmp_path, extremes, **overrides):
script = runner_prefix()
env = dict(os.environ, SEEDS='', EXTREMES=extremes, REPEATS='2', BASELINE='1',
ACCEL_REPEATS='0', SKIDPAD_REPEATS='0', OUT=str(tmp_path))
env.update(overrides)
return subprocess.run(['bash', '-c', script+'\nSKIDPAD_WORLD=/missing\nplan'],
env=env, text=True, capture_output=True)


def test_gate_plans_all_cases_and_keeps_matching_baselines(tmp_path):
result = plan(tmp_path, 'all')
assert result.returncode == 0, result.stderr
lines = result.stdout.splitlines()
assert len(lines) == 2*len(SCENARIOS)
assert len({line.split()[0] for line in lines}) == len(lines)
for line in lines:
if 'perception:=lidar' in line:
args = dict(arg.split(':=', 1) for arg in line.split()[1:])
assert gate_stack().items() <= args.items()
else:
assert 'enable_stereo_camera:=false' in line
scorer = load('extreme_gate', TOOLS/'score_gate.py')
for name in SCENARIOS:
expected = [f'baseline_{name}_s1', f'{name}_s1_r1']
actual = [line.split()[0] for line in lines if f'track_style:={name} ' in line]
assert actual == expected
row = scorer.score(str(tmp_path/'missing'), expected[1])
assert row['event'] == 'autocross'
assert row['track_style'] == name
row.update(outcome='lap', stop_dist_m=1., finished=True, max_v_after_stop=0.,
max_cte=0., max_pos_error=0., off_track_count='0', cones_hit='0',
lap_time_s=100.)
scorer.judge(row, {(name, '1'): 100., ('autocross', '1'): 10.})
assert row['passed']
# Every named planned row must fail if a campaign never actually ran it.
(tmp_path/'expected.txt').write_text('\n'.join(line.split()[0] for line in lines))
assert scorer.main(str(tmp_path)) == 1
with (tmp_path/'results.csv').open() as stream:
rows = list(csv.DictReader(stream))
assert len(rows) == len(lines)
assert all(row['outcome'] == 'missing' for row in rows)
assert all(row['passed'] == 'False' for row in rows if row['kind'] == 'gate')


def test_gate_accepts_subsets_and_rejects_unknown_names(tmp_path):
subset = plan(tmp_path, 'extreme_hairpin extreme_500m')
assert subset.returncode == 0
assert len(subset.stdout.splitlines()) == 4
invalid = plan(tmp_path, 'extreme_typo')
assert invalid.returncode == 2
assert 'unsupported extreme' in invalid.stderr


@pytest.mark.parametrize('name', SCENARIOS)
def test_fixture_spawn_precedes_the_entire_approach(name):
left, right, cones = world_geometry(PACKAGE/f'worlds/{name}_seed1.sdf')
expected = [(a+b)/2 for a, b in zip(left[0], right[0])]
root = ET.parse(PACKAGE/f'worlds/{name}_seed1.sdf')
include = next(x for x in root.findall('world/include')
if x.findtext('uri') == 'model://fsae_vehicle')
spawn = [float(v) for v in include.findtext('pose').split()]
assert spawn[:2] == pytest.approx(expected, abs=1e-4)
assert spawn[5] == 0.
course = CourseEnvelope(left, right, cones, load_vehicle(), True)
assert course.pose_check(spawn[0], spawn[1], spawn[5]) == (False, set())


@pytest.mark.parametrize('repeats', ['-1', 'bad', '1.5'])
def test_bad_extreme_repeat_count_fails_before_planning(tmp_path, repeats):
result = plan(tmp_path, 'all', EXTREME_REPEATS=repeats)
assert result.returncode == 2
assert 'EXTREME_REPEATS' in result.stderr
assert result.stdout == ''


def test_explicit_extreme_repeats_are_independent_of_regular_repeats(tmp_path):
result = plan(tmp_path, 'extreme_hairpin', EXTREME_REPEATS='3', REPEATS='7')
assert result.returncode == 0
assert [line.split()[0] for line in result.stdout.splitlines()] == [
'baseline_extreme_hairpin_s1', *(f'extreme_hairpin_s1_r{i}' for i in (1, 2, 3))]


def test_extreme_and_imported_rows_preserve_later_events(tmp_path):
world = tmp_path/'skidpad.sdf'
world.touch()
env = dict(os.environ, SEEDS='', EXTREMES='extreme_hairpin',
REAL_TRACKS='amz_fsg amz_fsi', ALLOW_NONCOMPLIANT='1', BASELINE='1',
ACCEL_REPEATS='1', SKIDPAD_REPEATS='1', OUT=str(tmp_path))
result = subprocess.run(
['bash', '-c', runner_prefix()+'\nSKIDPAD_WORLD="$1"\nchecked_plan', 'test', str(world)],
env=env, text=True, capture_output=True, check=True)
rows = {line.split()[0]: dict(arg.split(':=', 1) for arg in line.split()[1:])
for line in result.stdout.splitlines()}
expected = {'acceleration_r1', 'skidpad_r1'}
expected |= {f'{name}_s1_r1' for name in ('extreme_hairpin', 'amz_fsg', 'amz_fsi')}
expected |= {f'baseline_{name}_s1' for name in ('extreme_hairpin', 'amz_fsg', 'amz_fsi')}
assert set(rows) == expected
for name, args in rows.items():
assert (args['perception'] == 'sim') == name.startswith('baseline_')
assert args['safety'] == 'true'
if not name.startswith('baseline_'):
assert gate_stack().items() <= args.items()
Loading