Sensor coverage

Estimate how well a set of sensors observes a fixed world — how much of the room and which objects are seen, and by how many sensors (0..N) — and search for a layout (how many, which type, placed where) that reaches a target coverage. Implemented in roqsim_sensors.coverage; the 2D heatmap needs the optional coverage extra (pip install 'roqsim_sensors[coverage]', already installed by make venv), the 3D render needs only MuJoCo. Rendering works headless without any setup — import roqsim selects an offscreen backend for the machine (see roqsim.gl.select_offscreen_gl()); set MUJOCO_GL only to override it.

There are two front doors onto the same core, and one offline command for a sensor that moves:

  • the plugin sensor_coverage_probe — a world-YAML toggle that reports the coverage of the sensors already in a world, computed once, at configure, for the mounts as placed;

  • the CLI roqsim sensors coverage — a placement-search workbench that evaluates hypothetical candidate mounts and iterates toward a target;

  • roqsim sensors coverage swept — reads a recorded run and accumulates the union of everything a sensor on a moving frame covered over it.

The first two ask where to put a sensor; the third asks what a sensor that moved ended up seeing. They are the same range → FOV → line-of-sight computation, so a number from one is comparable with a number from another only when both sampled the same way — which is why all three build their points with one sample-set builder (coverage/sampling.py’s sample_set).

Concepts

  • Field of view. Every sensor reduces to one SensorFov — a posed angular sector: a camera is a rectangular FRUSTUM, a lidar a CONE_BAND (azimuth × elevation band). It is extracted per sensor type by an adapter (see Developer guide › Sensor coverage (analysis layer)), so a camera’s FOV comes from its MJCF fovy/resolution and a lidar’s from its plugin defaults — never re-typed.

  • Coverage count. For each sample point, the number of sensors that see it, gated by range → angular FOV → line of sight (occlusion by walls/furniture, but not by the sensor’s own mount — see below). k=1 means “seen by ≥1 sensor”; k=2 is redundant coverage.

  • Sample targets. volume is a 3D grid of free interior points (room coverage); objects are points on object surfaces, labelled by geom name (are these objects seen?). “Interior” is a room test – a point keeps a sample only when a horizontal ray meets something on every side – so in an open world (a cell on a table, a yard) with no walls every volume point is dropped; --open keeps them, still dropping points inside a geom.

  • Orientation matters. At the identity orientation a sensor points along +x (world), up = +z. To look down, a camera needs orientation: {pitch: 1.5708}; an upright Livox (vertical band −7°..+52°) must be inverted (orientation: {roll: 3.14159}) or it sees almost nothing below it. Near-zero coverage is usually an orientation mistake.

  • Camera range is an assumption. A camera has no physical far range; the far you give it is a detection range and too generous a value inflates coverage (depth cameras default it to their clip_far).

The plugin (world-YAML toggle)

List sensor_coverage_probe in a world’s components: to compute coverage once (at configure) and write report.json plus a render in a run (a world compiled only to look at it writes nothing); omit it for none. sensors: auto evaluates every MuJoCo camera in the world but a device’s depth camera, which is another stream of the device beside its colour camera (camera_common.DEPTH_CAMERA_SUFFIX); give an explicit list for lidars/Livox or hypothetical placements.

components:
  - sensor_coverage_probe:
      sensors:                   # or `auto`: every MuJoCo camera in the world
        - type: livox_mid360     # {type, pose, config?, label?}
          pose: {position: {x: 3, y: 1, z: 2.4}, orientation: {roll: 3.14159}}
      target: {k: 1, frac: 0.95} # judged into report.json's target_met
      sample: {volume: true, objects: true, resolution: 0.25, heights: [0.3, 1.0, 1.7]}
      out: coverage              # writes report.json + render(s) here
      render: both               # 3d | 2d | both | none
      palette: coverage          # 'coverage' (red 0->green many) | 'density' (light 0->dark many)
roqsim sim world.yaml --headless --steps 1

A sensor that moves: swept over a recording

What a sensor carried through a world saw over a run is computed afterwards, from the run’s recording (roqsim sim world.yaml --record run.mcap). A recording holds the full MuJoCo state per sample, so each sample restores the world as it was — the carrier where it was, and every moving occluder where it was — and the same range → FOV → line-of-sight gate as estimate is ORed into a union over one fixed sample set. Because the run is already recorded, the sensor, the frame it rides on and its range are chosen afterwards, and one run answers any number of them:

roqsim sensors coverage swept --recording run.mcap \
    --frame robot/oakd/oakd_rgb --type oakd_camera --config '{"far": 5.0}' \
    --sample volume --resolution 0.25 --heights 0.5 --out swept/

--frame is a frame path (Paths: endpoints and frames): an entity’s root, body, site, camera or declared frame (robot/base_link, robot/oakd/oakd_rgb), or a body, site or camera of the world’s own MJCF by its MuJoCo name — a sensor on a gantry in the world file is --frame gantry or --frame gantry_cam. --pose offsets the sensor in the frame’s coordinates, a geometry_msgs/Pose as JSON whose omitted components are 0.

On a camera frame the field of view is that camera’s: its intrinsics come from the model rather than from the catalog entry for --type, and its axes are MuJoCo’s camera frame (looking along -z, +y up), so --pose '{"position": {"z": -0.3}}' moves it 0.3 m along the view. --config overrides fovy/width/height and sets the range. On any other frame the catalog entry and --config state the field of view, looking along the frame’s +x, as a placement whose orientation is the identity does.

--from/--to bound the sim-time window evaluated, and --rate thins the samples to at most that many evaluations per sim second; a rate above the recording’s is refused, since the states it would need were not recorded. The sampling, region and target options are estimate’s.

