|
@ -31,8 +31,6 @@ |
|
|
|
|
|
|
|
|
mesh_bed_leveling mbl; |
|
|
mesh_bed_leveling mbl; |
|
|
|
|
|
|
|
|
bool mesh_bed_leveling::has_mesh; |
|
|
|
|
|
|
|
|
|
|
|
float mesh_bed_leveling::z_offset, |
|
|
float mesh_bed_leveling::z_offset, |
|
|
mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], |
|
|
mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], |
|
|
mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X], |
|
|
mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X], |
|
@ -47,7 +45,6 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void mesh_bed_leveling::reset() { |
|
|
void mesh_bed_leveling::reset() { |
|
|
has_mesh = false; |
|
|
|
|
|
z_offset = 0; |
|
|
z_offset = 0; |
|
|
ZERO(z_values); |
|
|
ZERO(z_values); |
|
|
} |
|
|
} |
|
@ -58,12 +55,12 @@ |
|
|
* Prepare a mesh-leveled linear move in a Cartesian setup, |
|
|
* Prepare a mesh-leveled linear move in a Cartesian setup, |
|
|
* splitting the move where it crosses mesh borders. |
|
|
* splitting the move where it crosses mesh borders. |
|
|
*/ |
|
|
*/ |
|
|
void mesh_line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) { |
|
|
void mesh_bed_leveling::line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) { |
|
|
// Get current and destination cells for this line
|
|
|
// Get current and destination cells for this line
|
|
|
int cx1 = mbl.cell_index_x(current_position[X_AXIS]), |
|
|
int cx1 = cell_index_x(current_position[X_AXIS]), |
|
|
cy1 = mbl.cell_index_y(current_position[Y_AXIS]), |
|
|
cy1 = cell_index_y(current_position[Y_AXIS]), |
|
|
cx2 = mbl.cell_index_x(destination[X_AXIS]), |
|
|
cx2 = cell_index_x(destination[X_AXIS]), |
|
|
cy2 = mbl.cell_index_y(destination[Y_AXIS]); |
|
|
cy2 = cell_index_y(destination[Y_AXIS]); |
|
|
NOMORE(cx1, GRID_MAX_POINTS_X - 2); |
|
|
NOMORE(cx1, GRID_MAX_POINTS_X - 2); |
|
|
NOMORE(cy1, GRID_MAX_POINTS_Y - 2); |
|
|
NOMORE(cy1, GRID_MAX_POINTS_Y - 2); |
|
|
NOMORE(cx2, GRID_MAX_POINTS_X - 2); |
|
|
NOMORE(cx2, GRID_MAX_POINTS_X - 2); |
|
@ -71,7 +68,7 @@ |
|
|
|
|
|
|
|
|
// Start and end in the same cell? No split needed.
|
|
|
// Start and end in the same cell? No split needed.
|
|
|
if (cx1 == cx2 && cy1 == cy2) { |
|
|
if (cx1 == cx2 && cy1 == cy2) { |
|
|
buffer_line_to_destination(fr_mm_s); |
|
|
line_to_destination(fr_mm_s); |
|
|
set_current_from_destination(); |
|
|
set_current_from_destination(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -87,7 +84,7 @@ |
|
|
// Split on the X grid line
|
|
|
// Split on the X grid line
|
|
|
CBI(x_splits, gcx); |
|
|
CBI(x_splits, gcx); |
|
|
COPY(end, destination); |
|
|
COPY(end, destination); |
|
|
destination[X_AXIS] = mbl.index_to_xpos[gcx]; |
|
|
destination[X_AXIS] = index_to_xpos[gcx]; |
|
|
normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]); |
|
|
normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]); |
|
|
destination[Y_AXIS] = MBL_SEGMENT_END(Y); |
|
|
destination[Y_AXIS] = MBL_SEGMENT_END(Y); |
|
|
} |
|
|
} |
|
@ -96,14 +93,14 @@ |
|
|
// Split on the Y grid line
|
|
|
// Split on the Y grid line
|
|
|
CBI(y_splits, gcy); |
|
|
CBI(y_splits, gcy); |
|
|
COPY(end, destination); |
|
|
COPY(end, destination); |
|
|
destination[Y_AXIS] = mbl.index_to_ypos[gcy]; |
|
|
destination[Y_AXIS] = index_to_ypos[gcy]; |
|
|
normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]); |
|
|
normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]); |
|
|
destination[X_AXIS] = MBL_SEGMENT_END(X); |
|
|
destination[X_AXIS] = MBL_SEGMENT_END(X); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// Must already have been split on these border(s)
|
|
|
// Must already have been split on these border(s)
|
|
|
// This should be a rare case.
|
|
|
// This should be a rare case.
|
|
|
buffer_line_to_destination(fr_mm_s); |
|
|
line_to_destination(fr_mm_s); |
|
|
set_current_from_destination(); |
|
|
set_current_from_destination(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -112,21 +109,21 @@ |
|
|
destination[E_AXIS] = MBL_SEGMENT_END(E); |
|
|
destination[E_AXIS] = MBL_SEGMENT_END(E); |
|
|
|
|
|
|
|
|
// Do the split and look for more borders
|
|
|
// Do the split and look for more borders
|
|
|
mesh_line_to_destination(fr_mm_s, x_splits, y_splits); |
|
|
line_to_destination(fr_mm_s, x_splits, y_splits); |
|
|
|
|
|
|
|
|
// Restore destination from stack
|
|
|
// Restore destination from stack
|
|
|
COPY(destination, end); |
|
|
COPY(destination, end); |
|
|
mesh_line_to_destination(fr_mm_s, x_splits, y_splits); |
|
|
line_to_destination(fr_mm_s, x_splits, y_splits); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES
|
|
|
#endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES
|
|
|
|
|
|
|
|
|
void mbl_mesh_report() { |
|
|
void mesh_bed_leveling::report_mesh() { |
|
|
SERIAL_PROTOCOLLNPGM("Num X,Y: " STRINGIFY(GRID_MAX_POINTS_X) "," STRINGIFY(GRID_MAX_POINTS_Y)); |
|
|
SERIAL_PROTOCOLLNPGM("Num X,Y: " STRINGIFY(GRID_MAX_POINTS_X) "," STRINGIFY(GRID_MAX_POINTS_Y)); |
|
|
SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(mbl.z_offset, 5); |
|
|
SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(z_offset, 5); |
|
|
SERIAL_PROTOCOLLNPGM("\nMeasured points:"); |
|
|
SERIAL_PROTOCOLLNPGM("\nMeasured points:"); |
|
|
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, |
|
|
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, |
|
|
[](const uint8_t ix, const uint8_t iy) { return mbl.z_values[ix][iy]; } |
|
|
[](const uint8_t ix, const uint8_t iy) { return z_values[ix][iy]; } |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|