2017-04-02 18:48:26 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-04-02 18:48:26 +02: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 22:35:25 +02:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
#include "../bedlevel.h"
|
2017-09-06 13:28:32 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "../../../Marlin.h"
|
2018-08-14 10:28:52 +02:00
|
|
|
#include "../../../HAL/shared/persistent_store_api.h"
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "../../../libs/hex_print_routines.h"
|
|
|
|
#include "../../../module/configuration_store.h"
|
|
|
|
#include "../../../lcd/ultralcd.h"
|
|
|
|
#include "../../../module/stepper.h"
|
|
|
|
#include "../../../module/planner.h"
|
2019-09-18 01:16:28 +02:00
|
|
|
#include "../../../module/motion.h"
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "../../../module/probe.h"
|
|
|
|
#include "../../../gcode/gcode.h"
|
|
|
|
#include "../../../libs/least_squares_fit.h"
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-07-19 03:29:34 +02:00
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
#include "../../../module/tool_change.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#include "../../../core/debug_out.h"
|
|
|
|
|
2019-03-17 13:57:54 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
#include "../../../lcd/extensible_ui/ui_api.h"
|
|
|
|
#endif
|
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
2017-05-22 19:33:50 +02:00
|
|
|
#define UBL_G29_P31
|
|
|
|
|
2017-05-22 18:39:57 +02:00
|
|
|
extern float destination[XYZE], current_position[XYZE];
|
2017-04-30 07:43:28 +02:00
|
|
|
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-02-11 12:43:03 +01:00
|
|
|
void _lcd_ubl_output_map_lcd();
|
2017-06-07 08:24:36 +02:00
|
|
|
#endif
|
|
|
|
|
2017-05-08 05:38:03 +02:00
|
|
|
#define SIZE_OF_LITTLE_RAISE 1
|
2017-04-02 18:48:26 +02:00
|
|
|
#define BIG_RAISE_NOT_NEEDED 0
|
2017-05-22 18:39:57 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
int unified_bed_leveling::g29_verbose_level,
|
|
|
|
unified_bed_leveling::g29_phase_value,
|
|
|
|
unified_bed_leveling::g29_repetition_cnt,
|
|
|
|
unified_bed_leveling::g29_storage_slot = 0,
|
2017-10-10 01:26:52 +02:00
|
|
|
unified_bed_leveling::g29_map_type;
|
2017-05-22 21:41:09 +02:00
|
|
|
bool unified_bed_leveling::g29_c_flag,
|
|
|
|
unified_bed_leveling::g29_x_flag,
|
|
|
|
unified_bed_leveling::g29_y_flag;
|
|
|
|
float unified_bed_leveling::g29_x_pos,
|
|
|
|
unified_bed_leveling::g29_y_pos,
|
2018-07-07 03:41:08 +02:00
|
|
|
unified_bed_leveling::g29_card_thickness = 0,
|
|
|
|
unified_bed_leveling::g29_constant = 0;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
int unified_bed_leveling::g29_grid_size;
|
|
|
|
#endif
|
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
/**
|
|
|
|
* G29: Unified Bed Leveling by Roxy
|
|
|
|
*
|
|
|
|
* Parameters understood by this leveling system:
|
|
|
|
*
|
|
|
|
* A Activate Activate the Unified Bed Leveling system.
|
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* B # Business Use the 'Business Card' mode of the Manual Probe subsystem with P2.
|
|
|
|
* Note: A non-compressible Spark Gap feeler gauge is recommended over a business card.
|
|
|
|
* In this mode of G29 P2, a business or index card is used as a shim that the nozzle can
|
|
|
|
* grab onto as it is lowered. In principle, the nozzle-bed distance is the same when the
|
|
|
|
* same resistance is felt in the shim. You can omit the numerical value on first invocation
|
|
|
|
* of G29 P2 B to measure shim thickness. Subsequent use of 'B' will apply the previously-
|
|
|
|
* measured thickness by default.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* C Continue G29 P1 C continues the generation of a partially-constructed Mesh without invalidating
|
|
|
|
* previous measurements.
|
|
|
|
*
|
2018-01-16 18:08:00 +01:00
|
|
|
* C G29 P2 C tells the Manual Probe subsystem to not use the current nozzle
|
2018-02-11 12:43:03 +01:00
|
|
|
* location in its search for the closest unmeasured Mesh Point. Instead, attempt to
|
|
|
|
* start at one end of the uprobed points and Continue sequentially.
|
2017-06-23 06:38:52 +02:00
|
|
|
*
|
|
|
|
* G29 P3 C specifies the Constant for the fill. Otherwise, uses a "reasonable" value.
|
|
|
|
*
|
|
|
|
* C Current G29 Z C uses the Current location (instead of bed center or nearest edge).
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
|
|
|
* D Disable Disable the Unified Bed Leveling system.
|
|
|
|
*
|
|
|
|
* E Stow_probe Stow the probe after each sampled point.
|
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* F # Fade Fade the amount of Mesh Based Compensation over a specified height. At the
|
2017-04-02 18:48:26 +02:00
|
|
|
* specified height, no correction is applied and natural printer kenimatics take over. If no
|
|
|
|
* number is specified for the command, 10mm is assumed to be reasonable.
|
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* H # Height With P2, 'H' specifies the Height to raise the nozzle after each manual probe of the bed.
|
|
|
|
* If omitted, the nozzle will raise by Z_CLEARANCE_BETWEEN_PROBES.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* H # Offset With P4, 'H' specifies the Offset above the mesh height to place the nozzle.
|
|
|
|
* If omitted, Z_CLEARANCE_BETWEEN_PROBES will be used.
|
|
|
|
*
|
|
|
|
* I # Invalidate Invalidate the specified number of Mesh Points near the given 'X' 'Y'. If X or Y are omitted,
|
|
|
|
* the nozzle location is used. If no 'I' value is given, only the point nearest to the location
|
|
|
|
* is invalidated. Use 'T' to produce a map afterward. This command is useful to invalidate a
|
|
|
|
* portion of the Mesh so it can be adjusted using other UBL tools. When attempting to invalidate
|
|
|
|
* an isolated bad mesh point, the 'T' option shows the nozzle position in the Mesh with (#). You
|
|
|
|
* can move the nozzle around and use this feature to select the center of the area (or cell) to
|
2017-04-02 18:48:26 +02:00
|
|
|
* invalidate.
|
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* J # Grid Perform a Grid Based Leveling of the current Mesh using a grid with n points on a side.
|
2017-05-15 23:25:01 +02:00
|
|
|
* Not specifying a grid size will invoke the 3-Point leveling function.
|
2017-04-16 02:14:40 +02:00
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* L Load Load Mesh from the previously activated location in the EEPROM.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* L # Load Load Mesh from the specified location in the EEPROM. Set this location as activated
|
2017-04-02 18:48:26 +02:00
|
|
|
* for subsequent Load and Store operations.
|
|
|
|
*
|
|
|
|
* The P or Phase commands are used for the bulk of the work to setup a Mesh. In general, your Mesh will
|
|
|
|
* start off being initialized with a G29 P0 or a G29 P1. Further refinement of the Mesh happens with
|
|
|
|
* each additional Phase that processes it.
|
|
|
|
*
|
|
|
|
* P0 Phase 0 Zero Mesh Data and turn off the Mesh Compensation System. This reverts the
|
|
|
|
* 3D Printer to the same state it was in before the Unified Bed Leveling Compensation
|
|
|
|
* was turned on. Setting the entire Mesh to Zero is a special case that allows
|
|
|
|
* a subsequent G or T leveling operation for backward compatibility.
|
|
|
|
*
|
|
|
|
* P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using
|
2018-03-19 07:18:57 +01:00
|
|
|
* the Z-Probe. Usually the probe can't reach all areas that the nozzle can reach. For delta
|
|
|
|
* printers only the areas where the probe and nozzle can both reach will be automatically probed.
|
2017-05-16 18:23:50 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* Unreachable points will be handled in Phase 2 and Phase 3.
|
|
|
|
*
|
|
|
|
* Use 'C' to leave the previous mesh intact and automatically probe needed points. This allows you
|
|
|
|
* to invalidate parts of the Mesh but still use Automatic Probing.
|
|
|
|
*
|
|
|
|
* The 'X' and 'Y' parameters prioritize where to try and measure points. If omitted, the current
|
|
|
|
* probe position is used.
|
|
|
|
*
|
|
|
|
* Use 'T' (Topology) to generate a report of mesh generation.
|
|
|
|
*
|
|
|
|
* P1 will suspend Mesh generation if the controller button is held down. Note that you may need
|
|
|
|
* to press and hold the switch for several seconds if moves are underway.
|
|
|
|
*
|
|
|
|
* P2 Phase 2 Probe unreachable points.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* Use 'H' to set the height between Mesh points. If omitted, Z_CLEARANCE_BETWEEN_PROBES is used.
|
|
|
|
* Smaller values will be quicker. Move the nozzle down till it barely touches the bed. Make sure the
|
|
|
|
* nozzle is clean and unobstructed. Use caution and move slowly. This can damage your printer!
|
|
|
|
* (Uses SIZE_OF_LITTLE_RAISE mm if the nozzle is moving less than BIG_RAISE_NOT_NEEDED mm.)
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* The 'H' value can be negative if the Mesh dips in a large area. Press and hold the
|
|
|
|
* controller button to terminate the current Phase 2 command. You can then re-issue "G29 P 2"
|
|
|
|
* with an 'H' parameter more suitable for the area you're manually probing. Note that the command
|
|
|
|
* tries to start in a corner of the bed where movement will be predictable. Override the distance
|
|
|
|
* calculation location with the X and Y parameters. You can print a Mesh Map (G29 T) to see where
|
|
|
|
* the mesh is invalidated and where the nozzle needs to move to complete the command. Use 'C' to
|
|
|
|
* indicate that the search should be based on the current position.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* The 'B' parameter for this command is described above. It places the manual probe subsystem into
|
|
|
|
* Business Card mode where the thickness of a business card is measured and then used to accurately
|
|
|
|
* set the nozzle height in all manual probing for the duration of the command. A Business card can
|
|
|
|
* be used, but you'll get better results with a flexible Shim that doesn't compress. This makes it
|
|
|
|
* easier to produce similar amounts of force and get more accurate measurements. Google if you're
|
|
|
|
* not sure how to use a shim.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* The 'T' (Map) parameter helps track Mesh building progress.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* NOTE: P2 requires an LCD controller!
|
2017-06-07 08:24:36 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* P3 Phase 3 Fill the unpopulated regions of the Mesh with a fixed value. There are two different paths to
|
|
|
|
* go down:
|
2017-04-26 03:50:17 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* - If a 'C' constant is specified, the closest invalid mesh points to the nozzle will be filled,
|
|
|
|
* and a repeat count can then also be specified with 'R'.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* - Leaving out 'C' invokes Smart Fill, which scans the mesh from the edges inward looking for
|
|
|
|
* invalid mesh points. Adjacent points are used to determine the bed slope. If the bed is sloped
|
|
|
|
* upward from the invalid point, it takes the value of the nearest point. If sloped downward, it's
|
|
|
|
* replaced by a value that puts all three points in a line. This version of G29 P3 is a quick, easy
|
|
|
|
* and (usually) safe way to populate unprobed mesh regions before continuing to G26 Mesh Validation
|
|
|
|
* Pattern. Note that this populates the mesh with unverified values. Pay attention and use caution.
|
2017-06-07 08:24:36 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* P4 Phase 4 Fine tune the Mesh. The Delta Mesh Compensation System assumes the existence of
|
|
|
|
* an LCD Panel. It is possible to fine tune the mesh without an LCD Panel using
|
|
|
|
* G42 and M421. See the UBL documentation for further details.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* Phase 4 is meant to be used with G26 Mesh Validation to fine tune the mesh by direct editing
|
|
|
|
* of Mesh Points. Raise and lower points to fine tune the mesh until it gives consistently reliable
|
|
|
|
* adhesion.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-23 06:38:52 +02:00
|
|
|
* P4 moves to the closest Mesh Point (and/or the given X Y), raises the nozzle above the mesh height
|
2018-04-16 03:49:14 +02:00
|
|
|
* by the given 'H' offset (or default 0), and waits while the controller is used to adjust the nozzle
|
|
|
|
* height. On click the displayed height is saved in the mesh.
|
2017-06-23 06:38:52 +02:00
|
|
|
*
|
|
|
|
* Start Phase 4 at a specific location with X and Y. Adjust a specific number of Mesh Points with
|
|
|
|
* the 'R' (Repeat) parameter. (If 'R' is left out, the whole matrix is assumed.) This command can be
|
|
|
|
* terminated early (e.g., after editing the area of interest) by pressing and holding the encoder button.
|
|
|
|
*
|
|
|
|
* The general form is G29 P4 [R points] [X position] [Y position]
|
|
|
|
*
|
|
|
|
* The H [offset] parameter is useful if a shim is used to fine-tune the mesh. For a 0.4mm shim the
|
|
|
|
* command would be G29 P4 H0.4. The nozzle is moved to the shim height, you adjust height to the shim,
|
|
|
|
* and on click the height minus the shim thickness will be saved in the mesh.
|
|
|
|
*
|
|
|
|
* !!Use with caution, as a very poor mesh could cause the nozzle to crash into the bed!!
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-06-07 08:24:36 +02:00
|
|
|
* NOTE: P4 is not available unless you have LCD support enabled!
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
|
|
|
* P5 Phase 5 Find Mean Mesh Height and Standard Deviation. Typically, it is easier to use and
|
|
|
|
* work with the Mesh if it is Mean Adjusted. You can specify a C parameter to
|
|
|
|
* Correct the Mesh to a 0.00 Mean Height. Adding a C parameter will automatically
|
|
|
|
* execute a G29 P6 C <mean height>.
|
|
|
|
*
|
|
|
|
* P6 Phase 6 Shift Mesh height. The entire Mesh's height is adjusted by the height specified
|
|
|
|
* with the C parameter. Being able to adjust the height of a Mesh is useful tool. It
|
|
|
|
* can be used to compensate for poorly calibrated Z-Probes and other errors. Ideally,
|
|
|
|
* you should have the Mesh adjusted for a Mean Height of 0.00 and the Z-Probe measuring
|
|
|
|
* 0.000 at the Z Home location.
|
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* Q Test Load specified Test Pattern to assist in checking correct operation of system. This
|
2017-04-02 18:48:26 +02:00
|
|
|
* command is not anticipated to be of much value to the typical user. It is intended
|
|
|
|
* for developers to help them verify correct operation of the Unified Bed Leveling System.
|
|
|
|
*
|
2017-05-21 12:28:38 +02:00
|
|
|
* R # Repeat Repeat this command the specified number of times. If no number is specified the
|
2017-04-26 03:50:17 +02:00
|
|
|
* command will be repeated GRID_MAX_POINTS_X * GRID_MAX_POINTS_Y times.
|
|
|
|
*
|
2017-04-02 18:48:26 +02:00
|
|
|
* S Store Store the current Mesh in the Activated area of the EEPROM. It will also store the
|
|
|
|
* current state of the Unified Bed Leveling system in the EEPROM.
|
|
|
|
*
|
|
|
|
* S # Store Store the current Mesh at the specified location in EEPROM. Activate this location
|
2017-04-22 23:04:28 +02:00
|
|
|
* for subsequent Load and Store operations. Valid storage slot numbers begin at 0 and
|
|
|
|
* extend to a limit related to the available EEPROM storage.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2018-04-17 22:52:56 +02:00
|
|
|
* S -1 Store Print the current Mesh as G-code that can be used to restore the mesh anytime.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-05-16 06:20:09 +02:00
|
|
|
* T Topology Display the Mesh Map Topology.
|
2017-05-16 18:23:50 +02:00
|
|
|
* 'T' can be used alone (e.g., G29 T) or in combination with most of the other commands.
|
|
|
|
* This option works with all Phase commands (e.g., G29 P4 R 5 T X 50 Y100 C -.1 O)
|
2019-07-04 02:26:43 +02:00
|
|
|
* This parameter can also specify a Map Type. T0 (the default) is user-readable. T1
|
2017-05-16 06:20:09 +02:00
|
|
|
* is suitable to paste into a spreadsheet for a 3D graph of the mesh.
|
|
|
|
*
|
2017-04-02 18:48:26 +02:00
|
|
|
* U Unlevel Perform a probe of the outer perimeter to assist in physically leveling unlevel beds.
|
2017-05-16 18:23:50 +02:00
|
|
|
* Only used for G29 P1 T U. This speeds up the probing of the edge of the bed. Useful
|
2017-05-16 01:46:07 +02:00
|
|
|
* when the entire bed doesn't need to be probed because it will be adjusted.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* V # Verbosity Set the verbosity level (0-4) for extra details. (Default 0)
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2017-05-16 01:46:07 +02:00
|
|
|
* X # X Location for this command
|
|
|
|
*
|
|
|
|
* Y # Y Location for this command
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2018-11-12 10:46:41 +01:00
|
|
|
* With UBL_DEVEL_DEBUGGING:
|
|
|
|
*
|
|
|
|
* K # Kompare Kompare current Mesh with stored Mesh #, replacing current Mesh with the result.
|
|
|
|
* This command literally performs a diff between two Meshes.
|
|
|
|
*
|
|
|
|
* Q-1 Dump EEPROM Dump the UBL contents stored in EEPROM as HEX format. Useful for developers to help
|
|
|
|
* verify correct operation of the UBL.
|
|
|
|
*
|
|
|
|
* W What? Display valuable UBL data.
|
|
|
|
*
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
|
|
|
* Release Notes:
|
|
|
|
* You MUST do M502, M500 to initialize the storage. Failure to do this will cause all
|
2018-01-16 18:08:00 +01:00
|
|
|
* kinds of problems. Enabling EEPROM Storage is required.
|
2017-04-02 18:48:26 +02:00
|
|
|
*
|
2018-03-19 00:56:09 +01:00
|
|
|
* When you do a G28 and G29 P1 to automatically build your first mesh, you are going to notice that
|
|
|
|
* UBL probes points increasingly further from the starting location. (The starting location defaults
|
|
|
|
* to the center of the bed.) In contrast, ABL and MBL follow a zigzag pattern. The spiral pattern is
|
|
|
|
* especially better for Delta printers, since it populates the center of the mesh first, allowing for
|
|
|
|
* a quicker test print to verify settings. You don't need to populate the entire mesh to use it.
|
|
|
|
* After all, you don't want to spend a lot of time generating a mesh only to realize the resolution
|
|
|
|
* or zprobe_zoffset are incorrect. Mesh-generation gathers points starting closest to the nozzle unless
|
|
|
|
* an (X,Y) coordinate pair is given.
|
|
|
|
*
|
|
|
|
* Unified Bed Leveling uses a lot of EEPROM storage to hold its data, and it takes some effort to get
|
|
|
|
* the mesh just right. To prevent this valuable data from being destroyed as the EEPROM structure
|
|
|
|
* evolves, UBL stores all mesh data at the end of EEPROM.
|
|
|
|
*
|
|
|
|
* UBL is founded on Edward Patel's Mesh Bed Leveling code. A big 'Thanks!' to him and the creators of
|
|
|
|
* 3-Point and Grid Based leveling. Combining their contributions we now have the functionality and
|
|
|
|
* features of all three systems combined.
|
2017-04-02 18:48:26 +02:00
|
|
|
*/
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
void unified_bed_leveling::G29() {
|
2017-04-26 03:50:17 +02:00
|
|
|
|
2019-06-27 20:00:55 +02:00
|
|
|
bool probe_deployed = false;
|
2018-06-20 05:54:20 +02:00
|
|
|
if (g29_parameter_parsing()) return; // Abort on parameter error
|
|
|
|
|
|
|
|
const int8_t p_val = parser.intval('P', -1);
|
|
|
|
const bool may_move = p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J');
|
2017-10-10 01:26:52 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
// Check for commands that require the printer to be homed
|
2018-06-20 05:54:20 +02:00
|
|
|
if (may_move) {
|
2019-06-23 00:22:09 +02:00
|
|
|
planner.synchronize();
|
2018-08-15 20:26:11 +02:00
|
|
|
if (axis_unhomed_error()) gcode.home_all_axes();
|
2018-06-20 05:54:20 +02:00
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
if (active_extruder != 0) tool_change(0);
|
|
|
|
#endif
|
2017-05-16 15:45:31 +02:00
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
// Invalidate Mesh Points. This command is a little bit asymmetrical because
|
2017-04-02 18:48:26 +02:00
|
|
|
// it directly specifies the repetition count and does not use the 'R' parameter.
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('I')) {
|
2017-04-17 00:33:22 +02:00
|
|
|
uint8_t cnt = 0;
|
2017-05-20 10:03:08 +02:00
|
|
|
g29_repetition_cnt = parser.has_value() ? parser.value_int() : 1;
|
2017-06-04 00:11:43 +02:00
|
|
|
if (g29_repetition_cnt >= GRID_MAX_POINTS) {
|
|
|
|
set_all_mesh_points_to_value(NAN);
|
2017-06-09 17:22:49 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-06-04 00:11:43 +02:00
|
|
|
while (g29_repetition_cnt--) {
|
|
|
|
if (cnt > 20) { cnt = 0; idle(); }
|
2019-05-09 18:45:55 +02:00
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, nullptr);
|
2017-06-04 00:11:43 +02:00
|
|
|
if (location.x_index < 0) {
|
|
|
|
// No more REACHABLE mesh points to invalidate, so we ASSUME the user
|
|
|
|
// meant to invalidate the ENTIRE mesh, which cannot be done with
|
|
|
|
// find_closest_mesh_point loop which only returns REACHABLE points.
|
|
|
|
set_all_mesh_points_to_value(NAN);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Entire Mesh invalidated.\n");
|
2017-06-04 00:11:43 +02:00
|
|
|
break; // No more invalid Mesh Points to populate
|
|
|
|
}
|
|
|
|
z_values[location.x_index][location.y_index] = NAN;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(location.x_index, location.y_index, 0);
|
|
|
|
#endif
|
2017-06-04 00:11:43 +02:00
|
|
|
cnt++;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Locations invalidated.\n");
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('Q')) {
|
|
|
|
const int test_pattern = parser.has_value() ? parser.value_int() : -99;
|
2017-05-15 23:25:01 +02:00
|
|
|
if (!WITHIN(test_pattern, -1, 2)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Invalid test_pattern value. (-1 to 2)\n");
|
2017-04-02 18:48:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Loading test_pattern values.\n");
|
2017-04-02 18:48:26 +02:00
|
|
|
switch (test_pattern) {
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
|
|
|
case -1:
|
|
|
|
g29_eeprom_dump();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
case 0:
|
2017-04-06 05:29:44 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a bowl shape - similar to
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
|
2018-07-07 03:41:08 +02:00
|
|
|
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
|
|
|
|
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
|
|
|
|
z_values[x][y] += 2.0f * HYPOT(p1, p2);
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
case 1:
|
2017-04-06 05:29:44 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
2018-07-07 03:41:08 +02:00
|
|
|
z_values[x][x] += 9.999f;
|
|
|
|
z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, x, z_values[x][x]);
|
|
|
|
ExtUI::onMeshUpdate(x, (x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1), z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1]);
|
|
|
|
#endif
|
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
case 2:
|
|
|
|
// Allow the user to specify the height because 10mm is a little extreme in some cases.
|
2019-03-17 13:57:54 +01:00
|
|
|
for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in
|
|
|
|
for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) { // the center of the bed
|
2018-07-07 03:41:08 +02:00
|
|
|
z_values[x][y] += parser.seen('C') ? g29_constant : 9.99f;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
2019-03-17 13:57:54 +01:00
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
#if HAS_BED_PROBE
|
2017-05-15 23:25:01 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
if (parser.seen('J')) {
|
|
|
|
if (g29_grid_size) { // if not 0 it is a normal n x n grid being probed
|
|
|
|
save_ubl_active_state_and_disable();
|
2018-01-16 18:08:00 +01:00
|
|
|
tilt_mesh_based_on_probed_grid(false /* false says to do normal grid probing */ );
|
2017-10-10 01:26:52 +02:00
|
|
|
restore_ubl_active_state_and_leave();
|
2017-05-15 23:25:01 +02:00
|
|
|
}
|
2017-10-10 01:26:52 +02:00
|
|
|
else { // grid_size == 0 : A 3-Point leveling has been requested
|
|
|
|
save_ubl_active_state_and_disable();
|
2018-01-16 18:08:00 +01:00
|
|
|
tilt_mesh_based_on_probed_grid(true /* true says to do 3-Point leveling */ );
|
2017-10-10 01:26:52 +02:00
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
}
|
2018-07-07 03:41:08 +02:00
|
|
|
do_blocking_move_to_xy(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)));
|
2018-03-11 19:07:55 +01:00
|
|
|
report_current_position();
|
2019-06-27 20:00:55 +02:00
|
|
|
probe_deployed = true;
|
2017-05-15 23:25:01 +02:00
|
|
|
}
|
2017-10-10 01:26:52 +02:00
|
|
|
|
|
|
|
#endif // HAS_BED_PROBE
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('P')) {
|
2017-10-14 04:56:27 +02:00
|
|
|
if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) {
|
|
|
|
storage_slot = 0;
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Default storage slot 0 selected.");
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
2017-05-07 01:59:16 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
switch (g29_phase_value) {
|
2017-04-02 18:48:26 +02:00
|
|
|
case 0:
|
|
|
|
//
|
|
|
|
// Zero Mesh Data
|
|
|
|
//
|
2017-05-22 21:41:09 +02:00
|
|
|
reset();
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Mesh zeroed.");
|
2017-04-02 18:48:26 +02:00
|
|
|
break;
|
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
|
2019-09-14 10:05:10 +02:00
|
|
|
case 1: {
|
2017-10-10 01:26:52 +02:00
|
|
|
//
|
|
|
|
// Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
|
|
|
|
//
|
|
|
|
if (!parser.seen('C')) {
|
|
|
|
invalidate();
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Mesh invalidated. Probing mesh.");
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
|
|
|
if (g29_verbose_level > 1) {
|
2019-03-14 08:25:42 +01:00
|
|
|
SERIAL_ECHOPAIR("Probing around (", g29_x_pos);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_CHAR(',');
|
|
|
|
SERIAL_ECHO(g29_y_pos);
|
|
|
|
SERIAL_ECHOLNPGM(").\n");
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
|
|
|
probe_entire_mesh(g29_x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, g29_y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
|
|
|
|
parser.seen('T'), parser.seen('E'), parser.seen('U'));
|
2018-03-11 19:07:55 +01:00
|
|
|
|
|
|
|
report_current_position();
|
2019-06-27 20:00:55 +02:00
|
|
|
probe_deployed = true;
|
2019-09-14 10:05:10 +02:00
|
|
|
} break;
|
2017-10-10 01:26:52 +02:00
|
|
|
|
2017-12-06 23:56:30 +01:00
|
|
|
#endif // HAS_BED_PROBE
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
case 2: {
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2017-06-07 08:24:36 +02:00
|
|
|
//
|
|
|
|
// Manually Probe Mesh in areas that can't be reached by the probe
|
|
|
|
//
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Manually probing unreachable mesh locations.");
|
2017-06-07 08:24:36 +02:00
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
2017-11-11 03:49:37 +01:00
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
if (parser.seen('C') && !g29_x_flag && !g29_y_flag) {
|
2017-06-07 08:24:36 +02:00
|
|
|
/**
|
|
|
|
* Use a good default location for the path.
|
|
|
|
* The flipped > and < operators in these comparisons is intentional.
|
|
|
|
* It should cause the probed points to follow a nice path on Cartesian printers.
|
|
|
|
* It may make sense to have Delta printers default to the center of the bed.
|
|
|
|
* Until that is decided, this can be forced with the X and Y parameters.
|
|
|
|
*/
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
g29_x_pos = X_HOME_POS;
|
|
|
|
g29_y_pos = Y_HOME_POS;
|
|
|
|
#else // cartesian
|
2017-07-22 05:54:39 +02:00
|
|
|
g29_x_pos = X_PROBE_OFFSET_FROM_EXTRUDER > 0 ? X_BED_SIZE : 0;
|
|
|
|
g29_y_pos = Y_PROBE_OFFSET_FROM_EXTRUDER < 0 ? Y_BED_SIZE : 0;
|
2017-06-07 08:24:36 +02:00
|
|
|
#endif
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
if (parser.seen('B')) {
|
2018-01-16 18:08:00 +01:00
|
|
|
g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness((float) Z_CLEARANCE_BETWEEN_PROBES);
|
2018-07-07 03:41:08 +02:00
|
|
|
if (ABS(g29_card_thickness) > 1.5f) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?Error in Business Card measurement.");
|
2017-06-07 08:24:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-27 20:00:55 +02:00
|
|
|
probe_deployed = true;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
if (!position_is_reachable(g29_x_pos, g29_y_pos)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("XY outside printable radius.");
|
2017-06-07 08:24:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-27 07:49:21 +02:00
|
|
|
const float height = parser.floatval('H', Z_CLEARANCE_BETWEEN_PROBES);
|
2017-06-07 08:24:36 +02:00
|
|
|
manually_probe_remaining_mesh(g29_x_pos, g29_y_pos, height, g29_card_thickness, parser.seen('T'));
|
2017-06-23 06:38:52 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("G29 P2 finished.");
|
2017-06-23 06:38:52 +02:00
|
|
|
|
2018-03-11 19:07:55 +01:00
|
|
|
report_current_position();
|
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
#else
|
2017-06-23 06:38:52 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?P2 is only available when an LCD is present.");
|
2017-06-07 08:24:36 +02:00
|
|
|
return;
|
2017-06-23 06:38:52 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
#endif
|
2017-05-03 00:41:55 +02:00
|
|
|
} break;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
case 3: {
|
2017-05-03 00:41:55 +02:00
|
|
|
/**
|
|
|
|
* Populate invalid mesh areas. Proceed with caution.
|
|
|
|
* Two choices are available:
|
|
|
|
* - Specify a constant with the 'C' parameter.
|
|
|
|
* - Allow 'G29 P3' to choose a 'reasonable' constant.
|
|
|
|
*/
|
2017-06-04 00:11:43 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
if (g29_c_flag) {
|
|
|
|
if (g29_repetition_cnt >= GRID_MAX_POINTS) {
|
2017-06-04 00:11:43 +02:00
|
|
|
set_all_mesh_points_to_value(g29_constant);
|
2017-05-16 01:46:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-05-22 21:41:09 +02:00
|
|
|
while (g29_repetition_cnt--) { // this only populates reachable mesh points near
|
2019-05-09 18:45:55 +02:00
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, nullptr);
|
2017-06-04 00:11:43 +02:00
|
|
|
if (location.x_index < 0) {
|
|
|
|
// No more REACHABLE INVALID mesh points to populate, so we ASSUME
|
|
|
|
// user meant to populate ALL INVALID mesh points to value
|
2017-06-23 06:38:52 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (isnan(z_values[x][y]))
|
2017-06-04 00:11:43 +02:00
|
|
|
z_values[x][y] = g29_constant;
|
|
|
|
break; // No more invalid Mesh Points to populate
|
|
|
|
}
|
2017-05-22 21:41:09 +02:00
|
|
|
z_values[location.x_index][location.y_index] = g29_constant;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(location.x_index, location.y_index, z_values[location.x_index][location.y_index]);
|
|
|
|
#endif
|
2017-05-12 05:33:47 +02:00
|
|
|
}
|
2017-04-26 03:50:17 +02:00
|
|
|
}
|
2017-06-23 06:38:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-05-20 10:03:08 +02:00
|
|
|
const float cvf = parser.value_float();
|
2018-07-07 03:41:08 +02:00
|
|
|
switch ((int)truncf(cvf * 10.0f) - 30) { // 3.1 -> 1
|
2017-05-22 19:33:50 +02:00
|
|
|
#if ENABLED(UBL_G29_P31)
|
|
|
|
case 1: {
|
|
|
|
|
|
|
|
// P3.1 use least squares fit to fill missing mesh values
|
|
|
|
// P3.10 zero weighting for distance, all grid points equal, best fit tilted plane
|
|
|
|
// P3.11 10X weighting for nearest grid points versus farthest grid points
|
|
|
|
// P3.12 100X distance weighting
|
|
|
|
// P3.13 1000X distance weighting, approaches simple average of nearest points
|
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
const float weight_power = (cvf - 3.10f) * 100.0f, // 3.12345 -> 2.345
|
|
|
|
weight_factor = weight_power ? POW(10.0f, weight_power) : 0;
|
2017-05-22 20:55:07 +02:00
|
|
|
smart_fill_wlsf(weight_factor);
|
2017-05-22 19:33:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 0: // P3 or P3.0
|
|
|
|
default: // and anything P3.x that's not P3.1
|
|
|
|
smart_fill_mesh(); // Do a 'Smart' fill using nearby known values
|
|
|
|
break;
|
|
|
|
}
|
2017-05-12 05:33:47 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
case 4: // Fine Tune (i.e., Edit) the Mesh
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2017-06-07 08:24:36 +02:00
|
|
|
fine_tune_mesh(g29_x_pos, g29_y_pos, parser.seen('T'));
|
|
|
|
#else
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?P4 is only available when an LCD is present.");
|
2017-06-07 08:24:36 +02:00
|
|
|
return;
|
|
|
|
#endif
|
2017-04-02 18:48:26 +02:00
|
|
|
break;
|
|
|
|
|
2018-04-28 15:14:20 +02:00
|
|
|
case 5: adjust_mesh_to_mean(g29_c_flag, g29_constant); break;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
case 6: shift_mesh_height(); break;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
2017-05-16 01:46:07 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
//
|
|
|
|
// Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
|
|
|
|
// good to have the extra information. Soon... we prune this to just a few items
|
|
|
|
//
|
|
|
|
if (parser.seen('W')) g29_what_command();
|
|
|
|
|
|
|
|
//
|
|
|
|
// When we are fully debugged, this may go away. But there are some valid
|
|
|
|
// use cases for the users. So we can wait and see what to do with it.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (parser.seen('K')) // Kompare Current Mesh Data to Specified Stored Mesh
|
|
|
|
g29_compare_current_mesh_to_stored_mesh();
|
|
|
|
|
|
|
|
#endif // UBL_DEVEL_DEBUGGING
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Load a Mesh from the EEPROM
|
|
|
|
//
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('L')) { // Load Current Mesh Data
|
2017-10-14 04:56:27 +02:00
|
|
|
g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-12-25 15:48:54 +01:00
|
|
|
int16_t a = settings.calc_num_meshes();
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-07 03:00:56 +02:00
|
|
|
if (!a) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?EEPROM storage not available.");
|
2017-04-02 18:48:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-07 03:00:56 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
if (!WITHIN(g29_storage_slot, 0, a - 1)) {
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1);
|
2017-05-07 03:00:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
settings.load_mesh(g29_storage_slot);
|
2017-10-14 04:56:27 +02:00
|
|
|
storage_slot = g29_storage_slot;
|
2017-05-07 03:00:56 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Done.");
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Store a Mesh in the EEPROM
|
|
|
|
//
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('S')) { // Store (or Save) Current Mesh Data
|
2017-10-14 04:56:27 +02:00
|
|
|
g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-03-21 22:54:45 +01:00
|
|
|
if (g29_storage_slot == -1) // Special case, the user wants to 'Export' the mesh to the
|
|
|
|
return report_current_mesh(); // host program to be saved on the user's computer
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-12-25 15:48:54 +01:00
|
|
|
int16_t a = settings.calc_num_meshes();
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-07 03:00:56 +02:00
|
|
|
if (!a) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?EEPROM storage not available.");
|
2017-04-02 18:48:26 +02:00
|
|
|
goto LEAVE;
|
|
|
|
}
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
if (!WITHIN(g29_storage_slot, 0, a - 1)) {
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1);
|
2017-05-07 03:00:56 +02:00
|
|
|
goto LEAVE;
|
|
|
|
}
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
settings.store_mesh(g29_storage_slot);
|
2017-10-14 04:56:27 +02:00
|
|
|
storage_slot = g29_storage_slot;
|
2017-05-07 03:00:56 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Done.");
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('T'))
|
2017-10-18 21:00:29 +02:00
|
|
|
display_map(g29_map_type);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
LEAVE:
|
|
|
|
|
2018-10-30 22:34:45 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.reset_alert_level();
|
|
|
|
ui.quick_feedback();
|
|
|
|
ui.reset_status();
|
|
|
|
ui.release();
|
2017-06-07 08:24:36 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-27 20:00:55 +02:00
|
|
|
#ifdef Z_PROBE_END_SCRIPT
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
|
|
|
|
if (probe_deployed) {
|
|
|
|
planner.synchronize();
|
2019-06-30 06:20:49 +02:00
|
|
|
gcode.process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
|
2019-06-27 20:00:55 +02:00
|
|
|
}
|
2019-07-01 05:29:33 +02:00
|
|
|
#else
|
|
|
|
UNUSED(probe_deployed);
|
2019-06-27 20:00:55 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
return;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 15:14:20 +02:00
|
|
|
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
|
2018-07-07 03:41:08 +02:00
|
|
|
float sum = 0;
|
2017-05-03 00:41:55 +02:00
|
|
|
int n = 0;
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
2017-05-22 21:41:09 +02:00
|
|
|
if (!isnan(z_values[x][y])) {
|
|
|
|
sum += z_values[x][y];
|
2017-04-02 18:48:26 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2017-05-03 00:41:55 +02:00
|
|
|
const float mean = sum / n;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
//
|
2017-05-16 01:32:26 +02:00
|
|
|
// Sum the squares of difference from mean
|
2017-04-02 18:48:26 +02:00
|
|
|
//
|
2018-07-07 03:41:08 +02:00
|
|
|
float sum_of_diff_squared = 0;
|
2017-05-03 00:41:55 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
2017-05-22 21:41:09 +02:00
|
|
|
if (!isnan(z_values[x][y]))
|
|
|
|
sum_of_diff_squared += sq(z_values[x][y] - mean);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
SERIAL_ECHOLNPAIR("# of samples: ", n);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-20 05:39:23 +02:00
|
|
|
const float sigma = SQRT(sum_of_diff_squared / (n + 1));
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-04-28 15:14:20 +02:00
|
|
|
if (cflag)
|
2017-05-03 00:41:55 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
2019-03-13 06:45:52 +01:00
|
|
|
if (!isnan(z_values[x][y])) {
|
2018-04-25 13:43:45 +02:00
|
|
|
z_values[x][y] -= mean + value;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-04-26 03:50:17 +02:00
|
|
|
void unified_bed_leveling::shift_mesh_height() {
|
2017-04-06 05:29:44 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
2019-03-13 06:45:52 +01:00
|
|
|
if (!isnan(z_values[x][y])) {
|
2017-05-22 21:41:09 +02:00
|
|
|
z_values[x][y] += g29_constant;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
#if HAS_BED_PROBE
|
2017-10-10 01:26:52 +02:00
|
|
|
/**
|
|
|
|
* Probe all invalidated locations of the mesh that can be reached by the probe.
|
|
|
|
* This attempts to fill in locations closest to the nozzle's start location first.
|
|
|
|
*/
|
2018-02-27 03:45:51 +01:00
|
|
|
void unified_bed_leveling::probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) {
|
2017-10-10 01:26:52 +02:00
|
|
|
mesh_index_pair location;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.capture();
|
2017-11-24 00:59:43 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
|
2017-10-10 01:26:52 +02:00
|
|
|
DEPLOY_PROBE();
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2019-08-18 03:14:14 +02:00
|
|
|
uint8_t count = GRID_MAX_POINTS;
|
2017-05-16 01:32:26 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
do {
|
2017-10-19 17:44:45 +02:00
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
|
|
|
2019-09-09 09:56:23 +02:00
|
|
|
const int point_num = (GRID_MAX_POINTS) - count + 1;
|
|
|
|
SERIAL_ECHOLNPAIR("\nProbing mesh point ", point_num, "/", int(GRID_MAX_POINTS), ".\n");
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_DISPLAY
|
2019-09-09 09:56:23 +02:00
|
|
|
ui.status_printf_P(0, PSTR(MSG_PROBING_MESH " %i/%i"), point_num, int(GRID_MAX_POINTS));
|
2019-08-02 03:11:26 +02:00
|
|
|
#endif
|
2019-05-18 02:02:21 +02:00
|
|
|
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 19:16:24 +01:00
|
|
|
if (ui.button_pressed()) {
|
|
|
|
ui.quick_feedback(false); // Preserve button state for click-and-hold
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("\nMesh only partially populated.\n");
|
2017-10-10 01:26:52 +02:00
|
|
|
STOW_PROBE();
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.wait_for_release();
|
|
|
|
ui.quick_feedback();
|
|
|
|
ui.release();
|
2019-06-30 05:49:50 +02:00
|
|
|
return restore_ubl_active_state_and_leave();
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-02-27 03:45:51 +01:00
|
|
|
if (do_furthest)
|
2017-10-19 17:44:45 +02:00
|
|
|
location = find_furthest_invalid_mesh_point();
|
|
|
|
else
|
2019-05-09 18:45:55 +02:00
|
|
|
location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_PROBE_AS_REFERENCE, nullptr);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
if (location.x_index >= 0) { // mesh point found and is reachable by probe
|
|
|
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
2019-04-04 03:21:06 +02:00
|
|
|
rawy = mesh_index_to_ypos(location.y_index),
|
2019-09-18 01:16:28 +02:00
|
|
|
measured_z = probe_at_point(rawx, rawy, stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling
|
2017-10-10 01:26:52 +02:00
|
|
|
z_values[location.x_index][location.y_index] = measured_z;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(location.x_index, location.y_index, measured_z);
|
|
|
|
#endif
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
2018-02-17 00:32:12 +01:00
|
|
|
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
|
2019-05-18 02:02:21 +02:00
|
|
|
|
2018-02-27 03:45:51 +01:00
|
|
|
} while (location.x_index >= 0 && --count);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
STOW_PROBE();
|
2018-03-21 07:08:44 +01:00
|
|
|
|
2018-04-30 10:25:47 +02:00
|
|
|
#ifdef Z_AFTER_PROBING
|
2018-03-21 07:08:44 +01:00
|
|
|
move_z_after_probing();
|
|
|
|
#endif
|
2018-03-11 19:07:55 +01:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
restore_ubl_active_state_and_leave();
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
do_blocking_move_to_xy(
|
2017-11-03 05:59:42 +01:00
|
|
|
constrain(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), MESH_MIN_X, MESH_MAX_X),
|
|
|
|
constrain(ry - (Y_PROBE_OFFSET_FROM_EXTRUDER), MESH_MIN_Y, MESH_MAX_Y)
|
2017-10-10 01:26:52 +02:00
|
|
|
);
|
2017-04-26 03:50:17 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
#endif // HAS_BED_PROBE
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2017-10-10 01:26:52 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
typedef void (*clickFunc_t)();
|
|
|
|
|
2019-05-09 18:45:55 +02:00
|
|
|
bool click_and_hold(const clickFunc_t func=nullptr) {
|
2018-11-11 19:16:24 +01:00
|
|
|
if (ui.button_pressed()) {
|
|
|
|
ui.quick_feedback(false); // Preserve button state for click-and-hold
|
|
|
|
const millis_t nxt = millis() + 1500UL;
|
|
|
|
while (ui.button_pressed()) { // Loop while the encoder is pressed. Uses hardware flag!
|
|
|
|
idle(); // idle, of course
|
|
|
|
if (ELAPSED(millis(), nxt)) { // After 1.5 seconds
|
|
|
|
ui.quick_feedback();
|
|
|
|
if (func) (*func)();
|
|
|
|
ui.wait_for_release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(15);
|
2018-11-11 19:16:24 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
void unified_bed_leveling::move_z_with_encoder(const float &multiplier) {
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.wait_for_release();
|
|
|
|
while (!ui.button_pressed()) {
|
2017-06-07 08:24:36 +02:00
|
|
|
idle();
|
2018-03-22 01:30:06 +01:00
|
|
|
gcode.reset_stepper_timeout(); // Keep steppers powered
|
2017-06-07 08:24:36 +02:00
|
|
|
if (encoder_diff) {
|
2017-12-07 04:28:04 +01:00
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier);
|
2017-06-07 08:24:36 +02:00
|
|
|
encoder_diff = 0;
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
2017-12-07 04:28:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float unified_bed_leveling::measure_point_with_encoder() {
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
2018-07-07 03:41:08 +02:00
|
|
|
move_z_with_encoder(0.01f);
|
2017-06-07 08:24:36 +02:00
|
|
|
return current_position[Z_AXIS];
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); }
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
float unified_bed_leveling::measure_business_card_thickness(float in_height) {
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.capture();
|
2017-06-07 08:24:36 +02:00
|
|
|
save_ubl_active_state_and_disable(); // Disable bed level correction for probing
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), in_height);
|
2019-07-06 01:01:21 +02:00
|
|
|
//, _MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS]) * 0.5f);
|
2018-05-12 08:38:02 +02:00
|
|
|
planner.synchronize();
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM("Place shim under nozzle");
|
2017-06-08 17:09:39 +02:00
|
|
|
LCD_MESSAGEPGM(MSG_UBL_BC_INSERT);
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.return_to_status();
|
2017-06-07 08:24:36 +02:00
|
|
|
echo_and_take_a_measurement();
|
2017-04-30 07:43:28 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
const float z1 = measure_point_with_encoder();
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
|
2018-05-12 08:38:02 +02:00
|
|
|
planner.synchronize();
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM("Remove shim");
|
2017-06-08 17:09:39 +02:00
|
|
|
LCD_MESSAGEPGM(MSG_UBL_BC_REMOVE);
|
2017-06-07 08:24:36 +02:00
|
|
|
echo_and_take_a_measurement();
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
const float z2 = measure_point_with_encoder();
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-05-13 08:10:34 +02:00
|
|
|
const float thickness = ABS(z1 - z2);
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
if (g29_verbose_level > 1) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPAIR_F("Business Card is ", thickness, 4);
|
|
|
|
SERIAL_ECHOLNPGM("mm thick.");
|
2017-06-07 08:24:36 +02:00
|
|
|
}
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.release();
|
2017-04-30 07:43:28 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
restore_ubl_active_state_and_leave();
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
return thickness;
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
void unified_bed_leveling::manually_probe_remaining_mesh(const float &rx, const float &ry, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.capture();
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
|
2018-01-16 18:08:00 +01:00
|
|
|
do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_clearance);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.return_to_status();
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
mesh_index_pair location;
|
|
|
|
do {
|
2019-05-09 18:45:55 +02:00
|
|
|
location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_NOZZLE_AS_REFERENCE, nullptr);
|
2017-06-07 08:24:36 +02:00
|
|
|
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
|
|
|
|
if (location.x_index < 0 && location.y_index < 0) continue;
|
2017-05-12 05:33:47 +02:00
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
const float xProbe = mesh_index_to_xpos(location.x_index),
|
|
|
|
yProbe = mesh_index_to_ypos(location.y_index);
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
if (!position_is_reachable(xProbe, yProbe)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points)
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-08 17:09:39 +02:00
|
|
|
LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-11-11 03:49:37 +01:00
|
|
|
do_blocking_move_to(xProbe, yProbe, Z_CLEARANCE_BETWEEN_PROBES);
|
2017-06-07 08:24:36 +02:00
|
|
|
do_blocking_move_to_z(z_clearance);
|
2017-05-12 00:09:31 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.capture();
|
2017-04-15 06:47:11 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing
|
2017-06-04 00:11:43 +02:00
|
|
|
|
2017-06-08 17:09:39 +02:00
|
|
|
serialprintPGM(parser.seen('B') ? PSTR(MSG_UBL_BC_INSERT) : PSTR(MSG_UBL_BC_INSERT2));
|
2017-06-07 08:24:36 +02:00
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
const float z_step = 0.01f; // existing behavior: 0.01mm per click, occasionally step
|
2018-07-01 22:20:28 +02:00
|
|
|
//const float z_step = planner.steps_to_mm[Z_AXIS]; // approx one step each click
|
2017-06-07 08:24:36 +02:00
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
move_z_with_encoder(z_step);
|
2017-06-07 08:24:36 +02:00
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
if (click_and_hold()) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("\nMesh only partially populated.");
|
2017-12-07 04:28:04 +01:00
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.release();
|
2019-06-30 05:49:50 +02:00
|
|
|
return restore_ubl_active_state_and_leave();
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(location.x_index, location.y_index, z_values[location.x_index][location.y_index]);
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
if (g29_verbose_level > 2)
|
|
|
|
SERIAL_ECHOLNPAIR_F("Mesh Point Measured at: ", z_values[location.x_index][location.y_index], 6);
|
2018-02-17 00:32:12 +01:00
|
|
|
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
|
2017-06-07 08:24:36 +02:00
|
|
|
} while (location.x_index >= 0 && location.y_index >= 0);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-01-19 02:57:18 +01:00
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-07 08:24:36 +02:00
|
|
|
restore_ubl_active_state_and_leave();
|
2017-11-11 03:49:37 +01:00
|
|
|
do_blocking_move_to(rx, ry, Z_CLEARANCE_DEPLOY_PROBE);
|
2017-06-07 08:24:36 +02:00
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
inline void set_message_with_feedback(PGM_P const msg_P) {
|
2018-11-18 05:21:44 +01:00
|
|
|
ui.set_status_P(msg_P);
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.quick_feedback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void abort_fine_tune() {
|
|
|
|
ui.return_to_status();
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
set_message_with_feedback(PSTR(MSG_EDITING_STOPPED));
|
|
|
|
}
|
|
|
|
|
|
|
|
void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
|
|
|
|
if (!parser.seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified
|
|
|
|
g29_repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided.
|
|
|
|
|
|
|
|
#if ENABLED(UBL_MESH_EDIT_MOVES_Z)
|
|
|
|
const float h_offset = parser.seenval('H') ? parser.value_linear_units() : 0;
|
|
|
|
if (!WITHIN(h_offset, 0, 10)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Offset out of bounds. (0 to 10mm)\n");
|
2018-11-11 19:16:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mesh_index_pair location;
|
|
|
|
|
|
|
|
if (!position_is_reachable(rx, ry)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("(X,Y) outside printable radius.");
|
2018-11-11 19:16:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
save_ubl_active_state_and_disable();
|
|
|
|
|
|
|
|
LCD_MESSAGEPGM(MSG_UBL_FINE_TUNE_MESH);
|
|
|
|
ui.capture(); // Take over control of the LCD encoder
|
|
|
|
|
|
|
|
do_blocking_move_to(rx, ry, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance
|
|
|
|
|
|
|
|
#if ENABLED(UBL_MESH_EDIT_MOVES_Z)
|
|
|
|
do_blocking_move_to_z(h_offset); // Move Z to the given 'H' offset
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint16_t not_done[16];
|
|
|
|
memset(not_done, 0xFF, sizeof(not_done));
|
|
|
|
do {
|
|
|
|
location = find_closest_mesh_point_of_type(SET_IN_BITMAP, rx, ry, USE_NOZZLE_AS_REFERENCE, not_done);
|
|
|
|
|
|
|
|
if (location.x_index < 0) break; // Stop when there are no more reachable points
|
|
|
|
|
|
|
|
bitmap_clear(not_done, location.x_index, location.y_index); // Mark this location as 'adjusted' so a new
|
|
|
|
// location is used on the next loop
|
|
|
|
|
|
|
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
|
|
|
rawy = mesh_index_to_ypos(location.y_index);
|
|
|
|
|
|
|
|
if (!position_is_reachable(rawx, rawy)) break; // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
|
|
|
|
|
|
|
|
do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point with probe clearance
|
|
|
|
|
|
|
|
#if ENABLED(UBL_MESH_EDIT_MOVES_Z)
|
|
|
|
do_blocking_move_to_z(h_offset); // Move Z to the given 'H' offset before editing
|
|
|
|
#endif
|
|
|
|
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type); // Display the current point
|
|
|
|
|
|
|
|
ui.refresh();
|
|
|
|
|
|
|
|
float new_z = z_values[location.x_index][location.y_index];
|
|
|
|
if (isnan(new_z)) new_z = 0; // Invalid points begin at 0
|
|
|
|
new_z = FLOOR(new_z * 1000) * 0.001f; // Chop off digits after the 1000ths place
|
|
|
|
|
|
|
|
lcd_mesh_edit_setup(new_z);
|
|
|
|
|
|
|
|
do {
|
|
|
|
new_z = lcd_mesh_edit();
|
|
|
|
#if ENABLED(UBL_MESH_EDIT_MOVES_Z)
|
|
|
|
do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
|
|
|
|
#endif
|
|
|
|
idle();
|
|
|
|
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
|
|
|
|
} while (!ui.button_pressed());
|
|
|
|
|
2018-11-24 04:05:59 +01:00
|
|
|
if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2019-06-30 05:49:50 +02:00
|
|
|
if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
z_values[location.x_index][location.y_index] = new_z; // Save the updated Z value
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(location.x_index, location.y_index, new_z);
|
|
|
|
#endif
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(20); // No switch noise
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.refresh();
|
|
|
|
|
|
|
|
} while (location.x_index >= 0 && --g29_repetition_cnt > 0);
|
|
|
|
|
|
|
|
ui.release();
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
|
|
|
|
do_blocking_move_to(rx, ry, Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
|
|
|
|
LCD_MESSAGEPGM(MSG_UBL_DONE_EDITING_MESH);
|
|
|
|
SERIAL_ECHOLNPGM("Done Editing Mesh");
|
|
|
|
|
|
|
|
if (lcd_map_control)
|
|
|
|
ui.goto_screen(_lcd_ubl_output_map_lcd);
|
|
|
|
else
|
|
|
|
ui.return_to_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU
|
2018-11-11 01:07:38 +01:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
bool unified_bed_leveling::g29_parameter_parsing() {
|
2017-04-16 02:14:40 +02:00
|
|
|
bool err_flag = false;
|
|
|
|
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 01:07:38 +01:00
|
|
|
set_message_with_feedback(PSTR(MSG_UBL_DOING_G29));
|
2017-06-07 08:24:36 +02:00
|
|
|
#endif
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
g29_constant = 0;
|
2017-05-22 21:41:09 +02:00
|
|
|
g29_repetition_cnt = 0;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-06-27 06:31:45 +02:00
|
|
|
g29_x_flag = parser.seenval('X');
|
2017-05-20 10:03:08 +02:00
|
|
|
g29_x_pos = g29_x_flag ? parser.value_float() : current_position[X_AXIS];
|
2017-06-27 06:31:45 +02:00
|
|
|
g29_y_flag = parser.seenval('Y');
|
2017-05-20 10:03:08 +02:00
|
|
|
g29_y_pos = g29_y_flag ? parser.value_float() : current_position[Y_AXIS];
|
2017-04-09 00:08:45 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('R')) {
|
|
|
|
g29_repetition_cnt = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS;
|
2017-05-22 21:41:09 +02:00
|
|
|
NOMORE(g29_repetition_cnt, GRID_MAX_POINTS);
|
|
|
|
if (g29_repetition_cnt < 1) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?(R)epetition count invalid (1+).\n");
|
2017-04-16 02:14:40 +02:00
|
|
|
return UBL_ERR;
|
|
|
|
}
|
|
|
|
}
|
2017-04-08 22:18:27 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
g29_verbose_level = parser.seen('V') ? parser.value_int() : 0;
|
2017-04-02 18:48:26 +02:00
|
|
|
if (!WITHIN(g29_verbose_level, 0, 4)) {
|
2019-09-11 09:46:52 +02:00
|
|
|
SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).\n");
|
2017-04-09 00:08:45 +02:00
|
|
|
err_flag = true;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('P')) {
|
2017-10-10 01:26:52 +02:00
|
|
|
const int pv = parser.value_int();
|
|
|
|
#if !HAS_BED_PROBE
|
|
|
|
if (pv == 1) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("G29 P1 requires a probe.\n");
|
2017-10-10 01:26:52 +02:00
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
g29_phase_value = pv;
|
2017-12-06 23:56:30 +01:00
|
|
|
if (!WITHIN(g29_phase_value, 0, 6)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?(P)hase value invalid (0-6).\n");
|
2017-12-06 23:56:30 +01:00
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-07 01:59:16 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
if (parser.seen('J')) {
|
2017-10-10 01:26:52 +02:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
g29_grid_size = parser.has_value() ? parser.value_int() : 0;
|
|
|
|
if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?Invalid grid size (J) specified (2-9).\n");
|
2017-10-10 01:26:52 +02:00
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
#else
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("G29 J action requires a probe.\n");
|
2017-04-09 00:08:45 +02:00
|
|
|
err_flag = true;
|
2017-10-10 01:26:52 +02:00
|
|
|
#endif
|
2017-04-07 01:46:47 +02:00
|
|
|
}
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
if (g29_x_flag != g29_y_flag) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Both X & Y locations must be specified.\n");
|
2017-04-09 00:08:45 +02:00
|
|
|
err_flag = true;
|
|
|
|
}
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-08-16 07:59:30 +02:00
|
|
|
// If X or Y are not valid, use center of the bed values
|
2017-11-03 05:59:42 +01:00
|
|
|
if (!WITHIN(g29_x_pos, X_MIN_BED, X_MAX_BED)) g29_x_pos = X_CENTER;
|
|
|
|
if (!WITHIN(g29_y_pos, Y_MIN_BED, Y_MAX_BED)) g29_y_pos = Y_CENTER;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-04-09 00:08:45 +02:00
|
|
|
if (err_flag) return UBL_ERR;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-20 10:03:08 +02:00
|
|
|
/**
|
|
|
|
* Activate or deactivate UBL
|
|
|
|
* Note: UBL's G29 restores the state set here when done.
|
|
|
|
* Leveling is being enabled here with old data, possibly
|
|
|
|
* none. Error handling should disable for safety...
|
|
|
|
*/
|
|
|
|
if (parser.seen('A')) {
|
|
|
|
if (parser.seen('D')) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?Can't activate and deactivate at the same time.\n");
|
2017-05-03 00:41:55 +02:00
|
|
|
return UBL_ERR;
|
|
|
|
}
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(true);
|
2017-05-22 21:41:09 +02:00
|
|
|
report_state();
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
2017-05-20 10:03:08 +02:00
|
|
|
else if (parser.seen('D')) {
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(false);
|
2017-05-22 21:41:09 +02:00
|
|
|
report_state();
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-03 00:41:55 +02:00
|
|
|
// Set global 'C' flag and its value
|
2017-05-20 10:03:08 +02:00
|
|
|
if ((g29_c_flag = parser.seen('C')))
|
|
|
|
g29_constant = parser.value_float();
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2017-04-02 18:48:26 +02:00
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
2017-06-27 06:31:45 +02:00
|
|
|
if (parser.seenval('F')) {
|
2017-05-20 10:03:08 +02:00
|
|
|
const float fh = parser.value_float();
|
2018-07-07 03:41:08 +02:00
|
|
|
if (!WITHIN(fh, 0, 100)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?(F)ade height for Bed Level Correction not plausible.\n");
|
2017-04-02 18:48:26 +02:00
|
|
|
return UBL_ERR;
|
|
|
|
}
|
2017-04-21 00:45:58 +02:00
|
|
|
set_z_fade_height(fh);
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-27 07:49:21 +02:00
|
|
|
g29_map_type = parser.intval('T');
|
2017-06-13 01:26:49 +02:00
|
|
|
if (!WITHIN(g29_map_type, 0, 2)) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Invalid map type.\n");
|
2017-04-02 18:48:26 +02:00
|
|
|
return UBL_ERR;
|
|
|
|
}
|
|
|
|
return UBL_OK;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
static uint8_t ubl_state_at_invocation = 0;
|
2017-06-07 08:24:36 +02:00
|
|
|
|
2018-10-10 04:31:20 +02:00
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
2017-12-07 04:28:04 +01:00
|
|
|
static uint8_t ubl_state_recursion_chk = 0;
|
|
|
|
#endif
|
2017-06-07 08:24:36 +02:00
|
|
|
|
2017-12-07 04:28:04 +01:00
|
|
|
void unified_bed_leveling::save_ubl_active_state_and_disable() {
|
2018-10-10 04:31:20 +02:00
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
2017-12-07 04:28:04 +01:00
|
|
|
ubl_state_recursion_chk++;
|
|
|
|
if (ubl_state_recursion_chk != 1) {
|
|
|
|
SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 01:07:38 +01:00
|
|
|
set_message_with_feedback(PSTR(MSG_UBL_SAVE_ERROR));
|
2017-12-07 04:28:04 +01:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-14 00:21:25 +02:00
|
|
|
ubl_state_at_invocation = planner.leveling_active;
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(false);
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-04-26 03:50:17 +02:00
|
|
|
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
|
2018-10-10 04:31:20 +02:00
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
2017-12-07 04:28:04 +01:00
|
|
|
if (--ubl_state_recursion_chk) {
|
|
|
|
SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
|
2018-11-03 08:07:53 +01:00
|
|
|
#if HAS_LCD_MENU
|
2018-11-11 01:07:38 +01:00
|
|
|
set_message_with_feedback(PSTR(MSG_UBL_RESTORE_ERROR));
|
2017-12-07 04:28:04 +01:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(ubl_state_at_invocation);
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 17:44:45 +02:00
|
|
|
mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
|
|
|
|
|
2017-12-06 23:56:30 +01:00
|
|
|
bool found_a_NAN = false, found_a_real = false;
|
|
|
|
|
2017-05-03 00:41:55 +02:00
|
|
|
mesh_index_pair out_mesh;
|
|
|
|
out_mesh.x_index = out_mesh.y_index = -1;
|
2018-07-07 03:41:08 +02:00
|
|
|
out_mesh.distance = -99999.99f;
|
2017-10-19 17:44:45 +02:00
|
|
|
|
|
|
|
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
|
2017-12-06 23:56:30 +01:00
|
|
|
if (isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
|
2017-10-19 17:44:45 +02:00
|
|
|
|
|
|
|
const float mx = mesh_index_to_xpos(i),
|
|
|
|
my = mesh_index_to_ypos(j);
|
|
|
|
|
2017-12-06 23:56:30 +01:00
|
|
|
if (!position_is_reachable_by_probe(mx, my)) // make sure the probe can get to the mesh point
|
2017-10-19 17:44:45 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
found_a_NAN = true;
|
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
int8_t closest_x = -1, closest_y = -1;
|
2018-07-07 03:41:08 +02:00
|
|
|
float d1, d2 = 99999.9f;
|
2017-10-19 17:44:45 +02:00
|
|
|
for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
|
|
|
for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
|
|
|
if (!isnan(z_values[k][l])) {
|
|
|
|
found_a_real = true;
|
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
// Add in a random weighting factor that scrambles the probing of the
|
|
|
|
// last half of the mesh (when every unprobed mesh point is one index
|
|
|
|
// from a probed location).
|
2017-10-19 17:44:45 +02:00
|
|
|
|
2018-07-01 22:20:28 +02:00
|
|
|
d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
|
2017-10-19 17:44:45 +02:00
|
|
|
|
|
|
|
if (d1 < d2) { // found a closer distance from invalid mesh point at (i,j) to defined mesh point at (k,l)
|
2018-02-11 12:43:03 +01:00
|
|
|
d2 = d1; // found a closer location with
|
|
|
|
closest_x = i; // an assigned mesh point value
|
2017-10-19 17:44:45 +02:00
|
|
|
closest_y = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-02-11 12:43:03 +01:00
|
|
|
// At this point d2 should have the closest defined mesh point to invalid mesh point (i,j)
|
2017-10-19 17:44:45 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
if (found_a_real && (closest_x >= 0) && (d2 > out_mesh.distance)) {
|
|
|
|
out_mesh.distance = d2; // found an invalid location with a greater distance
|
|
|
|
out_mesh.x_index = closest_x; // to a defined mesh point
|
|
|
|
out_mesh.y_index = closest_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for j
|
|
|
|
} // for i
|
|
|
|
|
|
|
|
if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
|
|
|
|
out_mesh.x_index = GRID_MAX_POINTS_X / 2;
|
|
|
|
out_mesh.y_index = GRID_MAX_POINTS_Y / 2;
|
2018-07-07 03:41:08 +02:00
|
|
|
out_mesh.distance = 1;
|
2017-10-19 17:44:45 +02:00
|
|
|
}
|
|
|
|
return out_mesh;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &rx, const float &ry, const bool probe_as_reference, uint16_t bits[16]) {
|
2017-10-19 17:44:45 +02:00
|
|
|
mesh_index_pair out_mesh;
|
|
|
|
out_mesh.x_index = out_mesh.y_index = -1;
|
2018-07-07 03:41:08 +02:00
|
|
|
out_mesh.distance = -99999.9f;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
// Get our reference position. Either the nozzle or probe location.
|
2019-02-06 04:30:20 +01:00
|
|
|
const float px = rx + (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
|
|
|
|
py = ry + (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
float best_so_far = 99999.99f;
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-10-19 17:44:45 +02:00
|
|
|
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
|
|
|
|
|| (type == REAL && !isnan(z_values[i][j]))
|
2017-11-26 02:35:27 +01:00
|
|
|
|| (type == SET_IN_BITMAP && is_bitmap_set(bits, i, j))
|
2017-04-02 18:48:26 +02:00
|
|
|
) {
|
|
|
|
// We only get here if we found a Mesh Point of the specified type
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
const float mx = mesh_index_to_xpos(i),
|
|
|
|
my = mesh_index_to_ypos(j);
|
2017-04-02 18:48:26 +02:00
|
|
|
|
|
|
|
// If using the probe as the reference there are some unreachable locations.
|
2017-05-21 12:28:38 +02:00
|
|
|
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
|
2017-04-02 18:48:26 +02:00
|
|
|
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
|
|
|
|
|
2017-11-03 05:59:42 +01:00
|
|
|
if (probe_as_reference ? !position_is_reachable_by_probe(mx, my) : !position_is_reachable(mx, my))
|
2017-05-12 05:33:47 +02:00
|
|
|
continue;
|
|
|
|
|
2017-05-22 05:09:51 +02:00
|
|
|
// Reachable. Check if it's the best_so_far location to the nozzle.
|
2017-04-02 18:48:26 +02:00
|
|
|
|
2017-05-22 05:09:51 +02:00
|
|
|
float distance = HYPOT(px - mx, py - my);
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2017-05-22 05:09:51 +02:00
|
|
|
// factor in the distance from the current location for the normal case
|
|
|
|
// so the nozzle isn't running all over the bed.
|
2018-07-07 03:41:08 +02:00
|
|
|
distance += HYPOT(current_position[X_AXIS] - mx, current_position[Y_AXIS] - my) * 0.1f;
|
2017-10-19 17:44:45 +02:00
|
|
|
if (distance < best_so_far) {
|
|
|
|
best_so_far = distance; // We found a closer location with
|
2017-05-03 00:41:55 +02:00
|
|
|
out_mesh.x_index = i; // the specified type of mesh value.
|
|
|
|
out_mesh.y_index = j;
|
2017-05-22 05:09:51 +02:00
|
|
|
out_mesh.distance = best_so_far;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for j
|
|
|
|
} // for i
|
2017-12-06 23:56:30 +01:00
|
|
|
|
2017-05-03 00:41:55 +02:00
|
|
|
return out_mesh;
|
2017-04-02 18:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-03 00:42:15 +02:00
|
|
|
/**
|
|
|
|
* 'Smart Fill': Scan from the outward edges of the mesh towards the center.
|
|
|
|
* If an invalid location is found, use the next two points (if valid) to
|
|
|
|
* calculate a 'reasonable' value for the unprobed mesh point.
|
|
|
|
*/
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
|
2017-05-03 00:42:15 +02:00
|
|
|
const int8_t x1 = x + xdir, x2 = x1 + xdir,
|
|
|
|
y1 = y + ydir, y2 = y1 + ydir;
|
|
|
|
// A NAN next to a pair of real values?
|
2017-05-22 21:41:09 +02:00
|
|
|
if (isnan(z_values[x][y]) && !isnan(z_values[x1][y1]) && !isnan(z_values[x2][y2])) {
|
|
|
|
if (z_values[x1][y1] < z_values[x2][y2]) // Angled downward?
|
|
|
|
z_values[x][y] = z_values[x1][y1]; // Use nearest (maybe a little too high.)
|
2017-05-03 08:19:44 +02:00
|
|
|
else
|
2018-07-07 03:41:08 +02:00
|
|
|
z_values[x][y] = 2.0f * z_values[x1][y1] - z_values[x2][y2]; // Angled upward...
|
2019-03-13 06:45:52 +01:00
|
|
|
|
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
|
|
|
|
2017-05-03 00:42:15 +02:00
|
|
|
return true;
|
2017-04-26 03:50:17 +02:00
|
|
|
}
|
2017-05-03 00:42:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
void unified_bed_leveling::smart_fill_mesh() {
|
2017-06-06 14:18:46 +02:00
|
|
|
static const smart_fill_info
|
|
|
|
info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
|
|
|
|
info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
|
|
|
|
info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right
|
|
|
|
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
|
|
|
|
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
|
|
|
|
|
2017-05-03 08:06:53 +02:00
|
|
|
for (uint8_t i = 0; i < COUNT(info); ++i) {
|
2017-09-08 22:35:25 +02:00
|
|
|
const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
|
2017-10-19 17:44:45 +02:00
|
|
|
const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
|
|
|
|
ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
|
2017-06-06 14:18:46 +02:00
|
|
|
if (pgm_read_byte(&f->yfirst)) {
|
|
|
|
const int8_t dir = ex > sx ? 1 : -1;
|
|
|
|
for (uint8_t y = sy; y != ey; ++y)
|
|
|
|
for (uint8_t x = sx; x != ex; x += dir)
|
2017-05-03 08:06:53 +02:00
|
|
|
if (smart_fill_one(x, y, dir, 0)) break;
|
|
|
|
}
|
|
|
|
else {
|
2017-06-06 14:18:46 +02:00
|
|
|
const int8_t dir = ey > sy ? 1 : -1;
|
|
|
|
for (uint8_t x = sx; x != ex; ++x)
|
|
|
|
for (uint8_t y = sy; y != ey; y += dir)
|
2017-05-03 08:06:53 +02:00
|
|
|
if (smart_fill_one(x, y, 0, dir)) break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 00:42:15 +02:00
|
|
|
}
|
2017-04-07 01:46:47 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
|
2018-05-01 14:05:18 +02:00
|
|
|
#include "../../../libs/vector_3.h"
|
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) {
|
2019-07-06 01:01:21 +02:00
|
|
|
constexpr int16_t x_min = _MAX(MIN_PROBE_X, MESH_MIN_X),
|
|
|
|
x_max = _MIN(MAX_PROBE_X, MESH_MAX_X),
|
|
|
|
y_min = _MAX(MIN_PROBE_Y, MESH_MIN_Y),
|
|
|
|
y_max = _MIN(MAX_PROBE_Y, MESH_MAX_Y);
|
2017-10-10 01:26:52 +02:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
bool abort_flag = false;
|
2018-01-16 18:08:00 +01:00
|
|
|
|
|
|
|
float measured_z;
|
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
const float dx = float(x_max - x_min) / (g29_grid_size - 1),
|
|
|
|
dy = float(y_max - y_min) / (g29_grid_size - 1);
|
2017-10-10 01:26:52 +02:00
|
|
|
|
|
|
|
struct linear_fit_data lsf_results;
|
2018-01-16 18:08:00 +01:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
//float z1, z2, z3; // Needed for algorithm validation down below.
|
2018-01-16 18:08:00 +01:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
if (do_3_pt_leveling) {
|
2019-05-18 02:02:21 +02:00
|
|
|
SERIAL_ECHOLNPGM("Tilting mesh (1/3)");
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_DISPLAY
|
2019-05-18 02:02:21 +02:00
|
|
|
ui.status_printf_P(0, PSTR(MSG_LCD_TILTING_MESH " 1/3"));
|
|
|
|
#endif
|
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
measured_z = probe_at_point(PROBE_PT_1_X, PROBE_PT_1_Y, PROBE_PT_RAISE, g29_verbose_level);
|
2018-01-16 18:08:00 +01:00
|
|
|
if (isnan(measured_z))
|
|
|
|
abort_flag = true;
|
|
|
|
else {
|
2018-03-19 07:22:21 +01:00
|
|
|
measured_z -= get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y);
|
2018-02-11 12:43:03 +01:00
|
|
|
//z1 = measured_z;
|
|
|
|
if (g29_verbose_level > 3) {
|
2018-01-16 18:08:00 +01:00
|
|
|
serial_spaces(16);
|
|
|
|
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
|
|
|
|
}
|
2018-03-19 07:22:21 +01:00
|
|
|
incremental_LSF(&lsf_results, PROBE_PT_1_X, PROBE_PT_1_Y, measured_z);
|
2018-01-16 18:08:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!abort_flag) {
|
2019-05-18 02:02:21 +02:00
|
|
|
SERIAL_ECHOLNPGM("Tilting mesh (2/3)");
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_DISPLAY
|
2019-05-18 02:02:21 +02:00
|
|
|
ui.status_printf_P(0, PSTR(MSG_LCD_TILTING_MESH " 2/3"));
|
|
|
|
#endif
|
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
measured_z = probe_at_point(PROBE_PT_2_X, PROBE_PT_2_Y, PROBE_PT_RAISE, g29_verbose_level);
|
2018-02-11 12:43:03 +01:00
|
|
|
//z2 = measured_z;
|
2018-01-16 18:08:00 +01:00
|
|
|
if (isnan(measured_z))
|
|
|
|
abort_flag = true;
|
|
|
|
else {
|
2018-03-19 07:22:21 +01:00
|
|
|
measured_z -= get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y);
|
2018-02-11 12:43:03 +01:00
|
|
|
if (g29_verbose_level > 3) {
|
2018-01-16 18:08:00 +01:00
|
|
|
serial_spaces(16);
|
|
|
|
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
|
|
|
|
}
|
2018-03-19 07:22:21 +01:00
|
|
|
incremental_LSF(&lsf_results, PROBE_PT_2_X, PROBE_PT_2_Y, measured_z);
|
2018-01-16 18:08:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!abort_flag) {
|
2019-05-18 02:02:21 +02:00
|
|
|
SERIAL_ECHOLNPGM("Tilting mesh (3/3)");
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_DISPLAY
|
2019-05-18 02:02:21 +02:00
|
|
|
ui.status_printf_P(0, PSTR(MSG_LCD_TILTING_MESH " 3/3"));
|
|
|
|
#endif
|
2019-05-26 22:24:10 +02:00
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
measured_z = probe_at_point(PROBE_PT_3_X, PROBE_PT_3_Y, PROBE_PT_STOW, g29_verbose_level);
|
2018-02-11 12:43:03 +01:00
|
|
|
//z3 = measured_z;
|
2018-01-16 18:08:00 +01:00
|
|
|
if (isnan(measured_z))
|
|
|
|
abort_flag = true;
|
|
|
|
else {
|
2018-03-19 07:22:21 +01:00
|
|
|
measured_z -= get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y);
|
2018-02-11 12:43:03 +01:00
|
|
|
if (g29_verbose_level > 3) {
|
2018-01-16 18:08:00 +01:00
|
|
|
serial_spaces(16);
|
|
|
|
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
|
|
|
|
}
|
2018-03-19 07:22:21 +01:00
|
|
|
incremental_LSF(&lsf_results, PROBE_PT_3_X, PROBE_PT_3_Y, measured_z);
|
2018-01-16 18:08:00 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 01:49:32 +02:00
|
|
|
|
2018-06-21 20:26:20 +02:00
|
|
|
STOW_PROBE();
|
|
|
|
#ifdef Z_AFTER_PROBING
|
|
|
|
move_z_after_probing();
|
|
|
|
#endif
|
2018-07-26 01:49:32 +02:00
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
if (abort_flag) {
|
2019-05-18 02:02:21 +02:00
|
|
|
SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
|
2018-01-16 18:08:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-02-11 12:43:03 +01:00
|
|
|
}
|
|
|
|
else { // !do_3_pt_leveling
|
2018-01-16 18:08:00 +01:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
bool zig_zag = false;
|
2019-05-26 22:24:10 +02:00
|
|
|
|
2019-09-09 09:56:23 +02:00
|
|
|
uint16_t total_points = g29_grid_size * g29_grid_size, point_num = 1;
|
2019-05-18 02:02:21 +02:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
|
|
|
|
const float rx = float(x_min) + ix * dx;
|
|
|
|
for (int8_t iy = 0; iy < g29_grid_size; iy++) {
|
|
|
|
const float ry = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
|
2018-01-16 18:08:00 +01:00
|
|
|
|
|
|
|
if (!abort_flag) {
|
2019-09-09 09:56:23 +02:00
|
|
|
SERIAL_ECHOLNPAIR("Tilting mesh point ", point_num, "/", total_points, "\n");
|
2019-08-02 03:11:26 +02:00
|
|
|
#if HAS_DISPLAY
|
2019-09-09 09:56:23 +02:00
|
|
|
ui.status_printf_P(0, PSTR(MSG_LCD_TILTING_MESH " %i/%i"), point_num, total_points);
|
2019-05-18 02:02:21 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
measured_z = probe_at_point(rx, ry, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling
|
2018-01-16 18:08:00 +01:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
abort_flag = isnan(measured_z);
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
DEBUG_CHAR('(');
|
|
|
|
DEBUG_ECHO_F(rx, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(ry, 7);
|
2019-08-18 03:14:14 +02:00
|
|
|
DEBUG_ECHOPGM(") logical: (");
|
2019-03-14 08:25:42 +01:00
|
|
|
DEBUG_ECHO_F(LOGICAL_X_POSITION(rx), 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(LOGICAL_Y_POSITION(ry), 7);
|
|
|
|
DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7);
|
|
|
|
DEBUG_ECHOPAIR_F(" correction: ", get_z_correction(rx, ry), 7);
|
|
|
|
}
|
2018-01-16 18:08:00 +01:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
measured_z -= get_z_correction(rx, ry) /* + zprobe_zoffset */ ;
|
2017-04-26 03:50:17 +02:00
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
|
|
|
|
|
2018-04-13 21:46:47 +02:00
|
|
|
if (g29_verbose_level > 3) {
|
|
|
|
serial_spaces(16);
|
|
|
|
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
|
|
|
|
}
|
2018-02-11 12:43:03 +01:00
|
|
|
incremental_LSF(&lsf_results, rx, ry, measured_z);
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
2019-05-18 02:02:21 +02:00
|
|
|
|
2019-09-09 09:56:23 +02:00
|
|
|
point_num++;
|
2018-01-16 18:08:00 +01:00
|
|
|
}
|
2017-05-03 00:41:55 +02:00
|
|
|
|
2018-02-11 12:43:03 +01:00
|
|
|
zig_zag ^= true;
|
|
|
|
}
|
2018-01-16 18:08:00 +01:00
|
|
|
}
|
2018-06-21 20:26:20 +02:00
|
|
|
STOW_PROBE();
|
|
|
|
#ifdef Z_AFTER_PROBING
|
|
|
|
move_z_after_probing();
|
|
|
|
#endif
|
2018-07-26 01:49:32 +02:00
|
|
|
|
2018-01-16 18:08:00 +01:00
|
|
|
if (abort_flag || finish_incremental_LSF(&lsf_results)) {
|
2017-10-10 01:26:52 +02:00
|
|
|
SERIAL_ECHOPGM("Could not complete LSF!");
|
|
|
|
return;
|
2017-04-30 07:43:28 +02:00
|
|
|
}
|
2017-04-07 01:46:47 +02:00
|
|
|
|
2018-07-07 03:41:08 +02:00
|
|
|
vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1).get_normal();
|
2017-10-10 01:26:52 +02:00
|
|
|
|
|
|
|
if (g29_verbose_level > 2) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
|
|
|
|
SERIAL_CHAR(',');
|
|
|
|
SERIAL_ECHO_F(normal.y, 7);
|
|
|
|
SERIAL_CHAR(',');
|
|
|
|
SERIAL_ECHO_F(normal.z, 7);
|
2017-10-10 01:26:52 +02:00
|
|
|
SERIAL_ECHOLNPGM("]");
|
2017-04-26 03:50:17 +02:00
|
|
|
}
|
2017-06-04 00:11:43 +02:00
|
|
|
|
2017-10-10 01:26:52 +02:00
|
|
|
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
float x_tmp = mesh_index_to_xpos(i),
|
|
|
|
y_tmp = mesh_index_to_ypos(j),
|
|
|
|
z_tmp = z_values[i][j];
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
DEBUG_ECHOPAIR_F("before rotation = [", x_tmp, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(y_tmp, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(z_tmp, 7);
|
|
|
|
DEBUG_ECHOPGM("] ---> ");
|
|
|
|
DEBUG_DELAY(20);
|
|
|
|
}
|
2017-10-10 01:26:52 +02:00
|
|
|
|
|
|
|
apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
DEBUG_ECHOPAIR_F("after rotation = [", x_tmp, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(y_tmp, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(z_tmp, 7);
|
|
|
|
DEBUG_ECHOLNPGM("]");
|
|
|
|
DEBUG_DELAY(55);
|
|
|
|
}
|
2017-10-10 01:26:52 +02:00
|
|
|
|
2018-02-26 22:02:19 +01:00
|
|
|
z_values[i][j] = z_tmp - lsf_results.D;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(i, j, z_values[i][j]);
|
|
|
|
#endif
|
2017-10-10 01:26:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 08:25:42 +01:00
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
rotation.debug(PSTR("rotation matrix:\n"));
|
|
|
|
DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
|
|
|
|
DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7);
|
|
|
|
DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
|
|
|
|
DEBUG_DELAY(55);
|
|
|
|
|
|
|
|
DEBUG_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(normal.y, 7);
|
|
|
|
DEBUG_CHAR(',');
|
|
|
|
DEBUG_ECHO_F(normal.z, 7);
|
|
|
|
DEBUG_ECHOLNPGM("]");
|
|
|
|
DEBUG_EOL();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The following code can be used to check the validity of the mesh tilting algorithm.
|
|
|
|
* When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting.
|
|
|
|
* The only difference is just 3 points are used in the calculations. That fact guarantees
|
|
|
|
* each probed point should have an exact match when a get_z_correction() for that location
|
|
|
|
* is calculated. The Z error between the probed point locations and the get_z_correction()
|
|
|
|
* numbers for those locations should be 0.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
float t, t1, d;
|
|
|
|
t = normal.x * (PROBE_PT_1_X) + normal.y * (PROBE_PT_1_Y);
|
|
|
|
d = t + normal.z * z1;
|
|
|
|
DEBUG_ECHOPAIR_F("D from 1st point: ", d, 6);
|
|
|
|
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z1-get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y), 6);
|
|
|
|
|
|
|
|
t = normal.x * (PROBE_PT_2_X) + normal.y * (PROBE_PT_2_Y);
|
|
|
|
d = t + normal.z * z2;
|
|
|
|
DEBUG_EOL();
|
|
|
|
DEBUG_ECHOPAIR_F("D from 2nd point: ", d, 6);
|
|
|
|
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z2-get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y), 6);
|
|
|
|
|
|
|
|
t = normal.x * (PROBE_PT_3_X) + normal.y * (PROBE_PT_3_Y);
|
|
|
|
d = t + normal.z * z3;
|
|
|
|
DEBUG_ECHOPAIR_F("D from 3rd point: ", d, 6);
|
|
|
|
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z3-get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y), 6);
|
|
|
|
|
|
|
|
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
|
|
|
|
d = t + normal.z * 0;
|
|
|
|
DEBUG_ECHOLNPAIR_F("D from home location with Z=0 : ", d, 6);
|
|
|
|
|
|
|
|
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
|
|
|
|
d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
|
|
|
|
DEBUG_ECHOPAIR_F("D from home location using mesh value for Z: ", d, 6);
|
|
|
|
|
|
|
|
DEBUG_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT, ",", Z_SAFE_HOMING_Y_POINT);
|
|
|
|
DEBUG_ECHOLNPAIR_F(") = ", get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6);
|
|
|
|
#endif
|
|
|
|
} // DEBUGGING(LEVELING)
|
2017-10-10 01:26:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_BED_PROBE
|
2017-04-07 01:46:47 +02:00
|
|
|
|
2017-05-22 19:33:50 +02:00
|
|
|
#if ENABLED(UBL_G29_P31)
|
2017-05-22 21:41:09 +02:00
|
|
|
void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) {
|
2017-05-22 19:33:50 +02:00
|
|
|
|
|
|
|
// For each undefined mesh point, compute a distance-weighted least squares fit
|
|
|
|
// from all the originally populated mesh points, weighted toward the point
|
|
|
|
// being extrapolated so that nearby points will have greater influence on
|
|
|
|
// the point being extrapolated. Then extrapolate the mesh point from WLSF.
|
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
static_assert(GRID_MAX_POINTS_Y <= 16, "GRID_MAX_POINTS_Y too big");
|
|
|
|
uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
|
2017-05-22 19:33:50 +02:00
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Extrapolating mesh...");
|
|
|
|
|
2019-07-06 01:01:21 +02:00
|
|
|
const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST);
|
2017-05-22 19:33:50 +02:00
|
|
|
|
2017-05-22 21:41:09 +02:00
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++)
|
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
|
|
|
|
if (!isnan(z_values[jx][jy]))
|
|
|
|
SBI(bitmap[jx], jy);
|
2017-05-22 19:33:50 +02:00
|
|
|
|
|
|
|
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
|
2017-05-22 21:41:09 +02:00
|
|
|
const float px = mesh_index_to_xpos(ix);
|
2017-05-22 19:33:50 +02:00
|
|
|
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
|
2017-05-22 21:41:09 +02:00
|
|
|
const float py = mesh_index_to_ypos(iy);
|
|
|
|
if (isnan(z_values[ix][iy])) {
|
2017-05-22 19:33:50 +02:00
|
|
|
// undefined mesh point at (px,py), compute weighted LSF from original valid mesh points.
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
|
2017-05-22 21:41:09 +02:00
|
|
|
const float rx = mesh_index_to_xpos(jx);
|
2017-05-22 19:33:50 +02:00
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
|
2017-05-22 21:41:09 +02:00
|
|
|
if (TEST(bitmap[jx], jy)) {
|
|
|
|
const float ry = mesh_index_to_ypos(jy),
|
|
|
|
rz = z_values[jx][jy],
|
2018-07-07 03:41:08 +02:00
|
|
|
w = 1 + weight_scaled / HYPOT((rx - px), (ry - py));
|
2017-05-22 19:33:50 +02:00
|
|
|
incremental_WLSF(&lsf_results, rx, ry, rz, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (finish_incremental_LSF(&lsf_results)) {
|
|
|
|
SERIAL_ECHOLNPGM("Insufficient data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const float ez = -lsf_results.D - lsf_results.A * px - lsf_results.B * py;
|
2017-05-22 21:41:09 +02:00
|
|
|
z_values[ix][iy] = ez;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]);
|
|
|
|
#endif
|
2017-05-22 19:33:50 +02:00
|
|
|
idle(); // housekeeping
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM("done");
|
|
|
|
}
|
|
|
|
#endif // UBL_G29_P31
|
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
|
|
|
/**
|
|
|
|
* Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
|
|
|
|
* good to have the extra information. Soon... we prune this to just a few items
|
|
|
|
*/
|
|
|
|
void unified_bed_leveling::g29_what_command() {
|
|
|
|
report_state();
|
|
|
|
|
|
|
|
if (storage_slot == -1)
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM("No Mesh Loaded.");
|
2019-03-05 13:46:19 +01:00
|
|
|
else
|
|
|
|
SERIAL_ECHOPAIR("Mesh ", storage_slot, " Loaded.");
|
2018-11-11 19:16:24 +01:00
|
|
|
SERIAL_EOL();
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR_F("planner.z_fade_height : ", planner.z_fade_height, 4);
|
2018-11-11 19:16:24 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
adjust_mesh_to_mean(g29_c_flag, g29_constant);
|
|
|
|
|
|
|
|
#if HAS_BED_PROBE
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR_F("zprobe_zoffset: ", zprobe_zoffset, 7);
|
2018-11-11 19:16:24 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-24 04:05:59 +01:00
|
|
|
SERIAL_ECHOLNPAIR("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50);
|
|
|
|
SERIAL_ECHOLNPAIR("MESH_MIN_Y " STRINGIFY(MESH_MIN_Y) "=", MESH_MIN_Y); serial_delay(50);
|
|
|
|
SERIAL_ECHOLNPAIR("MESH_MAX_X " STRINGIFY(MESH_MAX_X) "=", MESH_MAX_X); serial_delay(50);
|
|
|
|
SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y); serial_delay(50);
|
|
|
|
SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); serial_delay(50);
|
|
|
|
SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
SERIAL_ECHOLNPAIR("MESH_X_DIST ", MESH_X_DIST);
|
2018-11-24 04:05:59 +01:00
|
|
|
SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
|
2018-11-11 19:16:24 +01:00
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
|
|
|
|
SERIAL_ECHOPGM(" ");
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(25);
|
2018-11-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
|
2018-11-11 19:16:24 +01:00
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
|
|
|
|
SERIAL_ECHOPGM(" ");
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(25);
|
2018-11-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
|
|
|
|
#if HAS_KILL
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("Kill pin on :", int(KILL_PIN), " state:", READ(KILL_PIN));
|
2018-11-11 19:16:24 +01:00
|
|
|
#endif
|
|
|
|
SERIAL_EOL();
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
#if ENABLED(UBL_DEVEL_DEBUGGING)
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation, "\nubl_state_recursion_chk :", ubl_state_recursion_chk);
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("Meshes go from ", hex_address((void*)settings.meshes_start_index()), " to ", hex_address((void*)settings.meshes_end_index()));
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl)); SERIAL_EOL();
|
|
|
|
SERIAL_ECHOLNPAIR("z_value[][] size: ", (int)sizeof(z_values)); SERIAL_EOL();
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(25);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.meshes_end_index() - settings.meshes_start_index())));
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2018-11-11 19:16:24 +01:00
|
|
|
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("EEPROM can hold ", settings.calc_num_meshes(), " meshes.\n");
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(25);
|
2018-11-11 19:16:24 +01:00
|
|
|
#endif // UBL_DEVEL_DEBUGGING
|
|
|
|
|
|
|
|
if (!sanity_check()) {
|
|
|
|
echo_name();
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM(" sanity checks passed.");
|
2018-11-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When we are fully debugged, the EEPROM dump command will get deleted also. But
|
|
|
|
* right now, it is good to have the extra information. Soon... we prune this.
|
|
|
|
*/
|
|
|
|
void unified_bed_leveling::g29_eeprom_dump() {
|
|
|
|
uint8_t cccc;
|
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHO_MSG("EEPROM Dump:");
|
2018-11-11 19:16:24 +01:00
|
|
|
persistentStore.access_start();
|
|
|
|
for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) {
|
|
|
|
if (!(i & 0x3)) idle();
|
|
|
|
print_hex_word(i);
|
|
|
|
SERIAL_ECHOPGM(": ");
|
|
|
|
for (uint16_t j = 0; j < 16; j++) {
|
|
|
|
persistentStore.read_data(i + j, &cccc, sizeof(uint8_t));
|
|
|
|
print_hex_byte(cccc);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_CHAR(' ');
|
2018-11-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
SERIAL_EOL();
|
|
|
|
persistentStore.access_finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When we are fully debugged, this may go away. But there are some valid
|
|
|
|
* use cases for the users. So we can wait and see what to do with it.
|
|
|
|
*/
|
|
|
|
void unified_bed_leveling::g29_compare_current_mesh_to_stored_mesh() {
|
2019-03-05 14:53:15 +01:00
|
|
|
const int16_t a = settings.calc_num_meshes();
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
if (!a) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?EEPROM storage not available.");
|
2018-11-11 19:16:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-05 14:53:15 +01:00
|
|
|
if (!parser.has_value() || !WITHIN(g29_storage_slot, 0, a - 1)) {
|
|
|
|
SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1);
|
2018-11-11 19:16:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g29_storage_slot = parser.value_int();
|
|
|
|
|
|
|
|
float tmp_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
settings.load_mesh(g29_storage_slot, &tmp_z_values);
|
|
|
|
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh.");
|
2018-11-11 19:16:24 +01:00
|
|
|
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
2019-03-13 06:45:52 +01:00
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
2018-11-11 19:16:24 +01:00
|
|
|
z_values[x][y] -= tmp_z_values[x][y];
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
|
|
|
#endif
|
|
|
|
}
|
2018-11-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // UBL_DEVEL_DEBUGGING
|
|
|
|
|
2017-04-02 23:13:15 +02:00
|
|
|
#endif // AUTO_BED_LEVELING_UBL
|