Skip to content

feat: position resolution, teleport & host round-trip (p2-s4) - #71

Merged
JArmandoAnaya merged 8 commits into
mainfrom
feat/p2-s4-position-resolution
Jul 23, 2026
Merged

JArmandoAnaya merged 8 commits into
mainfrom
feat/p2-s4-position-resolution

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

Sprint p2-s4 (#18): one resolver for all §6.3.8 position types, and airtight control-ownership semantics. Kernel + C ABI + Python; XML lowering stays deferred to P4. ADR-0017.

What landed

  • ir::Position — the ten §6.3.8 variants as a std::variant, plus ir::Orientation and the now-canonical ir::ReferenceContext (moved from trajectory.h). WorldPosition gains append-only h/p/r.
  • runtime::PositionResolver — a standalone resolver (unit-testable without the engine) mapping any variant to a world pose or a diagnostic — none silently wrong (§5: the corrected ≥1.3 calculations apply to all versions):
    • self-contained: WorldPosition, RelativeWorldPosition (world-axis deltas), RelativeObjectPosition (entity-local, rotated via det_sincos), with §Orientation absolute/relative composition;
    • road family (Road/RelativeRoad/Lane/RelativeLane/Route) → UnsupportedFeature until the road backend (p3-s4);
    • TrajectoryPosition → UnsupportedFeature (p2-s5); GeoPosition → UnsupportedFeature with rule asam.net:xosc:1.1.0:positioning.geodetic_datum_defined.
  • Teleport / Acquire / AddEntity now resolve any ir::Position and write the full pose (position + orientation). A WorldPosition still converts implicitly.
  • Airtight control ownership — an engine-driven teleport aimed at a host-controlled entity is a reported mode violation (InvalidControlMode), state left to the host; the report_state round-trip and the ADR-0003 poll/publish order are re-verified.
  • C ABI (append-only): scn_engine_add_teleport_action_oriented / _relative. Python: Orientation, RelativeWorldPosition, RelativeObjectPosition, GeoPosition, WorldPosition h/p/r; example positions.py.

Tests & docs

  • position_test.cpp (every variant, orientation composition, the RelativeObject rotation pinned bit-for-bit against det_sincos), control_ownership_test.cpp (round-trip + mode violations + step order), plus teleport/acquire/add-entity/capi/python cases. 637 gtest + 154 pytest green; ASan/UBSan clean; format + detmath + coverage-matrix guards pass.
  • User-guide positions.md, ADR-0017, coverage matrix flipped.

Closes #18

Add the ten ASAM OpenSCENARIO §6.3.8 position variants to the IR as an
`ir::Position` std::variant, plus `ir::Orientation` and the canonical
`ir::ReferenceContext` (moved here from trajectory.h, which now includes it).
`WorldPosition` gains append-only h/p/r orientation fields.

Introduce a standalone `runtime::PositionResolver` that maps any variant to a
world `Pose` or a diagnostic — none silently wrong (§5: the corrected ≥1.3
calculations apply uniformly to all input versions):
- WorldPosition, RelativeWorldPosition (world-axis deltas) and
  RelativeObjectPosition (deltas rotated into the entity frame via det_sincos,
  ADR-0006) resolve fully, with §Orientation absolute/relative composition.
- Road/RelativeRoad/Lane/RelativeLane/Route report UnsupportedFeature until the
  road backend and s-axis tangents land (p3-s4).
- TrajectoryPosition reports UnsupportedFeature (p2-s5); GeoPosition reports it
  with rule asam.net:xosc:1.1.0:positioning.geodetic_datum_defined.

Tests (position_test.cpp): each variant, orientation composition, the
RelativeObject rotation pinned bit-for-bit against det_sincos, and an
exhaustiveness check that every variant returns a defined status.
Generalize TeleportAction from a bare WorldPosition to any §6.3.8 `ir::Position`
(a WorldPosition still converts implicitly). At apply time the engine resolves
the target through the PositionResolver via a new `Engine::resolve_position`
helper and writes the entity's full pose — position and orientation
(heading/pitch/roll), where before only x/y/z were written.

Control ownership is now airtight: a teleport aimed at a HostControlled entity
is a mode violation — reported (InvalidControlMode, warn-once) and skipped, its
state left entirely to the host (ADR-0003). A variant with no backend yet
(road/lane/route/geo/trajectory) is reported by resolve_position and the
teleport is a no-op — never silently wrong.

Init validation moves to a shared `validate_position` helper (finiteness of
numeric fields; declared reference entity for the relative variants); the
road-family and geo/trajectory variants are accepted at load and reported at
apply, so scenarios using them still initialize.

Tests (action_teleport_test.cpp): orientation is written, a RelativeWorldPosition
resolves against a reference entity, and an unsupported variant is reported and
leaves state untouched.
Add control_ownership_test.cpp pinning the ADR-0003 / ADR-0017 contract that the
generalized teleport now formalizes:
- report_state rejects engine-controlled (InvalidControlMode) and unknown
  (UnknownEntity) targets and fails before init (NotInitialized); it updates a
  host-controlled entity's state.
- a host-controlled entity is never integrated — a reported speed does not
  advance its position.
- the in-step order holds: every host poll precedes every engine publish, the
  published engine state matches state(), and the host entity is never published.
- a scenario condition observes a host-controlled entity's reported state (a
  SpeedCondition on the host gates an action on an engine entity) — the round-trip.
