Преглед изворни кода

Improves G12 zig-zag pattern

João Brázio пре 8 година
родитељ
комит
021544f572
3 измењених фајлова са 61 додато и 34 уклоњено
  1. 16
    11
      Marlin/Configuration.h
  2. 3
    2
      Marlin/Marlin_main.cpp
  3. 42
    21
      Marlin/nozzle.h

+ 16
- 11
Marlin/Configuration.h Прегледај датотеку

@@ -801,15 +801,20 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
801 801
 //       "strokes" i.e. back-and-forth movements between the starting and end
802 802
 //       points.
803 803
 //
804
-//   P1: This starts a zig-zag pattern between (Xs, Ys) and (Xe, Ye), "S"
805
-//       defines the number of zig-zag triangles to be done. Each "side"
806
-//       cannot be less than 5mm. As an example "G12 P1 S3" will execute:
807
-//
808
-//                                                /|   /|   /| (Xe, Ye)
809
-//                                               / |  / |  / |
810
-//                                              /  | /  | /  |
811
-//                                    (Xs, Ys) /   |/   |/   |
812
-//
804
+//   P1: This starts a zig-zag pattern between (X0, Y0) and (X1, Y1), "T"
805
+//       defines the number of zig-zag triangles to be done. "S" defines the
806
+//       number of strokes aka one back-and-forth movement. As an example
807
+//       sending "G12 P1 S1 T3" will execute:
808
+//
809
+//          --
810
+//         |  (X0, Y1) |     /\        /\        /\     | (X1, Y1)
811
+//         |           |    /  \      /  \      /  \    |
812
+//       A |           |   /    \    /    \    /    \   |
813
+//         |           |  /      \  /      \  /      \  |
814
+//         |  (X0, Y0) | /        \/        \/        \ | (X1, Y0)
815
+//          --         +--------------------------------+
816
+//                       |________|_________|_________|
817
+//                           T1        T2        T3
813 818
 //
814 819
 // Caveats: End point Z should use the same value as Start point Z.
815 820
 //
@@ -820,8 +825,8 @@ const bool Z_MIN_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the l
820 825
 
821 826
 #if ENABLED(CLEAN_NOZZLE_FEATURE)
822 827
   #define CLEAN_NOZZLE_STROKES  12
823
-  #define CLEAN_NOZZLE_START_PT { 30, 30, (Z_MIN_POS + 1), 0}
824
-  #define CLEAN_NOZZLE_END_PT   {100, 60, (Z_MIN_POS + 1), 0}
828
+  #define CLEAN_NOZZLE_START_PT { 30, 30, (Z_MIN_POS + 5), 0}
829
+  #define CLEAN_NOZZLE_END_PT   {100, 60, (Z_MIN_POS + 5), 0}
825 830
   //                            {  X,  Y,               Z, E}
826 831
 #endif
827 832
 

