Skip to content

2.1 Architecture

The Rust core in rust/core/src/ turns game packs and authored routes into collision-checked paths, timed trajectories, and robot-relative velocity commands. Java, Python, and C++ call its C ABI. Wasm links the core for browser previews. One plan follows this pipeline:

field -> visibility_graph -> pathfinding -> spline -> trajectory -> follower -> replanner -> ffi
          (geometry used by multiple stages; rotation and traversal feed
           trajectory and replanner respectively)

The diagram follows one plan. Module dependencies differ from it. The auto runtime owns replanners.

Game pack parsing, the geometry helpers and the C ABI are on this page. Each remaining module has its own page:

PageModules
Path planningvisibility_graph, pathfinding, spline, preferred obstacle clearance, contact check, traversal
Trajectory and headingtrajectory, rotation
Following, limits and calibrationfollower, output_limit, calibration
Replanner and auto runtimereplanner, auto_runtime

field: Game pack parsing

Entry point: parse_game_pack(toml: &str) -> Result<GamePack, FieldError>

It parses the TOML game pack file into a GamePack struct with these public queries:

Query on GamePackResult
obstacles_for(alliance)Iterator of &Obstacle, filtered by alliance
field_center()Point2d, the centerRotate pivot
zone_center(id)Option<Point2d>
point_in_obstacle(p, alliance)bool
point_in_zone(p, zone_id)bool
mirror_pose(pose)Pose2d, transformed by the field’s symmetry
avoid_zone_index_by_id(id)Option<usize>, the avoid-mask bit position of the first zone with the id
avoid_zone_mask_by_id(id)u64, the avoid-mask bits of every zone with the id (authored and derived copy)
default_avoid_mask()u64, enabled-by-default avoid zones
planning_sets(alliance, avoid_mask, cross_mask)(Vec<&Obstacle>, Vec<&Terrain>), hard obstacles and crossable terrain

The parsed GamePack is passed to Replanner as Arc<GamePack>, so the replanners of a multi-segment auto (one per segment) share one parsed field without copying.

pack_toml parses single-segment table headers, bare keys, unescaped double-quoted strings, decimal numbers, booleans, and arrays. Other syntax falls back to the toml crate, and so does an unsupported [meta] version. That fallback reports metadata errors before unknown-field errors. Tests compare both parsers on generated and edited documents. tests/fixtures/planning/packLoad/packDump.txt records the parsed repository packs.

geometry: Pure functions

All functions are pure. Point arguments below are Point2d values.

FunctionResult
segments_intersect(a, b, c, d)bool
segment_crosses_shape(start, end, shape: &Shape)bool
distance(a, b)f64, meters
distance_point_to_segment(p, start, end)f64, meters
inflate_corner(prev, corner, next, radius_m: f64)Point2d

segments_intersect detects a crossing when both segments straddle the other’s line, using exact cross-product signs. It accepts the rounded result when its error bound proves the sign. When it does not, it uses an exact expansion sum. It also detects an endpoint within TOUCH_M (1 nm) of the other segment’s line and box. Shared endpoints are excluded. Callers decide other boundary policy.

Disjoint boxes expanded by TOUCH_M rule out a crossing, except with NaN inputs. The arithmetic stays below overflow within EXACT_DOMAIN_M (1e6 m). For out-of-domain or nonfinite coordinates, or expansion factors that can underflow, overlapping boxes conservatively count as a crossing.

inflate_corner computes a corner’s miter node. That node is the corner pushed outward along its bisector until it stands the radius off both edge lines, clamped at twice the radius below 60 degrees. corner_nodes adds two bevel nodes at a sharper convex corner. corner_arc_nodes places nodes around a corner’s exterior arc using only arithmetic and square roots, so native and wasm32 builds place them on the same bits. Cache hits reuse the baked corner geometry.

