Skip to content

nav: CoPH drives a sim_world's vehicles (C5 part 2b) - #1461

Merged
transfix merged 10 commits into
masterfrom
nav/coph-c5c
Nov 23, 2026
Merged

transfix merged 10 commits into
masterfrom
nav/coph-c5c

Conversation

@transfix

Copy link
Copy Markdown
Owner

C5 part 2b of docs/roadmap/NAV-COPH-ROADMAP.md (§4.5): CoPH drives a sim_world's vehicles. Additive and default-off.

Stacked on #1460 (part 2a, the cars' learner), itself on #1413 (part 1). Until those merge, this PR's diff includes them. Merging it is Joe's call.

What lands

inc/cvc/nav/coph_driver.h: coph_driver, the twin of GRL-SNAM's cars controller (T4). It lives outside sim_world, as route_follower does (D10): attach agents, then call apply() before each sim.step().

  • Each CoPH step comes every ticks_per_step() ticks: 0.12 √s over veh.dt (D6). For each car:

    • its state in CoPH's frame (Froude scaling about an origin, D4);
    • its goal, clipped to 30 m along the straight line and slid on as it nears (D12);
    • its readings of the material plane's r~ at CoPH's 21 sensor points (a base risk without one);
    • the occupied cells within the scaled sensor radius, as disks (visible_obstacles).

    Then the fleet's boundary runs. Every car carries a car's learner (part 2a), with packets over a coph_channel.

  • Every tick, each car allocates its held force (coph_allocate, §3.3.2) and drives through override_command. A car that has arrived brakes.

  • Each car's ledger is in CoPH's frame, per unit mass:

    • the work of the force it took along its own displacement, and its own kinetic change;
    • the closed-form heat at the learner's damping, and the residual of the three;
    • the unallocated work, the risk cost and the allocation residual.
  • Fleet hooks: coph_fleet::input gains the force the plant took (the transition carries it, D5), the world's arrival, and a new goal. coph_agent and coph_ledger gain set_goal.

Results on Windows (MSVC 19.44, Release), nav_coph_driver_test

  • Byte-unchanged: with nothing attached, a 400-tick run matches a run without the driver, bit for bit.
  • Cadence and refusals: 2 ticks per CoPH step at s = 1 and 10 at s = 25; out-of-profile configurations are refused.
  • Two cars crossing: two RoboRacer-sized cars (s = 1) pass each other across a 20 m field and both arrive in 29.1 s, with 15 eligible deliveries between them. Their allocation residuals are 0.11 and 0.20.
  • The ledger's residual, about 1.1, measures how far a kinematic car is from CoPH's damped point mass: the car keeps its speed without drag, while the learner's damping books heat.
  • A block sensed late: a car driving head-on at a 1 m block senses it 1.25 m away. It cannot turn as CoPH's point mass would (a 0.74 m turning radius, and almost no lateral force at low speed). It stops 0.21 m short, where the router finds no clear start, and never touches the block. Turning that stop into a way round is the allocation research §3.3.2 leaves open; the test reports it.
  • Unchanged: G1–G13 give the same numbers. clang-format 18 is clean.

Next: part 2c

The plant_ledger items (D11). They need their own table, printed only with CoPH attached, because adding rows to the plant table changes every run's output (the .cvcrun columns, the panels, pycvc's item list and cvcGL's publish tests). sim_world's stats collector also needs a public hook for the driver's terms.

C4 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.4), additive and default-off: nothing calls it
yet; C5's fleet driver will.

- coph_packet.h: the demos' packet (cooperative.Packet, then MazePacket's geometry), and bytes():
  the length of its compact, key-sorted JSON, with Python's repr for floats (coph_repr, from
  std::to_chars's shortest digits) (D9). coph_exchange_state holds the received packets, the
  route evidence and its cells, and the reported geometry.
- coph_exchange.h:
  - coph_export: CooperativeLearner's bootstrap and candidate anchors, TerrainLearner's
    risk-ordered anchors and second bootstrap, MazeLearner's geometry. The resample indices are
    injected, or drawn from a seeded std::mt19937 through detail::pick_below (D8).
  - coph_assimilate: MazeLearner's geometry checks; CooperativeLearner's schema, provenance, age,
    order, payload and received cap; TerrainLearner's route evidence.
  - coph_expire and the two refreshes.
  - coph_fit_messages: the legacy receiver's whitened Gauss-Newton step, which coph_update now
    commits when packets are held.
