Unify debugging output with debug_out.h (#13388)

This commit is contained in:
Scott Lahteine
2019-03-14 02:25:42 -05:00
committed by GitHub
parent cc8a871705
commit f5bcc00570
25 changed files with 627 additions and 904 deletions

View File

@ -29,6 +29,9 @@
#include "../../../module/motion.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
int bilinear_grid_spacing[2], bilinear_start[2];
float bilinear_grid_factor[2],
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
@ -37,26 +40,21 @@ float bilinear_grid_factor[2],
* Extrapolate a single point from its neighbors
*/
static void extrapolate_one_point(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPGM("Extrapolate [");
if (x < 10) SERIAL_CHAR(' ');
SERIAL_ECHO((int)x);
SERIAL_CHAR(xdir ? (xdir > 0 ? '+' : '-') : ' ');
SERIAL_CHAR(' ');
if (y < 10) SERIAL_CHAR(' ');
SERIAL_ECHO((int)y);
SERIAL_CHAR(ydir ? (ydir > 0 ? '+' : '-') : ' ');
SERIAL_CHAR(']');
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPGM("Extrapolate [");
if (x < 10) DEBUG_CHAR(' ');
DEBUG_ECHO((int)x);
DEBUG_CHAR(xdir ? (xdir > 0 ? '+' : '-') : ' ');
DEBUG_CHAR(' ');
if (y < 10) DEBUG_CHAR(' ');
DEBUG_ECHO((int)y);
DEBUG_CHAR(ydir ? (ydir > 0 ? '+' : '-') : ' ');
DEBUG_ECHOLNPGM("]");
}
if (!isnan(z_values[x][y])) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" (done)");
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" (done)");
return; // Don't overwrite good values.
}
SERIAL_EOL();
// Get X neighbors, Y neighbors, and XY neighbors
const uint8_t x1 = x + xdir, y1 = y + ydir, x2 = x1 + xdir, y2 = y1 + ydir;

View File

@ -39,6 +39,9 @@
#include "../../lcd/ultralcd.h"
#endif
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../core/debug_out.h"
#if ENABLED(G26_MESH_VALIDATION)
bool g26_debug_flag; // = false
#endif
@ -122,9 +125,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
* Reset calibration results to zero.
*/
void reset_bed_level() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("reset_bed_level");
set_bed_leveling_enabled(false);
#if ENABLED(MESH_BED_LEVELING)
mbl.reset();

View File