- teleporting a host-controlled entity is a reported mode violation that leaves
  its state untouched.
…(p2-s4)

Generalize AcquirePositionAction and AddEntityAction from a bare WorldPosition
to any §6.3.8 `ir::Position`, resolved at apply time through the shared
`Engine::resolve_position` helper. AcquirePosition writes the resolved pose into
the route's last waypoint; AddEntity seeds the re-added entity's full pose —
`activate_entity` now seeds heading/pitch/roll from the resolved orientation, not
just x/y/z. An unresolvable target (no backend yet) reports and leaves the route
or entity set unchanged. Init validation for both routes through the shared
`validate_position` helper.

Tests: AcquirePosition resolves a RelativeObjectPosition into the last waypoint;
AddEntity seeds orientation from a resolved world pose; the AcquirePosition IR
test reads the target as an ir::Position variant.
Append two C ABI entry points (existing scn_engine_add_teleport_action is
unchanged) so foreign hosts can reach the self-contained position variants:
- scn_engine_add_teleport_action_oriented — WorldPosition with heading/pitch/roll.
- scn_engine_add_teleport_action_relative — RelativeWorldPosition (world-axis
  deltas) or RelativeObjectPosition (entity-local, object_frame != 0) about a
  reference entity.

Road/lane/route/geo/trajectory targets stay kernel-only until their backends
land (p3-s4/p2-s5) — exposing them now would only surface UnsupportedFeature.

Tests (capi_test.cpp): oriented teleport writes heading, relative teleport
resolves against a placed reference, and the null-argument suite covers both new
symbols (including the NULL reference entity).
Bind the self-contained §6.3.8 position variants and orientation to Python:
Orientation (with ReferenceContext, now documented as the shared absolute/
relative selector), RelativeWorldPosition, RelativeObjectPosition, and
GeoPosition (the one deferred variant, exposed to demonstrate the rule-cited
diagnostic). WorldPosition gains the h/p/r orientation keywords. TeleportAction,
AcquirePositionAction and AddEntityAction now accept any ir::Position; a
WorldPosition still converts implicitly. Re-exported explicitly from the scena
package.

Add python/examples/positions.py (world, relative-world, relative-object
teleports + the reported GeoPosition) and python/tests/test_positions.py.
Add the user-guide Positions and control ownership page (the ten §6.3.8
variants, world-vs-local deltas, orientation composition, and the engine-vs-
host round-trip) and link it from the index. Add ADR-0017 (position resolution
and control ownership) recording the ir::Position variant, the standalone
PositionResolver, the resolve-or-report policy, the yaw-only rotation, and the
airtight control-ownership decision.

Flip the coverage matrix: the self-contained position variants and Orientation
are delivered with their proving suites; the road/route/geo/trajectory variants
carry resolution owners (p3-s4/p2-s5) and are reported unsupported meanwhile;
the Teleport/Acquire/AddEntity rows record resolution through the resolver and
the teleport mode violation. check_coverage_matrix.py passes.
resolver_over captured a reference to its argument; the cases passing a
temporary map (`resolver_over({})`) left the resolver's lookup holding a
dangling reference, which AddressSanitizer flags as stack-use-after-scope. Copy
the table into the lookup so the resolver owns it. Test-only; the kernel
resolver stores the caller-provided lookup unchanged.
@JArmandoAnaya
JArmandoAnaya merged commit ffba802 into main Jul 23, 2026
9 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the feat/p2-s4-position-resolution branch July 23, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p2-s4] Position resolution, teleport & host round-trip

1 participant