Bläddra i källkod

Finish G12, update Nozzle::clean (#14642)

InsanityAutomation 5 år sedan
förälder
incheckning
b8cc61262f

+ 4
- 0
Marlin/src/feature/bedlevel/bedlevel.cpp Visa fil

@@ -100,6 +100,10 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
100 100
   }
101 101
 }
102 102
 
103
+TemporaryBedLevelingState::TemporaryBedLevelingState(const bool enable) : saved(planner.leveling_active) {
104
+  set_bed_leveling_enabled(enable);
105
+}
106
+
103 107
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
104 108
 
105 109
   void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {

+ 12
- 0
Marlin/src/feature/bedlevel/bedlevel.h Visa fil

@@ -46,6 +46,18 @@ void reset_bed_level();
46 46
   void _manual_goto_xy(const float &x, const float &y);
47 47
 #endif
48 48
 
49
+/**
50
+ * A class to save and change the bed leveling state,
51
+ * then restore it when it goes out of scope.
52
+ */
53
+class TemporaryBedLevelingState {
54
+  bool saved;
55
+  public:
56
+    TemporaryBedLevelingState(const bool enable);
57
+    ~TemporaryBedLevelingState() { set_bed_leveling_enabled(saved); }
58
+};
59
+#define TEMPORARY_BED_LEVELING_STATE(enable) TemporaryBedLevelingState tbls(enable)
60
+
49 61
 #if HAS_MESH
50 62
 
51 63
   typedef float (&bed_mesh_t)[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];

+ 1
- 1
Marlin/src/feature/pause.cpp Visa fil

@@ -436,7 +436,7 @@ bool pause_print(const float &retract, const point_t &park_point, const float &u
436 436
 
437 437
   // Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
438 438
   if (!axis_unhomed_error())
439
-    Nozzle::park(2, park_point);
439
+    nozzle.park(2, park_point);
440 440
 
441 441
   #if ENABLED(DUAL_X_CARRIAGE)
442 442
     const int8_t saved_ext        = active_extruder;

+ 1
- 1
Marlin/src/feature/prusa_MMU2/mmu2.cpp Visa fil

@@ -573,7 +573,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
573 573
         COPY(resume_position, current_position);
574 574
 
575 575
         if (move_axes && all_axes_homed())
576
-          Nozzle::park(2, park_point /*= NOZZLE_PARK_POINT*/);
576
+          nozzle.park(2, park_point /*= NOZZLE_PARK_POINT*/);
577 577
 
578 578
         if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
579 579
 

+ 0
- 15
Marlin/src/gcode/calibrate/G425.cpp Visa fil

@@ -74,7 +74,6 @@ struct measurements_t {
74 74
   float nozzle_outer_dimension[2] = {CALIBRATION_NOZZLE_OUTER_DIAMETER, CALIBRATION_NOZZLE_OUTER_DIAMETER};
75 75
 };
76 76
 
77
-#define TEMPORARY_BED_LEVELING_STATE(enable) TemporaryBedLevelingState tbls(enable)
78 77
 #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
79 78
 
80 79
 #if ENABLED(BACKLASH_GCODE)
@@ -90,20 +89,6 @@ struct measurements_t {
90 89
 #endif
91 90
 
92 91
 /**
93
- * A class to save and change the bed leveling state,
94
- * then restore it when it goes out of scope.
95
- */
96
-class TemporaryBedLevelingState {
97
-  bool saved;
98
-
99
-  public:
100
-    TemporaryBedLevelingState(const bool enable) : saved(planner.leveling_active) {
101
-      set_bed_leveling_enabled(enable);
102
-    }
103
-    ~TemporaryBedLevelingState() { set_bed_leveling_enabled(saved); }
104
-};
105
-
106
-/**
107 92
  * Move to a particular location. Up to three individual axes
108 93
  * and their destinations can be specified, in any order.
109 94
  */

+ 11
- 18
Marlin/src/gcode/feature/clean/G12.cpp Visa fil

@@ -42,32 +42,25 @@ void GcodeSuite::G12() {
42 42
   // Don't allow nozzle cleaning without homing first
43 43
   if (axis_unhomed_error()) return;
44 44
 
45
-  const bool seenxyz = parser.seen("XYZ"),
46
-             clean_x = !seenxyz || parser.boolval('X'),
47
-             clean_y = !seenxyz || parser.boolval('Y');
48
-
49
-  #if ENABLED(NOZZLE_CLEAN_NO_Z)
50
-    static constexpr bool clean_z = false;
51
-  #else
52
-    const bool clean_z = !seenxyz || parser.boolval('Z');
53
-  #endif
54
-
55 45
   const uint8_t pattern = parser.ushortval('P', 0),
56 46
                 strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES),
57 47
                 objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
58 48
   const float radius = parser.floatval('R', NOZZLE_CLEAN_CIRCLE_RADIUS);
59 49
 
60
-  #if HAS_LEVELING
61
-    const bool was_enabled = planner.leveling_active;
62
-    if (clean_z) set_bed_leveling_enabled(false);
63
-  #endif
64
-
65
-  Nozzle::clean(pattern, strokes, radius, objects, clean_x, clean_y, clean_z);
50
+  const bool seenxyz = parser.seen("XYZ");
51
+  const uint8_t cleans =  (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0)
52
+                        | (!seenxyz || parser.boolval('Y') ? _BV(Y_AXIS) : 0)
53
+                        #if DISABLED(NOZZLE_CLEAN_NO_Z)
54
+                          | (!seenxyz || parser.boolval('Z') ? _BV(Z_AXIS) : 0)
55
+                        #endif
56
+                      ;
66 57
 
67
-  // Re-enable bed level correction if it had been on
68 58
   #if HAS_LEVELING
69
-    if (clean_z) set_bed_leveling_enabled(was_enabled);
59
+    // Disable bed leveling if cleaning Z
60
+    TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active);
70 61
   #endif
62
+
63
+  nozzle.clean(pattern, strokes, radius, objects, cleans);
71 64
 }
72 65
 
73 66
 #endif // NOZZLE_CLEAN_FEATURE

+ 1
- 1
Marlin/src/gcode/feature/pause/G27.cpp Visa fil

@@ -35,7 +35,7 @@
35 35
 void GcodeSuite::G27() {
36 36
   // Don't allow nozzle parking without homing first
37 37
   if (axis_unhomed_error()) return;
38
-  Nozzle::park(parser.ushortval('P'));
38
+  nozzle.park(parser.ushortval('P'));
39 39
 }
40 40
 
41 41
 #endif // NOZZLE_PARK_FEATURE

+ 19
- 7
Marlin/src/libs/nozzle.cpp Visa fil

@@ -26,6 +26,8 @@
26 26
 
27 27
 #include "nozzle.h"
28 28
 
29
+Nozzle nozzle;
30
+
29 31
 #include "../Marlin.h"
30 32
 #include "../module/motion.h"
31 33
 #include "point_t.h"
@@ -155,24 +157,34 @@
155 157
    * @param pattern one of the available patterns
156 158
    * @param argument depends on the cleaning pattern
157 159
    */
158
-  void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const bool clean_x, const bool clean_y, const bool clean_z) {
160
+  void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) {
159 161
     point_t start = NOZZLE_CLEAN_START_POINT;
160 162
     point_t end = NOZZLE_CLEAN_END_POINT;
161
-    if (!clean_x) start.x = end.x = current_position[X_AXIS];
162
-    if (!clean_y) start.y = end.y = current_position[Y_AXIS];
163
-    if (!clean_z) start.z = end.z = current_position[Z_AXIS];
163
+
164
+    if (pattern == 2) {
165
+      if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
166
+        SERIAL_ECHOLNPGM("Warning : Clean Circle requires XY");
167
+        return;
168
+      }
169
+      end = NOZZLE_CLEAN_CIRCLE_MIDDLE;
170
+    }
171
+    else {
172
+      if (!TEST(cleans, X_AXIS)) start.x = end.x = current_position[X_AXIS];
173
+      if (!TEST(cleans, Y_AXIS)) start.y = end.y = current_position[Y_AXIS];
174
+    }
175
+    if (!TEST(cleans, Z_AXIS)) start.z = end.z = current_position[Z_AXIS];
164 176
 
