2017-09-06 11:28:32 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* 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-04 01:44:56 +00:00
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
|
|
|
|
|
2017-02-24 22:41:44 +00:00
|
|
|
#include "nozzle.h"
|
|
|
|
|
2017-09-06 11:28:32 +00:00
|
|
|
#include "../Marlin.h"
|
2017-09-08 03:33:16 +00:00
|
|
|
#include "../module/motion.h"
|
2017-02-24 22:41:44 +00:00
|
|
|
#include "point_t.h"
|
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stroke clean pattern
|
|
|
|
* @details Wipes the nozzle back and forth in a linear movement
|
|
|
|
*
|
|
|
|
* @param start point_t defining the starting point
|
|
|
|
* @param end point_t defining the ending point
|
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
*/
|
|
|
|
void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
|
2017-02-24 22:41:44 +00:00
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
|
|
#endif
|
2017-02-24 22:41:44 +00:00
|
|
|
|
|
|
|
// Move to the starting point
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(start.x, start.y, start.z);
|
2017-02-24 22:41:44 +00:00
|
|
|
|
|
|
|
// Start the stroke pattern
|
2017-11-04 01:44:56 +00:00
|
|
|
for (uint8_t i = 0; i < (strokes >> 1); i++) {
|
2017-02-24 22:41:44 +00:00
|
|
|
do_blocking_move_to_xy(end.x, end.y);
|
|
|
|
do_blocking_move_to_xy(start.x, start.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(ix, iy, iz);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Zig-zag clean pattern
|
|
|
|
* @details Apply a zig-zag cleaning pattern
|
|
|
|
*
|
|
|
|
* @param start point_t defining the starting point
|
|
|
|
* @param end point_t defining the ending point
|
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param objects number of triangles to do
|
|
|
|
*/
|
|
|
|
void Nozzle::zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
|
|
|
|
const float diffx = end.x - start.x, diffy = end.y - start.y;
|
|
|
|
if (!diffx || !diffy) return;
|
2017-02-24 22:41:44 +00:00
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
|
|
#endif
|
2017-02-24 22:41:44 +00:00
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(start.x, start.y, start.z);
|
2017-02-24 22:41:44 +00:00
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
const uint8_t zigs = objects << 1;
|
2018-05-13 06:10:34 +00:00
|
|
|
const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe?
|
2017-11-04 01:44:56 +00:00
|
|
|
const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
|
|
|
|
const point_t *side;
|
|
|
|
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 22:41:44 +00:00
|
|
|
}
|
2017-11-04 01:44:56 +00: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 22:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(ix, iy, iz);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Circular clean pattern
|
|
|
|
* @details Apply a circular cleaning pattern
|
|
|
|
*
|
|
|
|
* @param start point_t defining the middle of circle
|
|
|
|
* @param strokes number of strokes to execute
|
|
|
|
* @param radius radius of circle
|
|
|
|
*/
|
|
|
|
void Nozzle::circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
|
2017-02-24 22:41:44 +00:00
|
|
|
if (strokes == 0) return;
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
|
|
#endif
|
2017-02-24 22:41:44 +00:00
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(start.x, start.y, start.z);
|
2017-02-24 22:41:44 +00:00
|
|
|
|
2017-11-04 01:44:56 +00: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-09 00:50:05 +00: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 01:44:56 +00:00
|
|
|
);
|
2017-02-24 22:41:44 +00:00
|
|
|
|
|
|
|
// Let's be safe
|
|
|
|
do_blocking_move_to_xy(start.x, start.y);
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
2017-11-04 01:44:56 +00:00
|
|
|
do_blocking_move_to(ix, iy, iz);
|
2017-02-24 22:41:44 +00:00
|
|
|
#endif
|
2017-11-04 01:44:56 +00: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
|
|
|
|
*/
|
|
|
|
void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects/*=0*/) {
|
2017-02-24 22:41:44 +00:00
|
|
|
switch (pattern) {
|
|
|
|
case 1:
|
2017-11-04 01:44:56 +00:00
|
|
|
zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
|
2017-02-24 22:41:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2017-11-04 01:44:56 +00:00
|
|
|
circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
|
2017-02-24 22:41:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-04 01:44:56 +00:00
|
|
|
stroke(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes);
|
2017-02-24 22:41:44 +00:00
|
|
|
}
|
2017-11-04 01:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_CLEAN_FEATURE
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_PARK_FEATURE)
|
|
|
|
|
2018-01-04 04:39:12 +00:00
|
|
|
void Nozzle::park(const uint8_t z_action, const point_t &park /*= NOZZLE_PARK_POINT*/) {
|
2017-12-25 07:38:06 +00:00
|
|
|
const float fr_xy = NOZZLE_PARK_XY_FEEDRATE;
|
|
|
|
const float fr_z = NOZZLE_PARK_Z_FEEDRATE;
|
2017-11-04 01:44:56 +00:00
|
|
|
|
|
|
|
switch (z_action) {
|
|
|
|
case 1: // Go to Z-park height
|
2017-12-25 07:38:06 +00:00
|
|
|
do_blocking_move_to_z(park.z, fr_z);
|
2017-02-24 22:41:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // Raise by Z-park height
|
2018-05-13 06:10:34 +00:00
|
|
|
do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
|
2017-02-24 22:41:44 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
default: // Raise to at least the Z-park height
|
2018-05-13 06:10:34 +00:00
|
|
|
do_blocking_move_to_z(MAX(park.z, current_position[Z_AXIS]), fr_z);
|
2017-02-24 22:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-25 07:38:06 +00:00
|
|
|
do_blocking_move_to_xy(park.x, park.y, fr_xy);
|
2017-11-04 01:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NOZZLE_PARK_FEATURE
|
2017-02-24 22:41:44 +00:00
|
|
|
|
2017-11-04 01:44:56 +00:00
|
|
|
#endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE
|