NOZZLE_CLEAN_PATTERN_* (#25666)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
plampix 2023-04-24 01:12:47 +02:00 committed by GitHub
parent 9902097d91
commit df4f80622e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 195 additions and 143 deletions

View file

@ -2409,23 +2409,31 @@
//#define NOZZLE_CLEAN_FEATURE //#define NOZZLE_CLEAN_FEATURE
#if ENABLED(NOZZLE_CLEAN_FEATURE) #if ENABLED(NOZZLE_CLEAN_FEATURE)
// Default number of pattern repetitions #define NOZZLE_CLEAN_PATTERN_LINE // Provide 'G12 P0' - a simple linear cleaning pattern
#define NOZZLE_CLEAN_STROKES 12 #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 // Default pattern to use when 'P' is not provided to G12. One of the enabled options above.
#define NOZZLE_CLEAN_TRIANGLES 3 #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 } } // 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) }} // 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_START_POINT { { 30, 30, (Z_MIN_POS + 1) } }
#define NOZZLE_CLEAN_END_POINT { { 100, 60, (Z_MIN_POS + 1) } } #define NOZZLE_CLEAN_END_POINT { { 100, 60, (Z_MIN_POS + 1) } }
// Circular pattern radius #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE)
#define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5 #define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5 // (mm) Circular pattern radius
// Circular pattern circle fragments number #define NOZZLE_CLEAN_CIRCLE_FN 10 // Circular pattern circle number of segments
#define NOZZLE_CLEAN_CIRCLE_FN 10 #define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT // Middle point of circle
// Middle point of circle #endif
#define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT
// Move the nozzle to the initial position after cleaning // Move the nozzle to the initial position after cleaning
#define NOZZLE_CLEAN_GOBACK #define NOZZLE_CLEAN_GOBACK

View file

@ -57,10 +57,16 @@ void GcodeSuite::G12() {
} }
#endif #endif
const uint8_t pattern = parser.ushortval('P', 0), const uint8_t pattern = (
strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES), #if COUNT_ENABLED(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE) > 1
objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES); parser.ushortval('P', NOZZLE_CLEAN_DEFAULT_PATTERN)
const float radius = parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS); #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 bool seenxyz = parser.seen("XYZ");
const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0) const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0)

View file

@ -3816,6 +3816,21 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#undef _CLEAN_ASSERT #undef _CLEAN_ASSERT
#endif #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 * Sanity check for MIXING_EXTRUDER & DISTINCT_E_FACTORS these are not compatible
*/ */

View file

