diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index 9749d6d7..21b3200c 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -506,4 +506,6 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define HEATBED_V2 +//#define SUPPORT_VERBOSITY + #endif //__CONFIGURATION_PRUSA_H diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index bef1ea0e..71a816d8 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2972,9 +2972,11 @@ void process_commands() current_position[Y_AXIS] = pgm_read_float(bed_ref_points + 1); bool clamped = world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { clamped ? SERIAL_PROTOCOLPGM("First calibration point clamped.\n") : SERIAL_PROTOCOLPGM("No clamping for first calibration point.\n"); } + #endif //SUPPORT_VERBOSITY // mbl.get_meas_xy(0, 0, current_position[X_AXIS], current_position[Y_AXIS], false); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS] / 30, active_extruder); // Wait until the move is finished. @@ -2989,13 +2991,14 @@ void process_commands() int Z_PROBE_FEEDRATE = homing_feedrate[Z_AXIS] / 60; int Z_LIFT_FEEDRATE = homing_feedrate[Z_AXIS] / 40; bool has_z = is_bed_z_jitter_data_valid(); //checks if we have data from Z calibration (offsets of the Z heiths of the 8 calibration points from the first point) + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { has_z ? SERIAL_PROTOCOLPGM("Z jitter data from Z cal. valid.\n") : SERIAL_PROTOCOLPGM("Z jitter data from Z cal. not valid.\n"); } + #endif // SUPPORT_VERBOSITY setup_for_endstop_move(false); //save feedrate and feedmultiply, sets feedmultiply to 100 const char *kill_message = NULL; while (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) { - if (verbosity_level >= 1) SERIAL_ECHOLNPGM(""); // Get coords of a measuring point. ix = mesh_point % MESH_MEAS_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 iy = mesh_point / MESH_MEAS_NUM_X_POINTS; @@ -3005,13 +3008,16 @@ void process_commands() uint16_t z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); z0 = mbl.z_values[0][0] + *reinterpret_cast(&z_offset_u) * 0.01; //#if 0 + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { + SERIAL_ECHOLNPGM(""); SERIAL_ECHOPGM("Bed leveling, point: "); MYSERIAL.print(mesh_point); SERIAL_ECHOPGM(", calibration z: "); MYSERIAL.print(z0, 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY //#endif } @@ -3027,12 +3033,13 @@ void process_commands() world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { SERIAL_PROTOCOL(mesh_point); clamped ? SERIAL_PROTOCOLPGM(": xy clamped.\n") : SERIAL_PROTOCOLPGM(": no xy clamping\n"); } - + #endif // SUPPORT_VERBOSITY plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], XY_AXIS_FEEDRATE, active_extruder); st_synchronize(); @@ -3051,7 +3058,7 @@ void process_commands() kill_message = MSG_BED_LEVELING_FAILED_POINT_HIGH; break; } - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) { SERIAL_ECHOPGM("X: "); MYSERIAL.print(current_position[X_AXIS], 5); @@ -3060,13 +3067,13 @@ void process_commands() MYSERIAL.print(current_position[Y_AXIS], 5); SERIAL_PROTOCOLPGM("\n"); } - + #endif // SUPPORT_VERBOSITY float offset_z = 0; #ifdef PINDA_THERMISTOR offset_z = temp_compensation_pinda_thermistor_offset(); #endif //PINDA_THERMISTOR - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { SERIAL_ECHOPGM("mesh bed leveling: "); MYSERIAL.print(current_position[Z_AXIS], 5); @@ -3074,18 +3081,21 @@ void process_commands() MYSERIAL.print(offset_z, 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY mbl.set_z(ix, iy, current_position[Z_AXIS] - offset_z); //store measured z values z_values[iy][ix] = z - offset_z; custom_message_state--; mesh_point++; lcd_update(1); } - if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Mesh bed leveling while loop finished."); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { + SERIAL_ECHOLNPGM("Mesh bed leveling while loop finished."); SERIAL_ECHOLNPGM("MESH_HOME_Z_SEARCH: "); MYSERIAL.print(current_position[Z_AXIS], 5); } + #endif // SUPPORT_VERBOSITY plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], Z_LIFT_FEEDRATE, active_extruder); st_synchronize(); if (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) { @@ -3104,10 +3114,11 @@ void process_commands() babystep_apply(); // Apply Z height correction aka baby stepping before mesh bed leveing gets activated. SERIAL_ECHOLNPGM("babystep applied"); bool eeprom_bed_correction_valid = eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1; - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { eeprom_bed_correction_valid ? SERIAL_PROTOCOLPGM("Bed correction data valid\n") : SERIAL_PROTOCOLPGM("Bed correction data not valid\n"); } + #endif // SUPPORT_VERBOSITY for (uint8_t i = 0; i < 4; ++i) { unsigned char codes[4] = { 'L', 'R', 'F', 'B' }; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 9d44ce36..cccc1fd0 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -177,6 +177,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( ) { float angleDiff; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) { SERIAL_ECHOLNPGM("calculate machine skew and offset LS"); @@ -218,6 +219,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( } delay_keep_alive(100); } + #endif // SUPPORT_VERBOSITY // Run some iterations of the Gauss-Newton method of non-linear least squares. // Initial set of parameters: @@ -318,6 +320,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( a1 += h[2]; a2 += h[3]; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM("iteration: "); MYSERIAL.print(int(iter)); @@ -341,6 +344,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( MYSERIAL.print(180.f * a2 / M_PI, 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY } vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X; @@ -360,7 +364,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( fabs(a2) > bed_skew_angle_extreme) result = BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME; } - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { SERIAL_ECHOPGM("correction angles: "); MYSERIAL.print(180.f * a1 / M_PI, 5); @@ -392,7 +396,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( SERIAL_ECHOLNPGM("Error after correction: "); } - + #endif // SUPPORT_VERBOSITY // Measure the error after correction. for (uint8_t i = 0; i < npts; ++i) { float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1] + cntr[0]; @@ -400,33 +404,44 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( float errX = sqr(pgm_read_float(true_pts + i * 2) - x); float errY = sqr(pgm_read_float(true_pts + i * 2 + 1) - y); float err = sqrt(errX + errY); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) { SERIAL_ECHOPGM("point #"); MYSERIAL.print(int(i)); SERIAL_ECHOLNPGM(":"); } + #endif // SUPPORT_VERBOSITY if (point_on_1st_row(i)) { + #ifdef SUPPORT_VERBOSITY if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row"); + #endif // SUPPORT_VERBOSITY float w = point_weight_y(i, npts, measured_pts[2 * i + 1]); if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X || (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y)) { result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM(", weigth Y: "); MYSERIAL.print(w); if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X) SERIAL_ECHOPGM(", error X > max. error X"); if (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y) SERIAL_ECHOPGM(", error Y > max. error Y"); } + #endif // SUPPORT_VERBOSITY } } else { + #ifdef SUPPORT_VERBOSITY if(verbosity_level >=20 ) SERIAL_ECHOPGM("Point not on first row"); + #endif // SUPPORT_VERBOSITY if (err > BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN) { result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED; + #ifdef SUPPORT_VERBOSITY if(verbosity_level >= 20) SERIAL_ECHOPGM(", error > max. error euclidian"); + #endif // SUPPORT_VERBOSITY } } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) { SERIAL_ECHOLNPGM(""); SERIAL_ECHOPGM("measured: ("); @@ -451,7 +466,9 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM("Max. errors:"); SERIAL_ECHOPGM("Max. error X:"); @@ -462,11 +479,14 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( MYSERIAL.println(BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY #if 0 if (result == BED_SKEW_OFFSET_DETECTION_PERFECT && fabs(a1) < bed_skew_angle_mild && fabs(a2) < bed_skew_angle_mild) { - if (verbosity_level > 0) + #ifdef SUPPORT_VERBOSITY + if (verbosity_level > 0) SERIAL_ECHOLNPGM("Very little skew detected. Disabling skew correction."); + #endif // SUPPORT_VERBOSITY // Just disable the skew correction. vec_x[0] = MACHINE_AXIS_SCALE_X; vec_x[1] = 0.f; @@ -475,9 +495,11 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( } #else if (result == BED_SKEW_OFFSET_DETECTION_PERFECT) { - if (verbosity_level > 0) + #ifdef SUPPORT_VERBOSITY + if (verbosity_level > 0) SERIAL_ECHOLNPGM("Very little skew detected. Orthogonalizing the axes."); - // Orthogonalize the axes. + #endif // SUPPORT_VERBOSITY + // Orthogonalize the axes. a1 = 0.5f * (a1 + a2); vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X; vec_x[1] = sin(a1) * MACHINE_AXIS_SCALE_X; @@ -494,6 +516,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( float w = point_weight_x(i, npts, y); cntr[0] += w * (pgm_read_float(true_pts + i * 2) - x); wx += w; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { MYSERIAL.print(i); SERIAL_ECHOLNPGM(""); @@ -506,10 +529,11 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( SERIAL_ECHOLNPGM("wx:"); MYSERIAL.print(wx); } + #endif // SUPPORT_VERBOSITY w = point_weight_y(i, npts, y); cntr[1] += w * (pgm_read_float(true_pts + i * 2 + 1) - y); wy += w; - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("Weight_y:"); @@ -523,9 +547,12 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY + } cntr[0] /= wx; cntr[1] /= wy; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("Final cntr values:"); @@ -536,7 +563,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( MYSERIAL.print(cntr[1]); SERIAL_ECHOLNPGM(""); } - + #endif // SUPPORT_VERBOSITY } #endif @@ -558,7 +585,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( cntr[0] = cntrInv[0]; cntr[1] = cntrInv[1]; } - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 1) { // Show the adjusted state, before the fitting. SERIAL_ECHOPGM("X vector, adjusted: "); @@ -613,6 +640,8 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( } delay_keep_alive(100); } + #endif // SUPPORT_VERBOSITY + return result; } @@ -825,8 +854,10 @@ static inline void update_current_position_z() // At the current position, find the Z stop. inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int verbosity_level) { + #ifdef SUPPORT_VERBOSITY if(verbosity_level >= 10) SERIAL_ECHOLNPGM("find bed induction sensor point z"); - bool endstops_enabled = enable_endstops(true); + #endif // SUPPORT_VERBOSITY + bool endstops_enabled = enable_endstops(true); bool endstop_z_enabled = enable_z_endstop(false); float z = 0.f; endstop_z_hit_on_purpose(); @@ -880,8 +911,10 @@ error: #define FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP (0.2f) inline bool find_bed_induction_sensor_point_xy(int verbosity_level) { + #ifdef SUPPORT_VERBOSITY if(verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); - float feedrate = homing_feedrate[X_AXIS] / 60.f; + #endif // SUPPORT_VERBOSITY + float feedrate = homing_feedrate[X_AXIS] / 60.f; bool found = false; { @@ -893,19 +926,27 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level) uint8_t i; if (x0 < X_MIN_POS) { x0 = X_MIN_POS; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done."); + #endif // SUPPORT_VERBOSITY } if (x1 > X_MAX_POS) { x1 = X_MAX_POS; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done."); + #endif // SUPPORT_VERBOSITY } if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) { y0 = Y_MIN_POS_FOR_BED_CALIBRATION; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done."); + #endif // SUPPORT_VERBOSITY } if (y1 > Y_MAX_POS) { y1 = Y_MAX_POS; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done."); + #endif // SUPPORT_VERBOSITY } nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); @@ -1210,11 +1251,13 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver } b = current_position[X_AXIS]; if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) { + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { SERIAL_ECHOPGM("Point width too small: "); SERIAL_ECHO(b - a); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY // We force the calibration routine to move the Z axis slightly down to make the response more pronounced. if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { // Don't use the new X value. @@ -1225,10 +1268,12 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver point_small = true; } } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); } + #endif // SUPPORT_VERBOSITY // Go to the center. enable_z_endstop(false); @@ -1281,11 +1326,13 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver b = current_position[Y_AXIS]; if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) { // We force the calibration routine to move the Z axis slightly down to make the response more pronounced. - if (verbosity_level >= 5) { + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 5) { SERIAL_ECHOPGM("Point height too small: "); SERIAL_ECHO(b - a); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { // Don't use the new Y value. current_position[Y_AXIS] = center_old_y; @@ -1295,10 +1342,12 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver point_small = true; } } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { debug_output_point(PSTR("top" ), current_position[X_AXIS], a, current_position[Z_AXIS]); debug_output_point(PSTR("bottom"), current_position[X_AXIS], b, current_position[Z_AXIS]); } + #endif // SUPPORT_VERBOSITY // Go to the center. enable_z_endstop(false); @@ -1331,8 +1380,9 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) float center_old_y = current_position[Y_AXIS]; float a, b; bool result = true; - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) MYSERIAL.println("Improve bed induction sensor point3"); + #endif // SUPPORT_VERBOSITY // Was the sensor point detected too far in the minus Y axis? // If yes, the center of the induction point cannot be reached by the machine. { @@ -1350,7 +1400,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) y0 = Y_MIN_POS_FOR_BED_CALIBRATION; if (y1 > Y_MAX_POS) y1 = Y_MAX_POS; - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM("Initial position: "); SERIAL_ECHO(center_old_x); @@ -1358,6 +1408,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) SERIAL_ECHO(center_old_y); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY // Search in the positive Y direction, until a maximum diameter is found. // (the next diameter is smaller than the current one.) @@ -1389,10 +1440,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) // goto canceled; } b = current_position[X_AXIS]; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); } + #endif // SUPPORT_VERBOSITY float d = b - a; if (d > dmax) { xmax1 = 0.5f * (a + b); @@ -1403,9 +1456,11 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) } } if (dmax == 0.) { + #ifdef SUPPORT_VERBOSITY if (verbosity_level > 0) SERIAL_PROTOCOLPGM("failed - not found\n"); - current_position[X_AXIS] = center_old_x; + #endif // SUPPORT_VERBOSITY + current_position[X_AXIS] = center_old_x; current_position[Y_AXIS] = center_old_y; goto canceled; } @@ -1421,9 +1476,11 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) current_position[Y_AXIS] = center_old_y; goto canceled; } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); - y1 = current_position[Y_AXIS]; + #endif // SUPPORT_VERBOSITY + y1 = current_position[Y_AXIS]; } if (y1 <= y0) { @@ -1465,10 +1522,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) */ } b = current_position[X_AXIS]; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); } + #endif // SUPPORT_VERBOSITY float d = b - a; if (d > dmax) { xmax2 = 0.5f * (a + b); @@ -1516,10 +1575,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) */ } b = current_position[X_AXIS]; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); } + #endif // SUPPORT_VERBOSITY float d = b - a; if (d > dmax) { xmax = 0.5f * (a + b); @@ -1541,24 +1602,29 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) current_position[Y_AXIS] = center_old_y; goto canceled; } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); - if (current_position[Y_AXIS] - Y_MIN_POS_FOR_BED_CALIBRATION < 0.5f * dmax) { + #endif // SUPPORT_VERBOSITY + if (current_position[Y_AXIS] - Y_MIN_POS_FOR_BED_CALIBRATION < 0.5f * dmax) { // Probably not even a half circle was detected. The induction point is likely too far in the minus Y direction. // First verify, if the measurement has been done at a sufficient height. If no, lower the Z axis a bit. if (current_position[Y_AXIS] < ymax || dmax < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { - if (verbosity_level >= 5) { + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 5) { SERIAL_ECHOPGM("Partial point diameter too small: "); SERIAL_ECHO(dmax); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY result = false; } else { // Estimate the circle radius from the maximum diameter and height: float h = current_position[Y_AXIS] - ymax; float r = dmax * dmax / (8.f * h) + 0.5f * h; if (r < 0.8f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { - if (verbosity_level >= 5) { + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 5) { SERIAL_ECHOPGM("Partial point estimated radius too small: "); SERIAL_ECHO(r); SERIAL_ECHOPGM(", dmax:"); @@ -1567,6 +1633,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) SERIAL_ECHO(h); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY result = false; } else { // The point may end up outside of the machine working space. @@ -1593,6 +1660,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) enable_z_endstop(false); current_position[X_AXIS] = xmax; current_position[Y_AXIS] = ymax; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM("Adjusted position: "); SERIAL_ECHO(current_position[X_AXIS]); @@ -1600,6 +1668,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level) SERIAL_ECHO(current_position[Y_AXIS]); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY // Don't clamp current_position[Y_AXIS], because the out-of-reach Y coordinate may actually be true. // Only clamp the coordinate to go. @@ -1690,6 +1759,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level SERIAL_ECHOPGM("Iteration: "); MYSERIAL.println(int(iteration + 1)); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM("Vectors: "); @@ -1712,6 +1782,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level MYSERIAL.print(cntr[1], 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY #ifdef MESH_BED_CALIBRATION_SHOW_LCD uint8_t next_line; lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1, next_line); @@ -1737,6 +1808,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level // Go up to z_initial. go_to_current(homing_feedrate[Z_AXIS] / 60.f); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { // Go to Y0, wait, then go to Y-4. current_position[Y_AXIS] = 0.f; @@ -1748,6 +1820,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level SERIAL_ECHOLNPGM("At Y-4"); delay_keep_alive(5000); } + #endif // SUPPORT_VERBOSITY // Go to the measurement point position. //if (iteration == 0) { current_position[X_AXIS] = pgm_read_float(bed_ref_points_4 + k * 2); @@ -1765,6 +1838,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; }*/ + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM("current_position[X_AXIS]:"); MYSERIAL.print(current_position[X_AXIS], 5); @@ -1776,11 +1850,13 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level MYSERIAL.print(current_position[Z_AXIS], 5); SERIAL_ECHOLNPGM(""); } - + #endif // SUPPORT_VERBOSITY go_to_current(homing_feedrate[X_AXIS] / 60.f); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) delay_keep_alive(3000); + #endif // SUPPORT_VERBOSITY if (!find_bed_induction_sensor_point_xy(verbosity_level)) return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; #if 1 @@ -1805,15 +1881,19 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; } #endif + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) delay_keep_alive(3000); + #endif // SUPPORT_VERBOSITY // Save the detected point position and then clamp the Y coordinate, which may have been estimated // to lie outside the machine working space. + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM("Measured:"); MYSERIAL.println(current_position[X_AXIS]); MYSERIAL.println(current_position[Y_AXIS]); } + #endif // SUPPORT_VERBOSITY pt[0] = (pt[0] * iteration) / (iteration + 1); pt[0] += (current_position[X_AXIS]/(iteration + 1)); //count average pt[1] = (pt[1] * iteration) / (iteration + 1); @@ -1826,6 +1906,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level //pt[1] += current_position[Y_AXIS]; //if (iteration > 0) pt[1] = pt[1] / 2; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM(""); SERIAL_ECHOPGM("pt[0]:"); @@ -1833,6 +1914,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level SERIAL_ECHOPGM("pt[1]:"); MYSERIAL.println(pt[1]); } + #endif // SUPPORT_VERBOSITY if (current_position[Y_AXIS] < Y_MIN_POS) current_position[Y_AXIS] = Y_MIN_POS; @@ -1840,14 +1922,17 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level current_position[Z_AXIS] += 3.f + FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP * iteration * 0.3; //cntr[0] += pt[0]; //cntr[1] += pt[1]; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10 && k == 0) { // Show the zero. Test, whether the Y motor skipped steps. current_position[Y_AXIS] = MANUAL_Y_HOME_POS; go_to_current(homing_feedrate[X_AXIS] / 60.f); delay_keep_alive(3000); } + #endif // SUPPORT_VERBOSITY } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { // Test the positions. Are the positions reproducible? Now the calibration is active in the planner. delay_keep_alive(3000); @@ -1862,7 +1947,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level delay_keep_alive(3000); } } - + #endif // SUPPORT_VERBOSITY if (pts[1] < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) { too_far_mask |= 1 << 1; //front center point is out of reach SERIAL_ECHOLNPGM(""); @@ -1884,6 +1969,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 0), vec_y[0]); eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 4), vec_y[1]); #endif + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) { // Length of the vec_x float l = sqrt(vec_x[0] * vec_x[0] + vec_x[1] * vec_x[1]); @@ -1905,10 +1991,11 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level MYSERIAL.println(fabs(l)); SERIAL_ECHOLNPGM("Saving bed calibration vectors to EEPROM"); } + #endif // SUPPORT_VERBOSITY // Correct the current_position to match the transformed coordinate system after world2machine_rotation_and_skew and world2machine_shift were set. world2machine_update_current(); - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { // Test the positions. Are the positions reproducible? Now the calibration is active in the planner. delay_keep_alive(3000); @@ -1923,6 +2010,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level delay_keep_alive(3000); } } + #endif // SUPPORT_VERBOSITY return result; } if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED && too_far_mask == 2) return result; //if fitting failed and front center point is out of reach, terminate calibration and inform user @@ -1946,9 +2034,9 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 float *vec_y = vec_x + 2; float *cntr = vec_y + 2; memset(pts, 0, sizeof(float) * 7 * 7); - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) SERIAL_ECHOLNPGM("Improving bed offset and skew"); - + #endif // SUPPORT_VERBOSITY // Cache the current correction matrix. world2machine_initialize(); vec_x[0] = world2machine_rotation_and_skew[0][0]; @@ -1986,6 +2074,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 enable_endstops(false); enable_z_endstop(false); go_to_current(homing_feedrate[Z_AXIS]/60); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { // Go to Y0, wait, then go to Y-4. current_position[Y_AXIS] = 0.f; @@ -1997,6 +2086,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 SERIAL_ECHOLNPGM("At Y_MIN_POS"); delay_keep_alive(5000); } + #endif // SUPPORT_VERBOSITY // Go to the measurement point. // Use the coorrected coordinate, which is a result of find_bed_offset_and_skew(). current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[0]; @@ -2004,25 +2094,32 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 // The calibration points are very close to the min Y. if (current_position[Y_AXIS] < Y_MIN_POS_FOR_BED_CALIBRATION){ current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOPGM("Calibration point "); SERIAL_ECHO(mesh_point); SERIAL_ECHOPGM("lower than Ymin. Y coordinate clamping was used."); SERIAL_ECHOLNPGM(""); - } + } + #endif // SUPPORT_VERBOSITY } go_to_current(homing_feedrate[X_AXIS]/60); // Find its Z position by running the normal vertical search. - if (verbosity_level >= 10) + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 10) delay_keep_alive(3000); - find_bed_induction_sensor_point_z(); - if (verbosity_level >= 10) + #endif // SUPPORT_VERBOSITY + find_bed_induction_sensor_point_z(); + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 10) delay_keep_alive(3000); - // Try to move the Z axis down a bit to increase a chance of the sensor to trigger. + #endif // SUPPORT_VERBOSITY + // Try to move the Z axis down a bit to increase a chance of the sensor to trigger. current_position[Z_AXIS] -= 0.025f; // Improve the point position by searching its center in a current plane. int8_t n_errors = 3; for (int8_t iter = 0; iter < 8; ) { + #ifdef SUPPORT_VERBOSITY if (verbosity_level > 20) { SERIAL_ECHOPGM("Improving bed point "); SERIAL_ECHO(mesh_point); @@ -2032,6 +2129,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 MYSERIAL.print(current_position[Z_AXIS], 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY bool found = false; if (mesh_point < 2) { // Because the sensor cannot move in front of the first row @@ -2065,6 +2163,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 enable_endstops(false); enable_z_endstop(false); go_to_current(homing_feedrate[Z_AXIS]); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { SERIAL_ECHOPGM("Improving bed point "); SERIAL_ECHO(mesh_point); @@ -2074,10 +2173,13 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 MYSERIAL.print(current_position[Z_AXIS], 5); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY } } + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 10) delay_keep_alive(3000); + #endif // SUPPORT_VERBOSITY } // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); @@ -2089,6 +2191,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 enable_endstops(false); enable_z_endstop(false); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { // Test the positions. Are the positions reproducible? current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; @@ -2112,6 +2215,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 SERIAL_ECHOLNPGM(""); } } + #endif // SUPPORT_VERBOSITY { // First fill in the too_far_mask from the measured points. @@ -2127,6 +2231,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 for (uint8_t mesh_point = 0; mesh_point < 2; ++ mesh_point) { float y = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1]; distance_from_min[mesh_point] = (y - Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH); + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 20) { SERIAL_ECHOLNPGM(""); SERIAL_ECHOPGM("Distance from min:"); @@ -2136,6 +2241,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 MYSERIAL.print(y); SERIAL_ECHOLNPGM(""); } + #endif // SUPPORT_VERBOSITY if (y < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) too_far_mask |= 1 << mesh_point; } @@ -2157,7 +2263,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 enable_endstops(false); enable_z_endstop(false); - + #ifdef SUPPORT_VERBOSITY if (verbosity_level >= 5) { // Test the positions. Are the positions reproducible? Now the calibration is active in the planner. delay_keep_alive(3000); @@ -2186,6 +2292,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } } } + #endif // SUPPORT_VERBOSITY // Sample Z heights for the mesh bed leveling. // In addition, store the results into an eeprom, to be used later for verification of the bed leveling process.