Fix linear/3-point manual leveling buffer overrun

Fixes #10137
This commit is contained in:
Scott Lahteine 2018-03-24 15:13:39 -04:00
parent 8f461568e0
commit 3edf9904f4

View File

@ -4480,7 +4480,7 @@ void home_all_axes() { gcode_G28(true); }
ABL_VAR bool dryrun, abl_should_enable; ABL_VAR bool dryrun, abl_should_enable;
#if ENABLED(PROBE_MANUALLY) || ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(PROBE_MANUALLY) || ENABLED(AUTO_BED_LEVELING_LINEAR)
ABL_VAR int abl_probe_index; ABL_VAR int16_t abl_probe_index;
#endif #endif
#if HAS_SOFTWARE_ENDSTOPS && ENABLED(PROBE_MANUALLY) #if HAS_SOFTWARE_ENDSTOPS && ENABLED(PROBE_MANUALLY)
@ -4507,9 +4507,9 @@ void home_all_axes() { gcode_G28(true); }
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(AUTO_BED_LEVELING_LINEAR)
ABL_VAR int abl2; ABL_VAR int16_t abl_points;
#elif ENABLED(PROBE_MANUALLY) // Bilinear #elif ENABLED(PROBE_MANUALLY) // Bilinear
int constexpr abl2 = GRID_MAX_POINTS; int16_t constexpr abl_points = GRID_MAX_POINTS;
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@ -4528,7 +4528,7 @@ void home_all_axes() { gcode_G28(true); }
#elif ENABLED(AUTO_BED_LEVELING_3POINT) #elif ENABLED(AUTO_BED_LEVELING_3POINT)
#if ENABLED(PROBE_MANUALLY) #if ENABLED(PROBE_MANUALLY)
int constexpr abl2 = 3; // used to show total points int8_t constexpr abl_points = 3; // used to show total points
#endif #endif
// Probe at 3 arbitrary points // Probe at 3 arbitrary points
@ -4640,7 +4640,7 @@ void home_all_axes() { gcode_G28(true); }
return; return;
} }
abl2 = abl_grid_points_x * abl_grid_points_y; abl_points = abl_grid_points_x * abl_grid_points_y;
mean = 0; mean = 0;
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR) #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
@ -4756,8 +4756,8 @@ void home_all_axes() { gcode_G28(true); }
if (verbose_level || seenQ) { if (verbose_level || seenQ) {
SERIAL_PROTOCOLPGM("Manual G29 "); SERIAL_PROTOCOLPGM("Manual G29 ");
if (g29_in_progress) { if (g29_in_progress) {
SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl2)); SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl_points));
SERIAL_PROTOCOLLNPAIR(" of ", abl2); SERIAL_PROTOCOLLNPAIR(" of ", abl_points);
} }
else else
SERIAL_PROTOCOLLNPGM("idle"); SERIAL_PROTOCOLLNPGM("idle");
@ -4772,6 +4772,11 @@ void home_all_axes() { gcode_G28(true); }
#endif #endif
} }
else { else {
#if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT)
const uint16_t index = abl_probe_index - 1;
#endif
// For G29 after adjusting Z. // For G29 after adjusting Z.
// Save the previous Z before going to the next point // Save the previous Z before going to the next point
measured_z = current_position[Z_AXIS]; measured_z = current_position[Z_AXIS];
@ -4779,13 +4784,17 @@ void home_all_axes() { gcode_G28(true); }
#if ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(AUTO_BED_LEVELING_LINEAR)
mean += measured_z; mean += measured_z;
eqnBVector[abl_probe_index] = measured_z; eqnBVector[index] = measured_z;
eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe; eqnAMatrix[index + 0 * abl_points] = xProbe;
eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe; eqnAMatrix[index + 1 * abl_points] = yProbe;
eqnAMatrix[abl_probe_index + 2 * abl2] = 1; eqnAMatrix[index + 2 * abl_points] = 1;
incremental_LSF(&lsf_results, xProbe, yProbe, measured_z); incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
points[index].z = measured_z;
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR) #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
z_values[xCount][yCount] = measured_z + zoffset; z_values[xCount][yCount] = measured_z + zoffset;
@ -4798,10 +4807,6 @@ void home_all_axes() { gcode_G28(true); }
} }
#endif #endif
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
points[abl_probe_index].z = measured_z;
#endif #endif
} }
@ -4812,7 +4817,7 @@ void home_all_axes() { gcode_G28(true); }
#if ABL_GRID #if ABL_GRID
// Skip any unreachable points // Skip any unreachable points
while (abl_probe_index < abl2) { while (abl_probe_index < abl_points) {
// Set xCount, yCount based on abl_probe_index, with zig-zag // Set xCount, yCount based on abl_probe_index, with zig-zag
PR_OUTER_VAR = abl_probe_index / PR_INNER_END; PR_OUTER_VAR = abl_probe_index / PR_INNER_END;
@ -4839,7 +4844,7 @@ void home_all_axes() { gcode_G28(true); }
} }
// Is there a next point to move to? // Is there a next point to move to?
if (abl_probe_index < abl2) { if (abl_probe_index < abl_points) {
_manual_goto_xy(xProbe, yProbe); // Can be used here too! _manual_goto_xy(xProbe, yProbe); // Can be used here too!
#if HAS_SOFTWARE_ENDSTOPS #if HAS_SOFTWARE_ENDSTOPS
// Disable software endstops to allow manual adjustment // Disable software endstops to allow manual adjustment
@ -4863,7 +4868,7 @@ void home_all_axes() { gcode_G28(true); }
#elif ENABLED(AUTO_BED_LEVELING_3POINT) #elif ENABLED(AUTO_BED_LEVELING_3POINT)
// Probe at 3 arbitrary points // Probe at 3 arbitrary points
if (abl_probe_index < abl2) { if (abl_probe_index < abl_points) {
xProbe = points[abl_probe_index].x; xProbe = points[abl_probe_index].x;
yProbe = points[abl_probe_index].y; yProbe = points[abl_probe_index].y;
_manual_goto_xy(xProbe, yProbe); _manual_goto_xy(xProbe, yProbe);
@ -4959,9 +4964,9 @@ void home_all_axes() { gcode_G28(true); }
mean += measured_z; mean += measured_z;
eqnBVector[abl_probe_index] = measured_z; eqnBVector[abl_probe_index] = measured_z;
eqnAMatrix[abl_probe_index + 0 * abl2] = xProbe; eqnAMatrix[abl_probe_index + 0 * abl_points] = xProbe;
eqnAMatrix[abl_probe_index + 1 * abl2] = yProbe; eqnAMatrix[abl_probe_index + 1 * abl_points] = yProbe;
eqnAMatrix[abl_probe_index + 2 * abl2] = 1; eqnAMatrix[abl_probe_index + 2 * abl_points] = 1;
incremental_LSF(&lsf_results, xProbe, yProbe, measured_z); incremental_LSF(&lsf_results, xProbe, yProbe, measured_z);
@ -5069,7 +5074,7 @@ void home_all_axes() { gcode_G28(true); }
plane_equation_coefficients[1] = -lsf_results.B; // but that is not yet tested. plane_equation_coefficients[1] = -lsf_results.B; // but that is not yet tested.
plane_equation_coefficients[2] = -lsf_results.D; plane_equation_coefficients[2] = -lsf_results.D;
mean /= abl2; mean /= abl_points;
if (verbose_level) { if (verbose_level) {
SERIAL_PROTOCOLPGM("Eqn coefficients: a: "); SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
@ -5113,8 +5118,8 @@ void home_all_axes() { gcode_G28(true); }
for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) { for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
int ind = indexIntoAB[xx][yy]; int ind = indexIntoAB[xx][yy];
float diff = eqnBVector[ind] - mean, float diff = eqnBVector[ind] - mean,
x_tmp = eqnAMatrix[ind + 0 * abl2], x_tmp = eqnAMatrix[ind + 0 * abl_points],
y_tmp = eqnAMatrix[ind + 1 * abl2], y_tmp = eqnAMatrix[ind + 1 * abl_points],
z_tmp = 0; z_tmp = 0;
apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp); apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
@ -5137,8 +5142,8 @@ void home_all_axes() { gcode_G28(true); }
for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) { for (int8_t yy = abl_grid_points_y - 1; yy >= 0; yy--) {
for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) { for (uint8_t xx = 0; xx < abl_grid_points_x; xx++) {
int ind = indexIntoAB[xx][yy]; int ind = indexIntoAB[xx][yy];
float x_tmp = eqnAMatrix[ind + 0 * abl2], float x_tmp = eqnAMatrix[ind + 0 * abl_points],
y_tmp = eqnAMatrix[ind + 1 * abl2], y_tmp = eqnAMatrix[ind + 1 * abl_points],
z_tmp = 0; z_tmp = 0;
apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp); apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);