- coph_channel.h: the transport interface and coph_ideal_channel (seeded delay and jitter, drops,
  duplicates, an optional range).
- detail/coph_math.h: the features, Cholesky and slab distance that coph_learner.cpp and
  coph_exchange.cpp share (moved out of coph_learner.cpp unchanged).

nav_coph_exchange_test reproduces GRL-SNAM's G9 and G10 (CVC-Lab/GRL-SNAM#201;
data/coph_golden.json is its fixture). Every decision and byte count matches exactly, and the
values come within 0.074 of the tier's allowance on Windows. It also checks the channel's
statistics, production draws and JSON escapes.
C5 part 1 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off.

- coph_agent.h: the demos' whole learner (CrossingLearner) over C1-C4.
  - observe: CooperativeLearner's uids, navigation.observe_geometry's store, C1's ledger, the
    expiries, MazeLearner's geometry reports.
  - advance.
  - action: the routed control in the live navigation context.
  - update: CooperativeLearner's diagnostic controls around C3's update, then TerrainLearner's
    own anchors.
  - export and assimilate, with the received-geometry events.
- coph_fleet.h:
  - coph_fleet: the demos' runner (staggered_demo.execute) for agents that start together, over
    a coph_channel. Its boundaries observe and advance, export on the update cadence, deliver,
    update and act. It keeps records and each agent's energy account.
  - coph_crossing_world: the crossing demo's world, with its plant, its door and corridor hits
    and its sensing.
- C1-C3 gain the hooks it needs:
  - coph_ledger::commit;
  - the route change and the raw command in coph_control_meta;
  - coph_corridor_clear and coph_slab_sweep;
  - coph_field_vector;
  - TerrainLearner's local cells in the exchange state.

nav_coph_fleet_test reproduces GRL-SNAM's G12 (CVC-Lab/GRL-SNAM#202; data/coph_golden.json is its
fixture). Every decision matches, and positions and forces are within 2.8e-16 against an atol of
1e-6. The C++-only tests cover:
- refusals outside the profile;
- packets arriving after a channel's delay;
- a run of the whole crossing, which both agents finish (agent 0 in 92.0 s, the demo's
  reciprocal finish time) with each energy account's residual at 7e-15.

The vehicle driver and the plant_ledger items (D11) are part 2.
# Conflicts:
#	inc/cvc/nav/coph_exchange.h
#	inc/cvc/nav/coph_learner.h
#	inc/cvc/nav/coph_packet.h
#	inc/cvc/nav/detail/coph_math.h
#	src/cvc/CMakeLists.txt
#	src/cvc/nav/coph_exchange.cpp
#	src/cvc/tests/CMakeLists.txt
#	src/cvc/tests/data/coph_golden.json
C5 part 2a of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off. A car carries
the cars controller's learner (GRL-SNAM's CarLearner, demo 2b), not the crossing's: a bare
CooperativeLearner whose stages advance by MazeLearner's rule, routing with the profile's own planner
since a car's world has no surveyed network, and sending packets without maze or terrain layers.

- coph_learner.h:
  - coph_profile_route and coph_edge_clear port navigation.route without a maze graph: A* through
    the sensor footprints on a 0.1 m grid, with edges priced by the stages' risk, replanning on
    stagnation, the update cadence, a blocked waypoint or a newly sensed disk.
  - coph_control dispatches on the learner's network: an empty one takes the profile's router
    and drops the guard's corridor checks.
  - Each kept stage keeps its entry context, from which the replay and the pilot start.
- coph_agent with an empty network runs CooperativeLearner on Learner: no geometry reports, no
  terrain anchors, and CooperativeLearner's packet (coph_packet::maze false: no geometry keys in
  its JSON).
- coph_can_export: whether an export makes a packet, so the fleet asks a draw source only then.
- coph_crossing_world with no network and risk patches is CooperativeWorld's open field.

