Browse Source

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

InsanityAutomation 5 years ago
parent
commit
b8cc61262f

+ 4
- 0
Marlin/src/feature/bedlevel/bedlevel.cpp View File

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
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
107
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
104
 
108
 
105
   void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {
109
   void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {

+ 12
- 0
Marlin/src/feature/bedlevel/bedlevel.h View File

46
   void _manual_goto_xy(const float &x, const float &y);
46
   void _manual_goto_xy(const float &x, const float &y);
47
 #endif
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
 #if HAS_MESH
61
 #if HAS_MESH
50
 
62
 
51
   typedef float (&bed_mesh_t)[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
63
   typedef float (&bed_mesh_t)[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];

+ 1
- 1
Marlin/src/feature/pause.cpp View File

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

+ 1
- 1
Marlin/src/feature/prusa_MMU2/mmu2.cpp View File

573
         COPY(resume_position, current_position);
573
         COPY(resume_position, current_position);
574
 
574
 
575
         if (move_axes && all_axes_homed())
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
         if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
578
         if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
579
 
579
 

+ 0
- 15
Marlin/src/gcode/calibrate/G425.cpp View File

74
   float nozzle_outer_dimension[2] = {CALIBRATION_NOZZLE_OUTER_DIAMETER, CALIBRATION_NOZZLE_OUTER_DIAMETER};
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
 #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
77
 #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
79
 
78
 
80
 #if ENABLED(BACKLASH_GCODE)
79
 #if ENABLED(BACKLASH_GCODE)
90
 #endif
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
  * Move to a particular location. Up to three individual axes
92
  * Move to a particular location. Up to three individual axes
108
  * and their destinations can be specified, in any order.
93
  * and their destinations can be specified, in any order.
109
  */
94
  */

+ 11
- 18
Marlin/src/gcode/feature/clean/G12.cpp View File

42
   // Don't allow nozzle cleaning without homing first
42
   // Don't allow nozzle cleaning without homing first
43
   if (axis_unhomed_error()) return;
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
   const uint8_t pattern = parser.ushortval('P', 0),
45
   const uint8_t pattern = parser.ushortval('P', 0),
56
                 strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES),
46
                 strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES),
57
                 objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
47
                 objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
58
   const float radius = parser.floatval('R', NOZZLE_CLEAN_CIRCLE_RADIUS);
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
   #if HAS_LEVELING
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
   #endif
61
   #endif
62
+
63
+  nozzle.clean(pattern, strokes, radius, objects, cleans);
71
 }
64
 }
72
 
65
 
73
 #endif // NOZZLE_CLEAN_FEATURE
66
 #endif // NOZZLE_CLEAN_FEATURE

+ 1
- 1
Marlin/src/gcode/feature/pause/G27.cpp View File

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

+ 19
- 7
Marlin/src/libs/nozzle.cpp View File

26
 
26
 
27
 #include "nozzle.h"
27
 #include "nozzle.h"
28
 
28
 
29
+Nozzle nozzle;
30
+
29
 #include "../Marlin.h"
31
 #include "../Marlin.h"
30
 #include "../module/motion.h"
32
 #include "../module/motion.h"
31
 #include "point_t.h"
33
 #include "point_t.h"
155
    * @param pattern one of the available patterns
157
    * @param pattern one of the available patterns
156
    * @param argument depends on the cleaning pattern
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
     point_t start = NOZZLE_CLEAN_START_POINT;
161
     point_t start = NOZZLE_CLEAN_START_POINT;
160
     point_t end = NOZZLE_CLEAN_END_POINT;
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
     switch (pattern) {
177
     switch (pattern) {
166
       case 1:
178
       case 1:
167
-        zigzag(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_END_POINT, strokes, objects);
179
+        zigzag(start, end, strokes, objects);
168
         break;
180
         break;
169
 
181
 
170
       case 2:
182
       case 2:
171
-        circle(NOZZLE_CLEAN_START_POINT, NOZZLE_CLEAN_CIRCLE_MIDDLE, strokes, radius);
183
+        circle(start, end, strokes, radius);
172
         break;
184
         break;
173
 
185
 
174
       default:
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 View File

78
      * @param pattern one of the available patterns
78
      * @param pattern one of the available patterns
79
      * @param argument depends on the cleaning pattern
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
   #endif // NOZZLE_CLEAN_FEATURE
83
   #endif // NOZZLE_CLEAN_FEATURE
84
 
84
 
88
 
88
 
89
   #endif
89
   #endif
90
 };
90
 };
91
+
92
+extern Nozzle nozzle;

+ 5
- 11
Marlin/src/module/tool_change.cpp View File

822
          return invalid_extruder_error(tmp_extruder);
822
          return invalid_extruder_error(tmp_extruder);
823
     #endif
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
     if (tmp_extruder >= EXTRUDERS)
825
     if (tmp_extruder >= EXTRUDERS)
832
       return invalid_extruder_error(tmp_extruder);
826
       return invalid_extruder_error(tmp_extruder);
833
 
827
 
875
       }
869
       }
876
     #endif // TOOLCHANGE_FILAMENT_SWAP
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
     if (tmp_extruder != active_extruder) {
877
     if (tmp_extruder != active_extruder) {
879
 
878
 
880
       #if SWITCHING_NOZZLE_TWO_SERVOS
879
       #if SWITCHING_NOZZLE_TWO_SERVOS
1071
       fanmux_switch(active_extruder);
1070
       fanmux_switch(active_extruder);
1072
     #endif
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
     SERIAL_ECHO_START();
1073
     SERIAL_ECHO_START();
1080
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
1074
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
1081
 
1075
 

Loading…
Cancel
Save