Skip to content

CoPH's cars take a new goal after arriving, and run on world documents (C6 part 2b) - #1517

Merged
transfix merged 6 commits into
masterfrom
nav/coph-c6c
Nov 25, 2026
Merged

transfix merged 6 commits into
masterfrom
nav/coph-c6c

Conversation

@transfix

Copy link
Copy Markdown
Owner

Fixes the two limits of #1516's --controller coph. Stacked on #1516 (and #1504). Until those merge, this diff includes them; this PR's own commit is the last one.

1. A car takes a new goal after it arrives

Before, a CoPH car that reached its goal stayed parked, even with run.regoal on.

  • coph_fleet::resume(agent): an agent that finished at its goal (success, not a hit) runs again from the next boundary.
    • Its learner keeps what it learned and takes that input's goal.
    • That boundary observes without a transition and records an activation, as an agent's first boundary does.
    • It is refused for an agent that is still running, or that was ended by a hit or by the run's steps.
  • coph_driver calls it when the sim moves a done car's goal, as GRL-SNAM's cars controller (T4) clears a car's done.
  • NavCophFleet.resume() exposes it to Python.

2. --gym and --world-doc run CoPH

Those cars are a world document's, not a sim_world, so the native driver can't reach them. pycvc_gl.cars.CophControl runs the same fleet over NavCophFleet from any cars' CarsState, as a controller: steer, accel, info = ctl(s). It is coph_driver's twin:

  • Froude frames and CoPH's cadence, and the local goal (D4, D6, D12);
  • the 21 lattice readings of a constant risk, or of a risk(x, y) it is given;
  • the rays' hits within the scaled sensor radius, as disks;
  • nav_coph_allocate every tick, braking when done, and resume on a new goal.

The template uses it for GymCars and HostCars. Cars keeps the native driver, which reads the grid and the material layer.

docs/CARS.md and the roadmap drop both limits. What remains is noted: CophControl sees obstacles only along the rays, and a constant risk unless given one.

Checked on Windows (MSVC 19.44 Release, pycvc core with Python 3.11)

  • nav_coph_fleet_test passes 9, including the new CophFleet.ResumesOnlyAnAgentAtItsGoal.
  • nav_coph_driver_test passes 6. The new CophDriver.ACarTakesANewGoalAfterArriving drives a car to (8, 6), then (14, 6), in 386 ticks.
  • test_pycvc_nav_coph.py passes 1291 checks. A driven car given a new goal after arriving reaches it in 264 more ticks, while the other car stays parked.
  • Cars loaded from cars.py's source, two Humvee-sized cars crossing 60 m:
    • The native driver: both arrive in 649 ticks, and car 0 then reaches a new goal.
    • CophControl: both arrive in the same 649 ticks with no contact, and a new goal runs car 1 again.

Not run locally: test_pycvc_gl_cars.py, which adds the same checks plus CophControl on GymCars and a headless --gym --controller coph run. CI runs it; this box has no cvcGL.

bindings/pycvc/pycvc_nav_coph.i puts cvc::nav's CoPH in pycvc. It only marshals between Python
values and the library.

- Kernels: nav_coph_flow, nav_coph_balance, nav_coph_risk, nav_coph_potential,
  nav_coph_grad_potential, nav_coph_command, nav_coph_shaping and nav_coph_allocate. A packet's
  bytes are NavCophPacket.bytes(), its json()'s length (D9).
- Configurations are dicts over the demos' profile, keyed by coph_config's field names. An unknown
  key is an error, and validate() runs on the result. nav_coph_profile() and
  nav_coph_communication_profile() return the whole of each.
- NavCophAgent is one learner, a crossing one or a car's (network="none"): observe, advance,
  action, last_control, update, export_to (a NavCophPacket) and assimilate.
- NavCophFleet is the runner's fleet:
  - run_crossing() on the crossing world, with the GIL released; the sensor noise may be a Python
    callable, which takes the GIL back for each call;
  - boundary() for a world of the caller's;
  - samples, controls, updates, events and the energy accounts.

test_pycvc_nav_coph.py (ctest pycvc_nav_coph) checks:
- G2, G3 and G11 from coph_golden.json at its tier;
- the configuration dicts;
- a learner driven on the plant kernel exporting a packet that a second learner assimilates;
- a car's learner;
- the fleet on G12's crossing world and noise, as CophFleet.TheEnergyAccountStaysAtRoundOffOverALongRun
  runs it: both agents reach their goals, in 767 and 784 steps, with residuals at 7e-15.
…ion-local static

