|
@@ -20,246 +20,167 @@
|
20
|
20
|
*
|
21
|
21
|
*/
|
22
|
22
|
|
|
23
|
+#include "../inc/MarlinConfig.h"
|
|
24
|
+
|
|
25
|
+#if ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
|
|
26
|
+
|
23
|
27
|
#include "nozzle.h"
|
24
|
28
|
|
25
|
29
|
#include "../Marlin.h"
|
26
|
30
|
#include "../module/motion.h"
|
27
|
31
|
#include "point_t.h"
|
28
|
32
|
|
29
|
|
-#if ENABLED(DELTA)
|
30
|
|
- #include "../module/delta.h"
|
31
|
|
-#endif
|
32
|
|
-
|
33
|
|
-/**
|
34
|
|
- * @brief Stroke clean pattern
|
35
|
|
- * @details Wipes the nozzle back and forth in a linear movement
|
36
|
|
- *
|
37
|
|
- * @param start point_t defining the starting point
|
38
|
|
- * @param end point_t defining the ending point
|
39
|
|
- * @param strokes number of strokes to execute
|
40
|
|
- */
|
41
|
|
-void Nozzle::stroke(
|
42
|
|
- _UNUSED point_t const &start,
|
43
|
|
- _UNUSED point_t const &end,
|
44
|
|
- _UNUSED uint8_t const &strokes
|
45
|
|
-) {
|
46
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
47
|
|
-
|
|
33
|
+#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
34
|
+
|
|
35
|
+ /**
|
|
36
|
+ * @brief Stroke clean pattern
|
|
37
|
+ * @details Wipes the nozzle back and forth in a linear movement
|
|
38
|
+ *
|
|
39
|
+ * @param start point_t defining the starting point
|
|
40
|
+ * @param end point_t defining the ending point
|
|
41
|
+ * @param strokes number of strokes to execute
|
|
42
|
+ */
|
|
43
|
+ void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
|
48
|
44
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
49
|
|
- // Store the current coords
|
50
|
|
- point_t const initial = {
|
51
|
|
- current_position[X_AXIS],
|
52
|
|
- current_position[Y_AXIS],
|
53
|
|
- current_position[Z_AXIS],
|
54
|
|
- current_position[E_AXIS]
|
55
|
|
- };
|
56
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
|
45
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
46
|
+ #endif
|
57
|
47
|
|
58
|
48
|
// Move to the starting point
|
59
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
60
|
|
- do_blocking_move_to_z(start.z);
|
|
49
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
61
|
50
|
|
62
|
51
|
// Start the stroke pattern
|
63
|
|
- for (uint8_t i = 0; i < (strokes >>1); i++) {
|
|
52
|
+ for (uint8_t i = 0; i < (strokes >> 1); i++) {
|
64
|
53
|
do_blocking_move_to_xy(end.x, end.y);
|
65
|
54
|
do_blocking_move_to_xy(start.x, start.y);
|
66
|
55
|
}
|
67
|
56
|
|
68
|
57
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
69
|
|
- // Move the nozzle to the initial point
|
70
|
|
- do_blocking_move_to(initial.x, initial.y, initial.z);
|
71
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
72
|
|
-
|
73
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
74
|
|
-}
|
75
|
|
-
|
76
|
|
-/**
|
77
|
|
- * @brief Zig-zag clean pattern
|
78
|
|
- * @details Apply a zig-zag cleanning pattern
|
79
|
|
- *
|
80
|
|
- * @param start point_t defining the starting point
|
81
|
|
- * @param end point_t defining the ending point
|
82
|
|
- * @param strokes number of strokes to execute
|
83
|
|
- * @param objects number of objects to create
|
84
|
|
- */
|
85
|
|
-void Nozzle::zigzag(
|
86
|
|
- _UNUSED point_t const &start,
|
87
|
|
- _UNUSED point_t const &end,
|
88
|
|
- _UNUSED uint8_t const &strokes,
|
89
|
|
- _UNUSED uint8_t const &objects
|
90
|
|
-) {
|
91
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
92
|
|
- const float A = nozzle_clean_horizontal ? nozzle_clean_height : nozzle_clean_length, // [twice the] Amplitude
|
93
|
|
- P = (nozzle_clean_horizontal ? nozzle_clean_length : nozzle_clean_height) / (objects << 1); // Period
|
94
|
|
-
|
95
|
|
- // Don't allow impossible triangles
|
96
|
|
- if (A <= 0.0f || P <= 0.0f ) return;
|
|
58
|
+ do_blocking_move_to(ix, iy, iz);
|
|
59
|
+ #endif
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /**
|
|
63
|
+ * @brief Zig-zag clean pattern
|
|
64
|
+ * @details Apply a zig-zag cleaning pattern
|
|
65
|
+ *
|
|
66
|
+ * @param start point_t defining the starting point
|
|
67
|
+ * @param end point_t defining the ending point
|
|
68
|
+ * @param strokes number of strokes to execute
|
|
69
|
+ * @param objects number of triangles to do
|
|
70
|
+ */
|
|
71
|
+ void Nozzle::zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
|
|
72
|
+ const float diffx = end.x - start.x, diffy = end.y - start.y;
|
|
73
|
+ if (!diffx || !diffy) return;
|
97
|
74
|
|
98
|
75
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
99
|
|
- // Store the current coords
|
100
|
|
- point_t const initial = {
|
101
|
|
- current_position[X_AXIS],
|
102
|
|
- current_position[Y_AXIS],
|
103
|
|
- current_position[Z_AXIS],
|
104
|
|
- current_position[E_AXIS]
|
105
|
|
- };
|
106
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
|
76
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
77
|
+ #endif
|
107
|
78
|
|
108
|
|
- for (uint8_t j = 0; j < strokes; j++) {
|
109
|
|
- for (uint8_t i = 0; i < (objects << 1); i++) {
|
110
|
|
- float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
111
|
|
- float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
|
79
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
112
|
80
|
|
113
|
|
- do_blocking_move_to_xy(x, y);
|
114
|
|
- if (i == 0) do_blocking_move_to_z(start.z);
|
|
81
|
+ const uint8_t zigs = objects << 1;
|
|
82
|
+ const bool horiz = FABS(diffx) >= FABS(diffy); // Do a horizontal wipe?
|
|
83
|
+ const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
|
|
84
|
+ const point_t *side;
|
|
85
|
+ for (uint8_t j = 0; j < strokes; j++) {
|
|
86
|
+ for (int8_t i = 0; i < zigs; i++) {
|
|
87
|
+ side = (i & 1) ? &end : &start;
|
|
88
|
+ if (horiz)
|
|
89
|
+ do_blocking_move_to_xy(start.x + i * P, side->y);
|
|
90
|
+ else
|
|
91
|
+ do_blocking_move_to_xy(side->x, start.y + i * P);
|
115
|
92
|
}
|
116
|
|
-
|
117
|
|
- for (int i = (objects << 1); i > -1; i--) {
|
118
|
|
- float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
119
|
|
- float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
120
|
|
-
|
121
|
|
- do_blocking_move_to_xy(x, y);
|
|
93
|
+ for (int8_t i = zigs; i >= 0; i--) {
|
|
94
|
+ side = (i & 1) ? &end : &start;
|
|
95
|
+ if (horiz)
|
|
96
|
+ do_blocking_move_to_xy(start.x + i * P, side->y);
|
|
97
|
+ else
|
|
98
|
+ do_blocking_move_to_xy(side->x, start.y + i * P);
|
122
|
99
|
}
|
123
|
100
|
}
|
124
|
101
|
|
125
|
102
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
126
|
|
- // Move the nozzle to the initial point
|
127
|
|
- do_blocking_move_to_z(initial.z);
|
128
|
|
- do_blocking_move_to_xy(initial.x, initial.y);
|
129
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
130
|
|
-
|
131
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
132
|
|
-}
|
133
|
|
-
|
134
|
|
-
|
135
|
|
-/**
|
136
|
|
- * @brief Circular clean pattern
|
137
|
|
- * @details Apply a circular cleaning pattern
|
138
|
|
- *
|
139
|
|
- * @param start point_t defining the middle of circle
|
140
|
|
- * @param strokes number of strokes to execute
|
141
|
|
- * @param radius radius of circle
|
142
|
|
- */
|
143
|
|
-void Nozzle::circle(
|
144
|
|
- _UNUSED point_t const &start,
|
145
|
|
- _UNUSED point_t const &middle,
|
146
|
|
- _UNUSED uint8_t const &strokes,
|
147
|
|
- _UNUSED float const &radius
|
148
|
|
-) {
|
149
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
103
|
+ do_blocking_move_to(ix, iy, iz);
|
|
104
|
+ #endif
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ /**
|
|
108
|
+ * @brief Circular clean pattern
|
|
109
|
+ * @details Apply a circular cleaning pattern
|
|
110
|
+ *
|
|
111
|
+ * @param start point_t defining the middle of circle
|
|
112
|
+ * @param strokes number of strokes to execute
|
|
113
|
+ * @param radius radius of circle
|
|
114
|
+ */
|
|
115
|
+ void Nozzle::circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
|
150
|
116
|
if (strokes == 0) return;
|
151
|
117
|
|
152
|
118
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
153
|
|
- // Store the current coords
|
154
|
|
- point_t const initial = {
|
155
|
|
- current_position[X_AXIS],
|
156
|
|
- current_position[Y_AXIS],
|
157
|
|
- current_position[Z_AXIS],
|
158
|
|
- current_position[E_AXIS]
|
159
|
|
- };
|
160
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
161
|
|
-
|
162
|
|
- if (start.z <= current_position[Z_AXIS]) {
|
163
|
|
- // Order of movement is pretty darn important here
|
164
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
165
|
|
- do_blocking_move_to_z(start.z);
|
166
|
|
- }
|
167
|
|
- else {
|
168
|
|
- do_blocking_move_to_z(start.z);
|
169
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
170
|
|
- }
|
|
119
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
120
|
+ #endif
|
171
|
121
|
|
172
|
|
- float x, y;
|
173
|
|
- for (uint8_t s = 0; s < strokes; s++) {
|
174
|
|
- for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++) {
|
175
|
|
- x = middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
|
176
|
|
- y = middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
|
|
122
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
177
|
123
|
|
178
|
|
- do_blocking_move_to_xy(x, y);
|
179
|
|
- }
|
180
|
|
- }
|
|
124
|
+ for (uint8_t s = 0; s < strokes; s++)
|
|
125
|
+ for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
|
|
126
|
+ do_blocking_move_to_xy(
|
|
127
|
+ middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
|
|
128
|
+ middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius
|
|
129
|
+ );
|
181
|
130
|
|
182
|
131
|
// Let's be safe
|
183
|
132
|
do_blocking_move_to_xy(start.x, start.y);
|
184
|
133
|
|
185
|
134
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
186
|
|
- // Move the nozzle to the initial point
|
187
|
|
- if (start.z <= initial.z) {
|
188
|
|
- // As above order is important
|
189
|
|
- do_blocking_move_to_z(initial.z);
|
190
|
|
- do_blocking_move_to_xy(initial.x, initial.y);
|
191
|
|
- }
|
192
|
|
- else {
|
193
|
|
- do_blocking_move_to_xy(initial.x, initial.y);
|
194
|
|
- do_blocking_move_to_z(initial.z);
|
195
|
|
- }
|
196
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
197
|
|
-
|
198
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
199
|
|
-}
|
200
|
|
-
|
201
|
|
-/**
|
202
|
|
- * @brief Clean the nozzle
|
203
|
|
- * @details Starts the selected clean procedure pattern
|
204
|
|
- *
|
205
|
|
- * @param pattern one of the available patterns
|
206
|
|
- * @param argument depends on the cleaning pattern
|
207
|
|
- */
|
208
|
|
-void Nozzle::clean(
|
209
|
|
- _UNUSED uint8_t const &pattern,
|
210
|
|
- _UNUSED uint8_t const &strokes,
|
211
|
|
- _UNUSED float const &radius,
|
212
|
|
- _UNUSED uint8_t const &objects
|
213
|
|
-) {
|
214
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
215
|
|
- #if ENABLED(DELTA)
|
216
|
|
- if (current_position[Z_AXIS] > delta_clip_start_height)
|
217
|
|
- do_blocking_move_to_z(delta_clip_start_height);
|
|
135
|
+ do_blocking_move_to(ix, iy, iz);
|
218
|
136
|
#endif
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ /**
|
|
140
|
+ * @brief Clean the nozzle
|
|
141
|
+ * @details Starts the selected clean procedure pattern
|
|
142
|
+ *
|
|
143
|
+ * @param pattern one of the available patterns
|
|
144
|
+ * @param argument depends on the cleaning pattern
|
|
145
|
+ */
|
|
146
|
+ void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects/*=0*/) {
|
219
|
147
|
switch (pattern) {
|
220
|
148
|
case 1:
|
221
|
|
- Nozzle::zigzag(
|
222
|
|
- NOZZLE_CLEAN_START_POINT,
|
223
|
|
- NOZZLE_CLEAN_END_POINT, strokes, objects);
|
|
149
|
+ zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
|
224
|
150
|
break;
|
225
|
151
|
|
226
|
152
|
case 2:
|
227
|
|
- Nozzle::circle(
|
228
|
|
- NOZZLE_CLEAN_START_POINT,
|
229
|
|
- NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
|
|
153
|
+ circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
|
230
|
154
|
break;
|
231
|
155
|
|
232
|
156
|
default:
|
233
|
|
- Nozzle::stroke(
|
234
|
|
- NOZZLE_CLEAN_START_POINT,
|
235
|
|
- NOZZLE_CLEAN_END_POINT, strokes);
|
|
157
|
+ stroke(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes);
|
236
|
158
|
}
|
237
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
238
|
|
-}
|
239
|
|
-
|
240
|
|
-void Nozzle::park(
|
241
|
|
- _UNUSED uint8_t const &z_action
|
242
|
|
-) {
|
243
|
|
- #if ENABLED(NOZZLE_PARK_FEATURE)
|
244
|
|
- float const z = current_position[Z_AXIS];
|
245
|
|
- point_t const park = NOZZLE_PARK_POINT;
|
246
|
|
-
|
247
|
|
- switch(z_action) {
|
248
|
|
- case 1: // force Z-park height
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+#endif // NOZZLE_CLEAN_FEATURE
|
|
162
|
+
|
|
163
|
+#if ENABLED(NOZZLE_PARK_FEATURE)
|
|
164
|
+
|
|
165
|
+ void Nozzle::park(const uint8_t &z_action) {
|
|
166
|
+ const point_t park = NOZZLE_PARK_POINT;
|
|
167
|
+
|
|
168
|
+ switch (z_action) {
|
|
169
|
+ case 1: // Go to Z-park height
|
249
|
170
|
do_blocking_move_to_z(park.z);
|
250
|
171
|
break;
|
251
|
172
|
|
252
|
173
|
case 2: // Raise by Z-park height
|
253
|
|
- do_blocking_move_to_z(
|
254
|
|
- (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
|
|
174
|
+ do_blocking_move_to_z(min(current_position[Z_AXIS] + park.z, Z_MAX_POS));
|
255
|
175
|
break;
|
256
|
176
|
|
257
|
|
- default: // Raise to Z-park height if lower
|
258
|
|
- if (current_position[Z_AXIS] < park.z)
|
259
|
|
- do_blocking_move_to_z(park.z);
|
|
177
|
+ default: // Raise to at least the Z-park height
|
|
178
|
+ do_blocking_move_to_z(max(park.z, current_position[Z_AXIS]));
|
260
|
179
|
}
|
261
|
180
|
|
262
|
181
|
do_blocking_move_to_xy(park.x, park.y);
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+#endif // NOZZLE_PARK_FEATURE
|
263
|
185
|
|
264
|
|
- #endif // NOZZLE_PARK_FEATURE
|
265
|
|
-}
|
|
186
|
+#endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE
|