2017-09-06 13:28:32 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 13:28:32 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 13:28:32 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-06 13:28:32 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-11-04 02:44:56 +01:00
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2019-03-17 05:43:06 +01:00
|
|
|
#if EITHER(NOZZLE_CLEAN_FEATURE, NOZZLE_PARK_FEATURE)
|
2017-11-04 02:44:56 +01:00
|
|
|
|
2017-02-24 23:41:44 +01:00
|
|
|
#include "nozzle.h"
|
|
|
|
|
2019-07-17 10:41:04 +02:00
|
|
|
Nozzle nozzle;
|
|
|
|
|
2020-01-03 02:01:38 +01:00
|
|
|
#include "../MarlinCore.h"
|
2017-09-08 05:33:16 +02:00
|
|
|
#include "../module/motion.h"
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2020-12-20 05:02:38 +01:00
|
|
|
#if NOZZLE_CLEAN_MIN_TEMP > 20
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-04 02:44:56 +01:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stroke clean pattern
|
|
|
|
* @details Wipes the nozzle back and forth in a linear movement
|
|
|
|
*
|
2019-09-29 11:25:39 +02:00
|
|
|
* @param start xyz_pos_t defining the starting point
|
|
|
|
* @param end xyz_pos_t defining the ending point
|
2017-11-04 02:44:56 +01:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
*/
|
2019-09-29 11:25:39 +02:00
|
|
|
void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) {
|
2021-03-24 11:40:28 +01:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
|
|
|
const xyz_pos_t oldpos = current_position;
|
|
|
|
#endif
|
2017-02-24 23:41:44 +01:00
|
|
|
|
|
|
|
// Move to the starting point
|
2019-07-14 13:58:53 +02:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Z)
|
2020-08-22 23:20:37 +02:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Y)
|
|
|
|
do_blocking_move_to_x(start.x);
|
|
|
|
#else
|
|
|
|
do_blocking_move_to_xy(start);
|
|
|
|
#endif
|
2019-07-14 13:58:53 +02:00
|
|
|
#else
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to(start);
|
2019-07-14 13:58:53 +02:00
|
|
|
#endif
|
2017-02-24 23:41:44 +01:00
|
|
|
|
|
|
|
// Start the stroke pattern
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(i, strokes >> 1) {
|
2020-08-22 23:20:37 +02:00
|
|
|
#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
|
2017-02-24 23:41:44 +01:00
|
|
|
}
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(oldpos));
|
2017-11-04 02:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Zig-zag clean pattern
|
|
|
|
* @details Apply a zig-zag cleaning pattern
|
|
|
|
*
|
2019-09-29 11:25:39 +02:00
|
|
|
* @param start xyz_pos_t defining the starting point
|
|
|
|
* @param end xyz_pos_t defining the ending point
|
2017-11-04 02:44:56 +01:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param objects number of triangles to do
|
|
|
|
*/
|
2019-09-29 11:25:39 +02:00
|
|
|
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;
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2021-03-24 11:40:28 +01:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
|
|
|
const xyz_pos_t back = current_position;
|
|
|
|
#endif
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2019-07-14 13:58:53 +02:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Z)
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to_xy(start);
|
2019-07-14 13:58:53 +02:00
|
|
|
#else
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to(start);
|
2019-07-14 13:58:53 +02:00
|
|
|
#endif
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2017-11-04 02:44:56 +01:00
|
|
|
const uint8_t zigs = objects << 1;
|
2019-09-29 11:25:39 +02:00
|
|
|
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;
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(j, strokes) {
|
2017-11-04 02:44:56 +01:00
|
|
|
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);
|
2017-02-24 23:41:44 +01:00
|
|
|
}
|
2017-11-04 02:44:56 +01:00
|
|
|
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);
|
2017-02-24 23:41:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back));
|
2017-11-04 02:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Circular clean pattern
|
|
|
|
* @details Apply a circular cleaning pattern
|
|
|
|
*
|
2019-09-29 11:25:39 +02:00
|
|
|
* @param start xyz_pos_t defining the middle of circle
|
2017-11-04 02:44:56 +01:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param radius radius of circle
|
|
|
|
*/
|
2021-04-02 00:59:57 +02:00
|
|
|
void Nozzle::circle(const xyz_pos_t &start, const xyz_pos_t &middle, const uint8_t &strokes, const_float_t radius) {
|
2017-02-24 23:41:44 +01:00
|
|
|
if (strokes == 0) return;
|
|
|
|
|
2021-03-24 11:40:28 +01:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
|
|
|
const xyz_pos_t back = current_position;
|
|
|
|
#endif
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN(NOZZLE_CLEAN_NO_Z, do_blocking_move_to_xy, do_blocking_move_to)(start);
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_L_N(s, strokes)
|
|
|
|
LOOP_L_N(i, NOZZLE_CLEAN_CIRCLE_FN)
|
2017-11-04 02:44:56 +01:00
|
|
|
do_blocking_move_to_xy(
|
2017-12-09 01:50:05 +01:00
|
|
|
middle.x + sin((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
|
|
|
|
middle.y + cos((RADIANS(360) / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius
|
2017-11-04 02:44:56 +01:00
|
|
|
);
|
2017-02-24 23:41:44 +01:00
|
|
|
|
|
|
|
// Let's be safe
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to_xy(start);
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(NOZZLE_CLEAN_GOBACK, do_blocking_move_to(back));
|
2017-11-04 02:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Clean the nozzle
|
|
|
|
* @details Starts the selected clean procedure pattern
|
|
|
|
*
|
|
|
|
* @param pattern one of the available patterns
|
|
|
|
* @param argument depends on the cleaning pattern
|
|
|
|
*/
|
2021-04-02 00:59:57 +02:00
|
|
|
void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const_float_t radius, const uint8_t &objects, const uint8_t cleans) {
|
2020-01-21 09:51:23 +01:00
|
|
|
xyz_pos_t start[HOTENDS] = NOZZLE_CLEAN_START_POINT, end[HOTENDS] = NOZZLE_CLEAN_END_POINT, middle[HOTENDS] = NOZZLE_CLEAN_CIRCLE_MIDDLE;
|
2019-07-17 10:41:04 +02:00
|
|
|
|
2020-04-27 12:22:06 +02:00
|
|
|
const uint8_t arrPos = ANY(SINGLENOZZLE, MIXING_EXTRUDER) ? 0 : active_extruder;
|
|
|
|
|
2020-12-20 05:02:38 +01:00
|
|
|
#if NOZZLE_CLEAN_MIN_TEMP > 20
|
|
|
|
if (thermalManager.degTargetHotend(arrPos) < NOZZLE_CLEAN_MIN_TEMP) {
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_HEATUP)
|
|
|
|
SERIAL_ECHOLNPGM("Nozzle too Cold - Heating");
|
|
|
|
thermalManager.setTargetHotend(NOZZLE_CLEAN_MIN_TEMP, arrPos);
|
|
|
|
thermalManager.wait_for_hotend(arrPos);
|
|
|
|
#else
|
|
|
|
SERIAL_ECHOLNPGM("Nozzle too cold - Skipping wipe");
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-27 12:22:06 +02:00
|
|
|
#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); \
|
|
|
|
}while(0)
|
|
|
|
|
2020-10-12 23:48:04 +02:00
|
|
|
if (soft_endstop.enabled()) {
|
2020-04-29 10:25:35 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-04-27 12:22:06 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-07-17 10:41:04 +02:00
|
|
|
if (pattern == 2) {
|
|
|
|
if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
|
2020-04-27 12:22:06 +02:00
|
|
|
SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY");
|
2019-07-17 10:41:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-04-27 12:22:06 +02:00
|
|
|
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;
|
2019-07-17 10:41:04 +02:00
|
|
|
}
|
2020-04-27 12:22:06 +02:00
|
|
|
if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = current_position.z;
|
2019-07-14 13:58:53 +02:00
|
|
|
|
2017-02-24 23:41:44 +01:00
|
|
|
switch (pattern) {
|
2020-04-27 12:22:06 +02:00
|
|
|
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);
|
2017-02-24 23:41:44 +01:00
|
|
|
}
|
2017-11-04 02:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_CLEAN_FEATURE
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_PARK_FEATURE)
|
|
|
|
|
2021-05-04 03:55:05 +02:00
|
|
|
float Nozzle::park_mode_0_height(const_float_t park_z) {
|
|
|
|
// Apply a minimum raise, if specified. Use park.z as a minimum height instead.
|
|
|
|
return _MAX(park_z, // Minimum height over 0 based on input
|
|
|
|
_MIN(Z_MAX_POS, // Maximum height is fixed
|
|
|
|
#ifdef NOZZLE_PARK_Z_RAISE_MIN
|
|
|
|
NOZZLE_PARK_Z_RAISE_MIN + // Minimum raise...
|
|
|
|
#endif
|
|
|
|
current_position.z // ...over current position
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-29 11:25:39 +02:00
|
|
|
void Nozzle::park(const uint8_t z_action, const xyz_pos_t &park/*=NOZZLE_PARK_POINT*/) {
|
2019-09-26 08:28:09 +02:00
|
|
|
constexpr feedRate_t fr_xy = NOZZLE_PARK_XY_FEEDRATE, fr_z = NOZZLE_PARK_Z_FEEDRATE;
|
2017-11-04 02:44:56 +01:00
|
|
|
|
|
|
|
switch (z_action) {
|
|
|
|
case 1: // Go to Z-park height
|
2017-12-25 08:38:06 +01:00
|
|
|
do_blocking_move_to_z(park.z, fr_z);
|
2017-02-24 23:41:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Raise by Z-park height
|
2019-09-29 11:25:39 +02:00
|
|
|
do_blocking_move_to_z(_MIN(current_position.z + park.z, Z_MAX_POS), fr_z);
|
2017-02-24 23:41:44 +01:00
|
|
|
break;
|
|
|
|
|
2021-05-04 03:55:05 +02:00
|
|
|
default: // Raise by NOZZLE_PARK_Z_RAISE_MIN, use park.z as a minimum height
|
|
|
|
do_blocking_move_to_z(park_mode_0_height(park.z), fr_z);
|
|
|
|
break;
|
2017-02-24 23:41:44 +01:00
|
|
|
}
|
|
|
|
|
2020-04-25 17:42:34 +02:00
|
|
|
do_blocking_move_to_xy(
|
|
|
|
TERN(NOZZLE_PARK_Y_ONLY, current_position, park).x,
|
|
|
|
TERN(NOZZLE_PARK_X_ONLY, current_position, park).y,
|
|
|
|
fr_xy
|
|
|
|
);
|
2019-03-11 01:06:52 +01:00
|
|
|
|
|
|
|
report_current_position();
|
2017-11-04 02:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_PARK_FEATURE
|
2017-02-24 23:41:44 +01:00
|
|
|
|
2017-11-04 02:44:56 +01:00
|
|
|
#endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE
|