From df4f80622eb262fe39cc898e0237257b2870aa7f Mon Sep 17 00:00:00 2001 From: plampix Date: Mon, 24 Apr 2023 01:12:47 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20NOZZLE=5FCLEAN=5FPATTERN=5F*=20(#25?= =?UTF-8?q?666)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 28 ++- Marlin/src/gcode/feature/clean/G12.cpp | 14 +- Marlin/src/inc/SanityCheck.h | 15 ++ Marlin/src/libs/nozzle.cpp | 277 +++++++++++++------------ buildroot/tests/rambo | 4 +- 5 files changed, 195 insertions(+), 143 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 19407b6158..6e2f409613 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2409,23 +2409,31 @@ //#define NOZZLE_CLEAN_FEATURE #if ENABLED(NOZZLE_CLEAN_FEATURE) - // Default number of pattern repetitions - #define NOZZLE_CLEAN_STROKES 12 + #define NOZZLE_CLEAN_PATTERN_LINE // Provide 'G12 P0' - a simple linear cleaning pattern + #define NOZZLE_CLEAN_PATTERN_ZIGZAG // Provide 'G12 P1' - a zigzag cleaning pattern + #define NOZZLE_CLEAN_PATTERN_CIRCLE // Provide 'G12 P2' - a circular cleaning pattern - // Default number of triangles - #define NOZZLE_CLEAN_TRIANGLES 3 + // Default pattern to use when 'P' is not provided to G12. One of the enabled options above. + #define NOZZLE_CLEAN_DEFAULT_PATTERN 0 + + #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE) + #define NOZZLE_CLEAN_STROKES 12 // Default number of pattern repetitions + #endif + + #if ENABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG) + #define NOZZLE_CLEAN_TRIANGLES 3 // Default number of triangles + #endif // Specify positions for each tool as { { X, Y, Z }, { X, Y, Z } } // Dual hotend system may use { { -20, (Y_BED_SIZE / 2), (Z_MIN_POS + 1) }, { 420, (Y_BED_SIZE / 2), (Z_MIN_POS + 1) }} #define NOZZLE_CLEAN_START_POINT { { 30, 30, (Z_MIN_POS + 1) } } #define NOZZLE_CLEAN_END_POINT { { 100, 60, (Z_MIN_POS + 1) } } - // Circular pattern radius - #define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5 - // Circular pattern circle fragments number - #define NOZZLE_CLEAN_CIRCLE_FN 10 - // Middle point of circle - #define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + #define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5 // (mm) Circular pattern radius + #define NOZZLE_CLEAN_CIRCLE_FN 10 // Circular pattern circle number of segments + #define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT // Middle point of circle + #endif // Move the nozzle to the initial position after cleaning #define NOZZLE_CLEAN_GOBACK diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp index 0113170f1d..597d8ce0a0 100644 --- a/Marlin/src/gcode/feature/clean/G12.cpp +++ b/Marlin/src/gcode/feature/clean/G12.cpp @@ -57,10 +57,16 @@ void GcodeSuite::G12() { } #endif - const uint8_t pattern = parser.ushortval('P', 0), - strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES), - objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES); - const float radius = parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS); + const uint8_t pattern = ( + #if COUNT_ENABLED(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE) > 1 + parser.ushortval('P', NOZZLE_CLEAN_DEFAULT_PATTERN) + #else + NOZZLE_CLEAN_DEFAULT_PATTERN + #endif + ); + const uint8_t strokes = TERN0(NOZZLE_CLEAN_PATTERN_LINEAR, parser.ushortval('S', NOZZLE_CLEAN_STROKES)), + objects = TERN0(NOZZLE_CLEAN_PATTERN_ZIGZAG, parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES)); + const float radius = TERN0(NOZZLE_CLEAN_PATTERN_CIRCLE, parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS)); const bool seenxyz = parser.seen("XYZ"); const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 196b1dc4e3..2c2e17f4e3 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -3816,6 +3816,21 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive."); #undef _CLEAN_ASSERT #endif +/** + * Sanity check nozzle cleaning pattern settings + */ +#if ENABLED(NOZZLE_CLEAN_FEATURE) + #if NONE(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE) + #error "NOZZLE_CLEAN_FEATURE requires at least one of NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, and/or NOZZLE_CLEAN_PATTERN_CIRCLE." + #elif NOZZLE_CLEAN_DEFAULT_PATTERN == 0 && DISABLED(NOZZLE_CLEAN_PATTERN_LINE) + #error "NOZZLE_CLEAN_DEFAULT_PATTERN 0 (LINE) is not available. Enable NOZZLE_CLEAN_PATTERN_LINE or set a different NOZZLE_CLEAN_DEFAULT_PATTERN." + #elif NOZZLE_CLEAN_DEFAULT_PATTERN == 1 && DISABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG) + #error "NOZZLE_CLEAN_DEFAULT_PATTERN 1 (ZIGZAG) is not available. Enable NOZZLE_CLEAN_PATTERN_ZIGZAG or set a different NOZZLE_CLEAN_DEFAULT_PATTERN." + #elif NOZZLE_CLEAN_DEFAULT_PATTERN == 2 && DISABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + #error "NOZZLE_CLEAN_DEFAULT_PATTERN 2 (CIRCLE) is not available. Enable NOZZLE_CLEAN_PATTERN_CIRCLE or set a different NOZZLE_CLEAN_DEFAULT_PATTERN." + #endif +#endif + /** * Sanity check for MIXING_EXTRUDER & DISTINCT_E_FACTORS these are not compatible */ diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index 74f61c33d0..8f44c69c5c 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -37,119 +37,125 @@ Nozzle nozzle; #if ENABLED(NOZZLE_CLEAN_FEATURE) - /** - * @brief Stroke clean pattern - * @details Wipes the nozzle back and forth in a linear movement - * - * @param start xyz_pos_t defining the starting point - * @param end xyz_pos_t defining the ending point - * @param strokes number of strokes to execute - */ - void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) { - #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t oldpos = current_position; - #endif - - // Move to the starting point - #if ENABLED(NOZZLE_CLEAN_NO_Z) - #if ENABLED(NOZZLE_CLEAN_NO_Y) - do_blocking_move_to_x(start.x); - #else - do_blocking_move_to_xy(start); + #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE) + /** + * @brief Stroke clean pattern + * @details Wipes the nozzle back and forth in a linear movement + * + * @param start xyz_pos_t defining the starting point + * @param end xyz_pos_t defining the ending point + * @param strokes number of strokes to execute + */ + void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) { + #if ENABLED(NOZZLE_CLEAN_GOBACK) + const xyz_pos_t oldpos = current_position; #endif - #else - do_blocking_move_to(start); - #endif - // Start the stroke pattern - LOOP_L_N(i, strokes >> 1) { - #if ENABLED(NOZZLE_CLEAN_NO_Y) - do_blocking_move_to_x(end.x); - do_blocking_move_to_x(start.x); + // Move to the starting point + #if ENABLED(NOZZLE_CLEAN_NO_Z) + #if ENABLED(NOZZLE_CLEAN_NO_Y) + do_blocking_move_to_x(start.x); + #else + do_blocking_move_to_xy(start); + #endif #else - do_blocking_move_to_xy(end); - do_blocking_move_to_xy(start); + do_blocking_move_to(start); #endif + + // Start the stroke pattern + LOOP_L_N(i, strokes >> 1) { + #if ENABLED(NOZZLE_CLEAN_NO_Y) + do_blocking_move_to_x(end.x); + do_blocking_move_to_x(start.x); + #else + do_blocking_move_to_xy(end); + do_blocking_move_to_xy(start); + #endif + } + + TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(oldpos)); } + #endif - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(oldpos)); - } + #if ENABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG) + /** + * @brief Zig-zag clean pattern + * @details Apply a zig-zag cleaning pattern + * + * @param start xyz_pos_t defining the starting point + * @param end xyz_pos_t defining the ending point + * @param strokes number of strokes to execute + * @param objects number of triangles to do + */ + void Nozzle::zigzag(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes, const uint8_t &objects) { + const xy_pos_t diff = end - start; + if (!diff.x || !diff.y) return; - /** - * @brief Zig-zag clean pattern - * @details Apply a zig-zag cleaning pattern - * - * @param start xyz_pos_t defining the starting point - * @param end xyz_pos_t defining the ending point - * @param strokes number of strokes to execute - * @param objects number of triangles to do - */ - void Nozzle::zigzag(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes, const uint8_t &objects) { - const xy_pos_t diff = end - start; - if (!diff.x || !diff.y) return; + #if ENABLED(NOZZLE_CLEAN_GOBACK) + const xyz_pos_t back = current_position; + #endif - #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t back = current_position; - #endif + #if ENABLED(NOZZLE_CLEAN_NO_Z) + do_blocking_move_to_xy(start); + #else + do_blocking_move_to(start); + #endif - #if ENABLED(NOZZLE_CLEAN_NO_Z) + const uint8_t zigs = objects << 1; + const bool horiz = ABS(diff.x) >= ABS(diff.y); // Do a horizontal wipe? + const float P = (horiz ? diff.x : diff.y) / zigs; // Period of each zig / zag + const xyz_pos_t *side; + LOOP_L_N(j, strokes) { + for (int8_t i = 0; i < zigs; i++) { + side = (i & 1) ? &end : &start; + if (horiz) + do_blocking_move_to_xy(start.x + i * P, side->y); + else + do_blocking_move_to_xy(side->x, start.y + i * P); + } + for (int8_t i = zigs; i >= 0; i--) { + side = (i & 1) ? &end : &start; + if (horiz) + do_blocking_move_to_xy(start.x + i * P, side->y); + else + do_blocking_move_to_xy(side->x, start.y + i * P); + } + } + + TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); + } + #endif + + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + /** + * @brief Circular clean pattern + * @details Apply a circular cleaning pattern + * + * @param start xyz_pos_t defining the middle of circle + * @param strokes number of strokes to execute + * @param radius radius of circle + */ + void Nozzle::circle(const xyz_pos_t &start, const xyz_pos_t &middle, const uint8_t &strokes, const_float_t radius) { + if (strokes == 0) return; + + #if ENABLED(NOZZLE_CLEAN_GOBACK) + const xyz_pos_t back = current_position; + #endif + TERN(NOZZLE_CLEAN_NO_Z, do_blocking_move_to_xy, do_blocking_move_to)(start); + + LOOP_L_N(s, strokes) + LOOP_L_N(i, NOZZLE_CLEAN_CIRCLE_FN) + do_blocking_move_to_xy( + middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius, + middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius + ); + + // Let's be safe do_blocking_move_to_xy(start); - #else - do_blocking_move_to(start); - #endif - const uint8_t zigs = objects << 1; - const bool horiz = ABS(diff.x) >= ABS(diff.y); // Do a horizontal wipe? - const float P = (horiz ? diff.x : diff.y) / zigs; // Period of each zig / zag - const xyz_pos_t *side; - LOOP_L_N(j, strokes) { - for (int8_t i = 0; i < zigs; i++) { - side = (i & 1) ? &end : &start; - if (horiz) - do_blocking_move_to_xy(start.x + i * P, side->y); - else - do_blocking_move_to_xy(side->x, start.y + i * P); - } - for (int8_t i = zigs; i >= 0; i--) { - side = (i & 1) ? &end : &start; - if (horiz) - do_blocking_move_to_xy(start.x + i * P, side->y); - else - do_blocking_move_to_xy(side->x, start.y + i * P); - } + TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); } - - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); - } - - /** - * @brief Circular clean pattern - * @details Apply a circular cleaning pattern - * - * @param start xyz_pos_t defining the middle of circle - * @param strokes number of strokes to execute - * @param radius radius of circle - */ - void Nozzle::circle(const xyz_pos_t &start, const xyz_pos_t &middle, const uint8_t &strokes, const_float_t radius) { - if (strokes == 0) return; - - #if ENABLED(NOZZLE_CLEAN_GOBACK) - const xyz_pos_t back = current_position; - #endif - TERN(NOZZLE_CLEAN_NO_Z, do_blocking_move_to_xy, do_blocking_move_to)(start); - - LOOP_L_N(s, strokes) - LOOP_L_N(i, NOZZLE_CLEAN_CIRCLE_FN) - do_blocking_move_to_xy( - middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius, - middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius - ); - - // Let's be safe - do_blocking_move_to_xy(start); - - TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back)); - } + #endif /** * @brief Clean the nozzle @@ -159,10 +165,25 @@ Nozzle nozzle; * @param argument depends on the cleaning pattern */ void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const_float_t radius, const uint8_t &objects, const uint8_t cleans) { - xyz_pos_t start[HOTENDS] = NOZZLE_CLEAN_START_POINT, end[HOTENDS] = NOZZLE_CLEAN_END_POINT, middle[HOTENDS] = NOZZLE_CLEAN_CIRCLE_MIDDLE; + xyz_pos_t start[HOTENDS] = NOZZLE_CLEAN_START_POINT, end[HOTENDS] = NOZZLE_CLEAN_END_POINT; + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + xyz_pos_t middle[HOTENDS] = NOZZLE_CLEAN_CIRCLE_MIDDLE; + #endif const uint8_t arrPos = EITHER(SINGLENOZZLE, MIXING_EXTRUDER) ? 0 : active_extruder; + switch (pattern) { + #if DISABLED(NOZZLE_CLEAN_PATTERN_LINE) + case 0: SERIAL_ECHOLNPGM("Pattern ", F("LINE"), " not enabled."); return; + #endif + #if DISABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG) + case 1: SERIAL_ECHOLNPGM("Pattern ", F("ZIGZAG"), " not enabled."); return; + #endif + #if DISABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + case 2: SERIAL_ECHOLNPGM("Pattern ", F("CIRCULAR"), " not enabled."); return; + #endif + } + #if NOZZLE_CLEAN_MIN_TEMP > 20 if (thermalManager.degTargetHotend(arrPos) < NOZZLE_CLEAN_MIN_TEMP) { #if ENABLED(NOZZLE_CLEAN_HEATUP) @@ -179,45 +200,47 @@ Nozzle nozzle; #if HAS_SOFTWARE_ENDSTOPS #define LIMIT_AXIS(A) do{ \ - LIMIT( start[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ - LIMIT(middle[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ - LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ + LIMIT( start[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ + LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ + TERN_(NOZZLE_CLEAN_PATTERN_CIRCLE, LIMIT(middle[arrPos].A, soft_endstop.min.A, soft_endstop.max.A)); \ }while(0) if (soft_endstop.enabled()) { - - LIMIT_AXIS(x); - LIMIT_AXIS(y); - LIMIT_AXIS(z); - const bool radiusOutOfRange = (middle[arrPos].x + radius > soft_endstop.max.x) - || (middle[arrPos].x - radius < soft_endstop.min.x) - || (middle[arrPos].y + radius > soft_endstop.max.y) - || (middle[arrPos].y - radius < soft_endstop.min.y); - if (radiusOutOfRange && pattern == 2) { - SERIAL_ECHOLNPGM("Warning: Radius Out of Range"); - return; - } - + LIMIT_AXIS(x); LIMIT_AXIS(y); LIMIT_AXIS(z); + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + if (pattern == 2 && !(WITHIN(middle[arrPos].x, soft_endstop.min.x + radius, soft_endstop.max.x - radius) + && WITHIN(middle[arrPos].y, soft_endstop.min.y + radius, soft_endstop.max.y - radius)) + ) { + SERIAL_ECHOLNPGM("Warning: Radius Out of Range"); return; + } + #endif } #endif - if (pattern == 2) { - if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) { - SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY"); - return; + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + if (pattern == 2 && !(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) { + SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY"); return; } - } - else { + #endif + + if (TERN1(NOZZLE_CLEAN_PATTERN_CIRCLE, pattern != 2)) { if (!TEST(cleans, X_AXIS)) start[arrPos].x = end[arrPos].x = current_position.x; if (!TEST(cleans, Y_AXIS)) start[arrPos].y = end[arrPos].y = current_position.y; } if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = current_position.z; switch (pattern) { - case 1: zigzag(start[arrPos], end[arrPos], strokes, objects); break; - case 2: circle(start[arrPos], middle[arrPos], strokes, radius); break; - default: stroke(start[arrPos], end[arrPos], strokes); + default: + #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE) + case 0: stroke(start[arrPos], end[arrPos], strokes); + #endif + #if ENABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG) + case 1: zigzag(start[arrPos], end[arrPos], strokes, objects); break; + #endif + #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE) + case 2: circle(start[arrPos], middle[arrPos], strokes, radius); break; + #endif } } diff --git a/buildroot/tests/rambo b/buildroot/tests/rambo index 040773230a..b50f220404 100755 --- a/buildroot/tests/rambo +++ b/buildroot/tests/rambo @@ -98,8 +98,8 @@ opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CO NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \ ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE ADVANCED_PAUSE_CONTINUOUS_PURGE FILAMENT_LOAD_UNLOAD_GCODES \ PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL -opt_add M100_FREE_MEMORY_DUMPER -opt_add M100_FREE_MEMORY_CORRUPTOR +opt_disable NOZZLE_CLEAN_PATTERN_CIRCLE +opt_add M100_FREE_MEMORY_DUMPER M100_FREE_MEMORY_CORRUPTOR exec_test $1 $2 "MINIRAMBO | RRDGFSC | ABL Linear Manual | M100 | PWM_MOTOR_CURRENT | M600..." "$3" #