From b381e51a13d764ab6bd6f09279c4219280013fa6 Mon Sep 17 00:00:00 2001 From: Ted Hess Date: Fri, 29 Dec 2017 15:47:44 -0500 Subject: [PATCH] Add option to disable skew correction if XY calibration error is near perfect --- Firmware/Configuration.h | 2 +- Firmware/ConfigurationStore.cpp | 9 +- Firmware/language_all.cpp | 5 ++ Firmware/language_all.h | 2 + Firmware/language_en.h | 3 +- Firmware/mesh_bed_calibration.cpp | 145 +++++++++++++++--------------- 6 files changed, 90 insertions(+), 76 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 9049c8dc8..1340d732f 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -66,7 +66,7 @@ // E^2 address of custom MBC offsets array. // Correction of the bed leveling, in micrometers. // Current Range is: +/- 500um (stored as int16). -#define EEPROM_BED_CORRECTION_VALID 999 +#define EEPROM_BED_CORRECTION_VALID 499 #define EEPROM_BED_CORRECTION_OFFSETS (EEPROM_BED_CORRECTION_VALID - 16) // Currently running firmware, each digit stored as uint16_t. diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 0011e71df..68e1ad686 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -130,10 +130,11 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i, filament_size[2]); #endif #endif - /*MYSERIAL.print("Top address used:\n"); - MYSERIAL.print(i); - MYSERIAL.print("\n"); - */ +#if 0 + SERIAL_ECHO_START; + SERIAL_ECHOPAIR("Top address used: ", (unsigned long)i); + SERIAL_ECHOLN(""); +#endif char ver2[4]=EEPROM_VERSION; i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver2); // validate data diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index 8a7a3eb3a..fa36ef1cf 100644 --- a/Firmware/language_all.cpp +++ b/Firmware/language_all.cpp @@ -3077,6 +3077,11 @@ const char * const MSG_SILENT_MODE_ON_LANG_TABLE[LANG_NUM] PROGMEM = { MSG_SILENT_MODE_ON_DE }; +const char MSG_SKEW_CORRECTION_EN[] PROGMEM = "Very small XY skew. Disable skew correction?"; +const char * const MSG_SKEW_CORRECTION_LANG_TABLE[1] PROGMEM = { + MSG_SKEW_CORRECTION_EN +}; + const char MSG_SLIGHT_SKEW_EN[] PROGMEM = "Slight skew:"; const char MSG_SLIGHT_SKEW_CZ[] PROGMEM = "Lehke zkoseni:"; const char MSG_SLIGHT_SKEW_IT[] PROGMEM = "Incl. leggera:"; diff --git a/Firmware/language_all.h b/Firmware/language_all.h index 7e15e543b..a239c8105 100644 --- a/Firmware/language_all.h +++ b/Firmware/language_all.h @@ -562,6 +562,8 @@ extern const char* const MSG_SILENT_MODE_OFF_LANG_TABLE[LANG_NUM]; #define MSG_SILENT_MODE_OFF LANG_TABLE_SELECT(MSG_SILENT_MODE_OFF_LANG_TABLE) extern const char* const MSG_SILENT_MODE_ON_LANG_TABLE[LANG_NUM]; #define MSG_SILENT_MODE_ON LANG_TABLE_SELECT(MSG_SILENT_MODE_ON_LANG_TABLE) +extern const char* const MSG_SKEW_CORRECTION_LANG_TABLE[1]; +#define MSG_SKEW_CORRECTION LANG_TABLE_SELECT_EXPLICIT(MSG_SKEW_CORRECTION_LANG_TABLE, 0) extern const char* const MSG_SLIGHT_SKEW_LANG_TABLE[LANG_NUM]; #define MSG_SLIGHT_SKEW LANG_TABLE_SELECT(MSG_SLIGHT_SKEW_LANG_TABLE) extern const char* const MSG_SOFTWARE_RESET_LANG_TABLE[1]; diff --git a/Firmware/language_en.h b/Firmware/language_en.h index 7cbe2c7b0..316f99877 100644 --- a/Firmware/language_en.h +++ b/Firmware/language_en.h @@ -352,4 +352,5 @@ #define(lenght=20, lines=2) MSG_PLA_FILAMENT_LOADED "Is PLA filament loaded?" #define(lenght=20, lines=4) MSG_PLEASE_LOAD_PLA "Please load PLA filament first." #define(length=20, lines=8) MSG_FILE_CNT "Some files will not be sorted. Max. No. of files in 1 folder for sorting is 100." -#define(length=25, lines=1) MSG_M117_V2_CALIBRATION "M117 First layer cal." \ No newline at end of file +#define(length=25, lines=1) MSG_M117_V2_CALIBRATION "M117 First layer cal." +#define(length=20, lines=3) MSG_SKEW_CORRECTION "Very little skew detected. Disable correction?" diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 4569beb9f..91e84df6c 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -451,90 +451,95 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS( } #endif // SUPPORT_VERBOSITY - #if 1 if (result == BED_SKEW_OFFSET_DETECTION_PERFECT) { - if (verbosity_level > 0) - SERIAL_ECHOLNPGM("Very little skew detected. Disabling skew correction."); - // Just disable the skew correction. - vec_x[0] = MACHINE_AXIS_SCALE_X; - vec_x[1] = 0.f; - vec_y[0] = 0.f; - vec_y[1] = MACHINE_AXIS_SCALE_Y; - } - #else - if (result == BED_SKEW_OFFSET_DETECTION_PERFECT) { - #ifdef SUPPORT_VERBOSITY - if (verbosity_level > 0) - SERIAL_ECHOLNPGM("Very little skew detected. Orthogonalizing 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; - vec_y[0] = -sin(a1) * MACHINE_AXIS_SCALE_Y; - vec_y[1] = cos(a1) * MACHINE_AXIS_SCALE_Y; - // Refresh the offset. - cntr[0] = 0.f; - cntr[1] = 0.f; - float wx = 0.f; - float wy = 0.f; - for (int8_t i = 0; i < npts; ++ i) { - float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1]; - float y = vec_x[1] * measured_pts[i * 2] + vec_y[1] * measured_pts[i * 2 + 1]; - 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(""); - SERIAL_ECHOLNPGM("Weight_x:"); - MYSERIAL.print(w); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOLNPGM("cntr[0]:"); - MYSERIAL.print(cntr[0]); - SERIAL_ECHOLNPGM(""); - 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; + bool skew_correction = lcd_show_multiscreen_message_yes_no_and_wait_P(MSG_SKEW_CORRECTION, false, false); - #ifdef SUPPORT_VERBOSITY - if (verbosity_level >= 20) { - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOLNPGM("Weight_y:"); - MYSERIAL.print(w); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOLNPGM("cntr[1]:"); - MYSERIAL.print(cntr[1]); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOLNPGM("wy:"); - MYSERIAL.print(wy); - SERIAL_ECHOLNPGM(""); - SERIAL_ECHOLNPGM(""); - } - #endif // SUPPORT_VERBOSITY + lcd_update_enable(true); + lcd_update(2); + + if (skew_correction) { + #ifdef SUPPORT_VERBOSITY + if (verbosity_level > 0) + SERIAL_ECHOLNPGM("Very little skew detected. Disabling skew correction."); + #endif + // Just disable the skew correction. + vec_x[0] = MACHINE_AXIS_SCALE_X; + vec_x[1] = 0.f; + vec_y[0] = 0.f; + vec_y[1] = MACHINE_AXIS_SCALE_Y; + } else { + #ifdef SUPPORT_VERBOSITY + if (verbosity_level > 0) + SERIAL_ECHOLNPGM("Very little skew detected. Orthogonalizing the axes."); + #endif + // 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; + vec_y[0] = -sin(a1) * MACHINE_AXIS_SCALE_Y; + vec_y[1] = cos(a1) * MACHINE_AXIS_SCALE_Y; + // Refresh the offset. + cntr[0] = 0.f; + cntr[1] = 0.f; + float wx = 0.f; + float wy = 0.f; + for (int8_t i = 0; i < npts; ++ i) { + float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1]; + float y = vec_x[1] * measured_pts[i * 2] + vec_y[1] * measured_pts[i * 2 + 1]; + 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(""); + SERIAL_ECHOLNPGM("Weight_x:"); + MYSERIAL.print(w); + SERIAL_ECHOLNPGM(""); + SERIAL_ECHOLNPGM("cntr[0]:"); + MYSERIAL.print(cntr[0]); + SERIAL_ECHOLNPGM(""); + SERIAL_ECHOLNPGM("wx:"); + MYSERIAL.print(wx); } - cntr[0] /= wx; - cntr[1] /= wy; + #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("Final cntr values:"); - SERIAL_ECHOLNPGM("cntr[0]:"); - MYSERIAL.print(cntr[0]); + SERIAL_ECHOLNPGM("Weight_y:"); + MYSERIAL.print(w); SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("cntr[1]:"); MYSERIAL.print(cntr[1]); SERIAL_ECHOLNPGM(""); + SERIAL_ECHOLNPGM("wy:"); + MYSERIAL.print(wy); + 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:"); + SERIAL_ECHOLNPGM("cntr[0]:"); + MYSERIAL.print(cntr[0]); + SERIAL_ECHOLNPGM(""); + SERIAL_ECHOLNPGM("cntr[1]:"); + MYSERIAL.print(cntr[1]); + SERIAL_ECHOLNPGM(""); + } + #endif // SUPPORT_VERBOSITY + } } - #endif // Invert the transformation matrix made of vec_x, vec_y and cntr. {