+ 3
- 2
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -2718,7 +2718,7 @@ inline void gcode_G4() {
2718 2718
 #endif //FWRETRACT
2719 2719
 
2720 2720
 #if ENABLED(CLEAN_NOZZLE_FEATURE) && ENABLED(AUTO_BED_LEVELING_FEATURE)
2721
-  #include "clean_nozzle.h"
2721
+  #include "nozzle.h"
2722 2722
 
2723 2723
   inline void gcode_G12() {
2724 2724
     // Don't allow nozzle cleaning without homing first
@@ -2729,8 +2729,9 @@ inline void gcode_G4() {
2729 2729
 
2730 2730
     uint8_t const pattern = code_seen('P') ? code_value_ushort() : 0;
2731 2731
     uint8_t const strokes = code_seen('S') ? code_value_ushort() : CLEAN_NOZZLE_STROKES;
2732
+    uint8_t const objects = code_seen('T') ? code_value_ushort() : 3;
2732 2733
 
2733
-    CleanNozzle::start(pattern, strokes);
2734
+    Nozzle::clean(pattern, strokes, objects);
2734 2735
   }
2735 2736
 #endif
2736 2737
 

Marlin/clean_nozzle.h → Marlin/nozzle.h Прегледај датотеку

@@ -27,13 +27,13 @@
27 27
 #include "point_t.h"
28 28
 
29 29
 /**
30
- * @brief CleanNozzle class
30
+ * @brief Nozzle class
31 31
  *
32 32
  * @todo: Do not ignore the end.z value and allow XYZ movements
33 33
  * @todo: Currently this feature needs AUTO_BED_LEVELING_FEATURE to be active
34 34
  *  due to the do_blocking_move_to*() functions.
35 35
  */
36
-class CleanNozzle {
36
+class Nozzle {
37 37
   private:
38 38
     /**
39 39
      * @brief Stroke clean pattern
@@ -62,26 +62,46 @@ class CleanNozzle {
62 62
      *
63 63
      * @param start point_t defining the starting point
64 64
      * @param end point_t defining the ending point
65
-     * @param triangles number of triangles to execute
65
+     * @param strokes number of strokes to execute
66
+     * @param objects number of objects to create
66 67
      */
67
-    static void zigzag(point_t const &start, point_t const &end, uint8_t const &triangles)
68
+    static void zigzag(point_t const &start,
69
+      point_t const &end, uint8_t const &strokes, uint8_t const &objects)
68 70
     __attribute__ ((optimize ("Os"))) {
69
-      // Move to the starting point
70
-      do_blocking_move_to_xy(start.x, start.y);
71
-      do_blocking_move_to_z(start.z);
71
+      float A = fabs(end.y - start.y); // [twice the] Amplitude
72
+      float P = fabs(end.x - start.x) / (objects << 1); // Period
72 73
 
73
-      // Calculate the triangle side
74
-      float const a = fabs(end.x - start.x) / triangles;
74
+      // Don't allow impossible triangles
75
+      if (A <= 0.0f || P <= 0.0f ) return;
75 76
 
76
-      // Don't allow the sides (a, b) to be smaller than 5mm
77
-      if (a < 5 || fabs(end.y - start.y) < 5) return;
77
+      // Store the current coords
78
+      point_t const home = {
79
+        current_position[X_AXIS],
80
+        current_position[Y_AXIS],
81
+        current_position[Z_AXIS],
82
+        current_position[E_AXIS]
83
+      };
78 84
 
79
-      // Start the zig-zag pattern
80
-      for (uint8_t i = 0; i < triangles; i++) {
81
-        float const x = start.x + (a * (i + 1));
82
-        do_blocking_move_to_xy(x, end.y);
83
-        do_blocking_move_to_y(start.y);
85
+      for (uint8_t j = 0; j < strokes; j++) {
86
+        for (uint8_t i = 0; i < (objects << 1); i++) {
87
+          float const x = start.x + i * P;
88
+          float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
89
+
90
+          do_blocking_move_to_xy(x, y);
91
+          if (i == 0) do_blocking_move_to_z(start.z);
92
+        }
93
+
94
+        for (int i = (objects << 1); i > -1; i--) {
95
+          float const x = start.x + i * P;
96
+          float const y = start.y + (A/P) * (P - fabs(fmod((i*P), (2*P)) - P));
97
+
98
+          do_blocking_move_to_xy(x, y);
99
+        }
84 100
       }
101
+
102
+      // Move to home/start position
103
+      do_blocking_move_to_z(home.z);
104
+      do_blocking_move_to_xy(home.x, home.y);
85 105
     }
86 106
 
87 107
   public:
@@ -92,19 +112,20 @@ class CleanNozzle {
92 112
      * @param pattern one of the available patterns
93 113
      * @param argument depends on the cleaning pattern
94 114
      */
95
-    static void start(uint8_t const &pattern, uint8_t const &argument)
115
+    static void clean(uint8_t const &pattern,
116
+      uint8_t const &strokes, uint8_t const &objects = 0)
96 117
     __attribute__ ((optimize ("Os"))) {
97 118
       switch (pattern) {
98 119
         case 1:
99
-          CleanNozzle::zigzag(
120
+          Nozzle::zigzag(
100 121
             CLEAN_NOZZLE_START_PT,
101
-            CLEAN_NOZZLE_END_PT, argument);
122
+            CLEAN_NOZZLE_END_PT, strokes, objects);
102 123
           break;
103 124
 
104 125
         default:
105
-          CleanNozzle::stroke(
126
+          Nozzle::stroke(
106 127
             CLEAN_NOZZLE_START_PT,
107
-            CLEAN_NOZZLE_END_PT, argument);
128
+            CLEAN_NOZZLE_END_PT, strokes);
108 129
       }
109 130
     }
110 131
 };

Loading…
Откажи
Сачувај