2017-09-06 06:28:32 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-06 06:28:32 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-06 06:28:32 -05: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2019-03-16 23:43:06 -05:00
|
|
|
#if EITHER(NOZZLE_CLEAN_FEATURE, NOZZLE_PARK_FEATURE)
|
2017-11-03 20:44:56 -05:00
|
|
|
|
2017-02-24 16:41:44 -06:00
|
|
|
#include "nozzle.h"
|
|
|
|
|
2019-07-17 03:41:04 -05:00
|
|
|
Nozzle nozzle;
|
|
|
|
|
2017-09-06 06:28:32 -05:00
|
|
|
#include "../Marlin.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
#include "../module/motion.h"
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stroke clean pattern
|
|
|
|
* @details Wipes the nozzle back and forth in a linear movement
|
|
|
|
*
|
2019-09-29 04:25:39 -05:00
|
|
|
* @param start xyz_pos_t defining the starting point
|
|
|
|
* @param end xyz_pos_t defining the ending point
|
2017-11-03 20:44:56 -05:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
void Nozzle::stroke(const xyz_pos_t &start, const xyz_pos_t &end, const uint8_t &strokes) {
|
2017-02-24 16:41:44 -06:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyz_pos_t oldpos = current_position;
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
|
|
|
// Move to the starting point
|
2019-07-14 06:58:53 -05:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Z)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
|
|
|
// Start the stroke pattern
|
2017-11-03 20:44:56 -05:00
|
|
|
for (uint8_t i = 0; i < (strokes >> 1); i++) {
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(end);
|
|
|
|
do_blocking_move_to_xy(start);
|
2017-02-24 16:41:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(oldpos);
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Zig-zag clean pattern
|
|
|
|
* @details Apply a zig-zag cleaning pattern
|
|
|
|
*
|
2019-09-29 04:25:39 -05:00
|
|
|
* @param start xyz_pos_t defining the starting point
|
|
|
|
* @param end xyz_pos_t defining the ending point
|
2017-11-03 20:44:56 -05:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param objects number of triangles to do
|
|
|
|
*/
|
2019-09-29 04:25:39 -05: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 16:41:44 -06:00
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyz_pos_t back = current_position;
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2019-07-14 06:58:53 -05:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Z)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
const uint8_t zigs = objects << 1;
|
2019-09-29 04:25:39 -05: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;
|
2017-11-03 20:44:56 -05:00
|
|
|
for (uint8_t j = 0; j < strokes; j++) {
|
|
|
|
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 16:41:44 -06:00
|
|
|
}
|
2017-11-03 20:44:56 -05: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 16:41:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(back);
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Circular clean pattern
|
|
|
|
* @details Apply a circular cleaning pattern
|
|
|
|
*
|
2019-09-29 04:25:39 -05:00
|
|
|
* @param start xyz_pos_t defining the middle of circle
|
2017-11-03 20:44:56 -05:00
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param radius radius of circle
|
|
|
|
*/
|
2019-09-29 04:25:39 -05:00
|
|
|
void Nozzle::circle(const xyz_pos_t &start, const xyz_pos_t &middle, const uint8_t &strokes, const float &radius) {
|
2017-02-24 16:41:44 -06:00
|
|
|
if (strokes == 0) return;
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
const xyz_pos_t back = current_position;
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2019-07-14 06:58:53 -05:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_NO_Z)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#else
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(start);
|
2019-07-14 06:58:53 -05:00
|
|
|
#endif
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
for (uint8_t s = 0; s < strokes; s++)
|
|
|
|
for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
|
|
|
|
do_blocking_move_to_xy(
|
2017-12-08 18:50:05 -06: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-03 20:44:56 -05:00
|
|
|
);
|
2017-02-24 16:41:44 -06:00
|
|
|
|
|
|
|
// Let's be safe
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(start);
|
2017-02-24 16:41:44 -06:00
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to(back);
|
2017-02-24 16:41:44 -06:00
|
|
|
#endif
|
2017-11-03 20:44:56 -05: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
|
|
|
|
*/
|
2019-07-17 03:41:04 -05:00
|
|
|
void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) {
|
2019-09-29 04:25:39 -05:00
|
|
|
xyz_pos_t start = NOZZLE_CLEAN_START_POINT, end = NOZZLE_CLEAN_END_POINT;
|
2019-07-17 03:41:04 -05:00
|
|
|
|
|
|
|
if (pattern == 2) {
|
|
|
|
if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
|
|
|
|
SERIAL_ECHOLNPGM("Warning : Clean Circle requires XY");
|
|
|
|
return;
|
|
|
|
}
|
2019-09-29 04:25:39 -05:00
|
|
|
constexpr xyz_pos_t middle NOZZLE_CLEAN_CIRCLE_MIDDLE;
|
|
|
|
end = middle;
|
2019-07-17 03:41:04 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!TEST(cleans, X_AXIS)) start.x = end.x = current_position.x;
|
|
|
|
if (!TEST(cleans, Y_AXIS)) start.y = end.y = current_position.y;
|
2019-07-17 03:41:04 -05:00
|
|
|
}
|
2019-09-29 04:25:39 -05:00
|
|
|
if (!TEST(cleans, Z_AXIS)) start.z = end.z = current_position.z;
|
2019-07-14 06:58:53 -05:00
|
|
|
|
2017-02-24 16:41:44 -06:00
|
|
|
switch (pattern) {
|
2019-09-14 03:05:10 -05:00
|
|
|
case 1: zigzag(start, end, strokes, objects); break;
|
|
|
|
case 2: circle(start, end, strokes, radius); break;
|
|
|
|
default: stroke(start, end, strokes);
|
2017-02-24 16:41:44 -06:00
|
|
|
}
|
2017-11-03 20:44:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_CLEAN_FEATURE
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_PARK_FEATURE)
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
void Nozzle::park(const uint8_t z_action, const xyz_pos_t &park/*=NOZZLE_PARK_POINT*/) {
|
2019-09-26 01:28:09 -05:00
|
|
|
constexpr feedRate_t fr_xy = NOZZLE_PARK_XY_FEEDRATE, fr_z = NOZZLE_PARK_Z_FEEDRATE;
|
2017-11-03 20:44:56 -05:00
|
|
|
|
|
|
|
switch (z_action) {
|
|
|
|
case 1: // Go to Z-park height
|
2017-12-25 01:38:06 -06:00
|
|
|
do_blocking_move_to_z(park.z, fr_z);
|
2017-02-24 16:41:44 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Raise by Z-park height
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_z(_MIN(current_position.z + park.z, Z_MAX_POS), fr_z);
|
2017-02-24 16:41:44 -06:00
|
|
|
break;
|
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
default: // Raise to at least the Z-park height
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_z(_MAX(park.z, current_position.z), fr_z);
|
2017-02-24 16:41:44 -06:00
|
|
|
}
|
|
|
|
|
2019-09-29 04:25:39 -05:00
|
|
|
do_blocking_move_to_xy(park, fr_xy);
|
2019-03-10 19:06:52 -05:00
|
|
|
|
|
|
|
report_current_position();
|
2017-11-03 20:44:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_PARK_FEATURE
|
2017-02-24 16:41:44 -06:00
|
|
|
|
2017-11-03 20:44:56 -05:00
|
|
|
#endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE
|