@ -37,119 +37,125 @@ Nozzle nozzle;
#if ENABLED(NOZZLE_CLEAN_FEATURE) #if ENABLED(NOZZLE_CLEAN_FEATURE)
/** #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE)
* @brief Stroke clean pattern /**
* @details Wipes the nozzle back and forth in a linear movement * @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 start xyz_pos_t defining the starting point
* @param strokes number of strokes to execute * @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) void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) {
const xyz_pos_t oldpos = current_position; #if ENABLED(NOZZLE_CLEAN_GOBACK)
#endif const xyz_pos_t oldpos = current_position;
// 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 #endif
#else
do_blocking_move_to(start);
#endif
// Start the stroke pattern // Move to the starting point
LOOP_L_N(i, strokes >> 1) { #if ENABLED(NOZZLE_CLEAN_NO_Z)
#if ENABLED(NOZZLE_CLEAN_NO_Y) #if ENABLED(NOZZLE_CLEAN_NO_Y)
do_blocking_move_to_x(end.x); do_blocking_move_to_x(start.x);
do_blocking_move_to_x(start.x); #else
do_blocking_move_to_xy(start);
#endif
#else #else
do_blocking_move_to_xy(end); do_blocking_move_to(start);
do_blocking_move_to_xy(start);
#endif #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;
/** #if ENABLED(NOZZLE_CLEAN_GOBACK)
* @brief Zig-zag clean pattern const xyz_pos_t back = current_position;
* @details Apply a zig-zag cleaning pattern #endif
*
* @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) #if ENABLED(NOZZLE_CLEAN_NO_Z)
const xyz_pos_t back = current_position; do_blocking_move_to_xy(start);
#endif #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); do_blocking_move_to_xy(start);
#else
do_blocking_move_to(start);
#endif
const uint8_t zigs = objects << 1; TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back));
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);
}
} }
#endif
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));
}
/** /**
* @brief Clean the nozzle * @brief Clean the nozzle
@ -159,10 +165,25 @@ Nozzle nozzle;
* @param argument depends on the cleaning pattern * @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) { 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; 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 NOZZLE_CLEAN_MIN_TEMP > 20
if (thermalManager.degTargetHotend(arrPos) < NOZZLE_CLEAN_MIN_TEMP) { if (thermalManager.degTargetHotend(arrPos) < NOZZLE_CLEAN_MIN_TEMP) {
#if ENABLED(NOZZLE_CLEAN_HEATUP) #if ENABLED(NOZZLE_CLEAN_HEATUP)
@ -179,45 +200,47 @@ Nozzle nozzle;
#if HAS_SOFTWARE_ENDSTOPS #if HAS_SOFTWARE_ENDSTOPS
#define LIMIT_AXIS(A) do{ \ #define LIMIT_AXIS(A) do{ \
LIMIT( start[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ 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( 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) }while(0)
if (soft_endstop.enabled()) { if (soft_endstop.enabled()) {
LIMIT_AXIS(x); LIMIT_AXIS(y); LIMIT_AXIS(z);
LIMIT_AXIS(x); #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE)
LIMIT_AXIS(y); if (pattern == 2 && !(WITHIN(middle[arrPos].x, soft_endstop.min.x + radius, soft_endstop.max.x - radius)
LIMIT_AXIS(z); && WITHIN(middle[arrPos].y, soft_endstop.min.y + radius, soft_endstop.max.y - radius))
const bool radiusOutOfRange = (middle[arrPos].x + radius > soft_endstop.max.x) ) {
|| (middle[arrPos].x - radius < soft_endstop.min.x) SERIAL_ECHOLNPGM("Warning: Radius Out of Range"); return;
|| (middle[arrPos].y + radius > soft_endstop.max.y) }
|| (middle[arrPos].y - radius < soft_endstop.min.y); #endif
if (radiusOutOfRange && pattern == 2) {
SERIAL_ECHOLNPGM("Warning: Radius Out of Range");
return;
}
} }
#endif #endif
if (pattern == 2) { #if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE)
if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) { if (pattern == 2 && !(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY"); SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY"); return;
return;
} }
} #endif
else {
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, 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, 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; if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = current_position.z;
switch (pattern) { switch (pattern) {
case 1: zigzag(start[arrPos], end[arrPos], strokes, objects); break; default:
case 2: circle(start[arrPos], middle[arrPos], strokes, radius); break; #if ENABLED(NOZZLE_CLEAN_PATTERN_LINE)
default: stroke(start[arrPos], end[arrPos], strokes); 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
} }
} }

View file

@ -98,8 +98,8 @@ opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CO
NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \ NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \
ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE ADVANCED_PAUSE_CONTINUOUS_PURGE FILAMENT_LOAD_UNLOAD_GCODES \ ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE ADVANCED_PAUSE_CONTINUOUS_PURGE FILAMENT_LOAD_UNLOAD_GCODES \
PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL
opt_add M100_FREE_MEMORY_DUMPER opt_disable NOZZLE_CLEAN_PATTERN_CIRCLE
opt_add M100_FREE_MEMORY_CORRUPTOR 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" exec_test $1 $2 "MINIRAMBO | RRDGFSC | ABL Linear Manual | M100 | PWM_MOTOR_CURRENT | M600..." "$3"
# #