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