2.6 Replanning and rejoining the line
How a leg notices drift, plans a way back onto its original line, falls back
to a fresh path, and hands the result to the follower. Read it before
changing rust/core/src/replanner.rs, the replan knobs in any binding, or a
test that shoves a robot off its path.
The long-form rules (clock jumps, pose loss, the resume ramp, curve
certificates) are in the
Architecture chapter
and in the rejoin section
of its rotation chapter, and the team-facing page is
Replanning. This
chapter ties those to the code.
Where the code lives
| File | What it holds |
|---|---|
rust/core/src/replanner.rs | Replanner, ReplanSettings, ReplannerConfig, triggers, rejoin capture and planning, install and blend |
rust/core/src/trajectory.rs | Trajectory::rejoin_line, RejoinStart, Rejoined |
rust/core/src/rotation.rs | AngularProfile::rejoined, the heading join under an angular acceleration limit |
rust/core/src/follower.rs | POSE_JUMP_THRESHOLD_M (0.75 m) and is_pose_jump |
rust/core/src/worker_pool.rs | Lane, submit_again, Ticket::urgent, stop_if_cancelled, retire, say_warning |
rust/core/src/auto_log.rs | ReplanReason, ReplanOutcome, WarningCode::Rejoin |
rust/core/src/auto_runtime.rs | builds one Replanner per leg, moves its outcome and warnings into the route log (collect_drive_log) |
rust/core/src/ffi.rs | CReplanSettings, tempo_replanner_*, tempo_auto_replan_stats |
replanner.rs is very large, so navigate it by name:
grep -n "fn should_attempt_replan\|fn rejoin_ask\|fn plan_rejoin\|fn plan_connector\|fn connector_config\|fn remaining_route_config\|fn install_replan_product_from\|fn note_rejoin\|fn apply_blend" rust/core/src/replanner.rsSettings
ReplanSettings is the runtime record, mirrored field for field by
CReplanSettings in ffi.rs (the two booleans travel as u8).
| Field | Default (ReplanSettings::default) | Meaning |
|---|---|---|
enabled | true | false makes each tick follow without replanning |
tracking_error_threshold_m | 0.25 | cross-track distance that triggers a replan |
min_interval_s | 0.1 | least time between attempts, successful or not |
blend_duration_s | 0.25 | linear blend from the old command to the new |
async_replan | false | replans on a worker even in a replay runtime or a standalone Replanner |
The bindings never hand the core the 0.25 m record default on a built
robot, because each config builder derives the threshold as
max(3 * translation tolerance, 0.4 * footprint circumradius) unless a
threshold is given. The builders are Java TempoConfig.Settings.resolveReplanning,
Python _ConfigSettings._resolve_replanning and C++
ConfigAssembler::resolve_replanning in
cpp/include/tempo/detail/ConfigAssembler.h. drift(Sensitivity.HIGH) scales the
derived value by 0.5 and drift(Sensitivity.LOW) by 2.0.
The public surface for teams is ReplanningConfigs
(java/src/main/java/com/tempo/config/ReplanningConfigs.java,
python/tempo/config.py, cpp/include/tempo/ReplanningConfigs.h), given to
TempoConfig.withReplanning(...) or Composer.replanning(...):
| Java | Python and C++ | Field it sets |
|---|---|---|
new ReplanningConfigs() / off() | ReplanningConfigs() / off() | all, or enabled = false |
drift(Sensitivity) | drift(Sensitivity) | scale on the derived threshold (HIGH 0.5, LOW 2.0) |
drift(meters), drift(Distance) | drift(meters) | exact tracking_error_threshold_m |
rate(hz), rate(Frequency) | rate(hz) | min_interval_s = 1 / hz |
blend(seconds), blend(Time) | blend(seconds) | blend_duration_s |
openingFirst(boolean) | opening_first(bool) | async_replan |
mode(ReplanMode) | mode(ReplanMode) | mode |
Per-leg overrides go through Composer.replanning(...) and
noReplanning(). ReplanningConfigs.resolveAgainst keeps every knob a
leg does not name at the robot’s value (a bit mask, NAMED_THRESHOLD,
NAMED_RATE, NAMED_BLEND, NAMED_ASYNC, NAMED_MODE), and Composer.resolveLegReplanning
applies it at freeze. On the wire the robot settings are the route config’s
replan object and a leg’s override is its segment’s replan object, both
read in auto_runtime.rs (replan.trackingErrorThresholdM,
replan.minIntervalS, replan.blendDurationS, replan.enabled).
When a replan triggers
Replanner::compute runs every tick, and before drift checks it applies three
guards described in Architecture:
a clock step over CLOCK_JUMP_S (5 s), a pose jump over
POSE_JUMP_THRESHOLD_M (0.75 m, only with replanning on), and a tick with a
non-finite pose. A pose jump drops any job in flight, sets
force_replan_once with reason Relocalized and relocalize_hold, and
holds the output at zero until the replacement installs.
Replanner::should_attempt_replan then decides, in this order:
force_replan_oncefires first, ahead of the enable and rate gates. It is set by a pose jump, bymark_head_pending_upgrade(an opening head asking for its full route, reasonFullRoute), and byupdate_via_progresswhen the robot reaches a crossing point while a job planned before it was in flight (reasonCrossing).enabled == falsereturns no replan.- An attempt inside
min_interval_sof the last one returns no replan. - The spatial trigger:
follower.tracking_error_with_arcabovetracking_error_threshold_mgives reasonOffPath. - The temporal trigger, for time-indexed followers outside an open blend
window: distance to the clock-indexed reference above
TEMPORAL_DRIFT_MULTIPLIER(2.0) times the threshold gives reasonBehindScheduleand feedsnote_speed_deficit.
Ahead of the spatial trigger, a leg whose plan asks for more acceleration
than the drivetrain was measured to reach replans once with reason
BehindSchedule (see The measured reach).
The reason and the tracking error are kept in Replanner::attempt and end
up in the ReplanOutcome the log reports.
What a replan starts from
Replanner::remaining_route_config builds the config a fresh path plans
under:
- Vias the robot has reached are dropped, with their speed caps and curve
modes (
vias_passed_count). - A crossing already passed keeps its mask and speed cap but stops
anchoring vias (
anchor = false), and a crossing that names no heading takes the heading the robot entered it with (cross_hold_headings). heading.start_heading_radis the live pose’s heading andheading.initial_angular_velocity_rad_sthe turn rate the robot reached (angular_rate_reached_rad_s).- The start speed is the component of the departure velocity
(
departure_velocity) toward the next via or the end, clamped to the leg’s top speed, with no start tangent. The departure velocity is the robot’s measured motion (GroundVelocity, the pose step of each loop low-passed over 0.04 s, a step out of line with it read as a correction) where that is slower than the last command, else the command. The worker plans the fresh path from that start speed, then reads the departure velocity’s component along the way the planned path leaves the robot (its first 5 cm,departure_share). Where that differs from the start speed by more thanFRESH_DEPARTURE_TOLERANCE_MPS(0.1 m/s), it plans the path again from it (plan_fresh), so a path bending around what stands on the chord starts at the speed the robot carries its way. follower_latency_sis zero for the replan.
Heading intent survives the replan. A leg that names no keyframes, does not
face travel and is not steered by a live override gets an end keyframe at
ReplannerConfig::held_end_heading_rad (the last crossing heading, else the
start heading). Keyframes, planned aims and Rotation Lock spans the robot has
not passed keep their place along the path. Each fraction f of the leg
lies f * total - covered meters ahead and is rewritten as a share of the
stretch ahead (leg_covered_at). A keyframe already passed is dropped, and when
all are passed the last one’s heading holds to the end. A replan inside a
Rotation Lock starts from the heading the active plan holds there, which the
follower turns the robot back to.
Rejoining the line
The line and the ask
The line is a RejoinLine, the active plan as it stood when the first
rejoinable replan was asked for, with its LineMarks (each via’s arc and
each crossing’s terrain stretches, measured where the line was planned).
Replanner::rejoin_ask runs on the control tick that asks and returns
None, meaning a fresh path, when:
- The reason is
FullRouteorCrossing(onlyOffPath,BehindScheduleandRelocalizedrejoin). fresh_onlyis set, meaning the active plan is an opening head or a plan whose end an endpoint hold changed.- The leg has planned aims (
heading.planned_aims, filled only for mecanum legs inauto_runtime.rs), which place headings by distance. - The robot is inside a crossing it has entered and not passed.
Otherwise the ask captures, without scanning the line:
RejoinAsk field | Value |
|---|---|
from_m | the robot’s progress along the line: the larger of the current read and the farthest read so far (line_progress_m). After a relocalization the progress restarts and the worker finds the corrected pose’s own foot (search_from_m) |
limit_m | the farthest join: the next unreached via, the first stretch of an unentered anchored crossing less body_reach_m, and MIN_REJOIN_TAIL_M (0.5 m) before the line’s end |
on_line_m | the tracking threshold |
carried, commanded_mps, achieved_mps, turn_rate_rad_s | the departure velocity (departure_velocity), the last command’s speed, the low-passed ground speed (both zero after a relocalization), the reached turn rate |
crossings | only those already entered, with anchor and target cleared |
steered | reactive aims, or a host heading override within STEERED_WINDOW_S (0.5 s) |
blocked | turn_owed_before_crossing: the plan still owes a turn toward a targeted crossing’s heading by more than CROSSING_HEADING_TOLERANCE_RAD (0.05 rad) |
The doc comment on turn_owed_before_crossing records why a trailing turn
replans fresh, with the run counts from rust/core/tests/replan_heading_intent.rs.
Planning the join
Replanner::plan_rejoin runs beside the fresh plan’s inputs (on a worker
when replans are off the tick), and it never places a join behind from_m.
blockedreturnsErr(true), a fresh path with the warning.limit <= from_mreturnsErr(false), a fresh path, quietly.- Within
min(on_line_m, REJOIN_ON_LINE_M)(5 cm) of the line, ifstraight_to_line_clearfinds the straight sweep onto the nearest point clear,Trajectory::rejoin_line(None, ...)joins where the robot stands, carrying its speed along the line. - Otherwise it plans connectors to up to
REJOIN_CANDIDATES(4) joins ahead. The first liesleadpast the nearest point, whereleadis the larger of the offset and the cubic bend runv sqrt(6 d / a_c),vthe fastest of the low-passed ground speed, the departure speed and the last command’s speed (commanded_mps), clamped toREJOIN_LEAD_MIN_M(0.3) throughREJOIN_LEAD_MAX_M(4.0). Later ones step bymax(REJOIN_LEAD_STEP_M, lead / 2). None lies pastREJOIN_SKIP_M(1.5 m) plusREJOIN_SKIP_S(0.5 s) of the robot’s measured speed. - Every join is first tried arriving along the line, then every join
through an approach point
REJOIN_APPROACH_M(0.3 m) short of it (plan_connector, kept only when it arrives withinREJOIN_KINK_RADof the line’s direction). - A connector longer than the straight distance plus
REJOIN_DETOUR_M(2 m) is a detour and is skipped. Trajectory::rejoin_line(Some(connector), ...)splices the line on, andfinish_rejoincertifies the stretch of headings neither plan made (actual_heading_clear) and a mecanum plan’s wheel limits. The joined trajectory, a join where the robot stands included, must then pass the contact check with the leg’s remaining vias and end (stays_out), and one that enters something is passed over.- When nothing joins,
start_is_the_blockchecks whether a connector from the start moved just clear of an obstacle’s or the field edge’s clearance (start_moved_clear) would reach a join. If so the result isErr(false)(quiet), elseErr(true)(warn).
A connector that slows a robot faster than 0.5 m/s below half its speed, or
half the line’s speed at the join when that is lower (REJOIN_SAG_SHARE,
connector_sags), is kept aside while the other joins are tried. When every
join sags, the line leaves no room for one before the via or crossing it
still owes, and the best of them falls below a quarter of the robot’s speed
(REJOIN_STOP_SHARE), a fresh path replaces the join when it holds more
speed over the connector’s time, and the replan then reports Rejoin::Fresh.
connector_config is the short path’s config: end at the line’s point,
no vias, leave along the robot’s motion, at its whole speed, when the leg’s
curve mode is SegmentMode::Smooth and the motion points within 60 degrees
of the join (REJOIN_TANGENT_MIN_COSINE), else at the share of it along the
way to the join, arrive along the line at its speed,
an end keyframe at the line’s heading unless the leg faces travel or is
steered, no aims or locks, and only the already-entered crossings. It
plans through plan_route_latched, so the connector gets the leg’s full
obstacle check.
Splicing the line
Trajectory::rejoin_line copies the line from the join, moves its arc
after the connector’s and its clock after the connector’s end. A slower
arrival regains the line’s speed forward only, on the friction ellipse.
Headings join through AngularProfile::rejoined, a cubic that meets the
line where speeds agree or at the next span boundary and still honors the
angular acceleration limit, and without an angular profile the heading converges
sample by sample under the turn-rate cap (rust/core/src/trajectory.rs). A join that would skip a
keyframe, or whose heading cannot reach the line’s before it ends, returns
None. The full rules are in
Architecture.
The result
Replanner::plan_replan_product turns the outcome into Replanned:
Rejoin | When | Effect at install (note_rejoin) |
|---|---|---|
Spliced(SpliceMap) | a join held | splice maps progress on the active plan to the line; rejoin_warned clears |
Fresh | no ask, or a quiet refusal | nothing |
Blocked | a join was owed and none held | WarningCode::Rejoin once, until a later replan splices |
Joining a plan made ahead at a leg start
A robot runtime whose later leg starts off the plan made ahead for it, where
the plan’s clearance certifies no such start, hands the plan to the leg’s own
plan (StartJoin), which first joins it where the robot stands
(Replanner::join_at_leg_start). That is the where-it-stands join above
(join_where_it_stands, shared with plan_rejoin), from rest, before the
plan’s first via, starting at the robot’s heading. The join starts on the plan and not at the
robot, so it is taken only where the joined plan’s clearance bounds permit the
robot’s offset and heading from that start (Replanner::permits_start_from),
and the leg is planned afresh where the join does not hold or is not
permitted. The rules and the measured cost are in
Architecture.
The warning text is
[Tempo] no clear way back onto the planned path ahead; driving a new path to the target.
A replan with reason FullRoute or Crossing, or one installed after an
endpoint hold (line_retired), drops the line. A fresh product carries a
shared copy of its trajectory and marks (copy_wanted, plan_copy) when it
will replace the line or no line is kept, so taking it as the next line
copies nothing on the loop.
SpliceMap::line_arc maps a connector foot a of length L_c to
from_m + (to_m - from_m) a / L_c, and the tail to to_m + a - L_c.
path_progress, leg_covered_at and progress_mark read through it, so
covered plus left stays the line’s total and progress triggers and
keyframes in the skipped stretch fire during the connector.
The measured reach
DriveReach in auto_runtime.rs reads, on every loop whose sent commands
have ramped at 0.8 or more of the leg’s acceleration limit (and at least
4 m/s^2) along one direction for 16 loops, the robot’s speed change over the
later part of the ramp against the commands’. The share of the ramp it
reached, times the ramp, is one reading of the acceleration reached. Once
the running mean of the shares stands below 0.8, the runtime hands the
mean reach to the driving leg’s replanner (Replanner::plan_within_reach).
A drivetrain that only trails its commands by up to 0.1 s reads 0.89 or
more of the ramp and is left alone.
With a reach, every replan plans within it, along the way and across it
(remaining_route_config). A leg whose plan asks for more than 1.1 times
the reach replans once with reason BehindSchedule, as soon as the robot is
slower than 0.5 m/s or moves within 25 degrees of its next via or end
(reach_replan_ready), and a product that would start below half the robot’s
speed is not installed (reach_replan_sags). A line beyond the reach is
not rejoined because its braking distances are ones the drivetrain cannot brake
in.
Threading and install
tick -> should_attempt_replan -> rejoin_ask + remaining_route_config (on the tick)
-> submit_again(Lane::Soon, plan_replan_product) [worker]
-> later tick polls Ticket -> install_replan_product_from -> blendReplanner::replans_off_tick is true off wasm32 when async_replan is
set, or after
set_replans_off_tick, which the auto runtime calls for every leg in
PlanningMode::Robot. In that mode:
- The job goes on
Lane::Soon(a background worker’s job). Its inputs are captured on the tick, and it reads the plan cache as its first run read it, so the urgent worker can make it again to the bit. - With a plan-wait budget set (
set_replan_wait, fromPLAN_WAIT_BUDGET, 1.5 ms, lowered to what the loop has left), a plan that lands inside the wait installs on the same tick. A relocalization never installs inside the wait, so the jump tick always holds. - Each later tick polls. A poll that misses counts toward
REPLAN_URGENT_AFTER_MISSES(2), after whichTicket::urgentpromotes the job to the urgent worker. Landed::Done(None)(no route) andLanded::Faultsetreplan_failed, record an uninstalled outcome, release a relocalization hold, and keep the old follower. A fault’s message is kept for the runtime (take_worker_fault).- A replan with no route that a relocalization asked for, or that was asked
for at more than
STRANDED_ERROR_THRESHOLDS(3) tracking-error thresholds off the path, leaves the robot stranded (Stranded). The command slows the command last sent to the drivetrain, the runtime’s record where it keeps one, to rest within the leg’s linear and angular acceleration limits (stranded_command). The control status is 3: a host controller gets no reference, its binding sends the core’s command (ControlSessionin each language), and the runtime bounds that command by the leg’s limits from what was sent before it. No replan is asked for until the command sent reads rest (settle_stranded). From then one is asked for at every replan interval whatever the tracking error reads, since the brake can leave the robot on its old path; it plans from rest and may turn in place, and the plan that installs starts its clock on that tick and cuts over without a blend. With a replan from rest failed, or replanning switched off, no worker in flight andSTALL_TIMEOUT_Spassed since rest, the leg latchesstalled. - A replan from a pose on terrain the leg does not cross leaves it by the
side nearest the pose (
leaves_terrain_as_entered); a path that crosses to another side is planned again through a point off the near edge (plan_off_terrain), and failing that the replan has no route. A leg’s first plan from such a pose is not held to this. - A refused submission keeps the follower on its reference and tries again
after the interval when the replanner plans off the tick
(
replans_off_tick), and other configurations fall back to planning in the tick. wasm32 has no workers, so it plans in the tick.
The synchronous branch (async_replan off in a replay runtime or a
standalone Replanner) calls build_replan_product and installs in the
same tick, deterministic tick for tick.
a_rejoin_made_on_a_worker_is_the_one_made_in_the_tick pins that both paths
produce the same plan.
install_replan_product_from(replanned, start_s, now_s) starts the new
plan’s clock at the spawn tick (pending_replan_spawned_s), or at now_s
after a relocalization, bumps replans_completed and control_revision,
records the outcome (note_replan) and the rejoin (note_rejoin), then
installs the trajectory. install_new_trajectory builds a fresh follower
(prepare_follower), moves the old one to previous_follower and opens a
blend (begin_blend). A replan landing inside an unfinished blend holds
the last emitted command as the blend’s old side (blend_hold). A
relocalization installs with a hard cut, with no previous follower and no blend.
apply_blend emits alpha * new + (1 - alpha) * old with alpha rising
linearly over blend_duration_s, and a finished or non-finite window retires
the old follower on the reclaimer thread (worker_pool::retire).
What the runtime and the bindings see
| Output | Source | Where it surfaces |
|---|---|---|
| replan event | Replanner::take_replan_outcome -> AutoRuntime::collect_drive_log -> LogEvent::Replan | logging item REPLANS (bit 7): Replans/Count, Replans/Leg, Replans/Reason, Replans/Installed, Replans/TrackingError |
| reason codes | ReplanReason::code | replanReasons in tests/fixtures/api/logging.json: offPath, behindSchedule, relocalized, fullRoute, crossing |
| rejoin warning | Replanner::warn -> take_warnings -> LogEvent::Warning | code 11, rejoin, in warningCodes of the same fixture; also printed through worker_pool::say_warning |
| counters | replans_completed, last_replan_s, replan_failed | tempo_auto_replan_stats, tempo_replanner_replan_stats; Java TempoAuto.replanFailed() and RouteHandle#replanFailed(), Python and C++ replan_failed() |
AutoRuntime::set_log_mask turns warning capture on per replanner
(keep_warnings) and drops an outcome that ended before the mask was set.
Tests
| Test | What it pins |
|---|---|
rust/core/src/replanner.rs, mod rejoin_tests | rejoins ahead and never behind (a_shove_backward_never_rejoins_behind), on-path lag (behind_schedule_on_the_path_joins_where_the_robot_stands), progress through a splice, second shove returns to the original line, angular limits, a drifting robot’s join sized for its command (a_drifting_robot_rejoins_over_the_run_its_command_needs), worker equals tick, relocalization from rest with a hard cut, heads replaced before any rejoin, skip distance on a curve, field-edge lines, keyframes ahead, wedged robot stall latch, a straight join through an obstacle takes a connector, no join past an unentered crossing, heading that cannot catch the line |
rejoin_plan_time (ignored) | plan time of a rejoin against a fresh path from the same inputs, the sweep shoved 0.6 m to either side at 40 points; run with cargo test --release -p tempo-core --lib rejoin_plan_time -- --ignored --nocapture |
rust/core/src/replanner.rs, mod tests | pose jump hold and hard cut, worker landing, failed worker clears pending_replan, endpoint hold replacing a relocalization |
rust/core/tests/replan_rejoin.rs | a shoved sweep still passes every sweep point and keeps a whole-drive trigger in place; a shoved sweep rejoins before a targeted crossing |
rust/core/tests/replan_heading_intent.rs | a lagging robot on the regions page’s bump route keeps its heading intent and crosses on target |
rust/core/tests/replanner_shove.rs | the canonical 1.2 m lateral shove recovers and completes; two shoves each trigger one clean replan |
rust/core/tests/replan_stutter.rs | noisy odometry around the trench keeps corner speed and preplans |
rust/core/tests/weak_drivetrain.rs | a drivetrain reaching 3.6 of the 7.2 m/s^2 authored replans about once a leg and settles within 0.5 s of a route authored at 3.6 |
rust/core/src/replanner.rs, mod departure_tests | the ground velocity passes over a pose correction, a replan departs at the robot’s speed, a fresh path departs at the robot’s motion along its own way, a plan beyond the measured reach replans within it |
rust/core/src/rotation.rs | a_rejoined_profile_follows_the_head_then_the_shifted_tail and the other AngularProfile::rejoined cases |
java/.../ShoveRecoveryTest.java, python/tests/test_simulator.py (test_replanner_recovers_from_mid_run_shove), cpp/tests/test_shove_recovery.cpp | the same shove through each binding; keep them in step with the constants in replanner_shove.rs |
Run the core’s set with:
cd rust && cargo test -p tempo-core --lib rejoin_tests
cd rust && cargo test -p tempo-core --test replan_rejoin --test replan_heading_intent --test replanner_shoveNo shared fixture under tests/fixtures/ holds rejoin decisions, and the
behavior is pinned by the Rust tests above and by the wire names in
tests/fixtures/api/logging.json.
Changing replanning
- A change in
replanner.rscan move pinned hashes. Follow Pins and API surfaces and update only the pins whose targets changed. - A new rejoin constant belongs beside the others near
REJOIN_ON_LINE_M, with its physical justification in the doc comment. - A new
ReplanReasonorWarningCodeadds a code, a name intests/fixtures/api/logging.json, whichTempoLoggingTest,python/tests/test_logging.pyandcpp/tests/test_route_logging.cppread. - A new settings field changes
ReplanSettings,CReplanSettings, the route JSON readers inauto_runtime.rs, and all threeReplanningConfigsclasses. See the FFI contract and Wrapper conventions first. - Update the team page (Replanning) when a threshold or a fallback case a team can observe moves.