Add custom types for position (#15204)
This commit is contained in:
@ -61,15 +61,15 @@
|
||||
|
||||
#if ABL_GRID
|
||||
#if ENABLED(PROBE_Y_FIRST)
|
||||
#define PR_OUTER_VAR xCount
|
||||
#define PR_OUTER_END abl_grid_points_x
|
||||
#define PR_INNER_VAR yCount
|
||||
#define PR_INNER_END abl_grid_points_y
|
||||
#define PR_OUTER_VAR meshCount.x
|
||||
#define PR_OUTER_END abl_grid_points.x
|
||||
#define PR_INNER_VAR meshCount.y
|
||||
#define PR_INNER_END abl_grid_points.y
|
||||
#else
|
||||
#define PR_OUTER_VAR yCount
|
||||
#define PR_OUTER_END abl_grid_points_y
|
||||
#define PR_INNER_VAR xCount
|
||||
#define PR_INNER_END abl_grid_points_x
|
||||
#define PR_OUTER_VAR meshCount.y
|
||||
#define PR_OUTER_END abl_grid_points.y
|
||||
#define PR_INNER_VAR meshCount.x
|
||||
#define PR_INNER_END abl_grid_points.x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -210,7 +210,8 @@ G29_TYPE GcodeSuite::G29() {
|
||||
#endif
|
||||
|
||||
ABL_VAR int verbose_level;
|
||||
ABL_VAR float xProbe, yProbe, measured_z;
|
||||
ABL_VAR xy_pos_t probePos;
|
||||
ABL_VAR float measured_z;
|
||||
ABL_VAR bool dryrun, abl_should_enable;
|
||||
|
||||
#if EITHER(PROBE_MANUALLY, AUTO_BED_LEVELING_LINEAR)
|
||||
@ -224,20 +225,17 @@ G29_TYPE GcodeSuite::G29() {
|
||||
#if ABL_GRID
|
||||
|
||||
#if ENABLED(PROBE_MANUALLY)
|
||||
ABL_VAR uint8_t PR_OUTER_VAR;
|
||||
ABL_VAR int8_t PR_INNER_VAR;
|
||||
ABL_VAR xy_int8_t meshCount;
|
||||
#endif
|
||||
|
||||
ABL_VAR int left_probe_bed_position, right_probe_bed_position, front_probe_bed_position, back_probe_bed_position;
|
||||
ABL_VAR float xGridSpacing = 0, yGridSpacing = 0;
|
||||
ABL_VAR xy_int_t probe_position_lf, probe_position_rb;
|
||||
ABL_VAR xy_float_t gridSpacing = { 0, 0 };
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
ABL_VAR uint8_t abl_grid_points_x = GRID_MAX_POINTS_X,
|
||||
abl_grid_points_y = GRID_MAX_POINTS_Y;
|
||||
ABL_VAR bool do_topography_map;
|
||||
ABL_VAR xy_uint8_t abl_grid_points;
|
||||
#else // Bilinear
|
||||
uint8_t constexpr abl_grid_points_x = GRID_MAX_POINTS_X,
|
||||
abl_grid_points_y = GRID_MAX_POINTS_Y;
|
||||
constexpr xy_uint8_t abl_grid_points = { GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y };
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
@ -269,15 +267,15 @@ G29_TYPE GcodeSuite::G29() {
|
||||
const float x_min = probe_min_x(), x_max = probe_max_x(), y_min = probe_min_y(), y_max = probe_max_y();
|
||||
|
||||
ABL_VAR vector_3 points[3] = {
|
||||
#if ENABLED(HAS_FIXED_3POINT)
|
||||
vector_3(PROBE_PT_1_X, PROBE_PT_1_Y, 0),
|
||||
vector_3(PROBE_PT_2_X, PROBE_PT_2_Y, 0),
|
||||
vector_3(PROBE_PT_3_X, PROBE_PT_3_Y, 0)
|
||||
#else
|
||||
vector_3(x_min, y_min, 0),
|
||||
vector_3(x_max, y_min, 0),
|
||||
vector_3((x_max - x_min) / 2, y_max, 0)
|
||||
#endif
|
||||
#if ENABLED(HAS_FIXED_3POINT)
|
||||
{ PROBE_PT_1_X, PROBE_PT_1_Y, 0 },
|
||||
{ PROBE_PT_2_X, PROBE_PT_2_Y, 0 },
|
||||
{ PROBE_PT_3_X, PROBE_PT_3_Y, 0 }
|
||||
#else
|
||||
{ x_min, y_min, 0 },
|
||||
{ x_max, y_min, 0 },
|
||||
{ (x_max - x_min) / 2, y_max, 0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // AUTO_BED_LEVELING_3POINT
|
||||
@ -311,7 +309,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
G29_RETURN(false);
|
||||
}
|
||||
|
||||
const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position[Z_AXIS];
|
||||
const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position.z;
|
||||
if (!WITHIN(rz, -10, 10)) {
|
||||
SERIAL_ERROR_MSG("Bad Z value");
|
||||
G29_RETURN(false);
|
||||
@ -323,8 +321,8 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
if (!isnan(rx) && !isnan(ry)) {
|
||||
// Get nearest i / j from rx / ry
|
||||
i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
|
||||
j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing;
|
||||
i = (rx - bilinear_start.x + 0.5 * gridSpacing.x) / gridSpacing.x;
|
||||
j = (ry - bilinear_start.y + 0.5 * gridSpacing.y) / gridSpacing.y;
|
||||
LIMIT(i, 0, GRID_MAX_POINTS_X - 1);
|
||||
LIMIT(j, 0, GRID_MAX_POINTS_Y - 1);
|
||||
}
|
||||
@ -373,20 +371,22 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
// X and Y specify points in each direction, overriding the default
|
||||
// These values may be saved with the completed mesh
|
||||
abl_grid_points_x = parser.intval('X', GRID_MAX_POINTS_X);
|
||||
abl_grid_points_y = parser.intval('Y', GRID_MAX_POINTS_Y);
|
||||
if (parser.seenval('P')) abl_grid_points_x = abl_grid_points_y = parser.value_int();
|
||||
abl_grid_points.set(
|
||||
parser.byteval('X', GRID_MAX_POINTS_X),
|
||||
parser.byteval('Y', GRID_MAX_POINTS_Y)
|
||||
);
|
||||
if (parser.seenval('P')) abl_grid_points.x = abl_grid_points.y = parser.value_int();
|
||||
|
||||
if (!WITHIN(abl_grid_points_x, 2, GRID_MAX_POINTS_X)) {
|
||||
if (!WITHIN(abl_grid_points.x, 2, GRID_MAX_POINTS_X)) {
|
||||
SERIAL_ECHOLNPGM("?Probe points (X) implausible (2-" STRINGIFY(GRID_MAX_POINTS_X) ").");
|
||||
G29_RETURN(false);
|
||||
}
|
||||
if (!WITHIN(abl_grid_points_y, 2, GRID_MAX_POINTS_Y)) {
|
||||
if (!WITHIN(abl_grid_points.y, 2, GRID_MAX_POINTS_Y)) {
|
||||
SERIAL_ECHOLNPGM("?Probe points (Y) implausible (2-" STRINGIFY(GRID_MAX_POINTS_Y) ").");
|
||||
G29_RETURN(false);
|
||||
}
|
||||
|
||||
abl_points = abl_grid_points_x * abl_grid_points_y;
|
||||
abl_points = abl_grid_points.x * abl_grid_points.y;
|
||||
mean = 0;
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
@ -404,27 +404,35 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
if (parser.seen('H')) {
|
||||
const int16_t size = (int16_t)parser.value_linear_units();
|
||||
left_probe_bed_position = _MAX(X_CENTER - size / 2, x_min);
|
||||
right_probe_bed_position = _MIN(left_probe_bed_position + size, x_max);
|
||||
front_probe_bed_position = _MAX(Y_CENTER - size / 2, y_min);
|
||||
back_probe_bed_position = _MIN(front_probe_bed_position + size, y_max);
|
||||
probe_position_lf.set(
|
||||
_MAX(X_CENTER - size / 2, x_min),
|
||||
_MAX(Y_CENTER - size / 2, y_min)
|
||||
);
|
||||
probe_position_rb.set(
|
||||
_MIN(probe_position_lf.x + size, x_max),
|
||||
_MIN(probe_position_lf.y + size, y_max)
|
||||
);
|
||||
}
|
||||
else {
|
||||
left_probe_bed_position = parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MAX(X_CENTER - X_BED_SIZE / 2, x_min);
|
||||
right_probe_bed_position = parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MIN(left_probe_bed_position + X_BED_SIZE, x_max);
|
||||
front_probe_bed_position = parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MAX(Y_CENTER - Y_BED_SIZE / 2, y_min);
|
||||
back_probe_bed_position = parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MIN(front_probe_bed_position + Y_BED_SIZE, y_max);
|
||||
probe_position_lf.set(
|
||||
parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MAX(X_CENTER - (X_BED_SIZE) / 2, x_min),
|
||||
parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MAX(Y_CENTER - (Y_BED_SIZE) / 2, y_min)
|
||||
);
|
||||
probe_position_rb.set(
|
||||
parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MIN(probe_position_lf.x + X_BED_SIZE, x_max),
|
||||
parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MIN(probe_position_lf.y + Y_BED_SIZE, y_max)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
#if IS_SCARA || ENABLED(DELTA)
|
||||
!position_is_reachable_by_probe(left_probe_bed_position, 0)
|
||||
|| !position_is_reachable_by_probe(right_probe_bed_position, 0)
|
||||
|| !position_is_reachable_by_probe(0, front_probe_bed_position)
|
||||
|| !position_is_reachable_by_probe(0, back_probe_bed_position)
|
||||
!position_is_reachable_by_probe(probe_position_lf.x, 0)
|
||||
|| !position_is_reachable_by_probe(probe_position_rb.x, 0)
|
||||
|| !position_is_reachable_by_probe(0, probe_position_lf.y)
|
||||
|| !position_is_reachable_by_probe(0, probe_position_rb.y)
|
||||
#else
|
||||
!position_is_reachable_by_probe(left_probe_bed_position, front_probe_bed_position)
|
||||
|| !position_is_reachable_by_probe(right_probe_bed_position, back_probe_bed_position)
|
||||
!position_is_reachable_by_probe(probe_position_lf)
|
||||
|| !position_is_reachable_by_probe(probe_position_rb)
|
||||
#endif
|
||||
) {
|
||||
SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
|
||||
@ -432,8 +440,8 @@ G29_TYPE GcodeSuite::G29() {
|
||||
}
|
||||
|
||||
// probe at the points of a lattice grid
|
||||
xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (abl_grid_points_x - 1);
|
||||
yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (abl_grid_points_y - 1);
|
||||
gridSpacing.set((probe_position_rb.x - probe_position_lf.x) / (abl_grid_points.x - 1),
|
||||
(probe_position_rb.y - probe_position_lf.y) / (abl_grid_points.y - 1));
|
||||
|
||||
#endif // ABL_GRID
|
||||
|
||||
@ -464,19 +472,13 @@ G29_TYPE GcodeSuite::G29() {
|
||||
#if ENABLED(PROBE_MANUALLY)
|
||||
if (!no_action)
|
||||
#endif
|
||||
if ( xGridSpacing != bilinear_grid_spacing[X_AXIS]
|
||||
|| yGridSpacing != bilinear_grid_spacing[Y_AXIS]
|
||||
|| left_probe_bed_position != bilinear_start[X_AXIS]
|
||||
|| front_probe_bed_position != bilinear_start[Y_AXIS]
|
||||
) {
|
||||
if (gridSpacing != bilinear_grid_spacing || probe_position_lf != bilinear_start) {
|
||||
// Reset grid to 0.0 or "not probed". (Also disables ABL)
|
||||
reset_bed_level();
|
||||
|
||||
// Initialize a grid with the given dimensions
|
||||
bilinear_grid_spacing[X_AXIS] = xGridSpacing;
|
||||
bilinear_grid_spacing[Y_AXIS] = yGridSpacing;
|
||||
bilinear_start[X_AXIS] = left_probe_bed_position;
|
||||
bilinear_start[Y_AXIS] = front_probe_bed_position;
|
||||
bilinear_grid_spacing = gridSpacing.asInt();
|
||||
bilinear_start = probe_position_lf;
|
||||
|
||||
// Can't re-enable (on error) until the new grid is written
|
||||
abl_should_enable = false;
|
||||
@ -546,17 +548,17 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
// For G29 after adjusting Z.
|
||||
// Save the previous Z before going to the next point
|
||||
measured_z = current_position[Z_AXIS];
|
||||
measured_z = current_position.z;
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
|
||||
mean += measured_z;
|
||||
eqnBVector[index] = measured_z;
|
||||
eqnAMatrix[index + 0 * abl_points] = xProbe;
|
||||
eqnAMatrix[index + 1 * abl_points] = yProbe;
|
||||
eqnAMatrix[index + 0 * abl_points] = probePos.x;
|
||||
eqnAMatrix[index + 1 * abl_points] = probePos.y;
|
||||
eqnAMatrix[index + 2 * abl_points] = 1;
|
||||
|
||||
incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
|
||||
incremental_LSF(&lsf_results, probePos, measured_z);
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
|
||||
|
||||
@ -564,12 +566,13 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
|
||||
z_values[xCount][yCount] = measured_z + zoffset;
|
||||
const float newz = measured_z + zoffset;
|
||||
z_values[meshCount.x][meshCount.y] = newz;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(xCount, yCount, z_values[xCount][yCount]);
|
||||
ExtUI::onMeshUpdate(meshCount, newz);
|
||||
#endif
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Save X", xCount, " Y", yCount, " Z", measured_z + zoffset);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Save X", meshCount.x, " Y", meshCount.y, " Z", measured_z + zoffset);
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -583,7 +586,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
// Skip any unreachable points
|
||||
while (abl_probe_index < abl_points) {
|
||||
|
||||
// Set xCount, yCount based on abl_probe_index, with zig-zag
|
||||
// Set meshCount.x, meshCount.y based on abl_probe_index, with zig-zag
|
||||
PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
|
||||
PR_INNER_VAR = abl_probe_index - (PR_OUTER_VAR * PR_INNER_END);
|
||||
|
||||
@ -592,24 +595,23 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
if (zig) PR_INNER_VAR = (PR_INNER_END - 1) - PR_INNER_VAR;
|
||||
|
||||
const float xBase = xCount * xGridSpacing + left_probe_bed_position,
|
||||
yBase = yCount * yGridSpacing + front_probe_bed_position;
|
||||
const xy_pos_t base = probe_position_lf.asFloat() + gridSpacing * meshCount.asFloat();
|
||||
|
||||
xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
|
||||
yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
|
||||
probePos.set(FLOOR(base.x + (base.x < 0 ? 0 : 0.5)),
|
||||
FLOOR(base.y + (base.y < 0 ? 0 : 0.5)));
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
indexIntoAB[xCount][yCount] = abl_probe_index;
|
||||
indexIntoAB[meshCount.x][meshCount.y] = abl_probe_index;
|
||||
#endif
|
||||
|
||||
// Keep looping till a reachable point is found
|
||||
if (position_is_reachable(xProbe, yProbe)) break;
|
||||
if (position_is_reachable(probePos)) break;
|
||||
++abl_probe_index;
|
||||
}
|
||||
|
||||
// Is there a next point to move to?
|
||||
if (abl_probe_index < abl_points) {
|
||||
_manual_goto_xy(xProbe, yProbe); // Can be used here too!
|
||||
_manual_goto_xy(probePos); // Can be used here too!
|
||||
#if HAS_SOFTWARE_ENDSTOPS
|
||||
// Disable software endstops to allow manual adjustment
|
||||
// If G29 is not completed, they will not be re-enabled
|
||||
@ -633,9 +635,8 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
// Probe at 3 arbitrary points
|
||||
if (abl_probe_index < abl_points) {
|
||||
xProbe = points[abl_probe_index].x;
|
||||
yProbe = points[abl_probe_index].y;
|
||||
_manual_goto_xy(xProbe, yProbe);
|
||||
probePos = points[abl_probe_index];
|
||||
_manual_goto_xy(probePos);
|
||||
#if HAS_SOFTWARE_ENDSTOPS
|
||||
// Disable software endstops to allow manual adjustment
|
||||
// If G29 is not completed, they will not be re-enabled
|
||||
@ -654,11 +655,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
if (!dryrun) {
|
||||
vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
|
||||
if (planeNormal.z < 0) {
|
||||
planeNormal.x *= -1;
|
||||
planeNormal.y *= -1;
|
||||
planeNormal.z *= -1;
|
||||
}
|
||||
if (planeNormal.z < 0) planeNormal *= -1;
|
||||
planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
|
||||
|
||||
// Can't re-enable (on error) until the new grid is written
|
||||
@ -681,8 +678,11 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
measured_z = 0;
|
||||
|
||||
xy_int8_t meshCount;
|
||||
|
||||
// Outer loop is X with PROBE_Y_FIRST enabled
|
||||
// Outer loop is Y with PROBE_Y_FIRST disabled
|
||||
for (uint8_t PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_END && !isnan(measured_z); PR_OUTER_VAR++) {
|
||||
for (PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_END && !isnan(measured_z); PR_OUTER_VAR++) {
|
||||
|
||||
int8_t inStart, inStop, inInc;
|
||||
|
||||
@ -703,21 +703,21 @@ G29_TYPE GcodeSuite::G29() {
|
||||
uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_END) + 1;
|
||||
|
||||
// Inner loop is Y with PROBE_Y_FIRST enabled
|
||||
for (int8_t PR_INNER_VAR = inStart; PR_INNER_VAR != inStop; pt_index++, PR_INNER_VAR += inInc) {
|
||||
// Inner loop is X with PROBE_Y_FIRST disabled
|
||||
for (PR_INNER_VAR = inStart; PR_INNER_VAR != inStop; pt_index++, PR_INNER_VAR += inInc) {
|
||||
|
||||
const float xBase = left_probe_bed_position + xGridSpacing * xCount,
|
||||
yBase = front_probe_bed_position + yGridSpacing * yCount;
|
||||
const xy_pos_t base = probe_position_lf.asFloat() + gridSpacing * meshCount.asFloat();
|
||||
|
||||
xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
|
||||
yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
|
||||
probePos.set(FLOOR(base.x + (base.x < 0 ? 0 : 0.5)),
|
||||
FLOOR(base.y + (base.y < 0 ? 0 : 0.5)));
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
||||
indexIntoAB[xCount][yCount] = ++abl_probe_index; // 0...
|
||||
indexIntoAB[meshCount.x][meshCount.y] = ++abl_probe_index; // 0...
|
||||
#endif
|
||||
|
||||
#if IS_KINEMATIC
|
||||
// Avoid probing outside the round or hexagonal area
|
||||
if (!position_is_reachable_by_probe(xProbe, yProbe)) continue;
|
||||
if (!position_is_reachable_by_probe(probePos)) continue;
|
||||
#endif
|
||||
|
||||
if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), ".");
|
||||
@ -725,7 +725,7 @@ G29_TYPE GcodeSuite::G29() {
|
||||
ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), PSTR(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS));
|
||||
#endif
|
||||
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(xProbe, yProbe, raise_after, verbose_level);
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
|
||||
|
||||
if (isnan(measured_z)) {
|
||||
set_bed_leveling_enabled(abl_should_enable);
|
||||
@ -736,17 +736,17 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
mean += measured_z;
|
||||
eqnBVector[abl_probe_index] = measured_z;
|
||||
eqnAMatrix[abl_probe_index + 0 * abl_points] = xProbe;
|
||||
eqnAMatrix[abl_probe_index + 1 * abl_points] = yProbe;
|
||||
eqnAMatrix[abl_probe_index + 0 * abl_points] = probePos.x;
|
||||
eqnAMatrix[abl_probe_index + 1 * abl_points] = probePos.y;
|
||||
eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
|
||||
|
||||
incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
|
||||
incremental_LSF(&lsf_results, probePos, measured_z);
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
|
||||
z_values[xCount][yCount] = measured_z + zoffset;
|
||||
z_values[meshCount.x][meshCount.y] = measured_z + zoffset;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(xCount, yCount, z_values[xCount][yCount]);
|
||||
ExtUI::onMeshUpdate(meshCount.x, meshCount.y, z_values[meshCount.x][meshCount.y]);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -768,9 +768,8 @@ G29_TYPE GcodeSuite::G29() {
|
||||
#endif
|
||||
|
||||
// Retain the last probe position
|
||||
xProbe = points[i].x;
|
||||
yProbe = points[i].y;
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(xProbe, yProbe, raise_after, verbose_level);
|
||||
probePos = points[i];
|
||||
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
|
||||
if (isnan(measured_z)) {
|
||||
set_bed_leveling_enabled(abl_should_enable);
|
||||
break;
|
||||
@ -845,19 +844,19 @@ G29_TYPE GcodeSuite::G29() {
|
||||
* plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
|
||||
* so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
|
||||
*/
|
||||
float plane_equation_coefficients[3];
|
||||
struct { float a, b, d; } plane_equation_coefficients;
|
||||
|
||||
finish_incremental_LSF(&lsf_results);
|
||||
plane_equation_coefficients[0] = -lsf_results.A; // We should be able to eliminate the '-' on these three lines and down below
|
||||
plane_equation_coefficients[1] = -lsf_results.B; // but that is not yet tested.
|
||||
plane_equation_coefficients[2] = -lsf_results.D;
|
||||
plane_equation_coefficients.a = -lsf_results.A; // We should be able to eliminate the '-' on these three lines and down below
|
||||
plane_equation_coefficients.b = -lsf_results.B; // but that is not yet tested.
|
||||
plane_equation_coefficients.d = -lsf_results.D;
|
||||
|
||||
mean /= abl_points;
|
||||
|
||||
if (verbose_level) {
|
||||
SERIAL_ECHOPAIR_F("Eqn coefficients: a: ", plane_equation_coefficients[0], 8);
|
||||
SERIAL_ECHOPAIR_F(" b: ", plane_equation_coefficients[1], 8);
|
||||
SERIAL_ECHOPAIR_F(" d: ", plane_equation_coefficients[2], 8);
|
||||
SERIAL_ECHOPAIR_F("Eqn coefficients: a: ", plane_equation_coefficients.a, 8);
|
||||
SERIAL_ECHOPAIR_F(" b: ", plane_equation_coefficients.b, 8);
|
||||
SERIAL_ECHOPAIR_F(" d: ", plane_equation_coefficients.d, 8);
|
||||
if (verbose_level > 2)
|
||||
SERIAL_ECHOPAIR_F("\nMean of sampled points: ", mean, 8);
|
||||
SERIAL_EOL();
|
||||
@ -866,13 +865,34 @@ G29_TYPE GcodeSuite::G29() {
|
||||
// Create the matrix but don't correct the position yet
|
||||
if (!dryrun)
|
||||
planner.bed_level_matrix = matrix_3x3::create_look_at(
|
||||
vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1) // We can eliminate the '-' here and up above
|
||||
vector_3(-plane_equation_coefficients.a, -plane_equation_coefficients.b, 1) // We can eliminate the '-' here and up above
|
||||
);
|
||||
|
||||
// Show the Topography map if enabled
|
||||
if (do_topography_map) {
|
||||
|
||||
SERIAL_ECHOLNPGM("\nBed Height Topography:\n"
|
||||
float min_diff = 999;
|
||||
|
||||
auto print_topo_map = [&](PGM_P const title, const bool get_min) {
|
||||
serialprintPGM(title);
|
||||
for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) {
|
||||
for (uint8_t xx = 0; xx < abl_grid_points.x; xx++) {
|
||||
const int ind = indexIntoAB[xx][yy];
|
||||
xyz_float_t tmp = { eqnAMatrix[ind + 0 * abl_points],
|
||||
eqnAMatrix[ind + 1 * abl_points], 0 };
|
||||
apply_rotation_xyz(planner.bed_level_matrix, tmp);
|
||||
if (get_min) NOMORE(min_diff, eqnBVector[ind] - tmp.z);
|
||||
const float subval = get_min ? mean : tmp.z + min_diff,
|
||||
diff = eqnBVector[ind] - subval;
|
||||
SERIAL_CHAR(' '); if (diff >= 0.0) SERIAL_CHAR('+'); // Include + for column alignment
|
||||
SERIAL_ECHO_F(diff, 5);
|
||||
} // xx
|
||||
SERIAL_EOL();
|
||||
} // yy
|
||||
SERIAL_EOL();
|
||||
};
|
||||
|
||||
print_topo_map(PSTR("\nBed Height Topography:\n"
|
||||
" +--- BACK --+\n"
|
||||
" | |\n"
|
||||
" L | (+) | R\n"
|
||||
@ -882,56 +902,10 @@ G29_TYPE GcodeSuite::G29() {
|
||||
" | (-) | T\n"
|
||||
" | |\n"
|
||||
" O-- FRONT --+\n"
|
||||
" (0,0)");
|
||||
" (0,0)\n"), true);
|
||||
if (verbose_level > 3)
|
||||
print_topo_map(PSTR("\nCorrected Bed Height vs. Bed Topology:\n"), false);
|
||||
|
||||
float min_diff = 999;
|
||||
|
||||
for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
|
||||
for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
|
||||
int ind = indexIntoAB[xx][yy];
|
||||
float diff = eqnBVector[ind] - mean,
|
||||
x_tmp = eqnAMatrix[ind + 0 * abl_points],
|
||||
y_tmp = eqnAMatrix[ind + 1 * abl_points],
|
||||
z_tmp = 0;
|
||||
|
||||
apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
|
||||
|
||||
NOMORE(min_diff, eqnBVector[ind] - z_tmp);
|
||||
|
||||
if (diff >= 0.0)
|
||||
SERIAL_ECHOPGM(" +"); // Include + for column alignment
|
||||
else
|
||||
SERIAL_CHAR(' ');
|
||||
SERIAL_ECHO_F(diff, 5);
|
||||
} // xx
|
||||
SERIAL_EOL();
|
||||
} // yy
|
||||
SERIAL_EOL();
|
||||
|
||||
if (verbose_level > 3) {
|
||||
SERIAL_ECHOLNPGM("\nCorrected Bed Height vs. Bed Topology:");
|
||||
|
||||
for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
|
||||
for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
|
||||
int ind = indexIntoAB[xx][yy];
|
||||
float x_tmp = eqnAMatrix[ind + 0 * abl_points],
|
||||
y_tmp = eqnAMatrix[ind + 1 * abl_points],
|
||||
z_tmp = 0;
|
||||
|
||||
apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
|
||||
|
||||
float diff = eqnBVector[ind] - z_tmp - min_diff;
|
||||
if (diff >= 0.0)
|
||||
SERIAL_ECHOPGM(" +");
|
||||
// Include + for column alignment
|
||||
else
|
||||
SERIAL_CHAR(' ');
|
||||
SERIAL_ECHO_F(diff, 5);
|
||||
} // xx
|
||||
SERIAL_EOL();
|
||||
} // yy
|
||||
SERIAL_EOL();
|
||||
}
|
||||
} //do_topography_map
|
||||
|
||||
#endif // AUTO_BED_LEVELING_LINEAR
|
||||
@ -950,24 +924,20 @@ G29_TYPE GcodeSuite::G29() {
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("G29 uncorrected XYZ", current_position);
|
||||
|
||||
float converted[XYZ];
|
||||
COPY(converted, current_position);
|
||||
|
||||
planner.leveling_active = true;
|
||||
planner.unapply_leveling(converted); // use conversion machinery
|
||||
planner.leveling_active = false;
|
||||
xyze_pos_t converted = current_position;
|
||||
planner.force_unapply_leveling(converted); // use conversion machinery
|
||||
|
||||
// Use the last measured distance to the bed, if possible
|
||||
if ( NEAR(current_position[X_AXIS], xProbe - probe_offset[X_AXIS])
|
||||
&& NEAR(current_position[Y_AXIS], yProbe - probe_offset[Y_AXIS])
|
||||
if ( NEAR(current_position.x, probePos.x - probe_offset.x)
|
||||
&& NEAR(current_position.y, probePos.y - probe_offset.y)
|
||||
) {
|
||||
const float simple_z = current_position[Z_AXIS] - measured_z;
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted[Z_AXIS], " Discrepancy ", simple_z - converted[Z_AXIS]);
|
||||
converted[Z_AXIS] = simple_z;
|
||||
const float simple_z = current_position.z - measured_z;
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted.z, " Discrepancy ", simple_z - converted.z);
|
||||
converted.z = simple_z;
|
||||
}
|
||||
|
||||
// The rotated XY and corrected Z are now current_position
|
||||
COPY(current_position, converted);
|
||||
current_position = converted;
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position);
|
||||
}
|
||||
@ -975,13 +945,13 @@ G29_TYPE GcodeSuite::G29() {
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
|
||||
if (!dryrun) {
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("G29 uncorrected Z:", current_position[Z_AXIS]);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("G29 uncorrected Z:", current_position.z);
|
||||
|
||||
// Unapply the offset because it is going to be immediately applied
|
||||
// and cause compensation movement in Z
|
||||
current_position[Z_AXIS] -= bilinear_z_offset(current_position);
|
||||
current_position.z -= bilinear_z_offset(current_position);
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(" corrected Z:", current_position[Z_AXIS]);
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(" corrected Z:", current_position.z);
|
||||
}
|
||||
|
||||
#endif // ABL_PLANAR
|
||||
|
Reference in New Issue
Block a user