浏览代码

Cleanup Nozzle class, fix XY vs Z move order

Scott Lahteine 7 年前
父节点
当前提交
be73d5cc08
共有 3 个文件被更改,包括 134 次插入245 次删除
  1. 109
    188
      Marlin/src/libs/nozzle.cpp
  2. 20
    35
      Marlin/src/libs/nozzle.h
  3. 5
    22
      Marlin/src/libs/point_t.h

+ 109
- 188
Marlin/src/libs/nozzle.cpp 查看文件

@@ -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

+ 20
- 35
Marlin/src/libs/nozzle.h 查看文件

@@ -26,14 +26,6 @@
26 26
 #include "../inc/MarlinConfig.h"
27 27
 #include "point_t.h"
28 28
 
29
-#if ENABLED(NOZZLE_CLEAN_FEATURE)
30
-  constexpr float nozzle_clean_start_point[4] = NOZZLE_CLEAN_START_POINT,
31
-                  nozzle_clean_end_point[4] = NOZZLE_CLEAN_END_POINT,
32
-                  nozzle_clean_length = FABS(nozzle_clean_start_point[X_AXIS] - nozzle_clean_end_point[X_AXIS]), //abs x size of wipe pad
33
-                  nozzle_clean_height = FABS(nozzle_clean_start_point[Y_AXIS] - nozzle_clean_end_point[Y_AXIS]); //abs y size of wipe pad
34
-  constexpr bool nozzle_clean_horizontal = nozzle_clean_length >= nozzle_clean_height; //whether to zig-zag horizontally or vertically
35
-#endif // NOZZLE_CLEAN_FEATURE
36
-
37 29
 /**
38 30
  * @brief Nozzle class
39 31
  *
@@ -41,6 +33,9 @@
41 33
  */
42 34
 class Nozzle {
43 35
   private:
36
+
37
+  #if ENABLED(NOZZLE_CLEAN_FEATURE)
38
+
44 39
     /**
45 40
      * @brief Stroke clean pattern
46 41
      * @details Wipes the nozzle back and forth in a linear movement
@@ -49,11 +44,7 @@ class Nozzle {
49 44
      * @param end point_t defining the ending point
50 45
      * @param strokes number of strokes to execute
51 46
      */
52
-    static void stroke(
53
-      _UNUSED point_t const &start,
54
-      _UNUSED point_t const &end,
55
-      _UNUSED uint8_t const &strokes
56
-    ) _Os;
47
+    static void stroke(const point_t &start, const point_t &end, const uint8_t &strokes) _Os;
57 48
 
58 49
     /**
59 50
      * @brief Zig-zag clean pattern
@@ -64,12 +55,7 @@ class Nozzle {
64 55
      * @param strokes number of strokes to execute
65 56
      * @param objects number of objects to create
66 57
      */
67
-    static void zigzag(
68
-      _UNUSED point_t const &start,
69
-      _UNUSED point_t const &end,
70
-      _UNUSED uint8_t const &strokes,
71
-      _UNUSED uint8_t const &objects
72
-    ) _Os;
58
+    static void zigzag(const point_t &start, const point_t &end, const uint8_t &strokes, const uint8_t &objects) _Os;
73 59
 
74 60
     /**
75 61
      * @brief Circular clean pattern
@@ -79,14 +65,14 @@ class Nozzle {
79 65
      * @param strokes number of strokes to execute
80 66
      * @param radius radius of circle
81 67
      */
82
-    static void circle(
83
-      _UNUSED point_t const &start,
84
-      _UNUSED point_t const &middle,
85
-      _UNUSED uint8_t const &strokes,
86
-      _UNUSED float const &radius
87
-    ) _Os;
68
+    static void circle(const point_t &start, const point_t &middle, const uint8_t &strokes, const float &radius) _Os;
69
+
70
+  #endif // NOZZLE_CLEAN_FEATURE
88 71
 
89 72
   public:
73
+
74
+  #if ENABLED(NOZZLE_CLEAN_FEATURE)
75
+
90 76
     /**
91 77
      * @brief Clean the nozzle
92 78
      * @details Starts the selected clean procedure pattern
@@ -94,16 +80,15 @@ class Nozzle {
94 80
      * @param pattern one of the available patterns
95 81
      * @param argument depends on the cleaning pattern
96 82
      */
97
-    static void clean(
98
-      _UNUSED uint8_t const &pattern,
99
-      _UNUSED uint8_t const &strokes,
100
-      _UNUSED float const &radius,
101
-      _UNUSED uint8_t const &objects = 0
102
-    ) _Os;
103
-
104
-    static void park(
105
-      _UNUSED uint8_t const &z_action
106
-    ) _Os;
83
+    static void clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects=0) _Os;
84
+
85
+  #endif // NOZZLE_CLEAN_FEATURE
86
+
87
+  #if ENABLED(NOZZLE_PARK_FEATURE)
88
+
89
+    static void park(const uint8_t &z_action) _Os;
90
+
91
+  #endif
107 92
 };
108 93
 
109 94
 #endif // __NOZZLE_H__

+ 5
- 22
Marlin/src/libs/point_t.h 查看文件

@@ -31,19 +31,9 @@
31 31
  * @param x The x-coordinate of the point.
32 32
  * @param y The y-coordinate of the point.
33 33
  * @param z The z-coordinate of the point.
34
- * @param e The e-coordinate of the point.
35 34
  */
36 35
 struct point_t {
37
-  float x, y, z, e;
38
-
39
-  /**
40
-   * @brief Two dimensional point constructor
41
-   *
42
-   * @param x The x-coordinate of the point.
43
-   * @param y The y-coordinate of the point.
44
-   */
45
-  point_t(float const x, float const y)
46
-    : point_t(x, y, NAN, NAN) {}
36
+  float x, y, z;
47 37
 
48 38
   /**
49 39
    * @brief Three dimensional point constructor
@@ -52,23 +42,16 @@ struct point_t {
52 42
    * @param y The y-coordinate of the point.
53 43
    * @param z The z-coordinate of the point.
54 44
    */
55
-  point_t(float const x, float const y, float const z)
56
-    : point_t(x, y, z, NAN) {}
45
+  point_t(const float x, const float y, const float z) : x(x), y(y), z(z) {}
57 46
 
58 47
   /**
59
-   * @brief Tree dimensional point constructor with extrusion length
48
+   * @brief Two dimensional point constructor
60 49
    *
61 50
    * @param x The x-coordinate of the point.
62 51
    * @param y The y-coordinate of the point.
63
-   * @param z The z-coordinate of the point.
64
-   * @param e The e-coordinate of the point.
65 52
    */
66
-  point_t(float const x, float const y, float const z, float const e) {
67
-    this->x = x;
68
-    this->y = y;
69
-    this->z = z;
70
-    this->e = e;
71
-  }
53
+  point_t(const float x, const float y) : point_t(x, y, NAN) {}
54
+
72 55
 };
73 56
 
74 57
 #endif // __POINT_T__

正在加载...
取消
保存