Skip to content

Commit aec226e

Browse files
jamespearson04thinkyhead
authored andcommitted
🚸 Refinements for UBL G29 J (tilt mesh) (MarlinFirmware#25486)
1 parent ab3221c commit aec226e

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

Marlin/Configuration.h

+3
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,9 @@
20542054

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

2057+
//#define UBL_TILT_ON_MESH_POINTS // Use nearest mesh points with G29 J for better Z reference
2058+
//#define UBL_TILT_ON_MESH_POINTS_3POINT // Use nearest mesh points with G29 J0 (3-point)
2059+
20572060
#define UBL_MESH_EDIT_MOVES_Z // Sophisticated users prefer no movement of nozzle
20582061
#define UBL_SAVE_ACTIVE_ON_M500 // Save the currently active mesh in the current slot on M500
20592062

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

+34-11
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,14 @@ void unified_bed_leveling::smart_fill_mesh() {
14891489
xy_float_t points[3];
14901490
probe.get_three_points(points);
14911491

1492+
#if ENABLED(UBL_TILT_ON_MESH_POINTS_3POINT)
1493+
mesh_index_pair cpos[3];
1494+
LOOP_L_N(ix, 3) { // Convert points to coordinates of mesh points
1495+
cpos[ix] = find_closest_mesh_point_of_type(REAL, points[ix], true);
1496+
points[ix] = cpos[ix].meshpos();
1497+
}
1498+
#endif
1499+
14921500
#if ENABLED(VALIDATE_MESH_TILT)
14931501
float gotz[3]; // Used for algorithm validation below
14941502
#endif
@@ -1500,7 +1508,7 @@ void unified_bed_leveling::smart_fill_mesh() {
15001508
measured_z = probe.probe_at_point(points[i], i < 2 ? PROBE_PT_RAISE : PROBE_PT_LAST_STOW, param.V_verbosity);
15011509
if ((abort_flag = isnan(measured_z))) break;
15021510

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

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

1521-
#ifdef G29J_MESH_TILT_MARGIN
1522-
const float x_min = _MAX(probe.min_x() + (G29J_MESH_TILT_MARGIN), X_MIN_POS),
1523-
x_max = _MIN(probe.max_x() - (G29J_MESH_TILT_MARGIN), X_MAX_POS),
1524-
y_min = _MAX(probe.min_y() + (G29J_MESH_TILT_MARGIN), Y_MIN_POS),
1525-
y_max = _MIN(probe.max_y() - (G29J_MESH_TILT_MARGIN), Y_MAX_POS);
1526-
#else
1527-
const float x_min = probe.min_x(), x_max = probe.max_x(),
1528-
y_min = probe.min_y(), y_max = probe.max_y();
1529+
#ifndef G29J_MESH_TILT_MARGIN
1530+
#define G29J_MESH_TILT_MARGIN 0
15291531
#endif
1530-
const float dx = (x_max - x_min) / (param.J_grid_size - 1),
1532+
const float x_min = _MAX((X_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_X, probe.min_x()),
1533+
x_max = _MIN((X_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_X, probe.max_x()),
1534+
y_min = _MAX((Y_MIN_POS) + (G29J_MESH_TILT_MARGIN), MESH_MIN_Y, probe.min_y()),
1535+
y_max = _MIN((Y_MAX_POS) - (G29J_MESH_TILT_MARGIN), MESH_MAX_Y, probe.max_y()),
1536+
dx = (x_max - x_min) / (param.J_grid_size - 1),
15311537
dy = (y_max - y_min) / (param.J_grid_size - 1);
15321538

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

1550+
#if ENABLED(UBL_TILT_ON_MESH_POINTS)
1551+
#if ENABLED(DEBUG_LEVELING_FEATURE)
1552+
xy_pos_t oldRpos;
1553+
if (DEBUGGING(LEVELING)) oldRpos = rpos;
1554+
#endif
1555+
mesh_index_pair cpos;
1556+
rpos -= probe.offset;
1557+
cpos = find_closest_mesh_point_of_type(REAL, rpos, true);
1558+
rpos = cpos.meshpos();
1559+
#endif
1560+
15441561
SERIAL_ECHOLNPGM("Tilting mesh point ", point_num, "/", total_points, "\n");
15451562
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points));
15461563

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

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

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

15531570
#if ENABLED(DEBUG_LEVELING_FEATURE)
15541571
if (DEBUGGING(LEVELING)) {
15551572
const xy_pos_t lpos = rpos.asLogical();
1573+
#if ENABLED(UBL_TILT_ON_MESH_POINTS)
1574+
const xy_pos_t oldLpos = oldRpos.asLogical();
1575+
DEBUG_ECHOPGM("Calculated point: ("); DEBUG_ECHO_F(oldRpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(oldRpos.y, 7);
1576+
DEBUG_ECHOPAIR_F(") logical: (", oldLpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(oldLpos.y, 7);
1577+
DEBUG_ECHOPGM(")\nSelected mesh point: ");
1578+
#endif
15561579
DEBUG_CHAR('('); DEBUG_ECHO_F(rpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(rpos.y, 7);
15571580
DEBUG_ECHOPAIR_F(") logical: (", lpos.x, 7); DEBUG_CHAR(','); DEBUG_ECHO_F(lpos.y, 7);
15581581
DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7);

Marlin/src/inc/Conditionals_post.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3156,14 +3156,14 @@
31563156
// Probing points may be verified at compile time within the radius
31573157
// using static_assert(HYPOT2(X2-X1,Y2-Y1)<=sq(PRINTABLE_RADIUS),"bad probe point!")
31583158
// so that may be added to SanityCheck.h in the future.
3159-
#define _MESH_MIN_X (X_MIN_BED + MESH_INSET)
3160-
#define _MESH_MIN_Y (Y_MIN_BED + MESH_INSET)
3159+
#define _MESH_MIN_X (X_MIN_BED + (MESH_INSET))
3160+
#define _MESH_MIN_Y (Y_MIN_BED + (MESH_INSET))
31613161
#define _MESH_MAX_X (X_MAX_BED - (MESH_INSET))
31623162
#define _MESH_MAX_Y (Y_MAX_BED - (MESH_INSET))
31633163
#else
31643164
// Boundaries for Cartesian probing based on set limits
3165-
#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
3166-
#define _MESH_MIN_Y (_MAX(Y_MIN_BED + MESH_INSET, Y_MIN_POS)) // need NOZZLE_TO_PROBE_OFFSET in the mesh dimensions
3165+
#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
3166+
#define _MESH_MIN_Y (_MAX(Y_MIN_BED + (MESH_INSET), Y_MIN_POS)) // need NOZZLE_TO_PROBE_OFFSET in the mesh dimensions.
31673167
#define _MESH_MAX_X (_MIN(X_MAX_BED - (MESH_INSET), X_MAX_POS))
31683168
#define _MESH_MAX_Y (_MIN(Y_MAX_BED - (MESH_INSET), Y_MAX_POS))
31693169
#endif

Marlin/src/module/probe.h

+4
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ class Probe {
307307
points[0] = xy_float_t({ (X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0 });
308308
points[1] = xy_float_t({ (X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120 });
309309
points[2] = xy_float_t({ (X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240 });
310+
#elif ENABLED(AUTO_BED_LEVELING_UBL)
311+
points[0] = xy_float_t({ _MAX(MESH_MIN_X, min_x()), _MAX(MESH_MIN_Y, min_y()) });
312+
points[1] = xy_float_t({ _MIN(MESH_MAX_X, max_x()), _MAX(MESH_MIN_Y, min_y()) });
313+
points[2] = xy_float_t({ (_MAX(MESH_MIN_X, min_x()) + _MIN(MESH_MAX_X, max_x())) / 2, _MIN(MESH_MAX_Y, max_y()) });
310314
#else
311315
points[0] = xy_float_t({ min_x(), min_y() });
312316
points[1] = xy_float_t({ max_x(), min_y() });

buildroot/tests/mega2560

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE jp_kana DEFAULT_EJERK 10 \
4444
opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \
4545
SET_PROGRESS_MANUALLY SET_PROGRESS_PERCENT PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME STATUS_MESSAGE_SCROLLING SCROLL_LONG_FILENAMES \
4646
SDSUPPORT LONG_FILENAME_WRITE_SUPPORT SDCARD_SORT_ALPHA NO_SD_AUTOSTART USB_FLASH_DRIVE_SUPPORT CANCEL_OBJECTS \
47-
Z_PROBE_SLED AUTO_BED_LEVELING_UBL UBL_HILBERT_CURVE RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT \
47+
Z_PROBE_SLED AUTO_BED_LEVELING_UBL UBL_HILBERT_CURVE UBL_TILT_ON_MESH_POINTS UBL_TILT_ON_MESH_POINTS_3POINT \
48+
RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT \
4849
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN \
4950
MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE QUICK_HOME \
5051
NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL \

0 commit comments

Comments
 (0)