|
@@ -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
|
|
|
- }
|
|
|
|
|
|
- TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(oldpos));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @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_NO_Z)
|
|
|
- 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);
|
|
|
+ // 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
|
|
|
+
|
|
|
+ #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)
|
|
|
+ const xyz_pos_t back = current_position;
|
|
|
+ #endif
|
|
|
|
|
|
- TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back));
|
|
|
- }
|
|
|
+ #if ENABLED(NOZZLE_CLEAN_NO_Z)
|
|
|
+ do_blocking_move_to_xy(start);
|
|
|
+ #else
|
|
|
+ do_blocking_move_to(start);
|
|
|
+ #endif
|
|
|
|
|
|
- /**
|
|
|
- * @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;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- #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);
|
|
|
+ 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
|
|
|
- );
|
|
|
+ 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);
|
|
|
+ // Let's be safe
|
|
|
+ do_blocking_move_to_xy(start);
|
|
|
|
|
|
- TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back));
|
|
|
- }
|
|
|
+ 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
|
|
|
}
|
|
|
}
|
|
|
|