diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index d6901b71be34..408a0c4a38d8 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -68,6 +68,7 @@ void GcodeSuite::M420() { #if ENABLED(MARLIN_DEV_MODE) if (parser.intval('S') == 2) { + // Farthest XY coordinates that the probe can reach const float x_min = probe.min_x(), x_max = probe.max_x(), y_min = probe.min_y(), y_max = probe.max_y(); #if ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -75,7 +76,8 @@ void GcodeSuite::M420() { start.set(x_min, y_min); spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X), (y_max - y_min) / (GRID_MAX_CELLS_Y)); - bedlevel.set_grid(spacing, start); + // Shift the grid bounds by the probe offset because...? + bedlevel.set_grid(spacing, Probe::tool_xy_for_probe_xy(start)); #endif GRID_LOOP(x, y) { bedlevel.z_values[x][y] = 0.001 * random(-200, 200); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index c2a99cb16d32..bd3fc4a0244b 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -521,7 +521,9 @@ G29_TYPE GcodeSuite::G29() { #endif #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - if (!abl.dryrun && (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)) { + // Convert the probe-space grid origin to the motion/nozzle coordinate + const xy_pos_t grid_start = Probe::tool_xy_for_probe_xy(abl.probe_position_lf); + if (!abl.dryrun && (abl.gridSpacing != bedlevel.grid_spacing || grid_start != bedlevel.grid_start)) { reset_bed_level(); // Reset grid to 0.0 or "not probed". (Also disables ABL) abl.reenable = false; // Can't re-enable (on error) until the new grid is written } @@ -880,7 +882,7 @@ G29_TYPE GcodeSuite::G29() { if (abl.dryrun) bedlevel.print_leveling_grid(&abl.z_values); else { - bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf); + bedlevel.set_grid(abl.gridSpacing, Probe::tool_xy_for_probe_xy(abl.probe_position_lf)); COPY(bedlevel.z_values, abl.z_values); TERN_(IS_KINEMATIC, bedlevel.extrapolate_unprobed_bed_level()); bedlevel.refresh_bed_level(); diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index 4f2a10eb1aac..116e46a45318 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -244,6 +244,18 @@ class Probe { static constexpr xy_pos_t offset_xy = xy_pos_t({ 0, 0 }); // See #16767 #endif + // Input: A coordinate destination for the probe. + // Return: The tool position that will put the probe there. + // Also adjusted for the tool offset unless PROBING_TOOL is used. + // With PROBING_TOOL the probe offsets are presumed relative to that tool, not T0. + static xy_pos_t tool_xy_for_probe_xy(const xy_pos_t &probe_xy) { + xy_pos_t nozPos = DIFF_TERN(HAS_PROBE_XY_OFFSET, probe_xy, offset_xy); + #if DISABLED(DO_TOOLCHANGE_FOR_PROBING) + nozPos += xy_pos_t(motion.active_hotend_offset()); + #endif + return nozPos; + } + static bool deploy(const bool no_return=false) { return set_deployed(true, no_return); } static bool stow(const bool no_return=false) { return set_deployed(false, no_return); } diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index a83740b5d028..ac08111dc3c0 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -3190,7 +3190,7 @@ void MarlinSettings::postprocess() { #define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, bedlevel.z_values)) uint16_t MarlinSettings::calc_num_meshes() { - return MIN(MAX_SAVED_MESHES, (meshes_end - meshes_start_index()) / MESH_STORE_SIZE); + return _MIN(MAX_SAVED_MESHES, (meshes_end - meshes_start_index()) / MESH_STORE_SIZE); } int MarlinSettings::mesh_slot_offset(const int8_t slot) {