|
@@ -27,13 +27,13 @@
|
27
|
27
|
#include "point_t.h"
|
28
|
28
|
|
29
|
29
|
/**
|
30
|
|
- * @brief CleanNozzle class
|
|
30
|
+ * @brief Nozzle class
|
31
|
31
|
*
|
32
|
32
|
* @todo: Do not ignore the end.z value and allow XYZ movements
|
33
|
33
|
* @todo: Currently this feature needs AUTO_BED_LEVELING_FEATURE to be active
|
34
|
34
|
* due to the do_blocking_move_to*() functions.
|
35
|
35
|
*/
|
36
|
|
-class CleanNozzle {
|
|
36
|
+class Nozzle {
|
37
|
37
|
private:
|
38
|
38
|
/**
|
39
|
39
|
* @brief Stroke clean pattern
|
|
@@ -62,26 +62,46 @@ class CleanNozzle {
|
62
|
62
|
*
|
63
|
63
|
* @param start point_t defining the starting point
|
64
|
64
|
* @param end point_t defining the ending point
|
65
|
|
- * @param triangles number of triangles to execute
|
|
65
|
+ * @param strokes number of strokes to execute
|
|
66
|
+ * @param objects number of objects to create
|
66
|
67
|
*/
|
67
|
|
- static void zigzag(point_t const &start, point_t const &end, uint8_t const &triangles)
|
|
68
|
+ static void zigzag(point_t const &start,
|
|
69
|
+ point_t const &end, uint8_t const &strokes, uint8_t const &objects)
|
68
|
70
|
__attribute__ ((optimize ("Os"))) {
|
69
|
|
- // Move to the starting point
|
70
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
71
|
|
- do_blocking_move_to_z(start.z);
|
|
71
|
+ float A = fabs(end.y - start.y); // [twice the] Amplitude
|
|
72
|
+ float P = fabs(end.x - start.x) / (objects << 1); // Period
|
72
|
73
|
|
73
|
|
- // Calculate the triangle side
|
74
|
|
- float const a = fabs(end.x - start.x) / triangles;
|
|
74
|
+ // Don't allow impossible triangles
|
|
75
|
+ if (A <= 0.0f || P <= 0.0f ) return;
|
75
|
76
|
|
76
|
|
- // Don't allow the sides (a, b) to be smaller than 5mm
|
77
|
|
- if (a < 5 || fabs(end.y - start.y) < 5) return;
|
|
77
|
+ // Store the current coords
|
|
78
|
+ point_t const home = {
|
|
79
|
+ current_position[X_AXIS],
|
|
80
|
+ current_position[Y_AXIS],
|
|
81
|
+ current_position[Z_AXIS],
|
|
82
|
+ current_position[E_AXIS]
|
|
83
|
+ };
|
78
|
84
|
|
79
|
|
- // Start the zig-zag pattern
|
80
|
|
- for (uint8_t i = 0; i < triangles; i++) {
|
81
|
|
- float const x = start.x + (a * (i + 1));
|
82
|
|
- do_blocking_move_to_xy(x, end.y);
|
83
|
|
- do_blocking_move_to_y(start.y);
|
|
85
|
+ for (uint8_t j = 0; j < strokes; j++) {
|
|
86
|
+ for (uint8_t i = 0; i < (objects << 1); i++) {
|
|
87
|
+ float const x = start.x + i * P;
|
|
88
|
+ float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
|
|
89
|
+
|
|
90
|
+ do_blocking_move_to_xy(x, y);
|
|
91
|
+ if (i == 0) do_blocking_move_to_z(start.z);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ for (int i = (objects << 1); i > -1; i--) {
|
|
95
|
+ float const x = start.x + i * P;
|
|
96
|
+ float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
|
|
97
|
+
|
|
98
|
+ do_blocking_move_to_xy(x, y);
|
|
99
|
+ }
|
84
|
100
|
}
|
|
101
|
+
|
|
102
|
+ // Move to home/start position
|
|
103
|
+ do_blocking_move_to_z(home.z);
|
|
104
|
+ do_blocking_move_to_xy(home.x, home.y);
|
85
|
105
|
}
|
86
|
106
|
|
87
|
107
|
public:
|
|
@@ -92,19 +112,20 @@ class CleanNozzle {
|
92
|
112
|
* @param pattern one of the available patterns
|
93
|
113
|
* @param argument depends on the cleaning pattern
|
94
|
114
|
*/
|
95
|
|
- static void start(uint8_t const &pattern, uint8_t const &argument)
|
|
115
|
+ static void clean(uint8_t const &pattern,
|
|
116
|
+ uint8_t const &strokes, uint8_t const &objects = 0)
|
96
|
117
|
__attribute__ ((optimize ("Os"))) {
|
97
|
118
|
switch (pattern) {
|
98
|
119
|
case 1:
|
99
|
|
- CleanNozzle::zigzag(
|
|
120
|
+ Nozzle::zigzag(
|
100
|
121
|
CLEAN_NOZZLE_START_PT,
|
101
|
|
- CLEAN_NOZZLE_END_PT, argument);
|
|
122
|
+ CLEAN_NOZZLE_END_PT, strokes, objects);
|
102
|
123
|
break;
|
103
|
124
|
|
104
|
125
|
default:
|
105
|
|
- CleanNozzle::stroke(
|
|
126
|
+ Nozzle::stroke(
|
106
|
127
|
CLEAN_NOZZLE_START_PT,
|
107
|
|
- CLEAN_NOZZLE_END_PT, argument);
|
|
128
|
+ CLEAN_NOZZLE_END_PT, strokes);
|
108
|
129
|
}
|
109
|
130
|
}
|
110
|
131
|
};
|