165 177
     switch (pattern) {
166 178
       case 1:
167
-        zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
179
+        zigzag(start, end, strokes, objects);
168 180
         break;
169 181
 
170 182
       case 2:
171
-        circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
183
+        circle(start, end, strokes, radius);
172 184
         break;
173 185
 
174 186
       default:
175
-        stroke(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes);
187
+        stroke(start, end, strokes);
176 188
     }
177 189
   }
178 190
 

+ 3
- 1
Marlin/src/libs/nozzle.h Visa fil

@@ -78,7 +78,7 @@ class Nozzle {
78 78
      * @param pattern one of the available patterns
79 79
      * @param argument depends on the cleaning pattern
80 80
      */
81
-    static void clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const bool clean_x, const bool clean_y, const bool clean_z) _Os;
81
+    static void clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) _Os;
82 82
 
83 83
   #endif // NOZZLE_CLEAN_FEATURE
84 84
 
@@ -88,3 +88,5 @@ class Nozzle {
88 88
 
89 89
   #endif
90 90
 };
91
+
92
+extern Nozzle nozzle;

+ 5
- 11
Marlin/src/module/tool_change.cpp Visa fil

@@ -822,12 +822,6 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
822 822
          return invalid_extruder_error(tmp_extruder);
823 823
     #endif
824 824
 
825
-    #if HAS_LEVELING
826
-      // Set current position to the physical position
827
-      const bool leveling_was_active = planner.leveling_active;
828
-      set_bed_leveling_enabled(false);
829
-    #endif
830
-
831 825
     if (tmp_extruder >= EXTRUDERS)
832 826
       return invalid_extruder_error(tmp_extruder);
833 827
 
@@ -875,6 +869,11 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
875 869
       }
876 870
     #endif // TOOLCHANGE_FILAMENT_SWAP
877 871
 
872
+    #if HAS_LEVELING
873
+      // Set current position to the physical position
874
+      TEMPORARY_BED_LEVELING_STATE(false);
875
+    #endif
876
+
878 877
     if (tmp_extruder != active_extruder) {
879 878
 
880 879
       #if SWITCHING_NOZZLE_TWO_SERVOS
@@ -1071,11 +1070,6 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
1071 1070
       fanmux_switch(active_extruder);
1072 1071
     #endif
1073 1072
 
1074
-    #if HAS_LEVELING
1075
-      // Restore leveling to re-establish the logical position
1076
-      set_bed_leveling_enabled(leveling_was_active);
1077
-    #endif
1078
-
1079 1073
     SERIAL_ECHO_START();
1080 1074
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
1081 1075
 

Laddar…
Avbryt
Spara