devkit_ui.terrain_mask

terrain_mask.py ──────────────── Bridges the grid_map traversability layer (see devkit_bringup/config/terrain_traversability_filters.yaml) to the devkit_f2c_planner package’s _run_f2c() vector input.

_run_f2c() takes polygons (corners_ll, obstacle_rings — lists of lat/lon points), not a raster. grid_map’s traversable layer is a raster mask (0/1 per cell). This module is the missing step: threshold -> trace the boundary of the unsafe (0) region -> reproject each ring’s vertices back to lat/lon using the same equirectangular anchor devkit_f2c_planner already uses, so the traced obstacle rings line up with whatever field boundary _run_f2c() is given.

Pure functions, no ROS/grid_map_msgs dependency here — callers decode the GridMap message and pass in a plain numpy array + its resolution/origin, so this stays unit-testable without a running node.

Functions

traversability_mask_to_latlon_rings(mask, ...)

Trace the unsafe (mask < threshold) region into lat/lon rings.

devkit_ui.terrain_mask.traversability_mask_to_latlon_rings(mask: ndarray, resolution_m: float, origin_xy: tuple[float, float], anchor_lat: float, anchor_lon: float, threshold: float = 0.5, min_ring_area_m2: float = 1.0) → list[list[tuple[float, float]]][source]

Trace the unsafe (mask < threshold) region into lat/lon rings.

Parameters:
  • mask – 2D traversability layer, 1 = safe, 0 = unsafe (grid_map’s traversable layer, or any array on that convention).

  • resolution_m – metres per cell (grid_map’s map resolution).

  • origin_xy – (x, y) of mask[0, 0] in the same local-XY frame that anchor_lat/anchor_lon projects to via f2c_planner’s equirectangular approximation.

  • anchor_lat – the SAME anchor _run_f2c() will use for corners_ll[0] — mismatched anchors silently misalign the obstacle rings against the field boundary.

  • anchor_lon – the SAME anchor _run_f2c() will use for corners_ll[0] — mismatched anchors silently misalign the obstacle rings against the field boundary.

  • threshold – contour level; cells below this are “unsafe”.

  • min_ring_area_m2 – drop rings smaller than this (noise / single missed-coverage cells, not real unsafe regions).

Returns:

List of rings, each a list of (lat, lon) — directly usable as f2c_planner._run_f2c()’s obstacle_rings argument.