nav_coph_cars_test reproduces GRL-SNAM's G13 (CVC-Lab/GRL-SNAM#203; data/coph_golden.json is its
fixture). Every decision matches, including each planned route and every delivery, and positions
are within 5.6e-16 against an atol of 1e-6. G1 to G12 are unchanged.

The vehicle driver on sim_world and the plant_ledger items (D11) are part 2b.
C5 part 2b of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off:
coph_driver, the twin of GRL-SNAM's cars controller (T4), outside sim_world as route_follower is
(D10).

- coph_driver.h: attach agents, then apply() before each sim step.
  - Every ticks_per_step() ticks (0.12 sqrt(s) over veh.dt; D6) a CoPH step: each car's state in
    CoPH's frame (Froude scaling, D4), its local goal 30 m along the line (D12), its readings of
    the material plane's risk at CoPH's 21 sensor points, and the occupied cells within the
    scaled sensor radius as disks (visible_obstacles). Then the fleet's boundary.
  - Every tick each car allocates its held force (coph_allocate) and drives through
    override_command; a car that has arrived brakes.
  - Each car's ledger in CoPH's frame: the work of the force it took, its own kinetic change, the
    closed-form heat, their residual, the unallocated work, the risk cost and the allocation
    residual.
- coph_fleet::input gains the force the plant took (the transition carries it, D5), the world's
  arrival, and a new goal; coph_agent and coph_ledger gain set_goal.

nav_coph_driver_test (C++ only):
- with nothing attached, a 400-tick run is byte-unchanged;
- CoPH's cadence under Froude scaling, and the refusals;
- two RoboRacer-sized cars (s = 1) pass each other across a 20 m field and both arrive in 29.1 s,
  with packets between them (allocation residuals 0.11 and 0.20);
- a car driving head-on at a block it senses late stops 0.21 m short and never touches it.

G1 to G13 are unchanged. The plant_ledger items (D11) are part 2c.
#1413 landed as a squash (08a7386). Where master's copy of a file is still #1413's head
(487d501), this branch's copy is taken. src/cvc/tests/CMakeLists.txt takes master's TIMEOUT for
nav_coph_fleet_test (#1462) and gives nav_coph_cars_test the same 900 s: G13's cases take about
21 s each in a Debug job, and 116 s on the slow runner of #1461's first run.
#1413 landed as a squash, and nav/coph-c5b took master in (f32c670). The one conflict,
src/cvc/tests/CMakeLists.txt, keeps master's TIMEOUT for nav_coph_fleet_test (#1462) and
nav/coph-c5b's for nav_coph_cars_test, and gives nav_coph_driver_test the same 900 s.

#1461's first run failed package-linux / libcvc-debug on two timeouts at the PR Debug ctest's
300 s default, on a runner about 5x slower than usual (the fleet's goldens took 25 s against 5):
CophFleet.TheEnergyAccountStaysAtRoundOffOverALongRun, which #1462 fixes, and
CophDriver.ABlockSensedLateIsNeverHit. CophDriver.TwoCarsCrossTheField passed there in 298 s.
…ll for 6 s

The car stops 0.21 m short of the block at about tick 250 and stays there, but the run went on to
its 1500-tick cap: 10.2 s in Release, about 3.2 times the two-car crossing. That was more than the
300 s a PR's Debug ctest allows on the slow runner of #1461's first run, and more than the 900 s
the executable now has.

The run now also ends after 100 ticks (6 s) with the car's speed under 1e-3. It ends at tick 347
with the same result as before: at (10.71, 5.85), 0.21 m from the block at its closest, the last
control brake (no_start_connector), allocation residual 0.557. 2.0 s in Release on Windows.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 06:48
@transfix
transfix merged commit e1890d0 into master Nov 23, 2026
31 checks passed
@transfix
transfix deleted the nav/coph-c5c branch November 23, 2026 08:32
transfix added a commit that referenced this pull request Nov 23, 2026
#1461 was stacked on this branch and landed as a squash (e1890d0), so master now holds all of
this PR's changes plus #1461's. The two conflicts, src/cvc/tests/CMakeLists.txt (the driver test's
registration and TIMEOUT) and docs/roadmap/NAV-COPH-ROADMAP.md (the part 2b note), were #1461's
additions on master's side only, and take master's. The branch's tree is now master's.
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.

1 participant