Polygons with at least 16 vertices use PolygonIndex for crossing, containment, and boundary tests. Its tree groups edge runs by bounding box and skips a run only when doing so preserves the full scan’s result bit for bit. Each thread caches its last 8 polygon indexes, matching both address and vertex bits. Single-use hulls scan their edges directly.

ffi: C ABI surface

Every public Rust function exported to the bindings is in this file, with these design conventions:

  • Handles are opaque *mut c_void pointers that only Rust dereferences.
  • Fallible functions return a failure sentinel. tempo_last_error() returns a thread-local UTF-8 error string.
  • Every fallible entry point uses catch_unwind(AssertUnwindSafe(...)).
  • JNA boolean is 4 bytes and Rust bool is 1 byte, so mirror each ABI declaration. Java uses byte for byte-sized Boolean/status results and converts explicitly.
  • Buffer lengths use fixed-width u32 across 32-bit roboRIO and 64-bit hosts.

The file is divided by BEGIN/END ... ADDITIVE BOUNDARY marker comments. Native layouts are checked across the bindings. The full conventions are in ffi-contract.md.

The GamePack pointer is an Arc<GamePack> passed through Arc::into_raw. tempo_replanner_new increments the strong count. The Java GamePack and the Replanner both hold independent Arc clones.

Pack sharing

A parsed GamePack is read-only after construction and is shared through Arc. tempo_replanner_new costs one atomic increment per replanner. A deep copy would cost O(obstacles + tags + zones) allocation per segment.

The visibility graph has nonnegative Euclidean edge weights, so Dijkstra finds a shortest weighted route. Heap and adjacency ordering determine which equal-cost route is selected. Deterministic fixtures pin that behavior. A direct visible route bypasses graph search when the planner’s guards permit it.

Measure search changes at the complete-plan boundary, including endpoint visibility, clearance checks, and binding overhead. A faster search alone does not establish a faster plan. The output contracts are in pins-and-surfaces.md.

See: Rust Arc documentation, JNA overview.

Java command framework boundary

Every Java bundle uses the canonical neutral lifecycle in com.tempo.internal.commands. Core authoring and runtime classes reference neither command framework. CommandResults supplies concrete v2 return types for 2026 and alpha-6 and generic results for alpha-7 and alpha-8. RouteCommand owns route execution. The small public TempoCommand facade remains a v2 command on 2026 and alpha-6. The alpha-7 overlay (applied to alpha-8 too) contains the v3 adapter and these signature facades, with no copy of a core class. PoseResults preserves the 2026 Pose2d subtype and the 2027 builder signatures while the pose registry remains shared. Frameworks probes scheduler class names without initialization, then reflectively constructs internal.cmd2.Adapter or internal.cmd3.Adapter. When both JARs are present the commands and drivetrain requirements select the framework. Conflicting v2 and v3 inputs fail with both framework names. When neither is present the scheduler-free implementation is selected. Only adapter packages and the v2 signature facades link WPILib command types. Their classes remain outside the robot package scanned by OpModeRobot.

The Rust core still decides route events and phase changes. The v2 adapter forwards its lifecycle and group operations to Commands v2. The v3 adapter runs lifecycle bodies in yielding coroutines and implements groups with await/fork. A bridge owns its exported command identity. Weak input references preserve the identity of live team commands without retaining completed autos.

V3 propagates descendant failures to the root before throwing, so protected hook roots enqueue their execution for a private scheduler polled outside any active coroutine. Route cleanup owns ordinary hooks and AutoRun owns recoveries across route boundaries. This keeps failures inside the hook’s subtree. Cancellation calls the bridge’s guarded cleanup through onCancel, because v3 drops suspended continuations without running Java finally blocks. Recoveries continue into subsequent routes until they finish or another command claims their requirements. After the last step the auto retains its requirements until those recoveries end. Scheduler-free runs poll a private v3 scheduler from Tempo.update(). Stopping the auto cancels its commands.

esc

Loading search...