nx_bed_mesh.nx
buildroot/runtime/nx_bed_mesh.nx
about
nx_bed_mesh.nx -- slicer-side per-XY Z compensation from a probed
bed-mesh model.
=====================================================================
EXCEED axis (research baseline)
=====================================================================
Industry treatment of bed warp (as of 2026-05):
Klipper: BED_MESH_PROFILE_LOAD + Z_TILT_ADJUST -- mesh is
probed by firmware, Z-correction applied at GCODE
EXECUTION time. Slicer is bed-naive.
Marlin: M420 S1 -- runtime correction, same model.
RepRapFirmware: M557 + bed-mesh compensation, runtime.
OrcaSlicer 2.3.2: single-number "First Layer Print Height
Compensation" -- one global offset, not per-XY.
PrusaSlicer 2.7: mesh-leveling AWARE (knows the printer does it)
but emits FLAT first-layer G-code; relies on
firmware to compensate.
Bambu Studio: no slicer-side mesh compensation.
All four major slicers EMIT FLAT G-code for the first layer and
rely on firmware-side Z correction. This breaks for:
- Firmware without mesh leveling (older boards, custom builds)
- G-code archived / shared / printed on a different machine
- Printers with mesh data the operator wants embedded for
reproducibility
This file ships slicer-side bilinear-interp per-XY Z compensation
baked DIRECTLY into the Z coordinates of the emitted G-code, with
layer-tapered fade-out so the model still meets nominal Z by the
time bed warp stops mattering (typically 1-2 mm above bed).
=====================================================================
license_tier: ORIGINAL
dependencies 1 imports · 5 importers
imports: nx_syscalls.nx
imported by: nx_bed_mesh_adversarial_test.nxnx_bed_mesh_test.nxnx_bedmesh_emit_test.nxnx_gcode_emit.nxnx_print_exceed_compose_test.nx
structs
| 53 | struct NxBedMesh |
consts
| 39 | const NX_MAGIC_16384: i64 = 16384 |
| 43 | const NX_BED_MESH_OK: i64 = 0 |
| 44 | const NX_BED_MESH_ERR_BAD_INPUT: i64 = 1 |
| 45 | const NX_BED_MESH_ERR_BAD_INDEX: i64 = 2 |
| 64 | const NX_BED_MESH_BYTES: i64 = 64 |
| 69 | const NX_BED_MESH_TAPER_LAYERS: i64 = 10 |
functions
| 73 | func nx_bed_mesh_new(n_x: i64, n_y: i64, |
| 103 | func nx_bed_mesh_set_point(m: *NxBedMesh, ix: i64, iy: i64, |
| 121 | func nx_bed_mesh_z_offset(m: *NxBedMesh, x_q14: i64, y_q14: i64) -> i64 |
| 196 | func nx_bed_mesh_z_at_layer(m: *NxBedMesh, x_q14: i64, y_q14: i64, |