浏览代码

Cleanup Nozzle class, fix XY vs Z move order

Scott Lahteine 6 年前
父节点
当前提交
267c247da7
共有 3 个文件被更改,包括 157 次插入245 次删除
  1. 131
    184
      Marlin/nozzle.cpp
  2. 21
    36
      Marlin/nozzle.h
  3. 5
    25
      Marlin/point_t.h

+ 131
- 184
Marlin/nozzle.cpp 查看文件

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

+ 21
- 36
Marlin/nozzle.h 查看文件

@@ -26,14 +26,6 @@
26 26
 #include "Marlin.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
-#endif
94
+#endif // __NOZZLE_H__

+ 5
- 25
Marlin/point_t.h 查看文件

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

正在加载...
取消
保存