@@ -1489,6 +1489,14 @@ void unified_bed_leveling::smart_fill_mesh() {
1489
1489
xy_float_t points[3 ];
1490
1490
probe.get_three_points (points);
1491
1491
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
+
1492
1500
#if ENABLED(VALIDATE_MESH_TILT)
1493
1501
float gotz[3 ]; // Used for algorithm validation below
1494
1502
#endif
@@ -1500,7 +1508,7 @@ void unified_bed_leveling::smart_fill_mesh() {
1500
1508
measured_z = probe.probe_at_point (points[i], i < 2 ? PROBE_PT_RAISE : PROBE_PT_LAST_STOW, param.V_verbosity );
1501
1509
if ((abort_flag = isnan (measured_z))) break ;
1502
1510
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]) );
1504
1512
TERN_ (VALIDATE_MESH_TILT, gotz[i] = measured_z);
1505
1513
1506
1514
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() {
1518
1526
}
1519
1527
else { // !do_3_pt_leveling
1520
1528
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
1529
1531
#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 ),
1531
1537
dy = (y_max - y_min) / (param.J_grid_size - 1 );
1532
1538
1533
1539
bool zig_zag = false ;
@@ -1541,18 +1547,35 @@ void unified_bed_leveling::smart_fill_mesh() {
1541
1547
LOOP_L_N (iy, param.J_grid_size ) {
1542
1548
rpos.y = y_min + dy * (zig_zag ? param.J_grid_size - 1 - iy : iy);
1543
1549
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
+
1544
1561
SERIAL_ECHOLNPGM (" Tilting mesh point " , point_num, " /" , total_points, " \n " );
1545
1562
TERN_ (HAS_STATUS_MESSAGE, ui.status_printf (0 , F (S_FMT " %i/%i" ), GET_TEXT (MSG_LCD_TILTING_MESH), point_num, total_points));
1546
1563
1547
1564
measured_z = probe.probe_at_point (rpos, parser.seen_test (' E' ) ? PROBE_PT_STOW : PROBE_PT_RAISE, param.V_verbosity ); // TODO: Needs error handling
1548
1565
1549
1566
if ((abort_flag = isnan (measured_z))) break ;
1550
1567
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) );
1552
1569
1553
1570
#if ENABLED(DEBUG_LEVELING_FEATURE)
1554
1571
if (DEBUGGING (LEVELING)) {
1555
1572
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 (" )\n Selected mesh point: " );
1578
+ #endif
1556
1579
DEBUG_CHAR (' (' ); DEBUG_ECHO_F (rpos.x , 7 ); DEBUG_CHAR (' ,' ); DEBUG_ECHO_F (rpos.y , 7 );
1557
1580
DEBUG_ECHOPAIR_F (" ) logical: (" , lpos.x , 7 ); DEBUG_CHAR (' ,' ); DEBUG_ECHO_F (lpos.y , 7 );
1558
1581
DEBUG_ECHOPAIR_F (" ) measured: " , measured_z, 7 );
0 commit comments