pycvc-linux's writable-data scan (tools/singleton_scan) flagged config_fields()' static std::map
and its guard variable as new process-wide state in pycvcPYTHON_wrap.cxx. The table is now a
constexpr array of names and plain function pointers, which the compiler places in read-only data
(.data.rel.ro under PIC) with nothing initialised at run time; a lookup walks it. Behaviour is
unchanged: test_pycvc_nav_coph.py still passes its 1278 checks, as do test_pycvc_ph.py and
test_pycvc_nav_lab.py.
…ely (C6 part 2)

pycvc.NavCophDriver binds C5's coph_driver to a nav_sim_world_create handle. It holds a
reference to the handle while it lives, and its methods are attach, apply, ticks_per_step, steps,
done, account, controls and events. pycvc_gl.cars uses it:
- Cars(..., coph={...}) attaches every car, and step_coph() runs the driver's apply before the
  world's step. coph_froude() gives the Froude scale: the car's length over a RoboRacer's (D3, D4).
  coph_coeffs() gives each car's account for the coefficient plots and the log.
- The template takes --controller coph and --coph-scale, and the Run panel gains a CoPH choice.
  --gym and --world-doc refuse it, since the driver runs on a sim_world.
- docs/CARS.md documents it, including its limit: a CoPH car that arrives brakes and stays,
  taking no new goal.

The fleet's controls and events now share one converter between NavCophFleet and NavCophDriver.

Checked on Windows (pycvc core; this box has no cvcGL):
- test_pycvc_nav_coph.py: 1288 checks.
  - A driver with nothing attached leaves the run bit for bit.
  - Two RoboRacer-sized cars cross in 485 ticks, as CophDriver.TwoCarsCrossTheField does.
- Cars(coph=...) loaded from cars.py's source: two Humvee-sized cars on nav's bicycle cross 60 m
  of the flat world and both arrive in 37.9 s, with no contact, at s = 9.05.
- test_pycvc_gl_cars.py gains the same Cars check and a headless --controller coph run. CI runs
  it.
…s (C6 part 2b)

#1516 had two limits; this fixes both.

1. A car that arrived stayed parked even when given a new goal. coph_fleet::resume(agent) now lets
   an agent that finished at its goal run again from the next boundary, its learner keeping what
   it learned. That boundary observes without a transition and records an activation. Refused when
   the agent is running, or was ended by a hit or by the run's steps. coph_driver calls it when the
   sim moves a done car's goal, as GRL-SNAM's cars controller clears a car's done.
   NavCophFleet.resume() binds it.

2. --gym and --world-doc refused --controller coph, because the driver needs a sim_world.
   pycvc_gl.cars.CophControl runs the same fleet over NavCophFleet from any cars' CarsState, the
   twin of coph_driver:
   - Froude frames and CoPH's cadence;
   - the local goal;
   - the 21 lattice readings of a constant risk, or a risk(x, y) it is given;
   - the rays' hits within the scaled sensor radius as disks;
   - nav_coph_allocate every tick;
   - braking when done, and resume on a new goal.
   The template uses it for GymCars and HostCars. Cars keeps the native driver.

docs/CARS.md and the roadmap drop the two limits. What remains: CophControl sees obstacles only
along the rays, and a constant risk unless given one.

Checked on Windows:
- nav_coph_fleet_test (9, with CophFleet.ResumesOnlyAnAgentAtItsGoal) passes.
- nav_coph_driver_test (6) passes. CophDriver.ACarTakesANewGoalAfterArriving reaches (8, 6), then
  (14, 6), in 386 ticks.
- test_pycvc_nav_coph.py passes 1291 checks. A driven car given a new goal reaches it in 264 more
  ticks, while the other stays parked.
- Cars loaded from source: native, both cars cross and car 0 reaches a new goal. With CophControl
  both arrive in the same 649 ticks with no contact, and a new goal runs car 1 again.
- test_pycvc_gl_cars.py adds the same checks plus CophControl on GymCars and a headless
  --gym --controller coph run. CI runs it (no cvcGL here).
# Conflicts:
#	bindings/pycvc/pycvc_nav_coph.i
#	bindings/pycvc/test_pycvc_nav_coph.py
#	docs/roadmap/NAV-COPH-ROADMAP.md
#	src/cvc/tests/nav_coph_driver_test.cpp
# Conflicts:
#	bindings/pycvc/pymod_gl/cars.py
#	bindings/pycvc/test_pycvc_gl_cars.py
#	bindings/pycvc/test_pycvc_nav_coph.py
#	docs/CARS.md
#	docs/roadmap/NAV-COPH-ROADMAP.md
@transfix
transfix merged commit e7ec1df into master Nov 25, 2026
30 checks passed
@transfix
transfix deleted the nav/coph-c6c branch November 25, 2026 01:40
transfix added a commit that referenced this pull request Nov 25, 2026
Conflict in ari_test_command_test.cpp: #1508 gave FramesAndTimeout's stuck
document 5 s for the same Debug-runner flake that a651d0c gave 4 s;
master's version kept.
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