Improves G12 zig-zag pattern

2.0.x
João Brázio 9 years ago
parent b05a75655a
commit 021544f572

@ -801,15 +801,20 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
// "strokes" i.e. back-and-forth movements between the starting and end // "strokes" i.e. back-and-forth movements between the starting and end
// points. // points.
// //
// P1: This starts a zig-zag pattern between (Xs, Ys) and (Xe, Ye), "S" // P1: This starts a zig-zag pattern between (X0, Y0) and (X1, Y1), "T"
// defines the number of zig-zag triangles to be done. Each "side" // defines the number of zig-zag triangles to be done. "S" defines the
// cannot be less than 5mm. As an example "G12 P1 S3" will execute: // number of strokes aka one back-and-forth movement. As an example
// // sending "G12 P1 S1 T3" will execute:
// /| /| /| (Xe, Ye) //
// / | / | / | // --
// / | / | / | // | (X0, Y1) | /\ /\ /\ | (X1, Y1)
// (Xs, Ys) / |/ |/ | // | | / \ / \ / \ |
// // A | | / \ / \ / \ |
// | | / \ / \ / \ |
// | (X0, Y0) | / \/ \/ \ | (X1, Y0)
// -- +--------------------------------+
// |________|_________|_________|
// T1 T2 T3
// //
// Caveats: End point Z should use the same value as Start point Z. // Caveats: End point Z should use the same value as Start point Z.
// //
@ -820,8 +825,8 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
#if ENABLED(CLEAN_NOZZLE_FEATURE) #if ENABLED(CLEAN_NOZZLE_FEATURE)
#define CLEAN_NOZZLE_STROKES 12 #define CLEAN_NOZZLE_STROKES 12
#define CLEAN_NOZZLE_START_PT { 30, 30, (Z_MIN_POS + 1), 0} #define CLEAN_NOZZLE_START_PT { 30, 30, (Z_MIN_POS + 5), 0}
#define CLEAN_NOZZLE_END_PT {100, 60, (Z_MIN_POS + 1), 0} #define CLEAN_NOZZLE_END_PT {100, 60, (Z_MIN_POS + 5), 0}
// { X, Y, Z, E} // { X, Y, Z, E}
#endif #endif

@ -2718,7 +2718,7 @@ inline void gcode_G4() {
#endif //FWRETRACT #endif //FWRETRACT
#if ENABLED(CLEAN_NOZZLE_FEATURE) && ENABLED(AUTO_BED_LEVELING_FEATURE) #if ENABLED(CLEAN_NOZZLE_FEATURE) && ENABLED(AUTO_BED_LEVELING_FEATURE)
#include "clean_nozzle.h" #include "nozzle.h"
inline void gcode_G12() { inline void gcode_G12() {
// Don't allow nozzle cleaning without homing first // Don't allow nozzle cleaning without homing first
@ -2729,8 +2729,9 @@ inline void gcode_G4() {
uint8_t const pattern = code_seen('P') ? code_value_ushort() : 0; uint8_t const pattern = code_seen('P') ? code_value_ushort() : 0;
uint8_t const strokes = code_seen('S') ? code_value_ushort() : CLEAN_NOZZLE_STROKES; uint8_t const strokes = code_seen('S') ? code_value_ushort() : CLEAN_NOZZLE_STROKES;
uint8_t const objects = code_seen('T') ? code_value_ushort() : 3;
CleanNozzle::start(pattern, strokes); Nozzle::clean(pattern, strokes, objects);
} }
#endif #endif

@ -27,13 +27,13 @@
#include "point_t.h" #include "point_t.h"
/** /**
* @brief CleanNozzle class * @brief Nozzle class
* *
* @todo: Do not ignore the end.z value and allow XYZ movements * @todo: Do not ignore the end.z value and allow XYZ movements
* @todo: Currently this feature needs AUTO_BED_LEVELING_FEATURE to be active * @todo: Currently this feature needs AUTO_BED_LEVELING_FEATURE to be active
* due to the do_blocking_move_to*() functions. * due to the do_blocking_move_to*() functions.
*/ */
class CleanNozzle { class Nozzle {
private: private:
/** /**
* @brief Stroke clean pattern * @brief Stroke clean pattern
@ -62,26 +62,46 @@ class CleanNozzle {
* *
* @param start point_t defining the starting point * @param start point_t defining the starting point
* @param end point_t defining the ending point * @param end point_t defining the ending point
* @param triangles number of triangles to execute * @param strokes number of strokes to execute
* @param objects number of objects to create
*/ */
static void zigzag(point_t const &start, point_t const &end, uint8_t const &triangles) static void zigzag(point_t const &start,
point_t const &end, uint8_t const &strokes, uint8_t const &objects)
__attribute__ ((optimize ("Os"))) { __attribute__ ((optimize ("Os"))) {
// Move to the starting point float A = fabs(end.y - start.y); // [twice the] Amplitude
do_blocking_move_to_xy(start.x, start.y); float P = fabs(end.x - start.x) / (objects << 1); // Period
do_blocking_move_to_z(start.z);
// Calculate the triangle side // Don't allow impossible triangles
float const a = fabs(end.x - start.x) / triangles; if (A <= 0.0f || P <= 0.0f ) return;
// Don't allow the sides (a, b) to be smaller than 5mm // Store the current coords
if (a < 5 || fabs(end.y - start.y) < 5) return; point_t const home = {
current_position[X_AXIS],
current_position[Y_AXIS],
current_position[Z_AXIS],
current_position[E_AXIS]
};
// Start the zig-zag pattern for (uint8_t j = 0; j < strokes; j++) {
for (uint8_t i = 0; i < triangles; i++) { for (uint8_t i = 0; i < (objects << 1); i++) {
float const x = start.x + (a * (i + 1)); float const x = start.x + i * P;
do_blocking_move_to_xy(x, end.y); float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
do_blocking_move_to_y(start.y);
do_blocking_move_to_xy(x, y);
if (i == 0) do_blocking_move_to_z(start.z);
}
for (int i = (objects << 1); i > -1; i--) {
float const x = start.x + i * P;
float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
do_blocking_move_to_xy(x, y);
}
} }
// Move to home/start position
do_blocking_move_to_z(home.z);
do_blocking_move_to_xy(home.x, home.y);
} }
public: public:
@ -92,19 +112,20 @@ class CleanNozzle {
* @param pattern one of the available patterns * @param pattern one of the available patterns
* @param argument depends on the cleaning pattern * @param argument depends on the cleaning pattern
*/ */
static void start(uint8_t const &pattern, uint8_t const &argument) static void clean(uint8_t const &pattern,
uint8_t const &strokes, uint8_t const &objects = 0)
__attribute__ ((optimize ("Os"))) { __attribute__ ((optimize ("Os"))) {
switch (pattern) { switch (pattern) {
case 1: case 1:
CleanNozzle::zigzag( Nozzle::zigzag(
CLEAN_NOZZLE_START_PT, CLEAN_NOZZLE_START_PT,
CLEAN_NOZZLE_END_PT, argument); CLEAN_NOZZLE_END_PT, strokes, objects);
break; break;
default: default:
CleanNozzle::stroke( Nozzle::stroke(
CLEAN_NOZZLE_START_PT, CLEAN_NOZZLE_START_PT,
CLEAN_NOZZLE_END_PT, argument); CLEAN_NOZZLE_END_PT, strokes);
} }
} }
}; };
Loading…
Cancel
Save