report.json has the static estimate’s shape — the covered fraction, per_object, per_region and the uncovered_regions the sweep never reached — with the frame as the one placement, plus a swept block: the covered and sampled areas and the grid cell they are derived from, the number of evaluations and the window they span, and the visit distribution (how many evaluations each point was seen in, as a mean, a maximum and a histogram).

Three things about the figure, all in the conservative direction:

  • It is a lower bound, sampled at the recording’s rate. The field of view is evaluated at the recorded states and never interpolated between them, because an interpolated field of view has no line-of-sight test behind it and would report coverage through walls. What the sensor swept between two samples is not counted; recording at a higher --capture-fps raises the figure.

  • The sample set is fixed, built once from the state at the first evaluated sample, so the union is comparable across windows of one run — and a cell occupied at that sample, by the carrier or by an occluder, is never sampled.

  • The area is per xy column, over the volume grid only: covered_area_m2 counts the distinct --resolution-sized cells covered at any height, so sampling three heights does not triple the area. With no grid points both areas read -1.0 rather than 0.

A raycast excludes the body the frame rides on, since a sensor’s origin sits inside its housing — except the world body, whose geometry is the walls.

Adding a sensor the tool doesn’t know

If build_fov raises no coverage FOV adapter for sensor type '<type>', register one in roqsim_sensors/coverage/adapters.py (@register_adapter("<type>") returning a SensorFov) and add a CATALOG entry in catalog.py. The sensor plugin itself is never modified. See Developer guide › Sensor coverage (analysis layer) for the design.

A catalog entry states policy, not optics. Write cost, mount and description – how this device may realistically be deployed – and name the bundled model it describes. The optics are read from that model: fovy and resolution off the MJCF camera its manifest wires to the capture plugin, near/far off the manifest’s fov: block. So a camera’s field of view is stated once, in the model, and the same numbers drive spawn_sensor: {show_fov: true} and a coverage study. A lidar entry names no model and needs no optics at all – its adapter instantiates the plugin and reads the defaults it resolved.

Restating those numbers in the catalog is what an entry must not do – a copy cannot be kept true by attention, and a catalog that disagrees with the model it names is worse than one that says nothing – so there is deliberately no field to write one in. fov_overrides exists for the genuine exception – a study pinning a camera’s far, which is an analysis assumption rather than a property of the device.

Visualising a sensor’s FOV directly

Independently of coverage, spawn_sensor: {show_fov: true} draws a sensor’s field of view in the viewer/renders. Three paths, tried in this order:

  • a camera mount (the RealSense/Zivid models) synthesises a translucent view frustum from each camera but a depth camera beside a colour one, from its fovy/aspect spanning fov_near..``fov_range``, always clipped against world geometry into a visibility volume that stops at walls and objects (see below);

  • a camera-less model that ships a bundled _fov mesh reveals it (none of the current models: the Zivid ships one but has a camera, so it takes the frustum path);

  • otherwise a camera-less lidar whose manifest’s fov: block declares an angular band (h_min/h_max/v_min/v_max) synthesises a translucent angular sector shell from those datasheet angles, using the very ray convention the capture plugin casts with – a full 360deg dome for the Mid-360, a bounded forward 120deg x 70deg wedge for the Robin W1G, a flat fan for each 2D scanner.

fov_near/fov_range default to the sensor model’s own fov: {near, far} block in its <model>.manifest.yaml (device knowledge lives with the device – Zivid 1.3..5 m, D435 0.28..6 m, Mid-360 0.1..40 m, Robin W1G 0.1..70 m), so show_fov: true alone draws the correct band; a world may override either per placement. fov_near sets the near cap of the drawn volume, so its shape is the valid detection band. A model that has a camera always synthesises its frustum from that camera, even the Zivid (which also ships a bundled _fov envelope) – the baked envelope stays hidden. The worlds/all_sensors_demo.yaml world shows every sensor’s FOV and runs a coverage probe.

A synthesised camera frustum or lidar sector is always clipped into a visibility volume that stops at walls and objects instead of passing through them (a fov_rays grid, default [32, 24], is cast from the camera, and a sector’s own azimuth x elevation grid from the scan site) – occlusion is unconditional, not a per-placement opt-in. Only a bundled _fov envelope is drawn un-clipped: it is a baked mesh. The clip is a static build-time snapshot of the world built so far, so list scene/floorplan plugins before the sensors; dynamic bodies occlude at their spawn pose and the volume does not update at runtime. This is a per-sensor visual (what one sensor can see); for the quantitative per-area overlap count across all sensors use the coverage probe with palette: density.

A sensor never occludes itself

A real device’s lens sits on the outside of its housing, but a MuJoCo <camera> sits at the pose the datasheet gives — millimetres behind the geom that models that face. A visibility ray therefore leaves the origin already inside the sensor’s own body, and without care the sensor’s own housing is the first thing it hits. So every FOV carries the body it is mounted on (SensorFov.body_exclude, from cam_bodyid/site_bodyid) and the ray cast excludes it — the same bodyexclude mechanism the lidar plugin’s exclude_body uses for a scanner’s own housing.

Worth stating because the symptom does not look like occlusion. The D435 mount’s d435_front sits 4.3 mm ahead of its camera, which unexcluded blocks the whole central cone while wide-angle fringe rays still escape — so a mounted camera reports a plausible but low number rather than an obvious zero, and a narrow long-range sensor (the Zivid, near 1.3 m) reports exactly 0 coverage in a room it sees perfectly well. A study that lets a mount occlude its own camera therefore under-reports every spawn_sensor-mounted sensor. A hypothetical placement (a pose, not spawned) is unaffected: it has no body, because nothing of it exists to get in the way.