Skip to content

pycvc_gl.cars: a template for your own multi-car controller (any plant, Austin / generated / flat worlds, panels, headless) - #1035

Merged
transfix merged 5 commits into
masterfrom
feat/pycvc-gl-cars
Nov 7, 2026
Merged

transfix merged 5 commits into
masterfrom
feat/pycvc-gl-cars

Conversation

@transfix

@transfix transfix commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Stacked on #1031 (base feat/pycvc-nav-override). It needs that PR's bindings, so retarget it to master after #1031 merges.

Why

The lab's researchers want to test their own multi-car controllers in Python. The goal is general, not tied to one navigator:

  • turn on world physics from Ariadne;
  • use arbitrary worlds, with the Austin bundle from cvcpkg by default, through the data: block;
  • use libcvc's terrain generator as an alternative to existing geometry;
  • show readouts and rasters from the rollout, and coefficients, with data both ways;
  • tune the navigator's settings from the document;
  • run headless too.

What

pycvc_gl.cars is a library, plus a template to copy. python -m pycvc_gl.cars --copy DIR writes cars.py (a controller and its parameters) and cars.ari (the panels).

  • Your controller. controller(s, p) gets every car's state each tick, as numpy arrays in SI units:

    • pose, speed and wheel angle;
    • velocity, goal and range rays;
    • collisions, limits and sizes.

    It returns (steer, accel) per car, which each car's plant takes in the navigator's place (nav_sim_world_override). An optional third value, {"coeffs": ...}, is plotted and logged. cost(s, p, i, X, Y) is drawn as a raster.

  • The world (run.world). Each world gives the cars the same occupancy, terrain height and collision geometry, so a controller can't tell them apart.

    • data, the default: the document's data: block, cvcpkg://cy-pca/scene-austin-south-small (lazy). Run's URI field or --uri loads another package or a local bundle.
    • generated: pycvc.generate_world from the World window's world.* keys, with Regenerate. Python generates the world for the cars, the navigator and Jolt, and the scene's generated_world node draws the same world.
    • flat: a flat square.
  • The plant: nav_plant.vehicle (plant_host): kinematic, humvee, roboracer, a comma list, dynamic[:presets] or dynamic4w. It switches live, the cars keeping their poses. Jolt collides with the world's own terrain and buildings.

  • Settings: libcvc's own keys (nav.*, nav.vehicle.*, nav_plant.*), with their units and ranges.

    • You can set them in init:, on sliders (the Settings window), with --set / --params, or from Python.
    • settings() lists them.
    • They apply on the next tick. A new plant switches at once; cars, world and controller rebuild the run.
  • Panels:

    • readouts and a row per car;
    • speed and gap plots;
    • four coefficient plots: the controller's terms, or the navigator's alpha / beta / gamma / lam_* / potential / clearance;
    • two rasters around the chosen car, heading up: signed distance with the predicted path (rollout(): your controller on nav's bicycle), goal and the other cars; and your cost, or the navigator's belief.
  • Headless: --headless --frames N --log run.npz. Exit 1 when the controller raises; exit 3 when --min-arrivals is unmet. The log holds:

    • states and commands per tick;
    • coefficients;
    • rasters and predicted paths every --raster-every ticks;
    • meta: the world's source or the generator's parameters, the seed, and every setting's value.
  • Navigator baseline: --controller navigator, with --nav-weights for a .cvcnav policy. GRL-SNAM can pass its trained one.

Packaging and docs:

  • pycvc_gl now installs and stages *.ari files beside its modules, for cars.ari.
  • docs/CARS.md is the guide. Its settings table is generated from the keys' own metadata, and it says what kinematic vs Jolt vs dynamic means for a controller, with measured steering lag and slip.
  • README.md, ARIADNE.md §9.3 and the pycvc README link to it.

A cvcGL limitation found (not fixed here)

A scene node's visible: hides that node's own actor only (SceneNode::setVisible). What a source: { data } node drew as children, and a generated_world node's meshes beside it, stay on screen. Yet ARIADNE.md says a node hidden with visible: "is gone from every view".

The template works around it: it clears data.city by pointing it at a dataset with nothing to draw, and hides gen_* by name. A real fix would make visibility hide a subtree, and have generated_world's parts follow their node. That's a separate change.

Tests (local: Windows, MSVC 14.44, Jolt on, with #1031)

test_pycvc_gl_cars.py: 39 checks pass, headless.

  • The worlds: flat, generated, and a city from the store (a temp bundle).
  • The bicycle: a straight run, and the limits.
  • Commands: a NaN goes to the navigator; ranges; collisions.
  • Settings in the tree: vmax caps the speed, and settings() reports units and ranges.
  • Jolt: a live switch to RoboRacers keeps the poses, and a car backs up.
  • The navigator's coefficients.
  • rollout, local_raster and CarsLog (npz and csv).
  • The template run headless:
    • flat;
    • generated, with its params logged;
    • a city by --uri;
    • exit 3 and exit 1;
    • the navigator's coefficients logged;
    • --copy.

By hand:

  • Offscreen renders of Austin (aerial image, panels, rasters) and a generated world, each with the other world hidden.
  • Headless runs on all three worlds.
  • The default world loads from the cvcpkg package (cached) in about 4 s.

…mmands on any plant

sim_world::override_command takes a caller's (steer, accel) for one step in the
navigator's place, on nav's bicycle and on a plant (Jolt's nav_plant, the dynamic
vehicle). pycvc had no way to reach it, so a Python controller could not drive the
agents itself. nav_sim_world_override(sim, steer, accel) takes (N,) arrays (NaN leaves
that agent to the navigator) and returns how many took a command.
nav_sim_world_set_pose(sim, i, x, y, heading, speed=0) binds sim_world::set_pose, so
agents can start at chosen headings before a plant attaches at their poses.

test_pycvc_nav_override.py checks the overridden bicycle against libcvc's
kinematic_step in numpy to float precision, NaN pass-through, one-step scope, the lock
and top-speed holds, malformed arrays, set_pose, and a Jolt Humvee attached at a set
pose driving straight then turning left on a positive steer.
pycvc.plant_host binds cvc::physics::plant_host: the plant a sim_world drives on,
chosen by name (kinematic, humvee, roboracer, a comma list, dynamic[:presets],
dynamic4w[:presets]), in code (use) or live from the state tree (pull reads
<prefix>.nav_plant.vehicle and the plant's own knobs). set_geometry takes a
world_geometry (a city bundle's data_world, a generated world) as the colliders and
starts the vehicles on its terrain (plant_host_options' ground_height, which nothing set
before, so vehicles spawned at ground_z under a city's relief). kind, driving, limits,
state, vehicle_state and body read the active plant. The host holds the sim_world it
drives and puts it back on the bicycle before it goes.

pycvc.generate_world binds cvc::world::generate_world on a dict of its params (the
generated_world node's world.* key names or the struct's) and an optional building
library: world() for physics and nav, terrain(), height(), info(). It is a pure
function of its params, so Python gets the scene node's world from the same keys.

test_pycvc_plant_host.py: 24 checks (generator determinism and errors; the presets;
Jolt Humvees and their limits; a Humvee started on a generated world's terrain and
driven by an override; a live switch from the state tree to RoboRacers, an unknown name
ignored, back to the bicycle and on to the dynamic plant; both lifetimes).
…iadne document

python -m pycvc_gl.cars --copy DIR writes cars.py and cars.ari: controller(s, p) gets
every car's state as numpy arrays each tick and returns (steer, accel) per car, which
each car's plant takes in the navigator's place (nav_sim_world_override).

- The world: the document's data: block (scene-austin-south-small from cvcpkg.org by
  default; Run's URI or --uri loads another package or a local bundle), libcvc's
  terrain generator (the World window's world.* keys, Regenerate; Python generates the
  world for the cars, the navigator and the physics, the scene's generated_world node
  draws the same one), or a flat square. Each gives the same occupancy, terrain height
  and collision geometry.
- The plant: nav_plant.vehicle (plant_host): kinematic, humvee, roboracer, a comma
  list, dynamic[:presets], dynamic4w; it switches live, the cars keeping their poses.
- Settings: libcvc's own keys (nav.*, nav.vehicle.*, nav_plant.*), set in init:,
  bound to sliders, --set / --params, or from Python; settings() lists them with their
  units and ranges.
- Panels: readouts, a row per car, speed and gap plots, four coefficient plots (the
  controller's info or the navigator's telemetry: alpha, beta, gamma, ...), and rasters
  around the chosen car (signed distance with the predicted path, the controller's
  cost or the navigator's belief).
- Headless: --headless --frames N --log run.npz (states, commands, coefficients, rasters,
  predicted paths, and the world, seed and every setting in meta); exit 1 when the
  controller raises, 3 when --min-arrivals is unmet.
- Navigator baseline: --controller navigator, and --nav-weights for a .cvcnav policy.

pycvc_gl now ships *.ari files beside its modules. docs/CARS.md describes it (the
settings table generated from the keys' own metadata), linked from README.md,
ARIADNE.md 9.3 and the pycvc README. test_pycvc_gl_cars.py: 39 checks, headless.
A policy is trained in a normalized frame (GRL-SNAM's published one at 1 unit = 300 m);
Cars(scale=...) and --nav-scale build the sim_world in it, so --nav-weights drives in
the frame it expects. The default stays nav's 0.05. The log's meta records it.
transfix added a commit to CVC-Lab/GRL-SNAM that referenced this pull request Nov 6, 2026
…ator baseline

The template moved to libcvc as pycvc_gl.cars (transfix/libcvc#1035, on #1031's
bindings): general rather than GRL-SNAM specific, with the plant and the navigator's
settings in the document's state tree, Austin from the data: block by default, the
terrain generator as an alternative, rasters and coefficient panels, and the same
run headless. GRL-SNAM keeps a thin entry: grl-snam ariadne cars runs it (or --copy),
and --grl-policy gives libcvc's navigator the published grl-snam-weights policy,
exported to .cvcnav and run in its trained frame (--nav-scale). With a pycvc_gl
before 3.7.12 the entry says what to install.

grl_snam/cars.py and the template copy are gone. The README, the quickstart, PLANTS.md
and grl_snam/ariadne/README.md link to libcvc's docs/CARS.md.
tests/test_ariadne_cars.py: 5 tests (the entry, its message without the template, a
headless run, --copy, the navigator on GRL-SNAM's policy).
Base automatically changed from feat/pycvc-nav-override to master November 7, 2026 01:07
@transfix
transfix merged commit 797ba4d into master Nov 7, 2026
45 of 48 checks passed
@transfix
transfix deleted the feat/pycvc-gl-cars branch November 7, 2026 04:16
transfix added a commit to CVC-Lab/GRL-SNAM that referenced this pull request Nov 7, 2026
… GRL-SNAM's policy as a baseline (#155)

* Ariadne: a cars template for your own multi-car controller, on kinematic or Jolt physics

grl-snam ariadne cars runs N Ackermann cars that a controller of the user's own
drives: controller(s, p) at the top of a copyable cars.py gets every car's state
(pose, speed, wheel angle, goal, range rays, collisions, limits) as numpy arrays each
tick and returns (steer, accel) per car, bypassing the navigator. --copy DIR writes
cars.py and cars.ari to edit. The document's sliders feed the controller's parameters
(ctl.*), New goals / Reset call back into Python, and the panels show a row per car
and two plots. --headless --frames N --log run.npz|csv runs without GL and records
every tick's states and commands.

grl_snam.cars is the library under it: plants kinematic (nav's bicycle), jolt
(roboracer, humvee, or a comma list cycled over the cars) and dynamic; worlds flat,
blocks (scaled to the cars) and austin. With a pycvc that has nav_sim_world_override
(transfix/libcvc#1031) every plant runs in libcvc's sim_world with the command in its
navigator's place; with an older pycvc, kinematic runs the same bicycle in numpy and
jolt drives physics_world.drive (no reverse). navigator=True runs libcvc's navigator
as a baseline.

The README, the quickstart and PLANTS.md link the Ariadne ports and the template;
grl_snam/ariadne/README.md gains a 'Write your own multi-car controller' section:
the state, the panels, why the plant is the host's choice and not the document's,
what kinematic vs Jolt means for a controller (steering rate, the driver model, tire
slip, measured), and batch runs. tests/test_cars.py: 23 tests (3 need the override
binding and skip without it; none needs torch).

* cars: Austin with its aerial image, loaded once through the document's data store

--world austin drew the city with load_geometry_bundle, which paints the terrain one
colour, so the aerial image never showed. cars.ari now has the city node live.ari has
(source: data city, shown only on the Austin world), and cars.py loads Austin into the
data store at data.city: an installed bundle when there is one, else
scene-austin-south-small from cvcpkg.org, downloaded once and cached. The terrain is
drawn with satellite.png draped, and grl_snam.cars builds its occupancy and terrain
from the same loaded objects (austin_world(city=...)), so the bundle is read once.
A headless test runs the port on Austin when a bundle is installed.

* cars: run libcvc's multi-car template; GRL-SNAM's policy as the navigator baseline

The template moved to libcvc as pycvc_gl.cars (transfix/libcvc#1035, on #1031's
bindings): general rather than GRL-SNAM specific, with the plant and the navigator's
settings in the document's state tree, Austin from the data: block by default, the
terrain generator as an alternative, rasters and coefficient panels, and the same
run headless. GRL-SNAM keeps a thin entry: grl-snam ariadne cars runs it (or --copy),
and --grl-policy gives libcvc's navigator the published grl-snam-weights policy,
exported to .cvcnav and run in its trained frame (--nav-scale). With a pycvc_gl
before 3.7.12 the entry says what to install.

grl_snam/cars.py and the template copy are gone. The README, the quickstart, PLANTS.md
and grl_snam/ariadne/README.md link to libcvc's docs/CARS.md.
tests/test_ariadne_cars.py: 5 tests (the entry, its message without the template, a
headless run, --copy, the navigator on GRL-SNAM's policy).
transfix added a commit that referenced this pull request Nov 7, 2026
Bumps the project version and every recipe's upstream_version from 3.7.11 to 3.7.12. The v3.7.12 tag on this commit is the first release with the multi-car controller template (pycvc_gl.cars, #1031 #1035 #1040), the hidden-subtree fix in cvcGL (#1037), the discrete-gradient dyn_bike step (#978), semi-implicit Euler by default in the nav rollout (#981), the implicit contact damper (#1004, #1038), and generated_world's roads and water (#1032, #1034).
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