|
@@ -1,238 +1,185 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+#include "MarlinConfig.h"
|
|
24
|
+
|
|
25
|
+#if ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
|
|
26
|
+
|
1
|
27
|
#include "nozzle.h"
|
2
|
28
|
|
3
|
29
|
#include "Marlin.h"
|
4
|
30
|
#include "point_t.h"
|
5
|
31
|
|
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
|
|
- _UNUSED point_t const &start,
|
16
|
|
- _UNUSED point_t const &end,
|
17
|
|
- _UNUSED uint8_t const &strokes
|
18
|
|
-) {
|
19
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
20
|
|
-
|
|
32
|
+#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
33
|
+
|
|
34
|
+ /**
|
|
35
|
+ * @brief Stroke clean pattern
|
|
36
|
+ * @details Wipes the nozzle back and forth in a linear movement
|
|
37
|
+ *
|
|
38
|
+ * @param start point_t defining the starting point
|
|
39
|
+ * @param end point_t defining the ending point
|
|
40
|
+ * @param strokes number of strokes to execute
|
|
41
|
+ */
|
|
42
|
+ void Nozzle::stroke(const point_t &start, const point_t &end, const uint8_t &strokes) {
|
21
|
43
|
#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
|
|
44
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
45
|
+ #endif
|
30
|
46
|
|
31
|
47
|
// Move to the starting point
|
32
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
33
|
|
- do_blocking_move_to_z(start.z);
|
|
48
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
34
|
49
|
|
35
|
50
|
// Start the stroke pattern
|
36
|
|
- for (uint8_t i = 0; i < (strokes >>1); i++) {
|
|
51
|
+ for (uint8_t i = 0; i < (strokes >> 1); i++) {
|
37
|
52
|
do_blocking_move_to_xy(end.x, end.y);
|
38
|
53
|
do_blocking_move_to_xy(start.x, start.y);
|
39
|
54
|
}
|
40
|
55
|
|
41
|
56
|
#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
|
|
- _UNUSED point_t const &start,
|
60
|
|
- _UNUSED point_t const &end,
|
61
|
|
- _UNUSED uint8_t const &strokes,
|
62
|
|
- _UNUSED uint8_t const &objects
|
63
|
|
-) {
|
64
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
65
|
|
- const float A = nozzle_clean_horizontal ? nozzle_clean_height : nozzle_clean_length, // [twice the] Amplitude
|
66
|
|
- P = (nozzle_clean_horizontal ? nozzle_clean_length : nozzle_clean_height) / (objects << 1); // Period
|
67
|
|
-
|
68
|
|
- // Don't allow impossible triangles
|
69
|
|
- if (A <= 0.0f || P <= 0.0f ) return;
|
|
57
|
+ do_blocking_move_to(ix, iy, iz);
|
|
58
|
+ #endif
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ /**
|
|
62
|
+ * @brief Zig-zag clean pattern
|
|
63
|
+ * @details Apply a zig-zag cleaning pattern
|
|
64
|
+ *
|
|
65
|
+ * @param start point_t defining the starting point
|
|
66
|
+ * @param end point_t defining the ending point
|
|
67
|
+ * @param strokes number of strokes to execute
|
|
68
|
+ * @param objects number of triangles to do
|
|
69
|
+ */
|
|
70
|
+ void Nozzle::zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) {
|
|
71
|
+ const float diffx = end.x - start.x, diffy = end.y - start.y;
|
|
72
|
+ if (!diffx || !diffy) return;
|
70
|
73
|
|
71
|
74
|
#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
|
|
75
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
76
|
+ #endif
|
80
|
77
|
|
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 + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
84
|
|
- float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
|
78
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
85
|
79
|
|
86
|
|
- do_blocking_move_to_xy(x, y);
|
87
|
|
- if (i == 0) do_blocking_move_to_z(start.z);
|
|
80
|
+ const uint8_t zigs = objects << 1;
|
|
81
|
+ const bool horiz = FABS(diffx) >= FABS(diffy); // Do a horizontal wipe?
|
|
82
|
+ const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
|
|
83
|
+ point_t *side;
|
|
84
|
+ for (uint8_t j = 0; j < strokes; j++) {
|
|
85
|
+ for (int8_t i = 0; i < zigs; i++) {
|
|
86
|
+ side = (i & 1) ? &end : &start;
|
|
87
|
+ if (horiz)
|
|
88
|
+ do_blocking_move_to_xy(start.x + i * P, side->y);
|
|
89
|
+ else
|
|
90
|
+ do_blocking_move_to_xy(side->x, start.y + i * P);
|
88
|
91
|
}
|
89
|
|
-
|
90
|
|
- for (int i = (objects << 1); i > -1; i--) {
|
91
|
|
- float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
92
|
|
- float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
|
93
|
|
-
|
94
|
|
- do_blocking_move_to_xy(x, y);
|
|
92
|
+ for (int8_t i = zigs; i >= 0; i--) {
|
|
93
|
+ side = (i & 1) ? &end : &start;
|
|
94
|
+ if (horiz)
|
|
95
|
+ do_blocking_move_to_xy(start.x + i * P, side->y);
|
|
96
|
+ else
|
|
97
|
+ do_blocking_move_to_xy(side->x, start.y + i * P);
|
95
|
98
|
}
|
96
|
99
|
}
|
97
|
100
|
|
98
|
101
|
#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
|
|
- _UNUSED point_t const &start,
|
118
|
|
- _UNUSED point_t const &middle,
|
119
|
|
- _UNUSED uint8_t const &strokes,
|
120
|
|
- _UNUSED float const &radius
|
121
|
|
-) {
|
122
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
102
|
+ do_blocking_move_to(ix, iy, iz);
|
|
103
|
+ #endif
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ /**
|
|
107
|
+ * @brief Circular clean pattern
|
|
108
|
+ * @details Apply a circular cleaning pattern
|
|
109
|
+ *
|
|
110
|
+ * @param start point_t defining the middle of circle
|
|
111
|
+ * @param strokes number of strokes to execute
|
|
112
|
+ * @param radius radius of circle
|
|
113
|
+ */
|
|
114
|
+ void Nozzle::circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) {
|
123
|
115
|
if (strokes == 0) return;
|
124
|
116
|
|
125
|
117
|
#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
|
|
- }
|
140
|
|
- else {
|
141
|
|
- do_blocking_move_to_z(start.z);
|
142
|
|
- do_blocking_move_to_xy(start.x, start.y);
|
143
|
|
- }
|
|
118
|
+ const float ix = current_position[X_AXIS], iy = current_position[Y_AXIS], iz = current_position[Z_AXIS];
|
|
119
|
+ #endif
|
144
|
120
|
|
145
|
|
- float x, y;
|
146
|
|
- for (uint8_t s = 0; s < strokes; s++) {
|
147
|
|
- for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++) {
|
148
|
|
- x = middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
|
149
|
|
- y = middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius;
|
|
121
|
+ do_blocking_move_to(start.x, start.y, start.z);
|
150
|
122
|
|
151
|
|
- do_blocking_move_to_xy(x, y);
|
152
|
|
- }
|
153
|
|
- }
|
|
123
|
+ for (uint8_t s = 0; s < strokes; s++)
|
|
124
|
+ for (uint8_t i = 0; i < NOZZLE_CLEAN_CIRCLE_FN; i++)
|
|
125
|
+ do_blocking_move_to_xy(
|
|
126
|
+ middle.x + sin((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius,
|
|
127
|
+ middle.y + cos((M_2_PI / NOZZLE_CLEAN_CIRCLE_FN) * i) * radius
|
|
128
|
+ );
|
154
|
129
|
|
155
|
130
|
// Let's be safe
|
156
|
131
|
do_blocking_move_to_xy(start.x, start.y);
|
157
|
132
|
|
158
|
133
|
#if ENABLED(NOZZLE_CLEAN_GOBACK)
|
159
|
|
- // Move the nozzle to the initial point
|
160
|
|
- if (start.z <= initial.z) {
|
161
|
|
- // As above order is important
|
162
|
|
- do_blocking_move_to_z(initial.z);
|
163
|
|
- do_blocking_move_to_xy(initial.x, initial.y);
|
164
|
|
- }
|
165
|
|
- else {
|
166
|
|
- do_blocking_move_to_xy(initial.x, initial.y);
|
167
|
|
- do_blocking_move_to_z(initial.z);
|
168
|
|
- }
|
169
|
|
- #endif // NOZZLE_CLEAN_GOBACK
|
170
|
|
-
|
171
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
172
|
|
-}
|
173
|
|
-
|
174
|
|
-/**
|
175
|
|
- * @brief Clean the nozzle
|
176
|
|
- * @details Starts the selected clean procedure pattern
|
177
|
|
- *
|
178
|
|
- * @param pattern one of the available patterns
|
179
|
|
- * @param argument depends on the cleaning pattern
|
180
|
|
- */
|
181
|
|
-void Nozzle::clean(
|
182
|
|
- _UNUSED uint8_t const &pattern,
|
183
|
|
- _UNUSED uint8_t const &strokes,
|
184
|
|
- _UNUSED float const &radius,
|
185
|
|
- _UNUSED uint8_t const &objects
|
186
|
|
-) {
|
187
|
|
- #if ENABLED(NOZZLE_CLEAN_FEATURE)
|
188
|
|
- #if ENABLED(DELTA)
|
189
|
|
- if (current_position[Z_AXIS] > delta_clip_start_height)
|
190
|
|
- do_blocking_move_to_z(delta_clip_start_height);
|
|
134
|
+ do_blocking_move_to(ix, iy, iz);
|
191
|
135
|
#endif
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ /**
|
|
139
|
+ * @brief Clean the nozzle
|
|
140
|
+ * @details Starts the selected clean procedure pattern
|
|
141
|
+ *
|
|
142
|
+ * @param pattern one of the available patterns
|
|
143
|
+ * @param argument depends on the cleaning pattern
|
|
144
|
+ */
|
|
145
|
+ void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects/*=0*/) {
|
192
|
146
|
switch (pattern) {
|
193
|
147
|
case 1:
|
194
|
|
- Nozzle::zigzag(
|
195
|
|
- NOZZLE_CLEAN_START_POINT,
|
196
|
|
- NOZZLE_CLEAN_END_POINT, strokes, objects);
|
|
148
|
+ zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
|
197
|
149
|
break;
|
198
|
150
|
|
199
|
151
|
case 2:
|
200
|
|
- Nozzle::circle(
|
201
|
|
- NOZZLE_CLEAN_START_POINT,
|
202
|
|
- NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
|
|
152
|
+ circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
|
203
|
153
|
break;
|
204
|
154
|
|
205
|
155
|
default:
|
206
|
|
- Nozzle::stroke(
|
207
|
|
- NOZZLE_CLEAN_START_POINT,
|
208
|
|
- NOZZLE_CLEAN_END_POINT, strokes);
|
|
156
|
+ stroke(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes);
|
209
|
157
|
}
|
210
|
|
- #endif // NOZZLE_CLEAN_FEATURE
|
211
|
|
-}
|
212
|
|
-
|
213
|
|
-void Nozzle::park(
|
214
|
|
- _UNUSED uint8_t const &z_action
|
215
|
|
-) {
|
216
|
|
- #if ENABLED(NOZZLE_PARK_FEATURE)
|
217
|
|
- float const z = current_position[Z_AXIS];
|
218
|
|
- point_t const park = NOZZLE_PARK_POINT;
|
219
|
|
-
|
220
|
|
- switch(z_action) {
|
221
|
|
- case 1: // force Z-park height
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+#endif // NOZZLE_CLEAN_FEATURE
|
|
161
|
+
|
|
162
|
+#if ENABLED(NOZZLE_PARK_FEATURE)
|
|
163
|
+
|
|
164
|
+ void Nozzle::park(const uint8_t &z_action) {
|
|
165
|
+ const point_t park = NOZZLE_PARK_POINT;
|
|
166
|
+
|
|
167
|
+ switch (z_action) {
|
|
168
|
+ case 1: // Go to Z-park height
|
222
|
169
|
do_blocking_move_to_z(park.z);
|
223
|
170
|
break;
|
224
|
171
|
|
225
|
172
|
case 2: // Raise by Z-park height
|
226
|
|
- do_blocking_move_to_z(
|
227
|
|
- (z + park.z > Z_MAX_POS) ? Z_MAX_POS : z + park.z);
|
|
173
|
+ do_blocking_move_to_z(min(current_position[Z_AXIS] + park.z, Z_MAX_POS));
|
228
|
174
|
break;
|
229
|
175
|
|
230
|
|
- default: // Raise to Z-park height if lower
|
231
|
|
- if (current_position[Z_AXIS] < park.z)
|
232
|
|
- do_blocking_move_to_z(park.z);
|
|
176
|
+ default: // Raise to at least the Z-park height
|
|
177
|
+ do_blocking_move_to_z(max(park.z, current_position[Z_AXIS]));
|
233
|
178
|
}
|
234
|
179
|
|
235
|
180
|
do_blocking_move_to_xy(park.x, park.y);
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+#endif // NOZZLE_PARK_FEATURE
|
236
|
184
|
|
237
|
|
- #endif // NOZZLE_PARK_FEATURE
|
238
|
|
-}
|
|
185
|
+#endif // NOZZLE_CLEAN_FEATURE || NOZZLE_PARK_FEATURE
|