Skip to content

pycvc: nav_terrain_build, the terrain planes as numpy arrays - #696

Merged
transfix merged 1 commit into
masterfrom
feat/pycvc-terrain-build
Oct 18, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/pycvc-terrain-build

Conversation

@transfix

Copy link
Copy Markdown
Owner

This is the C++ reference for a Python twin of P5's terrain plane, which closes the open item "GRL-SNAM's Python twin of H1". grl-snam-dbg's grade force (H1 in _compose_forces) needs the same planes.

pycvc.nav_terrain_build(heights, cell_w, config) runs terrain_build and returns a dict:

  • slope: (2, rows, cols) float32, dz/dx then dz/dy;
  • grade_cost: (rows, cols) float32, 1 at the vehicle's limit;
  • infeasible: (rows, cols) uint8;
  • limit: the tangent of the steepest feasible slope.

config is nav_plant.terrain_config_of's dict form; missing keys keep the defaults.

Test

test_pycvc_physics.py, 68 checks on Windows:

  • Against numpy, bit for bit: the slope is np.gradient of the float32 heights, and the grade cost is min(1, sin(atan t) / sin(atan limit)) in double, stored as float32.
  • Also: the infeasible cells, a tip ratio lowering the limit, and cell_w 0 refused.

The new pycvc-linux CI job (#694) runs it on every PR once that merges.

The C++ reference for a Python twin of P5's terrain plane (the open item
"GRL-SNAM's Python twin of H1"). grl-snam-dbg's grade force needs the
same planes. nav_terrain_build(heights, cell_w, config) runs
terrain_build and returns its slope ((2, rows, cols) float32), grade
cost, infeasible cells and limit; config is terrain_config_of's dict
form.

test_pycvc_physics checks it against numpy, bit for bit: the slope is
np.gradient of the float32 heights, and the grade cost is
min(1, sin(atan t) / sin(atan limit)) in double, stored float32. It
also checks the infeasible cells, a tip ratio lowering the limit, and
cell_w 0 refused (68 checks).
transfix added a commit to CVC-Lab/GRL-SNAM that referenced this pull request Oct 18, 2026
grl_snam/terrain.py is the twin of libcvc's cvc/nav/terrain.h, the
terrain-physics plane of the vehicle-physics plan's P5:
- terrain_planes(heights, cell_w, max_grade, tip_ratio, tip_margin):
  the slope, the grade cost (sin over the sine of the vehicle's limit)
  and the infeasible cells, bit-identical to cvc::nav::terrain_build;
- terrain_limit;
- terrain_material(heights, bounds, ...): the grade cost and the
  infeasible cells as a MaterialGrid, whose field gives the material
  force law the soft grade force and the barrier, as
  sim_world::set_terrain builds them;
- climb_weight, the H5 route cost's per-metre weight.

tests/test_terrain.py: a plane's slope and cost, a tip ratio lowering
the limit, the material field pushing downhill, and, with a pycvc
carrying nav_terrain_build (transfix/libcvc#696), the planes equal to
libcvc's bit for bit under three configs (5 passed locally).
@transfix
transfix merged commit 4f03e1f into master Oct 18, 2026
15 checks passed
@transfix
transfix deleted the feat/pycvc-terrain-build branch October 18, 2026 22:17
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