@ -29,6 +29,9 @@
#include "../../../lcd/ultralcd.h"
#include "../../../Marlin.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#define UBL_VERSION "1.01"
#define UBL_OK false
#define UBL_ERR true
@ -199,12 +202,11 @@ class unified_bed_leveling {
*/
static inline float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1_i") : PSTR("yi") );
SERIAL_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")");
}
#endif
if (DEBUGGING(LEVELING)) {
if (WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("yi"); else DEBUG_ECHOPGM("x1_i");
DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")");
}
// The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN.
return (
@ -229,12 +231,11 @@ class unified_bed_leveling {
//
static inline float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
serialprintPGM(!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("y1_i"));
SERIAL_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")");
}
#endif
if (DEBUGGING(LEVELING)) {
if (WITHIN(xi, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("y1_i"); else DEBUG_ECHOPGM("xi");
DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")");
}
// The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN.
return (
@ -285,17 +286,12 @@ class unified_bed_leveling {
mesh_index_to_ypos(cy), z1,
mesh_index_to_ypos(cy + 1), z2);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR(" raw get_z_correction(", rx0);
SERIAL_CHAR(','); SERIAL_ECHO(ry0);
SERIAL_ECHOPAIR_F(") = ", z0, 6);
}
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) SERIAL_ECHOLNPAIR_F(" >>>---> ", z0, 6);
#endif
if (DEBUGGING(MESH_ADJUST)) {
DEBUG_ECHOPAIR(" raw get_z_correction(", rx0);
DEBUG_CHAR(','); DEBUG_ECHO(ry0);
DEBUG_ECHOPAIR_F(") = ", z0, 6);
DEBUG_ECHOLNPAIR_F(" >>>---> ", z0, 6);
}
if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
z0 = 0.0; // in ubl.z_values[][] and propagate through the
@ -303,15 +299,13 @@ class unified_bed_leveling {
// because part of the Mesh is undefined and we don't have the
// information we need to complete the height correction.
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0);
SERIAL_CHAR(',');
SERIAL_ECHO(ry0);
SERIAL_CHAR(')');
SERIAL_EOL();
}
#endif
if (DEBUGGING(MESH_ADJUST)) {
DEBUG_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0);
DEBUG_CHAR(',');
DEBUG_ECHO(ry0);
DEBUG_CHAR(')');
DEBUG_EOL();
}
}
return z0;
}
@ -342,3 +336,6 @@ class unified_bed_leveling {
extern unified_bed_leveling ubl;
#define Z_VALUES(X,Y) ubl.z_values[X][Y]
// Prevent debugging propagating to other files
#include "../../../core/debug_out.h"

View File

@ -46,6 +46,9 @@
#include "../../../module/tool_change.h"
#endif
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#include <math.h>
#define UBL_G29_P31
@ -442,7 +445,7 @@
SERIAL_ECHOLNPGM("Mesh invalidated. Probing mesh.");
}
if (g29_verbose_level > 1) {
SERIAL_ECHOPAIR("Probing Mesh Points Closest to (", g29_x_pos);
SERIAL_ECHOPAIR("Probing around (", g29_x_pos);
SERIAL_CHAR(',');
SERIAL_ECHO(g29_y_pos);
SERIAL_ECHOLNPGM(").\n");
@ -1463,27 +1466,24 @@
abort_flag = isnan(measured_z);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_CHAR('(');
SERIAL_ECHO_F(rx, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(ry, 7);
SERIAL_ECHOPGM(") logical: ");
SERIAL_CHAR('(');
SERIAL_ECHO_F(LOGICAL_X_POSITION(rx), 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(LOGICAL_Y_POSITION(ry), 7);
SERIAL_ECHOPAIR_F(") measured: ", measured_z, 7);
SERIAL_ECHOPAIR_F(" correction: ", get_z_correction(rx, ry), 7);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_CHAR('(');
DEBUG_ECHO_F(rx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(ry, 7);
DEBUG_ECHOPGM(") logical: ");
DEBUG_CHAR('(');
DEBUG_ECHO_F(LOGICAL_X_POSITION(rx), 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(LOGICAL_Y_POSITION(ry), 7);
DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7);
DEBUG_ECHOPAIR_F(" correction: ", get_z_correction(rx, ry), 7);
}
measured_z -= get_z_correction(rx, ry) /* + zprobe_zoffset */ ;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
#endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7);
if (g29_verbose_level > 3) {
serial_spaces(16);
SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z);
@ -1524,31 +1524,27 @@
y_tmp = mesh_index_to_ypos(j),
z_tmp = z_values[i][j];
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR_F("before rotation = [", x_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(y_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(z_tmp, 7);
SERIAL_ECHOPGM("] ---> ");
serial_delay(20);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", x_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(y_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(z_tmp, 7);
DEBUG_ECHOPGM("] ---> ");
DEBUG_DELAY(20);
}
apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR_F("after rotation = [", x_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(y_tmp, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(z_tmp, 7);
SERIAL_ECHOLNPGM("]");
serial_delay(55);
}
#endif
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("after rotation = [", x_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(y_tmp, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(z_tmp, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_DELAY(55);
}
z_values[i][j] = z_tmp - lsf_results.D;
#if ENABLED(EXTENSIBLE_UI)
@ -1557,62 +1553,59 @@
}
}
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
rotation.debug(PSTR("rotation matrix:\n"));
SERIAL_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
SERIAL_ECHOPAIR_F(" B=", lsf_results.B, 7);
SERIAL_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
serial_delay(55);
if (DEBUGGING(LEVELING)) {
rotation.debug(PSTR("rotation matrix:\n"));
DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7);
DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7);
DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7);
DEBUG_DELAY(55);
SERIAL_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(normal.y, 7);
SERIAL_CHAR(',');
SERIAL_ECHO_F(normal.z, 7);
SERIAL_ECHOLNPGM("]");
SERIAL_EOL();
DEBUG_ECHOPAIR_F("bed plane normal = [", normal.x, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(normal.y, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(normal.z, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_EOL();
/**
* The following code can be used to check the validity of the mesh tilting algorithm.
* When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting.
* The only difference is just 3 points are used in the calculations. That fact guarantees
* each probed point should have an exact match when a get_z_correction() for that location
* is calculated. The Z error between the probed point locations and the get_z_correction()
* numbers for those locations should be 0.
*/
#if 0
float t, t1, d;
t = normal.x * (PROBE_PT_1_X) + normal.y * (PROBE_PT_1_Y);
d = t + normal.z * z1;
SERIAL_ECHOPAIR_F("D from 1st point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z1-get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y), 6);
/**
* The following code can be used to check the validity of the mesh tilting algorithm.
* When a 3-Point Mesh Tilt is done, the same algorithm is used as the grid based tilting.
* The only difference is just 3 points are used in the calculations. That fact guarantees
* each probed point should have an exact match when a get_z_correction() for that location
* is calculated. The Z error between the probed point locations and the get_z_correction()
* numbers for those locations should be 0.
*/
#if 0
float t, t1, d;
t = normal.x * (PROBE_PT_1_X) + normal.y * (PROBE_PT_1_Y);
d = t + normal.z * z1;
DEBUG_ECHOPAIR_F("D from 1st point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z1-get_z_correction(PROBE_PT_1_X, PROBE_PT_1_Y), 6);
t = normal.x * (PROBE_PT_2_X) + normal.y * (PROBE_PT_2_Y);
d = t + normal.z * z2;
SERIAL_EOL();
SERIAL_ECHOPAIR_F("D from 2nd point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z2-get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y), 6);
t = normal.x * (PROBE_PT_2_X) + normal.y * (PROBE_PT_2_Y);
d = t + normal.z * z2;
DEBUG_EOL();
DEBUG_ECHOPAIR_F("D from 2nd point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z2-get_z_correction(PROBE_PT_2_X, PROBE_PT_2_Y), 6);
t = normal.x * (PROBE_PT_3_X) + normal.y * (PROBE_PT_3_Y);
d = t + normal.z * z3;
SERIAL_ECHOPAIR_F("D from 3rd point: ", d, 6);
SERIAL_ECHOLNPAIR_F(" Z error: ", normal.z*z3-get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y), 6);
t = normal.x * (PROBE_PT_3_X) + normal.y * (PROBE_PT_3_Y);
d = t + normal.z * z3;
DEBUG_ECHOPAIR_F("D from 3rd point: ", d, 6);
DEBUG_ECHOLNPAIR_F(" Z error: ", normal.z*z3-get_z_correction(PROBE_PT_3_X, PROBE_PT_3_Y), 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + normal.z * 0;
SERIAL_ECHOLNPAIR_F("D from home location with Z=0 : ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + normal.z * 0;
DEBUG_ECHOLNPAIR_F("D from home location with Z=0 : ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
SERIAL_ECHOPAIR_F("D from home location using mesh value for Z: ", d, 6);
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
DEBUG_ECHOPAIR_F("D from home location using mesh value for Z: ", d, 6);
SERIAL_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT);
SERIAL_ECHOPAIR(",", Z_SAFE_HOMING_Y_POINT);
SERIAL_ECHOLNPAIR_F(") = ", get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6);
#endif
} // DEBUGGING(LEVELING)
#endif
DEBUG_ECHOPAIR(" Z error: (", Z_SAFE_HOMING_X_POINT, ",", Z_SAFE_HOMING_Y_POINT);
DEBUG_ECHOLNPAIR_F(") = ", get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT), 6);
#endif
} // DEBUGGING(LEVELING)
}