Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBL G29 J Level on Mesh points #25486

Merged
merged 21 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,9 @@

//#define UBL_HILBERT_CURVE // Use Hilbert distribution for less travel when probing multiple points

//#define UBL_TILT_ON_MESH_POINTS // Use nearest mesh points with G29 J for better Z reference
//#define UBL_TILT_ON_MESH_POINTS_3POINT // Use nearest mesh points with G29 J0 (3-point)

#define UBL_MESH_EDIT_MOVES_Z // Sophisticated users prefer no movement of nozzle
#define UBL_SAVE_ACTIVE_ON_M500 // Save the currently active mesh in the current slot on M500

Expand Down
45 changes: 34 additions & 11 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,14 @@ void unified_bed_leveling::smart_fill_mesh() {
xy_float_t points[3];
probe.get_three_points(points);

#if ENABLED(UBL_TILT_ON_MESH_POINTS_3POINT)
mesh_index_pair cpos[3];
LOOP_L_N(ix, 3) { // Convert points to coordinates of mesh points
cpos[ix] = find_closest_mesh_point_of_type(REAL, points[ix], true);
points[ix] = cpos[ix].meshpos();
}
#endif

#if ENABLED(VALIDATE_MESH_TILT)
float gotz[3]; // Used for algorithm validation below
#endif
Expand All @@ -1500,7 +1508,7 @@ void unified_bed_leveling::smart_fill_mesh() {
measured_z = probe.probe_at_point(points[i], i < 2 ? PROBE_PT_RAISE : PROBE_PT_LAST_STOW, param.V_verbosity);
if ((abort_flag = isnan(measured_z))) break;

measured_z -= get_z_correction(points[i]);
measured_z -= TERN(UBL_TILT_ON_MESH_POINTS_3POINT, z_values[cpos[i].pos.x][cpos[i].pos.y], get_z_correction(points[i]));
TERN_(VALIDATE_MESH_TILT, gotz[i] = measured_z);

if (param.V_verbosity > 3) { serial_spaces(16); SERIAL_ECHOLNPGM("Corrected_Z=", measured_z); }
Expand All @@ -1518,16 +1526,14 @@ void unified_bed_leveling::smart_fill_mesh() {
}
else { // !do_3_pt_leveling

#ifdef G29J_MESH_TILT_MARGIN
const float x_min = _MAX(probe.min_x() + (G29J_MESH_TILT_MARGIN), X_MIN_POS),
x_max = _MIN(probe.max_x() - (G29J_MESH_TILT_MARGIN), X_MAX_POS),
y_min = _MAX(probe.min_y() + (G29J_MESH_TILT_MARGIN), Y_MIN_POS),
y_max = _MIN(probe.max_y() - (G29J_MESH_TILT_MARGIN), Y_MAX_POS);
#else
const float x_min = probe.min_x(), x_max = probe.max_x(),
y_min = probe.min_y(), y_max = probe.max_y();
#ifndef G29J_MESH_TILT_MARGIN
#define G29J_MESH_TILT_MARGIN 0
#endif
const float dx = (x_max - x_min) / (param.J_grid_size - 1),
const float x_min = _MAX((X_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_X, probe.min_x()),
x_max = _MIN((X_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_X, probe.max_x()),
y_min = _MAX((Y_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_Y, probe.min_y()),
y_max = _MIN((Y_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_Y, probe.max_y()),
dx = (x_max - x_min) / (param.J_grid_size - 1),
dy = (y_max - y_min) / (param.J_grid_size - 1);

bool zig_zag = false;
Expand All @@ -1541,18 +1547,35 @@ void unified_bed_leveling::smart_fill_mesh() {
LOOP_L_N(iy, param.J_grid_size) {
rpos.y = y_min + dy * (zig_zag ? param.J_grid_size - 1 - iy : iy);

#if ENABLED(UBL_TILT_ON_MESH_POINTS)
#if ENABLED(DEBUG_LEVELING_FEATURE)
xy_pos_t oldRpos;
if (DEBUGGING(LEVELING)) oldRpos = rpos;
#endif
mesh_index_pair cpos;
rpos -= probe.offset;
cpos = find_closest_mesh_point_of_type(REAL, rpos, true);
rpos = cpos.meshpos();
#endif

SERIAL_ECHOLNPGM("Tilting mesh point ", point_num, "/", total_points, "\n");
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points));

measured_z = probe.probe_at_point(rpos, parser.seen_test('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity); // TODO: Needs error handling

if ((abort_flag = isnan(measured_z))) break;

const float zcorr = get_z_correction(rpos);
const float zcorr = TERN(UBL_TILT_ON_MESH_POINTS, z_values[cpos.pos.x][cpos.pos.y], get_z_correction(rpos));

#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
const xy_pos_t lpos = rpos.asLogical();
#if ENABLED(UBL_TILT_ON_MESH_POINTS)
const xy_pos_t oldLpos = oldRpos.asLogical();
DEBUG_ECHOPGM("Calculated point: ("); DEBUG_ECHO_F(oldRpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(oldRpos.y, 7);
DEBUG_ECHOPAIR_F(") logical: (", oldLpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(oldLpos.y, 7);
DEBUG_ECHOPGM(")\nSelected mesh point: ");
#endif
DEBUG_CHAR('('); DEBUG_ECHO_F(rpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(rpos.y, 7);
DEBUG_ECHOPAIR_F(") logical: (", lpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(lpos.y, 7);
DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3156,14 +3156,14 @@
// Probing points may be verified at compile time within the radius
// using static_assert(HYPOT2(X2-X1,Y2-Y1)<=sq(PRINTABLE_RADIUS),"bad probe point!")
// so that may be added to SanityCheck.h in the future.
#define _MESH_MIN_X (X_MIN_BED + MESH_INSET)
#define _MESH_MIN_Y (Y_MIN_BED + MESH_INSET)
#define _MESH_MIN_X (X_MIN_BED + (MESH_INSET))
#define _MESH_MIN_Y (Y_MIN_BED + (MESH_INSET))
#define _MESH_MAX_X (X_MAX_BED - (MESH_INSET))
#define _MESH_MAX_Y (Y_MAX_BED - (MESH_INSET))
#else
// Boundaries for Cartesian probing based on set limits
#define _MESH_MIN_X (_MAX(X_MIN_BED + MESH_INSET, X_MIN_POS)) // UBL is careful not to probe off the bed. It does not
#define _MESH_MIN_Y (_MAX(Y_MIN_BED + MESH_INSET, Y_MIN_POS)) // need NOZZLE_TO_PROBE_OFFSET in the mesh dimensions
#define _MESH_MIN_X (_MAX(X_MIN_BED + (MESH_INSET), X_MIN_POS)) // UBL is careful not to probe off the bed. It doesn't
#define _MESH_MIN_Y (_MAX(Y_MIN_BED + (MESH_INSET), Y_MIN_POS)) // need NOZZLE_TO_PROBE_OFFSET in the mesh dimensions.
#define _MESH_MAX_X (_MIN(X_MAX_BED - (MESH_INSET), X_MAX_POS))
#define _MESH_MAX_Y (_MIN(Y_MAX_BED - (MESH_INSET), Y_MAX_POS))
#endif
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ class Probe {
points[0] = xy_float_t({ (X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0 });
points[1] = xy_float_t({ (X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120 });
points[2] = xy_float_t({ (X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240 });
#elif ENABLED(AUTO_BED_LEVELING_UBL)
points[0] = xy_float_t({ _MAX(MESH_MIN_X, min_x()), _MAX(MESH_MIN_Y, min_y()) });
points[1] = xy_float_t({ _MIN(MESH_MAX_X, max_x()), _MAX(MESH_MIN_Y, min_y()) });
points[2] = xy_float_t({ (_MAX(MESH_MIN_X, min_x()) + _MIN(MESH_MAX_X, max_x())) / 2, _MIN(MESH_MAX_Y, max_y()) });
#else
points[0] = xy_float_t({ min_x(), min_y() });
points[1] = xy_float_t({ max_x(), min_y() });
Expand Down
3 changes: 2 additions & 1 deletion buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE jp_kana DEFAULT_EJERK 10 \
opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \
SET_PROGRESS_MANUALLY SET_PROGRESS_PERCENT PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME STATUS_MESSAGE_SCROLLING SCROLL_LONG_FILENAMES \
SDSUPPORT LONG_FILENAME_WRITE_SUPPORT SDCARD_SORT_ALPHA NO_SD_AUTOSTART USB_FLASH_DRIVE_SUPPORT CANCEL_OBJECTS \
Z_PROBE_SLED AUTO_BED_LEVELING_UBL UBL_HILBERT_CURVE RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT \
Z_PROBE_SLED AUTO_BED_LEVELING_UBL UBL_HILBERT_CURVE UBL_TILT_ON_MESH_POINTS UBL_TILT_ON_MESH_POINTS_3POINT \
RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT \
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN \
MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE QUICK_HOME \
NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL \
Expand Down