2017-09-06 06:28:31 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 06:28:31 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 06:28:31 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
|
|
|
* G29.cpp - Auto Bed Leveling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../../inc/MarlinConfig.h"
|
|
|
|
|
2019-02-24 20:29:03 -06:00
|
|
|
#if HAS_ABL_NOT_UBL
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#include "../../gcode.h"
|
|
|
|
#include "../../../feature/bedlevel/bedlevel.h"
|
|
|
|
#include "../../../module/motion.h"
|
|
|
|
#include "../../../module/planner.h"
|
|
|
|
#include "../../../module/stepper.h"
|
|
|
|
#include "../../../module/probe.h"
|
2017-11-07 15:36:33 -06:00
|
|
|
#include "../../queue.h"
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2019-08-01 20:11:26 -05:00
|
|
|
#if HAS_DISPLAY
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "../../../lcd/ultralcd.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
#include "../../../libs/least_squares_fit.h"
|
|
|
|
#endif
|
|
|
|
|
2018-05-01 07:05:18 -05:00
|
|
|
#if ABL_PLANAR
|
|
|
|
#include "../../../libs/vector_3.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#include "../../../core/debug_out.h"
|
|
|
|
|
2019-04-26 02:32:01 -05:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
#include "../../../lcd/extensible_ui/ui_api.h"
|
|
|
|
#endif
|
|
|
|
|
2019-05-26 14:53:21 -05:00
|
|
|
#if HOTENDS > 1
|
|
|
|
#include "../../../module/tool_change.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
#if ABL_GRID
|
|
|
|
#if ENABLED(PROBE_Y_FIRST)
|
2019-09-29 04:25:39 -05:00
|
|
|
#define PR_OUTER_VAR meshCount.x
|
|
|
|
#define PR_OUTER_END abl_grid_points.x
|
|
|
|
#define PR_INNER_VAR meshCount.y
|
|
|
|
#define PR_INNER_END abl_grid_points.y
|
2017-09-06 06:28:31 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
#define PR_OUTER_VAR meshCount.y
|
|
|
|
#define PR_OUTER_END abl_grid_points.y
|
|
|
|
#define PR_INNER_VAR meshCount.x
|
|
|
|
#define PR_INNER_END abl_grid_points.x
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-06-29 20:48:11 -05:00
|
|
|
#if ENABLED(G29_RETRY_AND_RECOVER)
|
|
|
|
#define G29_RETURN(b) return b;
|
|
|
|
#else
|
|
|
|
#define G29_RETURN(b) return;
|
2018-07-25 18:49:32 -05:00
|
|
|
#endif
|
2018-06-29 20:48:11 -05:00
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
/**
|
|
|
|
* G29: Detailed Z probe, probes the bed at 3 or more points.
|
|
|
|
* Will fail if the printer has not been homed with G28.
|
|
|
|
*
|
|
|
|
* Enhanced G29 Auto Bed Leveling Probe Routine
|
|
|
|
*
|
2018-06-11 21:51:48 -05:00
|
|
|
* O Auto-level only if needed
|
|
|
|
*
|
2017-09-06 06:28:31 -05:00
|
|
|
* D Dry-Run mode. Just evaluate the bed Topology - Don't apply
|
|
|
|
* or alter the bed level data. Useful to check the topology
|
|
|
|
* after a first run of G29.
|
|
|
|
*
|
|
|
|
* J Jettison current bed leveling data
|
|
|
|
*
|
|
|
|
* V Set the verbose level (0-4). Example: "G29 V3"
|
|
|
|
*
|
|
|
|
* Parameters With LINEAR leveling only:
|
|
|
|
*
|
|
|
|
* P Set the size of the grid that will be probed (P x P points).
|
|
|
|
* Example: "G29 P4"
|
|
|
|
*
|
|
|
|
* X Set the X size of the grid that will be probed (X x Y points).
|
|
|
|
* Example: "G29 X7 Y5"
|
|
|
|
*
|
|
|
|
* Y Set the Y size of the grid that will be probed (X x Y points).
|
|
|
|
*
|
|
|
|
* T Generate a Bed Topology Report. Example: "G29 P5 T" for a detailed report.
|
|
|
|
* This is useful for manual bed leveling and finding flaws in the bed (to
|
|
|
|
* assist with part placement).
|
|
|
|
* Not supported by non-linear delta printer bed leveling.
|
|
|
|
*
|
|
|
|
* Parameters With LINEAR and BILINEAR leveling only:
|
|
|
|
*
|
|
|
|
* S Set the XY travel speed between probe points (in units/min)
|
|
|
|
*
|
2018-10-27 20:30:21 -05:00
|
|
|
* H Set bounds to a centered square H x H units in size
|
|
|
|
*
|
|
|
|
* -or-
|
|
|
|
*
|
2017-09-06 06:28:31 -05:00
|
|
|
* F Set the Front limit of the probing grid
|
|
|
|
* B Set the Back limit of the probing grid
|
|
|
|
* L Set the Left limit of the probing grid
|
|
|
|
* R Set the Right limit of the probing grid
|
|
|
|
*
|
|
|
|
* Parameters with DEBUG_LEVELING_FEATURE only:
|
|
|
|
*
|
|
|
|
* C Make a totally fake grid with no actual probing.
|
|
|
|
* For use in testing when no probing is possible.
|
|
|
|
*
|
|
|
|
* Parameters with BILINEAR leveling only:
|
|
|
|
*
|
|
|
|
* Z Supply an additional Z probe offset
|
|
|
|
*
|
|
|
|
* Extra parameters with PROBE_MANUALLY:
|
|
|
|
*
|
|
|
|
* To do manual probing simply repeat G29 until the procedure is complete.
|
|
|
|
* The first G29 accepts parameters. 'G29 Q' for status, 'G29 A' to abort.
|
|
|
|
*
|
|
|
|
* Q Query leveling and G29 state
|
|
|
|
*
|
|
|
|
* A Abort current leveling procedure
|
|
|
|
*
|
|
|
|
* Extra parameters with BILINEAR only:
|
|
|
|
*
|
|
|
|
* W Write a mesh point. (If G29 is idle.)
|
|
|
|
* I X index for mesh point
|
|
|
|
* J Y index for mesh point
|
|
|
|
* X X for mesh point, overrides I
|
|
|
|
* Y Y for mesh point, overrides J
|
|
|
|
* Z Z for mesh point. Otherwise, raw current Z.
|
|
|
|
*
|
|
|
|
* Without PROBE_MANUALLY:
|
|
|
|
*
|
|
|
|
* E By default G29 will engage the Z probe, test the bed, then disengage.
|
|
|
|
* Include "E" to engage/disengage the Z probe for each sample.
|
|
|
|
* There's no extra effect if you have a fixed Z probe.
|
|
|
|
*
|
|
|
|
*/
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_TYPE GcodeSuite::G29() {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(DEBUG_LEVELING_FEATURE, PROBE_MANUALLY)
|
2018-01-23 13:08:46 -06:00
|
|
|
const bool seenQ = parser.seen('Q');
|
|
|
|
#else
|
|
|
|
constexpr bool seenQ = false;
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// G29 Q is also available if debugging
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
const uint8_t old_debug_flags = marlin_debug_flags;
|
2018-11-05 22:48:28 -06:00
|
|
|
if (seenQ) marlin_debug_flags |= MARLIN_DEBUG_LEVELING;
|
2017-09-06 06:28:31 -05:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
2017-10-14 02:46:05 -05:00
|
|
|
DEBUG_POS(">>> G29", current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
log_machine_info();
|
|
|
|
}
|
|
|
|
marlin_debug_flags = old_debug_flags;
|
|
|
|
#if DISABLED(PROBE_MANUALLY)
|
2018-06-29 20:48:11 -05:00
|
|
|
if (seenQ) G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
2018-01-23 13:08:46 -06:00
|
|
|
const bool seenA = parser.seen('A');
|
2017-09-06 06:28:31 -05:00
|
|
|
#else
|
2018-01-23 13:08:46 -06:00
|
|
|
constexpr bool seenA = false;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2018-01-23 13:08:46 -06:00
|
|
|
const bool no_action = seenA || seenQ,
|
|
|
|
faux =
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(PROBE_MANUALLY)
|
|
|
|
parser.boolval('C')
|
|
|
|
#else
|
|
|
|
no_action
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// Don't allow auto-leveling without homing first
|
2018-06-29 20:48:11 -05:00
|
|
|
if (axis_unhomed_error()) G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2018-06-11 21:51:48 -05:00
|
|
|
if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Auto-level not needed, skip\n<<< G29");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2018-06-11 21:51:48 -05:00
|
|
|
}
|
2018-06-11 21:57:26 -05:00
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// Define local vars 'static' for manual probing, 'auto' otherwise
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
|
|
|
#define ABL_VAR static
|
|
|
|
#else
|
|
|
|
#define ABL_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ABL_VAR int verbose_level;
|
2019-09-29 04:25:39 -05:00
|
|
|
ABL_VAR xy_pos_t probePos;
|
|
|
|
ABL_VAR float measured_z;
|
2017-09-06 06:28:31 -05:00
|
|
|
ABL_VAR bool dryrun, abl_should_enable;
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
|
2017-09-06 06:28:31 -05:00
|
|
|
ABL_VAR int abl_probe_index;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_SOFTWARE_ENDSTOPS && ENABLED(PROBE_MANUALLY)
|
2019-03-13 05:48:36 -05:00
|
|
|
ABL_VAR bool saved_soft_endstops_state = true;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ABL_GRID
|
|
|
|
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
2019-10-31 13:13:51 -05:00
|
|
|
ABL_VAR xy_uint8_t meshCount;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
ABL_VAR xy_int_t probe_position_lf, probe_position_rb;
|
|
|
|
ABL_VAR xy_float_t gridSpacing = { 0, 0 };
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
ABL_VAR bool do_topography_map;
|
2019-09-29 04:25:39 -05:00
|
|
|
ABL_VAR xy_uint8_t abl_grid_points;
|
2017-09-06 06:28:31 -05:00
|
|
|
#else // Bilinear
|
2019-09-29 04:25:39 -05:00
|
|
|
constexpr xy_uint8_t abl_grid_points = { GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y };
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
2018-03-28 18:37:08 -05:00
|
|
|
ABL_VAR int abl_points;
|
2017-09-08 15:35:25 -05:00
|
|
|
#elif ENABLED(PROBE_MANUALLY) // Bilinear
|
2018-03-28 18:37:08 -05:00
|
|
|
int constexpr abl_points = GRID_MAX_POINTS;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
ABL_VAR float zoffset;
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
|
|
|
|
ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
|
2019-08-01 20:11:26 -05:00
|
|
|
ABL_VAR float eqnAMatrix[(GRID_MAX_POINTS) * 3], // "A" matrix of the linear system of equations
|
|
|
|
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
|
2017-09-06 06:28:31 -05:00
|
|
|
mean;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
2018-03-28 18:37:08 -05:00
|
|
|
int constexpr abl_points = 3; // used to show total points
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Probe at 3 arbitrary points
|
2019-09-25 02:43:41 -05:00
|
|
|
const float x_min = probe_min_x(), x_max = probe_max_x(), y_min = probe_min_y(), y_max = probe_max_y();
|
2019-09-28 01:19:11 -05:00
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
ABL_VAR vector_3 points[3] = {
|
2019-09-29 04:25:39 -05:00
|
|
|
#if ENABLED(HAS_FIXED_3POINT)
|
|
|
|
{ PROBE_PT_1_X, PROBE_PT_1_Y, 0 },
|
|
|
|
{ PROBE_PT_2_X, PROBE_PT_2_Y, 0 },
|
|
|
|
{ PROBE_PT_3_X, PROBE_PT_3_Y, 0 }
|
|
|
|
#else
|
|
|
|
{ x_min, y_min, 0 },
|
|
|
|
{ x_max, y_min, 0 },
|
|
|
|
{ (x_max - x_min) / 2, y_max, 0 }
|
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_3POINT
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On the initial G29 fetch command parameters.
|
|
|
|
*/
|
|
|
|
if (!g29_in_progress) {
|
|
|
|
|
2019-05-26 14:53:21 -05:00
|
|
|
#if HOTENDS > 1
|
2018-06-19 22:54:20 -05:00
|
|
|
if (active_extruder != 0) tool_change(0);
|
|
|
|
#endif
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
|
2017-09-06 06:28:31 -05:00
|
|
|
abl_probe_index = -1;
|
|
|
|
#endif
|
|
|
|
|
2017-10-13 17:21:25 -05:00
|
|
|
abl_should_enable = planner.leveling_active;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
2018-02-01 03:17:42 -06:00
|
|
|
const bool seen_w = parser.seen('W');
|
|
|
|
if (seen_w) {
|
2017-09-06 06:28:31 -05:00
|
|
|
if (!leveling_is_valid()) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ERROR_MSG("No bilinear grid");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position.z;
|
2017-11-02 23:59:42 -05:00
|
|
|
if (!WITHIN(rz, -10, 10)) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ERROR_MSG("Bad Z value");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
2017-11-02 23:59:42 -05:00
|
|
|
const float rx = RAW_X_POSITION(parser.linearval('X', NAN)),
|
|
|
|
ry = RAW_Y_POSITION(parser.linearval('Y', NAN));
|
2019-08-01 20:11:26 -05:00
|
|
|
int8_t i = parser.byteval('I', -1), j = parser.byteval('J', -1);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2017-11-02 23:59:42 -05:00
|
|
|
if (!isnan(rx) && !isnan(ry)) {
|
|
|
|
// Get nearest i / j from rx / ry
|
2019-09-29 04:25:39 -05:00
|
|
|
i = (rx - bilinear_start.x + 0.5 * gridSpacing.x) / gridSpacing.x;
|
|
|
|
j = (ry - bilinear_start.y + 0.5 * gridSpacing.y) / gridSpacing.y;
|
2019-07-10 03:33:28 -05:00
|
|
|
LIMIT(i, 0, GRID_MAX_POINTS_X - 1);
|
|
|
|
LIMIT(j, 0, GRID_MAX_POINTS_Y - 1);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) {
|
|
|
|
set_bed_leveling_enabled(false);
|
2017-11-02 23:59:42 -05:00
|
|
|
z_values[i][j] = rz;
|
2017-09-06 06:28:31 -05:00
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
bed_level_virt_interpolate();
|
|
|
|
#endif
|
2019-03-13 00:45:52 -05:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(i, j, rz);
|
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2017-12-10 21:17:07 -06:00
|
|
|
if (abl_should_enable) report_current_position();
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
} // parser.seen('W')
|
|
|
|
|
2018-02-01 03:17:42 -06:00
|
|
|
#else
|
|
|
|
|
|
|
|
constexpr bool seen_w = false;
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2017-12-25 08:29:31 -06:00
|
|
|
// Jettison bed leveling data
|
2018-02-01 03:17:42 -06:00
|
|
|
if (!seen_w && parser.seen('J')) {
|
2017-12-25 08:29:31 -06:00
|
|
|
reset_bed_level();
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-12-25 08:29:31 -06:00
|
|
|
}
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
verbose_level = parser.intval('V');
|
|
|
|
if (!WITHIN(verbose_level, 0, 4)) {
|
2019-09-11 02:46:52 -05:00
|
|
|
SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dryrun = parser.boolval('D')
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
|
|
|
|| no_action
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
|
|
|
|
do_topography_map = verbose_level > 2 || parser.boolval('T');
|
|
|
|
|
|
|
|
// X and Y specify points in each direction, overriding the default
|
|
|
|
// These values may be saved with the completed mesh
|
2019-09-29 04:25:39 -05:00
|
|
|
abl_grid_points.set(
|
|
|
|
parser.byteval('X', GRID_MAX_POINTS_X),
|
|
|
|
parser.byteval('Y', GRID_MAX_POINTS_Y)
|
|
|
|
);
|
|
|
|
if (parser.seenval('P')) abl_grid_points.x = abl_grid_points.y = parser.value_int();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!WITHIN(abl_grid_points.x, 2, GRID_MAX_POINTS_X)) {
|
2019-09-11 02:46:52 -05:00
|
|
|
SERIAL_ECHOLNPGM("?Probe points (X) implausible (2-" STRINGIFY(GRID_MAX_POINTS_X) ").");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2018-02-10 16:53:58 -06:00
|
|
|
}
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!WITHIN(abl_grid_points.y, 2, GRID_MAX_POINTS_Y)) {
|
2019-09-11 02:46:52 -05:00
|
|
|
SERIAL_ECHOLNPGM("?Probe points (Y) implausible (2-" STRINGIFY(GRID_MAX_POINTS_Y) ").");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
abl_points = abl_grid_points.x * abl_grid_points.y;
|
2017-09-06 06:28:31 -05:00
|
|
|
mean = 0;
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
zoffset = parser.linearval('Z');
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ABL_GRID
|
|
|
|
|
|
|
|
xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_SPEED));
|
|
|
|
|
2019-09-24 23:34:07 -05:00
|
|
|
const float x_min = probe_min_x(), x_max = probe_max_x(),
|
|
|
|
y_min = probe_min_y(), y_max = probe_max_y();
|
|
|
|
|
2018-10-27 20:30:21 -05:00
|
|
|
if (parser.seen('H')) {
|
|
|
|
const int16_t size = (int16_t)parser.value_linear_units();
|
2019-09-29 04:25:39 -05:00
|
|
|
probe_position_lf.set(
|
|
|
|
_MAX(X_CENTER - size / 2, x_min),
|
|
|
|
_MAX(Y_CENTER - size / 2, y_min)
|
|
|
|
);
|
|
|
|
probe_position_rb.set(
|
|
|
|
_MIN(probe_position_lf.x + size, x_max),
|
|
|
|
_MIN(probe_position_lf.y + size, y_max)
|
|
|
|
);
|
2018-10-27 20:30:21 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-09-29 04:25:39 -05:00
|
|
|
probe_position_lf.set(
|
|
|
|
parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MAX(X_CENTER - (X_BED_SIZE) / 2, x_min),
|
|
|
|
parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MAX(Y_CENTER - (Y_BED_SIZE) / 2, y_min)
|
|
|
|
);
|
|
|
|
probe_position_rb.set(
|
|
|
|
parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MIN(probe_position_lf.x + X_BED_SIZE, x_max),
|
|
|
|
parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MIN(probe_position_lf.y + Y_BED_SIZE, y_max)
|
|
|
|
);
|
2018-10-27 20:30:21 -05:00
|
|
|
}
|
2017-11-07 15:36:33 -06:00
|
|
|
|
2018-04-27 00:33:58 -05:00
|
|
|
if (
|
|
|
|
#if IS_SCARA || ENABLED(DELTA)
|
2019-09-29 04:25:39 -05:00
|
|
|
!position_is_reachable_by_probe(probe_position_lf.x, 0)
|
|
|
|
|| !position_is_reachable_by_probe(probe_position_rb.x, 0)
|
|
|
|
|| !position_is_reachable_by_probe(0, probe_position_lf.y)
|
|
|
|
|| !position_is_reachable_by_probe(0, probe_position_rb.y)
|
2018-04-27 00:33:58 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
!position_is_reachable_by_probe(probe_position_lf)
|
|
|
|
|| !position_is_reachable_by_probe(probe_position_rb)
|
2018-04-27 00:33:58 -05:00
|
|
|
#endif
|
|
|
|
) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// probe at the points of a lattice grid
|
2019-09-29 04:25:39 -05:00
|
|
|
gridSpacing.set((probe_position_rb.x - probe_position_lf.x) / (abl_grid_points.x - 1),
|
|
|
|
(probe_position_rb.y - probe_position_lf.y) / (abl_grid_points.y - 1));
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#endif // ABL_GRID
|
|
|
|
|
|
|
|
if (verbose_level > 0) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("G29 Auto Bed Leveling");
|
|
|
|
if (dryrun) SERIAL_ECHOPGM(" (DRYRUN)");
|
2017-12-25 08:29:31 -06:00
|
|
|
SERIAL_EOL();
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2017-12-25 08:29:31 -06:00
|
|
|
// Disable auto bed leveling during G29.
|
2017-12-25 06:32:33 -06:00
|
|
|
// Be formal so G29 can be done successively without G28.
|
2018-01-23 13:08:46 -06:00
|
|
|
if (!no_action) set_bed_leveling_enabled(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
// Deploy the probe. Probe will raise if needed.
|
|
|
|
if (DEPLOY_PROBE()) {
|
2017-12-25 06:32:33 -06:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-23 20:58:01 -05:00
|
|
|
if (!faux) remember_feedrate_scaling_off();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
|
|
|
if (!no_action)
|
|
|
|
#endif
|
2019-09-29 04:25:39 -05:00
|
|
|
if (gridSpacing != bilinear_grid_spacing || probe_position_lf != bilinear_start) {
|
2017-09-06 06:28:31 -05:00
|
|
|
// Reset grid to 0.0 or "not probed". (Also disables ABL)
|
|
|
|
reset_bed_level();
|
|
|
|
|
|
|
|
// Initialize a grid with the given dimensions
|
2019-09-29 04:25:39 -05:00
|
|
|
bilinear_grid_spacing = gridSpacing.asInt();
|
|
|
|
bilinear_start = probe_position_lf;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Can't re-enable (on error) until the new grid is written
|
|
|
|
abl_should_enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_BILINEAR
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> 3-point Leveling");
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Probe at 3 arbitrary points
|
|
|
|
points[0].z = points[1].z = points[2].z = 0;
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_3POINT
|
|
|
|
|
|
|
|
} // !g29_in_progress
|
|
|
|
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
|
|
|
|
|
|
|
// For manual probing, get the next index to probe now.
|
|
|
|
// On the first probe this will be incremented to 0.
|
|
|
|
if (!no_action) {
|
|
|
|
++abl_probe_index;
|
|
|
|
g29_in_progress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Abort current G29 procedure, go back to idle state
|
|
|
|
if (seenA && g29_in_progress) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("Manual G29 aborted");
|
2017-09-06 06:28:31 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-03-13 05:48:36 -05:00
|
|
|
soft_endstops_enabled = saved_soft_endstops_state;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
2017-12-25 06:32:33 -06:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2017-09-06 06:28:31 -05:00
|
|
|
g29_in_progress = false;
|
|
|
|
#if ENABLED(LCD_BED_LEVELING)
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.wait_for_bl_move = false;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query G29 status
|
|
|
|
if (verbose_level || seenQ) {
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOPGM("Manual G29 ");
|
2017-09-06 06:28:31 -05:00
|
|
|
if (g29_in_progress) {
|
2019-07-05 18:01:21 -05:00
|
|
|
SERIAL_ECHOPAIR("point ", _MIN(abl_probe_index + 1, abl_points));
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPAIR(" of ", abl_points);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("idle");
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
2018-06-29 20:48:11 -05:00
|
|
|
if (no_action) G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
if (abl_probe_index == 0) {
|
2018-04-13 20:19:18 -05:00
|
|
|
// For the initial G29 S2 save software endstop state
|
2017-09-06 06:28:31 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-03-13 05:48:36 -05:00
|
|
|
saved_soft_endstops_state = soft_endstops_enabled;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
2018-04-13 20:19:18 -05:00
|
|
|
// Move close to the bed before the first point
|
2018-04-17 20:32:56 -05:00
|
|
|
do_blocking_move_to_z(0);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else {
|
2018-03-28 18:37:08 -05:00
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT)
|
2018-03-28 18:37:08 -05:00
|
|
|
const uint16_t index = abl_probe_index - 1;
|
|
|
|
#endif
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// For G29 after adjusting Z.
|
|
|
|
// Save the previous Z before going to the next point
|
2019-09-29 04:25:39 -05:00
|
|
|
measured_z = current_position.z;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
|
|
|
|
mean += measured_z;
|
2018-03-28 18:37:08 -05:00
|
|
|
eqnBVector[index] = measured_z;
|
2019-09-29 04:25:39 -05:00
|
|
|
eqnAMatrix[index + 0 * abl_points] = probePos.x;
|
|
|
|
eqnAMatrix[index + 1 * abl_points] = probePos.y;
|
2018-03-28 18:37:08 -05:00
|
|
|
eqnAMatrix[index + 2 * abl_points] = 1;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
incremental_LSF(&lsf_results, probePos, measured_z);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2018-03-28 18:37:08 -05:00
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
|
|
|
points[index].z = measured_z;
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const float newz = measured_z + zoffset;
|
|
|
|
z_values[meshCount.x][meshCount.y] = newz;
|
2019-03-13 00:45:52 -05:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2019-09-29 04:25:39 -05:00
|
|
|
ExtUI::onMeshUpdate(meshCount, newz);
|
2019-03-13 00:45:52 -05:00
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Save X", meshCount.x, " Y", meshCount.y, " Z", measured_z + zoffset);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If there's another point to sample, move there with optional lift.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if ABL_GRID
|
|
|
|
|
|
|
|
// Skip any unreachable points
|
2018-03-28 18:37:08 -05:00
|
|
|
while (abl_probe_index < abl_points) {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
// Set meshCount.x, meshCount.y based on abl_probe_index, with zig-zag
|
2017-09-06 06:28:31 -05:00
|
|
|
PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
|
|
|
|
PR_INNER_VAR = abl_probe_index - (PR_OUTER_VAR * PR_INNER_END);
|
|
|
|
|
|
|
|
// Probe in reverse order for every other row/column
|
|
|
|
bool zig = (PR_OUTER_VAR & 1); // != ((PR_OUTER_END) & 1);
|
|
|
|
|
|
|
|
if (zig) PR_INNER_VAR = (PR_INNER_END - 1) - PR_INNER_VAR;
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const xy_pos_t base = probe_position_lf.asFloat() + gridSpacing * meshCount.asFloat();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
probePos.set(FLOOR(base.x + (base.x < 0 ? 0 : 0.5)),
|
|
|
|
FLOOR(base.y + (base.y < 0 ? 0 : 0.5)));
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
2019-09-29 04:25:39 -05:00
|
|
|
indexIntoAB[meshCount.x][meshCount.y] = abl_probe_index;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Keep looping till a reachable point is found
|
2019-09-29 04:25:39 -05:00
|
|
|
if (position_is_reachable(probePos)) break;
|
2017-09-06 06:28:31 -05:00
|
|
|
++abl_probe_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is there a next point to move to?
|
2018-03-28 18:37:08 -05:00
|
|
|
if (abl_probe_index < abl_points) {
|
2019-09-29 04:25:39 -05:00
|
|
|
_manual_goto_xy(probePos); // Can be used here too!
|
2017-09-06 06:28:31 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
|
|
|
// Disable software endstops to allow manual adjustment
|
|
|
|
// If G29 is not completed, they will not be re-enabled
|
|
|
|
soft_endstops_enabled = false;
|
|
|
|
#endif
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Leveling done! Fall through to G29 finishing code below
|
|
|
|
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("Grid probing done.");
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Re-enable software endstops, if needed
|
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-03-13 05:48:36 -05:00
|
|
|
soft_endstops_enabled = saved_soft_endstops_state;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
|
|
|
// Probe at 3 arbitrary points
|
2018-03-28 18:37:08 -05:00
|
|
|
if (abl_probe_index < abl_points) {
|
2019-09-29 04:25:39 -05:00
|
|
|
probePos = points[abl_probe_index];
|
|
|
|
_manual_goto_xy(probePos);
|
2017-09-06 06:28:31 -05:00
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
|
|
|
// Disable software endstops to allow manual adjustment
|
|
|
|
// If G29 is not completed, they will not be re-enabled
|
|
|
|
soft_endstops_enabled = false;
|
|
|
|
#endif
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(false);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2018-11-29 16:58:58 -06:00
|
|
|
SERIAL_ECHOLNPGM("3-point probing done.");
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Re-enable software endstops, if needed
|
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
2019-03-13 05:48:36 -05:00
|
|
|
soft_endstops_enabled = saved_soft_endstops_state;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!dryrun) {
|
|
|
|
vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
|
2019-09-29 04:25:39 -05:00
|
|
|
if (planeNormal.z < 0) planeNormal *= -1;
|
2017-09-06 06:28:31 -05:00
|
|
|
planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
|
|
|
|
|
|
|
|
// Can't re-enable (on error) until the new grid is written
|
|
|
|
abl_should_enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_3POINT
|
|
|
|
|
|
|
|
#else // !PROBE_MANUALLY
|
|
|
|
{
|
2018-03-21 01:01:43 -05:00
|
|
|
const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
measured_z = 0;
|
|
|
|
|
|
|
|
#if ABL_GRID
|
|
|
|
|
|
|
|
bool zig = PR_OUTER_END & 1; // Always end at RIGHT and BACK_PROBE_BED_POSITION
|
|
|
|
|
2017-11-06 22:57:05 -06:00
|
|
|
measured_z = 0;
|
|
|
|
|
2019-10-31 13:13:51 -05:00
|
|
|
xy_uint8_t meshCount;
|
2019-09-29 04:25:39 -05:00
|
|
|
|
|
|
|
// Outer loop is X with PROBE_Y_FIRST enabled
|
2017-09-06 06:28:31 -05:00
|
|
|
// Outer loop is Y with PROBE_Y_FIRST disabled
|
2019-09-29 04:25:39 -05:00
|
|
|
for (PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_END && !isnan(measured_z); PR_OUTER_VAR++) {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-11-01 15:38:41 -05:00
|
|
|
uint8_t inStart, inStop, inInc;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
if (zig) { // away from origin
|
|
|
|
inStart = 0;
|
|
|
|
inStop = PR_INNER_END;
|
|
|
|
inInc = 1;
|
|
|
|
}
|
|
|
|
else { // towards origin
|
|
|
|
inStart = PR_INNER_END - 1;
|
2019-11-01 15:38:41 -05:00
|
|
|
inStop = 0xFF;
|
|
|
|
inInc = 0xFF;
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
zig ^= true; // zag
|
|
|
|
|
2019-08-01 20:11:26 -05:00
|
|
|
// An index to print current state
|
|
|
|
uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_END) + 1;
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// Inner loop is Y with PROBE_Y_FIRST enabled
|
2019-09-29 04:25:39 -05:00
|
|
|
// Inner loop is X with PROBE_Y_FIRST disabled
|
|
|
|
for (PR_INNER_VAR = inStart; PR_INNER_VAR != inStop; pt_index++, PR_INNER_VAR += inInc) {
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
const xy_pos_t base = probe_position_lf.asFloat() + gridSpacing * meshCount.asFloat();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
probePos.set(FLOOR(base.x + (base.x < 0 ? 0 : 0.5)),
|
|
|
|
FLOOR(base.y + (base.y < 0 ? 0 : 0.5)));
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
2019-09-29 04:25:39 -05:00
|
|
|
indexIntoAB[meshCount.x][meshCount.y] = ++abl_probe_index; // 0...
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
// Avoid probing outside the round or hexagonal area
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!position_is_reachable_by_probe(probePos)) continue;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
|
2019-08-01 20:11:26 -05:00
|
|
|
if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), ".");
|
|
|
|
#if HAS_DISPLAY
|
2019-10-09 19:46:10 -05:00
|
|
|
ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS));
|
2019-08-01 20:11:26 -05:00
|
|
|
#endif
|
|
|
|
|
2019-10-26 13:39:12 -05:00
|
|
|
measured_z = faux ? 0.001f * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
if (isnan(measured_z)) {
|
2017-12-25 06:32:33 -06:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2019-08-01 20:11:26 -05:00
|
|
|
break; // Breaks out of both loops
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
|
|
|
|
mean += measured_z;
|
|
|
|
eqnBVector[abl_probe_index] = measured_z;
|
2019-09-29 04:25:39 -05:00
|
|
|
eqnAMatrix[abl_probe_index + 0 * abl_points] = probePos.x;
|
|
|
|
eqnAMatrix[abl_probe_index + 1 * abl_points] = probePos.y;
|
2018-03-28 18:37:08 -05:00
|
|
|
eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
incremental_LSF(&lsf_results, probePos, measured_z);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
z_values[meshCount.x][meshCount.y] = measured_z + zoffset;
|
2019-03-13 00:45:52 -05:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2019-10-31 13:13:51 -05:00
|
|
|
ExtUI::onMeshUpdate(meshCount, z_values[meshCount.x][meshCount.y]);
|
2019-03-13 00:45:52 -05:00
|
|
|
#endif
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
abl_should_enable = false;
|
|
|
|
idle();
|
|
|
|
|
|
|
|
} // inner
|
|
|
|
} // outer
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
|
|
|
|
|
|
// Probe at 3 arbitrary points
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 3; ++i) {
|
2019-08-01 20:11:26 -05:00
|
|
|
if (verbose_level) SERIAL_ECHOLNPAIR("Probing point ", int(i), "/3.");
|
|
|
|
#if HAS_DISPLAY
|
2019-10-09 19:46:10 -05:00
|
|
|
ui.status_printf_P(0, PSTR(S_FMT" %i/3"), GET_TEXT(MSG_PROBING_MESH)), int(i);
|
2019-08-01 20:11:26 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
// Retain the last probe position
|
2019-09-29 04:25:39 -05:00
|
|
|
probePos = points[i];
|
|
|
|
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
|
2017-09-06 06:28:31 -05:00
|
|
|
if (isnan(measured_z)) {
|
2017-12-25 06:32:33 -06:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2017-09-06 06:28:31 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
points[i].z = measured_z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dryrun && !isnan(measured_z)) {
|
|
|
|
vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
|
2019-09-14 03:05:10 -05:00
|
|
|
if (planeNormal.z < 0) planeNormal *= -1;
|
2017-09-06 06:28:31 -05:00
|
|
|
planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
|
|
|
|
|
|
|
|
// Can't re-enable (on error) until the new grid is written
|
|
|
|
abl_should_enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_3POINT
|
|
|
|
|
2019-08-01 20:11:26 -05:00
|
|
|
#if HAS_DISPLAY
|
|
|
|
ui.reset_status();
|
|
|
|
#endif
|
|
|
|
|
2018-03-11 13:07:55 -05:00
|
|
|
// Stow the probe. No raise for FIX_MOUNTED_PROBE.
|
2017-09-06 06:28:31 -05:00
|
|
|
if (STOW_PROBE()) {
|
2017-12-25 06:32:33 -06:00
|
|
|
set_bed_leveling_enabled(abl_should_enable);
|
2017-09-06 06:28:31 -05:00
|
|
|
measured_z = NAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !PROBE_MANUALLY
|
|
|
|
|
|
|
|
//
|
|
|
|
// G29 Finishing Code
|
|
|
|
//
|
|
|
|
// Unless this is a dry run, auto bed leveling will
|
|
|
|
// definitely be enabled after this point.
|
|
|
|
//
|
|
|
|
// If code above wants to continue leveling, it should
|
|
|
|
// return or loop before this point.
|
|
|
|
//
|
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("> probing complete", current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
#if ENABLED(PROBE_MANUALLY)
|
|
|
|
g29_in_progress = false;
|
|
|
|
#if ENABLED(LCD_BED_LEVELING)
|
2018-11-11 12:16:24 -06:00
|
|
|
ui.wait_for_bl_move = false;
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Calculate leveling, print reports, correct the position
|
|
|
|
if (!isnan(measured_z)) {
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
if (!dryrun) extrapolate_unprobed_bed_level();
|
|
|
|
print_bilinear_leveling_grid();
|
|
|
|
|
|
|
|
refresh_bed_level();
|
|
|
|
|
|
|
|
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
|
|
|
|
print_bilinear_leveling_grid_virt();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
|
|
|
|
|
|
|
|
// For LINEAR leveling calculate matrix, print reports, correct the position
|
|
|
|
|
|
|
|
/**
|
|
|
|
* solve the plane equation ax + by + d = z
|
|
|
|
* A is the matrix with rows [x y 1] for all the probed points
|
|
|
|
* B is the vector of the Z positions
|
|
|
|
* the normal vector to the plane is formed by the coefficients of the
|
|
|
|
* plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
|
|
|
|
* so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
struct { float a, b, d; } plane_equation_coefficients;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
finish_incremental_LSF(&lsf_results);
|
2019-09-29 04:25:39 -05:00
|
|
|
plane_equation_coefficients.a = -lsf_results.A; // We should be able to eliminate the '-' on these three lines and down below
|
|
|
|
plane_equation_coefficients.b = -lsf_results.B; // but that is not yet tested.
|
|
|
|
plane_equation_coefficients.d = -lsf_results.D;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2018-03-28 18:37:08 -05:00
|
|
|
mean /= abl_points;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
if (verbose_level) {
|
2019-09-29 04:25:39 -05:00
|
|
|
SERIAL_ECHOPAIR_F("Eqn coefficients: a: ", plane_equation_coefficients.a, 8);
|
|
|
|
SERIAL_ECHOPAIR_F(" b: ", plane_equation_coefficients.b, 8);
|
|
|
|
SERIAL_ECHOPAIR_F(" d: ", plane_equation_coefficients.d, 8);
|
2018-11-29 16:58:58 -06:00
|
|
|
if (verbose_level > 2)
|
|
|
|
SERIAL_ECHOPAIR_F("\nMean of sampled points: ", mean, 8);
|
2017-09-06 06:28:31 -05:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the matrix but don't correct the position yet
|
|
|
|
if (!dryrun)
|
|
|
|
planner.bed_level_matrix = matrix_3x3::create_look_at(
|
2019-09-29 04:25:39 -05:00
|
|
|
vector_3(-plane_equation_coefficients.a, -plane_equation_coefficients.b, 1) // We can eliminate the '-' here and up above
|
2017-09-06 06:28:31 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Show the Topography map if enabled
|
|
|
|
if (do_topography_map) {
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
float min_diff = 999;
|
|
|
|
|
|
|
|
auto print_topo_map = [&](PGM_P const title, const bool get_min) {
|
|
|
|
serialprintPGM(title);
|
|
|
|
for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) {
|
|
|
|
for (uint8_t xx = 0; xx < abl_grid_points.x; xx++) {
|
|
|
|
const int ind = indexIntoAB[xx][yy];
|
|
|
|
xyz_float_t tmp = { eqnAMatrix[ind + 0 * abl_points],
|
|
|
|
eqnAMatrix[ind + 1 * abl_points], 0 };
|
|
|
|
apply_rotation_xyz(planner.bed_level_matrix, tmp);
|
|
|
|
if (get_min) NOMORE(min_diff, eqnBVector[ind] - tmp.z);
|
|
|
|
const float subval = get_min ? mean : tmp.z + min_diff,
|
|
|
|
diff = eqnBVector[ind] - subval;
|
|
|
|
SERIAL_CHAR(' '); if (diff >= 0.0) SERIAL_CHAR('+'); // Include + for column alignment
|
|
|
|
SERIAL_ECHO_F(diff, 5);
|
|
|
|
} // xx
|
|
|
|
SERIAL_EOL();
|
|
|
|
} // yy
|
|
|
|
SERIAL_EOL();
|
|
|
|
};
|
|
|
|
|
|
|
|
print_topo_map(PSTR("\nBed Height Topography:\n"
|
2017-09-06 06:28:31 -05:00
|
|
|
" +--- BACK --+\n"
|
|
|
|
" | |\n"
|
|
|
|
" L | (+) | R\n"
|
|
|
|
" E | | I\n"
|
|
|
|
" F | (-) N (+) | G\n"
|
|
|
|
" T | | H\n"
|
|
|
|
" | (-) | T\n"
|
|
|
|
" | |\n"
|
|
|
|
" O-- FRONT --+\n"
|
2019-09-29 04:25:39 -05:00
|
|
|
" (0,0)\n"), true);
|
|
|
|
if (verbose_level > 3)
|
|
|
|
print_topo_map(PSTR("\nCorrected Bed Height vs. Bed Topology:\n"), false);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
} //do_topography_map
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_LINEAR
|
|
|
|
|
|
|
|
#if ABL_PLANAR
|
|
|
|
|
|
|
|
// For LINEAR and 3POINT leveling correct the current position
|
|
|
|
|
|
|
|
if (verbose_level > 0)
|
|
|
|
planner.bed_level_matrix.debug(PSTR("\n\nBed Level Correction Matrix:"));
|
|
|
|
|
|
|
|
if (!dryrun) {
|
|
|
|
//
|
|
|
|
// Correct the current XYZ position based on the tilted plane.
|
|
|
|
//
|
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("G29 uncorrected XYZ", current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
xyze_pos_t converted = current_position;
|
|
|
|
planner.force_unapply_leveling(converted); // use conversion machinery
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Use the last measured distance to the bed, if possible
|
2019-09-29 04:25:39 -05:00
|
|
|
if ( NEAR(current_position.x, probePos.x - probe_offset.x)
|
|
|
|
&& NEAR(current_position.y, probePos.y - probe_offset.y)
|
2017-09-06 06:28:31 -05:00
|
|
|
) {
|
2019-09-29 04:25:39 -05:00
|
|
|
const float simple_z = current_position.z - measured_z;
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted.z, " Discrepancy ", simple_z - converted.z);
|
|
|
|
converted.z = simple_z;
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// The rotated XY and corrected Z are now current_position
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position = converted;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
if (!dryrun) {
|
2019-09-29 04:25:39 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("G29 uncorrected Z:", current_position.z);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
// Unapply the offset because it is going to be immediately applied
|
|
|
|
// and cause compensation movement in Z
|
2019-09-29 04:25:39 -05:00
|
|
|
current_position.z -= bilinear_z_offset(current_position);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(" corrected Z:", current_position.z);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ABL_PLANAR
|
|
|
|
|
|
|
|
// Auto Bed Leveling is complete! Enable if possible.
|
2017-10-13 17:21:25 -05:00
|
|
|
planner.leveling_active = dryrun ? abl_should_enable : true;
|
2017-09-06 06:28:31 -05:00
|
|
|
} // !isnan(measured_z)
|
|
|
|
|
|
|
|
// Restore state after probing
|
2019-09-23 20:58:01 -05:00
|
|
|
if (!faux) restore_feedrate_and_scaling();
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-03-14 02:25:42 -05:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2017-10-13 17:21:25 -05:00
|
|
|
if (planner.leveling_active)
|
2018-09-16 21:24:15 -05:00
|
|
|
sync_plan_position();
|
2018-03-11 13:07:55 -05:00
|
|
|
|
2018-04-30 03:25:47 -05:00
|
|
|
#if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
|
2018-03-11 13:07:55 -05:00
|
|
|
move_z_after_probing();
|
|
|
|
#endif
|
|
|
|
|
2019-07-14 04:28:38 -05:00
|
|
|
#ifdef Z_PROBE_END_SCRIPT
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
|
|
|
|
planner.synchronize();
|
|
|
|
process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
|
|
|
|
#endif
|
|
|
|
|
2018-03-11 13:07:55 -05:00
|
|
|
report_current_position();
|
2018-07-25 18:49:32 -05:00
|
|
|
|
2018-06-29 20:48:11 -05:00
|
|
|
G29_RETURN(isnan(measured_z));
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
2017-09-08 15:35:25 -05:00
|
|
|
|
2019-02-24 20:29:03 -06:00
|
|
|
#endif // HAS_ABL_NOT_UBL
|