From c4d7b801b93b709551d01f862e22208d7f2f413d Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Fri, 27 Oct 2017 16:12:37 +0200 Subject: [PATCH 1/4] Initial version. XYZ cal works, but bed ref. points coordinates must be checked. --- Firmware/Configuration.h | 2 + Firmware/Marlin.h | 3 +- Firmware/Marlin_main.cpp | 7 ++-- Firmware/language_cz.h | 2 +- Firmware/language_de.h | 2 +- Firmware/language_en.h | 2 +- Firmware/language_es.h | 2 +- Firmware/language_it.h | 2 +- Firmware/language_pl.h | 2 +- Firmware/mesh_bed_calibration.cpp | 62 +++++++++++++++++-------------- Firmware/ultralcd.cpp | 9 +++-- 11 files changed, 52 insertions(+), 43 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index e6b8cb9a..02a482a7 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -77,6 +77,8 @@ // Power loss errors #define EEPROM_POWER_COUNT (EEPROM_UVLO_MESH_BED_LEVELING-17) +#define EEPROM_XYZ_CAL_SKEW (EEPROM_POWER_COUNT - 4) //float for skew backup + // Currently running firmware, each digit stored as uint16_t. // The flavor differentiates a dev, alpha, beta, release candidate or a release version. #define EEPROM_FIRMWARE_VERSION_END (FW_PRUSA3D_MAGIC_LEN+8) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 8c964efe..bed03958 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -338,8 +338,7 @@ extern unsigned long start_pause_print; extern bool mesh_bed_leveling_flag; extern bool mesh_bed_run_from_menu; -extern float distance_from_min[3]; -extern float angleDiff; +extern float distance_from_min[2]; extern void calculate_volumetric_multipliers(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8d0304bc..026b194f 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -310,8 +310,7 @@ unsigned int custom_message_type; unsigned int custom_message_state; char snmm_filaments_used = 0; -float distance_from_min[3]; -float angleDiff; +float distance_from_min[2]; bool fan_state[2]; int fan_edge_counter[2]; @@ -1450,7 +1449,7 @@ inline void gcode_M900() { #ifdef TMC2130 bool calibrate_z_auto() { - lcd_display_message_fullscreen_P(MSG_CALIBRATE_Z_AUTO); + //lcd_display_message_fullscreen_P(MSG_CALIBRATE_Z_AUTO); bool endstops_enabled = enable_endstops(true); int axis_up_dir = -home_dir(Z_AXIS); tmc2130_home_enter(Z_AXIS_MASK); @@ -6891,6 +6890,7 @@ extern uint32_t sdpos_atomic; void uvlo_() { + unsigned long time_start = millis(); // Conserve power as soon as possible. disable_x(); disable_y(); @@ -6986,6 +6986,7 @@ void uvlo_() eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, power_count); SERIAL_ECHOLNPGM("UVLO - end"); + MYSERIAL.println(millis() - time_start); cli(); while(1); } diff --git a/Firmware/language_cz.h b/Firmware/language_cz.h index 5f2e36af..f6eb993e 100644 --- a/Firmware/language_cz.h +++ b/Firmware/language_cz.h @@ -219,7 +219,7 @@ #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Hledam kalibracni bod podlozky" #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " z 4" #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Zlepsuji presnost kalibracniho bodu" -#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " z 9" +#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " z 4" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Merim referencni vysku kalibracniho bodu" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " z 9" #define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Iterace " diff --git a/Firmware/language_de.h b/Firmware/language_de.h index fe5f4182..87c02a29 100644 --- a/Firmware/language_de.h +++ b/Firmware/language_de.h @@ -206,7 +206,7 @@ +#define(length = 60) MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Suchen Bed Kalibrierpunkt" + #define(length = 14) MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " von 4" + #define(length = 60) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Verbesserung Bed Kalibrierpunkt" -+ #define(length = 14) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " von 9" ++ #define(length = 14) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " von 4" + #define(length = 60) MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Messen der Referenzhoehe des Kalibrierpunktes" + #define(length = 14) MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " von 9" #define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Iteration " diff --git a/Firmware/language_en.h b/Firmware/language_en.h index bd9aaddb..44a7b0f4 100644 --- a/Firmware/language_en.h +++ b/Firmware/language_en.h @@ -218,7 +218,7 @@ #define(length=60) MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Searching bed calibration point" #define(length=14) MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " of 4" #define(length=60) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Improving bed calibration point" -#define(length=14) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " of 9" +#define(length=14) MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " of 4" #define(length=60) MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Measuring reference height of calibration point" #define(length=14) MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " of 9" #define(length=20) MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Iteration " diff --git a/Firmware/language_es.h b/Firmware/language_es.h index d44cda83..6544d666 100644 --- a/Firmware/language_es.h +++ b/Firmware/language_es.h @@ -202,7 +202,7 @@ #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Buscando cama punto de calibracion" #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " de 4" #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Mejorando cama punto de calibracion" -#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " de 9" +#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " de 4" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Medir la altura del punto de la calibracion" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " de 9" diff --git a/Firmware/language_it.h b/Firmware/language_it.h index 62975476..42737a57 100644 --- a/Firmware/language_it.h +++ b/Firmware/language_it.h @@ -193,7 +193,7 @@ #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Ricerca del letto punto di calibraz." #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " su 4" #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Perfezion. il letto punto di calibraz." -#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " su 9" +#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " su 4" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Misurare l'altezza di riferimento del punto di calibrazione" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " su 9" #define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Reiterazione " diff --git a/Firmware/language_pl.h b/Firmware/language_pl.h index 3cd283de..2bce5ede 100644 --- a/Firmware/language_pl.h +++ b/Firmware/language_pl.h @@ -208,7 +208,7 @@ #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE1 "Szukam punktu kalibracyjnego podkladki" #define MSG_FIND_BED_OFFSET_AND_SKEW_LINE2 " z 4" #define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE1 "Poprawiam precyzyjnosc punktu kalibracyjnego" -#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " z 9" +#define MSG_IMPROVE_BED_OFFSET_AND_SKEW_LINE2 " z 4" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1 "Okreslam wysokosc odniesienia punktu kalibracyjnego" #define MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2 " z 9" #define MSG_FIND_BED_OFFSET_AND_SKEW_ITERATION "Iteracja " diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 19880b42..9d44ce36 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -56,10 +56,15 @@ const float bed_skew_angle_extreme = (0.25f * M_PI / 180.f); // Positions of the bed reference points in the machine coordinates, referenced to the P.I.N.D.A sensor. // The points are the following: center front, center right, center rear, center left. const float bed_ref_points_4[] PROGMEM = { - 115.f - BED_ZERO_REF_X, 8.4f - BED_ZERO_REF_Y, - 216.f - BED_ZERO_REF_X, 104.4f - BED_ZERO_REF_Y, - 115.f - BED_ZERO_REF_X, 200.4f - BED_ZERO_REF_Y, - 13.f - BED_ZERO_REF_X, 104.4f - BED_ZERO_REF_Y + //115.f - BED_ZERO_REF_X, 8.4f - BED_ZERO_REF_Y, + //216.f - BED_ZERO_REF_X, 104.4f - BED_ZERO_REF_Y, + //115.f - BED_ZERO_REF_X, 200.4f - BED_ZERO_REF_Y, + //13.f - BED_ZERO_REF_X, 104.4f - BED_ZERO_REF_Y + + 13.f - BED_ZERO_REF_X, 8.4f - BED_ZERO_REF_Y, + 221.f - BED_ZERO_REF_X, 8.4f - BED_ZERO_REF_Y, + 221.f - BED_ZERO_REF_X, 200.4f - BED_ZERO_REF_Y, + 13.f - BED_ZERO_REF_X, 200.4f - BED_ZERO_REF_Y }; const float bed_ref_points[] PROGMEM = { @@ -104,10 +109,9 @@ const float bed_ref_points[] PROGMEM = { static inline float sqr(float x) { return x * x; } -static inline bool point_on_1st_row(const uint8_t i, const uint8_t npts) +static inline bool point_on_1st_row(const uint8_t i) { - if (npts == 4) return (i == 0); - else return (i < 3); + return (i < 2); } // Weight of a point coordinate in a least squares optimization. @@ -117,7 +121,7 @@ static inline bool point_on_1st_row(const uint8_t i, const uint8_t npts) static inline float point_weight_x(const uint8_t i, const uint8_t npts, const float &y) { float w = 1.f; - if (point_on_1st_row(i, npts)) { + if (point_on_1st_row(i)) { if (y >= Y_MIN_POS_CALIBRATION_POINT_ACCURATE) { w = WEIGHT_FIRST_ROW_X_HIGH; } else if (y < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) { @@ -139,7 +143,7 @@ static inline float point_weight_x(const uint8_t i, const uint8_t npts, const fl static inline float point_weight_y(const uint8_t i, const uint8_t npts, const float &y) { float w = 1.f; - if (point_on_1st_row(i, npts)) { + if (point_on_1st_row(i)) { if (y >= Y_MIN_POS_CALIBRATION_POINT_ACCURATE) { w = WEIGHT_FIRST_ROW_Y_HIGH; } else if (y < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) { @@ -172,6 +176,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( int8_t verbosity_level ) { + float angleDiff; if (verbosity_level >= 10) { SERIAL_ECHOLNPGM("calculate machine skew and offset LS"); @@ -346,6 +351,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( BedSkewOffsetDetectionResultType result = BED_SKEW_OFFSET_DETECTION_PERFECT; { angleDiff = fabs(a2 - a1); + eeprom_update_float((float*)(EEPROM_XYZ_CAL_SKEW), angleDiff); //storing xyz cal. skew to be able to show in support menu later if (angleDiff > bed_skew_angle_mild) result = (angleDiff > bed_skew_angle_extreme) ? BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME : @@ -400,7 +406,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( SERIAL_ECHOLNPGM(":"); } - if (point_on_1st_row(i, npts)) { + if (point_on_1st_row(i)) { if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row"); float w = point_weight_y(i, npts, measured_pts[2 * i + 1]); if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X || @@ -1779,7 +1785,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; #if 1 - if (k == 0) { + if (k == 0 || k == 1) { // Improve the position of the 1st row sensor points by a zig-zag movement. find_bed_induction_sensor_point_z(); int8_t i = 4; @@ -1966,7 +1972,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 // Collect a matrix of 9x9 points. BedSkewOffsetDetectionResultType result = BED_SKEW_OFFSET_DETECTION_PERFECT; - for (int8_t mesh_point = 0; mesh_point < 9; ++ mesh_point) { + for (int8_t mesh_point = 0; mesh_point < 4; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); // Print the decrasing ID of the measurement point. @@ -1993,8 +1999,8 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } // 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+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[0]; - current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[1]; + 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]; + current_position[Y_AXIS] = 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]; // 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; @@ -2027,7 +2033,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 SERIAL_ECHOLNPGM(""); } bool found = false; - if (mesh_point < 3) { + if (mesh_point < 2) { // Because the sensor cannot move in front of the first row // of the sensor points, the y position cannot be measured // by a cross center method. @@ -2036,7 +2042,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 } else { switch (method) { case 0: found = improve_bed_induction_sensor_point(); break; - case 1: found = improve_bed_induction_sensor_point2(mesh_point < 3, verbosity_level); break; + case 1: found = improve_bed_induction_sensor_point2(mesh_point < 2, verbosity_level); break; default: break; } } @@ -2077,7 +2083,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 refresh_cmd_timeout(); // Average the last 4 measurements. - for (int8_t i = 0; i < 18; ++ i) + for (int8_t i = 0; i < 8; ++ i) pts[i] *= (1.f/4.f); enable_endstops(false); @@ -2086,7 +2092,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 if (verbosity_level >= 5) { // Test the positions. Are the positions reproducible? current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; - for (int8_t mesh_point = 0; mesh_point < 9; ++ mesh_point) { + for (int8_t mesh_point = 0; mesh_point < 4; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); // Go to the measurement point. @@ -2109,17 +2115,17 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 { // First fill in the too_far_mask from the measured points. - for (uint8_t mesh_point = 0; mesh_point < 3; ++ mesh_point) + for (uint8_t mesh_point = 0; mesh_point < 2; ++ mesh_point) if (pts[mesh_point * 2 + 1] < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) too_far_mask |= 1 << mesh_point; - result = calculate_machine_skew_and_offset_LS(pts, 9, bed_ref_points, vec_x, vec_y, cntr, verbosity_level); + result = calculate_machine_skew_and_offset_LS(pts, 4, bed_ref_points_4, vec_x, vec_y, cntr, verbosity_level); if (result < 0) { SERIAL_ECHOLNPGM("Calculation of the machine skew and offset failed."); goto canceled; } // In case of success, update the too_far_mask from the calculated points. - for (uint8_t mesh_point = 0; mesh_point < 3; ++ mesh_point) { - float y = vec_x[1] * pgm_read_float(bed_ref_points+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points+mesh_point*2+1) + cntr[1]; + 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); if (verbosity_level >= 20) { SERIAL_ECHOLNPGM(""); @@ -2156,13 +2162,13 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8 // Test the positions. Are the positions reproducible? Now the calibration is active in the planner. delay_keep_alive(3000); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; - for (int8_t mesh_point = 0; mesh_point < 9; ++ mesh_point) { + for (int8_t mesh_point = 0; mesh_point < 4; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); // Go to the measurement point. // Use the coorrected coordinate, which is a result of find_bed_offset_and_skew(). - current_position[X_AXIS] = pgm_read_float(bed_ref_points+mesh_point*2); - current_position[Y_AXIS] = pgm_read_float(bed_ref_points+mesh_point*2+1); + current_position[X_AXIS] = pgm_read_float(bed_ref_points_4+mesh_point*2); + current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+mesh_point*2+1); if (verbosity_level >= 10) { go_to_current(homing_feedrate[X_AXIS]/60); delay_keep_alive(3000); @@ -2483,9 +2489,9 @@ void count_xyz_details() { }; a2 = -1 * asin(vec_y[0] / MACHINE_AXIS_SCALE_Y); a1 = asin(vec_x[1] / MACHINE_AXIS_SCALE_X); - angleDiff = fabs(a2 - a1); - for (uint8_t mesh_point = 0; mesh_point < 3; ++mesh_point) { - float y = vec_x[1] * pgm_read_float(bed_ref_points + mesh_point * 2) + vec_y[1] * pgm_read_float(bed_ref_points + mesh_point * 2 + 1) + cntr[1]; + //angleDiff = fabs(a2 - a1); + 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); } } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 40d75e0a..d45cb0c6 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1536,15 +1536,16 @@ static void lcd_move_e() } void lcd_service_mode_show_result() { + float angleDiff; lcd_set_custom_characters_degree(); count_xyz_details(); + angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW)); lcd_update_enable(false); lcd_implementation_clear(); lcd_printPGM(PSTR("Y distance from min:")); lcd_print_at_PGM(0, 1, PSTR("Left:")); - lcd_print_at_PGM(0, 2, PSTR("Center:")); lcd_print_at_PGM(0, 3, PSTR("Right:")); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 2; i++) { if(distance_from_min[i] < 200) { lcd_print_at_PGM(8, i + 1, PSTR("")); lcd.print(distance_from_min[i]); @@ -2818,11 +2819,11 @@ static void lcd_settings_menu() MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84")); } - if (FSensorStateMenu == 0) { + /*if (FSensorStateMenu == 0) { MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set); } else { MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set); - } + }*/ if (SilentModeMenu == 0) { MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); From 967594edf090672bc386879294c50ecd6f79b652 Mon Sep 17 00:00:00 2001 From: michalprusa Date: Fri, 3 Nov 2017 20:27:52 +0100 Subject: [PATCH 2/4] Added G-CODE "PRUSA FAN" to report RPM of both fans --- Firmware/Marlin_main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 30980c57..67573cba 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1779,7 +1779,15 @@ void process_commands() else if (code_seen("PRN")) { MYSERIAL.println(status_number); - }else if (code_seen("fn")) { + }else if (code_seen("FAN")) { + MYSERIAL.print("E0:"); + MYSERIAL.print(60*fan_speed[0]); + MYSERIAL.println(" RPM"); + MYSERIAL.print("PRN0:"); + MYSERIAL.print(60*fan_speed[1]); + MYSERIAL.println(" RPM"); + + }else if (code_seen("fn")) { if (farm_mode) { MYSERIAL.println(farm_no); } From c36b7be90ca9de65c75cc013a335cd9befc717ad Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Tue, 7 Nov 2017 11:36:41 +0100 Subject: [PATCH 3/4] SUPPORT_VERBOSITY initial version --- Firmware/Marlin_main.cpp | 25 +++-- Firmware/mesh_bed_calibration.cpp | 165 ++++++++++++++++++++++++------ 2 files changed, 154 insertions(+), 36 deletions(-) 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. From 67c76104a5f0135bf68d9f898a4d63387ba15d17 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Tue, 7 Nov 2017 11:39:11 +0100 Subject: [PATCH 4/4] Configuration_prusa updated --- Firmware/Configuration_prusa.h | 2 ++ 1 file changed, 2 insertions(+) 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