From da2abad6368a804797cf7bf62e12f0a2cb936233 Mon Sep 17 00:00:00 2001 From: LVD-AC Date: Mon, 1 May 2017 14:05:59 +0200 Subject: [PATCH 1/3] Various cleanups of G33 - update comment section - redefined P5 grid - minor clean to probe radius routine - updated EEPROM version to V37 according remark in #6517 --- Marlin/Marlin_main.cpp | 170 +++++++++++++++++---------------- Marlin/configuration_store.cpp | 4 +- 2 files changed, 89 insertions(+), 85 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 5a31605383..322b5a93cf 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -61,7 +61,7 @@ * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location) * G31 - Dock sled (Z_PROBE_SLED only) * G32 - Undock sled (Z_PROBE_SLED only) - * G33 - Delta '1-4-7-point' auto calibration : "G33 V P " (Requires DELTA) + * G33 - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION) * G38 - Probe target - similar to G28 except it uses the Z_MIN_PROBE for all three axes * G90 - Use Absolute Coordinates * G91 - Use Relative Coordinates @@ -3904,7 +3904,7 @@ inline void gcode_G28() { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28"); #endif -} +} // G28 void home_all_axes() { gcode_G28(); } @@ -5057,46 +5057,64 @@ void home_all_axes() { gcode_G28(); } #if ENABLED(DELTA_AUTO_CALIBRATION) /** - * G33 - Delta '1-4-7-point' auto calibration (Requires DELTA) - * - * Usage: - * G33 - * - * Vn = verbose level (n=0-2 default 1) - * n=0 dry-run mode: setting + probe results / no calibration - * n=1 settings - * n=2 setting + probe results - * Pn = n=-7 -> +7 : n*n probe points - * calibrates height ('1 point'), endstops, and delta radius ('4 points') - * and tower angles with n > 2 ('7+ points') - * n=1 probes center / sets height only - * n=2 probes center and towers / sets height, endstops and delta radius - * n=3 probes all points: center, towers and opposite towers / sets all - * n>3 probes all points multiple times and averages - * A = abort 1 point delta height calibration after 1 probe - * O = use oposite tower points instead of tower points with 4 point calibration - * T = do not calibrate tower angles with 7+ point calibration + * G33 - Delta '1-4-7-point' Auto-Calibration + * Calibrate height, endstops, delta radius, and tower angles. + * + * Parameters: + * + * P Number of probe points: + * + * P1 Probe center and set height only. + * P2 Probe center and towers. Set height, endstops, and delta radius. + * P3 Probe all positions: center, towers and opposite towers. Set all. + * P4-P7 Probe all positions at different locations and average them. + * + * A Abort delta height calibration after 1 probe (only P1) + * + * O Use opposite tower points instead of tower points (only P2) + * + * T Don't calibrate tower angle corrections (P3-P7) + * + * V Verbose level: + * + * V0 Dry-run mode. Report settings and probe results. No calibration. + * V1 Report settings + * V2 Report settings and probe results */ inline void gcode_G33() { - stepper.synchronize(); + const int8_t probe_points = code_seen('P') ? code_value_int() : DELTA_CALIBRATION_DEFAULT_POINTS; + if (!WITHIN(probe_points, 1, 7)) { + SERIAL_PROTOCOLLNPGM("?(P)oints is implausible (1 to 7)."); + return; + } + + const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1; + if (!WITHIN(verbose_level, 0, 2)) { + SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-2)."); + return; + } + + const bool do_height_only = probe_points == 1, + do_center_and_towers = probe_points == 2, + do_all_positions = probe_points == 3, + do_circle_x2 = probe_points == 5, + do_circle_x3 = probe_points == 6, + do_circle_x4 = probe_points == 7, + probe_center_plus_3 = probe_points >= 3, + point_averaging = probe_points >= 4, + probe_center_plus_6 = probe_points >= 5; + + const char negating_parameter = do_height_only ? 'A' : do_center_and_towers ? 'O' : 'T'; + int8_t probe_mode = code_seen(negating_parameter) && code_value_bool() ? -probe_points : probe_points; + + SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate"); #if HAS_LEVELING set_bed_leveling_enabled(false); #endif - int8_t pp = (code_seen('P') ? code_value_int() : DELTA_CALIBRATION_DEFAULT_POINTS), - probe_mode = (WITHIN(pp, 1, 7) ? pp : DELTA_CALIBRATION_DEFAULT_POINTS); - - probe_mode = (code_seen('A') && probe_mode == 1 ? -probe_mode : probe_mode); - probe_mode = (code_seen('O') && probe_mode == 2 ? -probe_mode : probe_mode); - probe_mode = (code_seen('T') && probe_mode > 2 ? -probe_mode : probe_mode); - - int8_t verbose_level = (code_seen('V') ? code_value_byte() : 1); - - if (!WITHIN(verbose_level, 0, 2)) verbose_level = 1; - - gcode_G28(); + home_all_axes(); const static char save_message[] PROGMEM = "Save with M500 and/or copy to Configuration.h"; float test_precision, @@ -5109,31 +5127,17 @@ void home_all_axes() { gcode_G28(); } dr_old = delta_radius, zh_old = home_offset[Z_AXIS], alpha_old = delta_tower_angle_trim[A_AXIS], - beta_old = delta_tower_angle_trim[B_AXIS]; - int8_t iterations = 0, - probe_points = abs(probe_mode); - const bool pp_equals_1 = (probe_points == 1), - pp_equals_2 = (probe_points == 2), - pp_equals_3 = (probe_points == 3), - pp_equals_4 = (probe_points == 4), - pp_equals_5 = (probe_points == 5), - pp_equals_6 = (probe_points == 6), - pp_equals_7 = (probe_points == 7), - pp_greather_2 = (probe_points > 2), - pp_greather_3 = (probe_points > 3), - pp_greather_4 = (probe_points > 4), - pp_greather_5 = (probe_points > 5); - + beta_old = delta_tower_angle_trim[B_AXIS]; + // print settings - SERIAL_PROTOCOLLNPGM("G33 Auto Calibrate"); SERIAL_PROTOCOLPGM("Checking... AC"); if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)"); SERIAL_EOL; LCD_MESSAGEPGM("Checking... AC"); SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]); - if (!pp_equals_1) { + if (!do_height_only) { SERIAL_PROTOCOLPGM(" Ex:"); if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+'); SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2); @@ -5161,6 +5165,8 @@ void home_all_axes() { gcode_G28(); } DEPLOY_PROBE(); #endif + int8_t iterations = 0; + do { float z_at_pt[13] = { 0 }, @@ -5171,54 +5177,52 @@ void home_all_axes() { gcode_G28(); } test_precision = zero_std_dev; iterations++; - // probe the points + // Probe the points - if (!pp_equals_3 && !pp_equals_6) { // probe the centre + if (!do_all_positions && !do_circle_x3) { // probe the center setup_for_endstop_or_probe_move(); z_at_pt[0] += probe_pt(0.0, 0.0 , true, 1); clean_up_after_endstop_or_probe_move(); } - if (pp_greather_2) { // probe extra centre points - for (int8_t axis = (pp_greather_4 ? 11 : 9); axis > 0; axis -= (pp_greather_4 ? 2 : 4)) { + if (probe_center_plus_3) { // probe extra center points + for (int8_t axis = probe_center_plus_6 ? 11 : 9; axis > 0; axis -= probe_center_plus_6 ? 2 : 4) { setup_for_endstop_or_probe_move(); z_at_pt[0] += probe_pt( cos(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius), sin(RADIANS(180 + 30 * axis)) * (0.1 * delta_calibration_radius), true, 1); clean_up_after_endstop_or_probe_move(); } - z_at_pt[0] /= (pp_equals_5 ? 7 : probe_points); + z_at_pt[0] /= float(do_circle_x2 ? 7 : probe_points); } - if (!pp_equals_1) { // probe the radius - float start_circles = (pp_equals_7 ? -1.5 : pp_equals_6 || pp_equals_5 ? -1 : 0), - end_circles = -start_circles; + if (!do_height_only) { // probe the radius bool zig_zag = true; - for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; - axis += (pp_equals_2 ? 4 : pp_equals_3 || pp_equals_5 ? 2 : 1)) { - for (float circles = start_circles ; circles <= end_circles; circles++) { + for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; + axis += (do_center_and_towers ? 4 : do_all_positions ? 2 : 1)) { + float offset_circles = (do_circle_x4 ? (zig_zag ? 1.5 : 1.0) : + do_circle_x3 ? (zig_zag ? 1.0 : 0.5) : + do_circle_x2 ? (zig_zag ? 0.5 : 0.0) : 0); + for (float circles = -offset_circles ; circles <= offset_circles; circles++) { setup_for_endstop_or_probe_move(); z_at_pt[axis] += probe_pt( - cos(RADIANS(180 + 30 * axis)) * - (1 + circles * 0.1 * (zig_zag ? 1 : -1)) * delta_calibration_radius, - sin(RADIANS(180 + 30 * axis)) * - (1 + circles * 0.1 * (zig_zag ? 1 : -1)) * delta_calibration_radius, true, 1); + cos(RADIANS(180 + 30 * axis)) * delta_calibration_radius * + (1 + circles * 0.1 * (zig_zag ? 1 : -1)), + sin(RADIANS(180 + 30 * axis)) * delta_calibration_radius * + (1 + circles * 0.1 * (zig_zag ? 1 : -1)), true, 1); clean_up_after_endstop_or_probe_move(); } - start_circles += (pp_greather_5 ? (zig_zag ? 0.5 : -0.5) : 0); - end_circles = -start_circles; zig_zag = !zig_zag; - z_at_pt[axis] /= (pp_equals_7 ? (zig_zag ? 4.0 : 3.0) : - pp_equals_6 ? (zig_zag ? 3.0 : 2.0) : pp_equals_5 ? 3 : 1); + z_at_pt[axis] /= (2 * offset_circles + 1); } } - if (pp_greather_3 && !pp_equals_5) // average intermediates to tower and opposites - for (uint8_t axis = 1; axis < 13; axis += 2) + if (point_averaging) // average intermediates to tower and opposites + for (uint8_t axis = 1; axis <= 11; axis += 2) z_at_pt[axis] = (z_at_pt[axis] + (z_at_pt[axis + 1] + z_at_pt[(axis + 10) % 12 + 1]) / 2.0) / 2.0; S1 += z_at_pt[0]; S2 += sq(z_at_pt[0]); N++; - if (!pp_equals_1) // std dev from zero plane - for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; axis += (pp_equals_2 ? 4 : 2)) { + if (!do_height_only) // std dev from zero plane + for (uint8_t axis = (probe_mode == -2 ? 3 : 1); axis < 13; axis += (do_center_and_towers ? 4 : 2)) { S1 += z_at_pt[axis]; S2 += sq(z_at_pt[axis]); N++; @@ -5279,7 +5283,7 @@ void home_all_axes() { gcode_G28(); } e_delta[Y_AXIS] = Z1050(0) - Z0175(1) + Z0350(5) - Z0175(9) + Z0175(7) - Z0350(11) + Z0175(3); e_delta[Z_AXIS] = Z1050(0) - Z0175(1) - Z0175(5) + Z0350(9) + Z0175(7) + Z0175(11) - Z0350(3); r_delta = Z2250(0) - Z0375(1) - Z0375(5) - Z0375(9) - Z0375(7) - Z0375(11) - Z0375(3); - + if (probe_mode > 0) { // negative disables tower angles t_alpha = + Z0444(1) - Z0888(5) + Z0444(9) + Z0444(7) - Z0888(11) + Z0444(3); t_beta = - Z0888(1) + Z0444(5) + Z0444(9) - Z0888(7) + Z0444(11) + Z0444(3); @@ -5315,7 +5319,7 @@ void home_all_axes() { gcode_G28(); } SERIAL_PROTOCOLPGM(". c:"); if (z_at_pt[0] > 0) SERIAL_CHAR('+'); SERIAL_PROTOCOL_F(z_at_pt[0], 2); - if (probe_mode == 2 || pp_greather_2) { + if (probe_mode == 2 || probe_center_plus_3) { SERIAL_PROTOCOLPGM(" x:"); if (z_at_pt[1] >= 0) SERIAL_CHAR('+'); SERIAL_PROTOCOL_F(z_at_pt[1], 2); @@ -5327,8 +5331,8 @@ void home_all_axes() { gcode_G28(); } SERIAL_PROTOCOL_F(z_at_pt[9], 2); } if (probe_mode != -2) SERIAL_EOL; - if (probe_mode == -2 || pp_greather_2) { - if (pp_greather_2) { + if (probe_mode == -2 || probe_center_plus_3) { + if (probe_center_plus_3) { SERIAL_CHAR('.'); SERIAL_PROTOCOL_SP(13); } @@ -5364,7 +5368,7 @@ void home_all_axes() { gcode_G28(); } lcd_setstatus(mess); } SERIAL_PROTOCOLPAIR(".Height:", DELTA_HEIGHT + home_offset[Z_AXIS]); - if (!pp_equals_1) { + if (!do_height_only) { SERIAL_PROTOCOLPGM(" Ex:"); if (endstop_adj[A_AXIS] >= 0) SERIAL_CHAR('+'); SERIAL_PROTOCOL_F(endstop_adj[A_AXIS], 2); @@ -5411,7 +5415,7 @@ void home_all_axes() { gcode_G28(); } stepper.synchronize(); - gcode_G28(); + home_all_axes(); } while (zero_std_dev < test_precision && iterations < 31); @@ -6416,7 +6420,7 @@ inline void gcode_M42() { clean_up_after_endstop_or_probe_move(); // Re-enable bed level correction if it had been on - #if HAS_ABL + #if HAS_LEVELING set_bed_leveling_enabled(was_enabled); #endif @@ -8602,7 +8606,7 @@ inline void gcode_M503() { #else UNUSED(no_babystep); #endif - + #if ENABLED(DELTA) // correct the delta_height home_offset[Z_AXIS] -= diff; #endif @@ -9874,7 +9878,7 @@ void process_next_command() { #if ENABLED(DELTA_AUTO_CALIBRATION) - case 33: // G33: Delta Auto Calibrate + case 33: // G33: Delta Auto-Calibration gcode_G33(); break; diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 2427d2a043..039c69acb8 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -36,13 +36,13 @@ * */ -#define EEPROM_VERSION "V36" +#define EEPROM_VERSION "V37" // Change EEPROM version if these are changed: #define EEPROM_OFFSET 100 /** - * V35 EEPROM Layout: + * V37 EEPROM Layout: * * 100 Version (char x4) * 104 EEPROM Checksum (uint16_t) From 0449f69179cfa8c3085d84357263c94d16631147 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 2 May 2017 01:06:25 -0500 Subject: [PATCH 2/3] Cleanup patch to recent merge --- Marlin/ubl.cpp | 2 +- Marlin/ubl.h | 2 +- Marlin/ubl_G29.cpp | 2 +- Marlin/ubl_motion.cpp | 18 ++++++++---------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Marlin/ubl.cpp b/Marlin/ubl.cpp index 2c46a31669..aa1fc88739 100755 --- a/Marlin/ubl.cpp +++ b/Marlin/ubl.cpp @@ -39,7 +39,7 @@ void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); } bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); } - int ubl_cnt=0; + uint8_t ubl_cnt = 0; static void serial_echo_xy(const uint16_t x, const uint16_t y) { SERIAL_CHAR('('); diff --git a/Marlin/ubl.h b/Marlin/ubl.h index 70ddf6bba9..63aa10cb59 100644 --- a/Marlin/ubl.h +++ b/Marlin/ubl.h @@ -66,7 +66,7 @@ void gcode_G26(); void gcode_G29(); - extern int ubl_cnt; + extern uint8_t ubl_cnt; /////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Marlin/ubl_G29.cpp b/Marlin/ubl_G29.cpp index c21a1a2eef..b2c4a7ef41 100644 --- a/Marlin/ubl_G29.cpp +++ b/Marlin/ubl_G29.cpp @@ -1195,7 +1195,7 @@ SERIAL_EOL; safe_delay(50); - SERIAL_PROTOCOLLNPAIR("UBL object count: ", ubl_cnt); + SERIAL_PROTOCOLLNPAIR("UBL object count: ", (int)ubl_cnt); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) SERIAL_PROTOCOLLNPAIR("planner.z_fade_height : ", planner.z_fade_height); diff --git a/Marlin/ubl_motion.cpp b/Marlin/ubl_motion.cpp index a2fe2e99fa..cd211c96ba 100644 --- a/Marlin/ubl_motion.cpp +++ b/Marlin/ubl_motion.cpp @@ -1,4 +1,3 @@ - /** * Marlin 3D Printer Firmware * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] @@ -275,15 +274,14 @@ if (y != start[Y_AXIS]) { if (!inf_normalized_flag) { -// on_axis_distance = y - start[Y_AXIS]; + //on_axis_distance = y - start[Y_AXIS]; on_axis_distance = use_x_dist ? x - start[X_AXIS] : y - start[Y_AXIS]; -// on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; -// on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; - -// on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; -// on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist; z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist; @@ -350,11 +348,11 @@ if (x != start[X_AXIS]) { if (!inf_normalized_flag) { -// on_axis_distance = x - start[X_AXIS]; + //on_axis_distance = x - start[X_AXIS]; on_axis_distance = use_x_dist ? x - start[X_AXIS] : y - start[Y_AXIS]; -// on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; -// on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS]; + //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS]; e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist; // is based on X or Y because this is a horizontal move z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist; From ca1dd739a3bed730ca76606d65423034cab2a67e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 2 May 2017 13:50:36 -0500 Subject: [PATCH 3/3] Organize ubl.h defines by the files they serve --- Marlin/ubl.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Marlin/ubl.h b/Marlin/ubl.h index 63aa10cb59..73f9b1c0ef 100644 --- a/Marlin/ubl.h +++ b/Marlin/ubl.h @@ -40,29 +40,38 @@ float distance; // When populated, the distance from the search location } mesh_index_pair; + // ubl.cpp + + void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y); + void bit_set(uint16_t bits[16], uint8_t x, uint8_t y); + bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y); + + // ubl_motion.cpp + + void debug_current_and_destination(const char * const title); + void ubl_line_to_destination(const float&, uint8_t); + + // ubl_G29.cpp + enum MeshPointType { INVALID, REAL, SET_IN_BITMAP }; void dump(char * const str, const float &f); - bool ubl_lcd_clicked(); void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool); - void debug_current_and_destination(const char * const title); - void ubl_line_to_destination(const float&, uint8_t); void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool); float measure_business_card_thickness(const float&); mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, unsigned int[16], bool); void shift_mesh_height(); + void fine_tune_mesh(const float&, const float&, const bool); bool g29_parameter_parsing(); void g29_what_command(); void g29_eeprom_dump(); void g29_compare_current_mesh_to_stored_mesh(); - void fine_tune_mesh(const float&, const float&, const bool); - void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y); - void bit_set(uint16_t bits[16], uint8_t x, uint8_t y); - bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y); + + // External references + char *ftostr43sign(const float&, char); - + bool ubl_lcd_clicked(); void home_all_axes(); - void gcode_G26(); void gcode_G29(); @@ -75,7 +84,6 @@ void lcd_quick_feedback(); #endif - #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1)) #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))