Browse Source

Consolidate probe clearance, add section debug (#18576)

* Better section / function log
* Add do_z_clearance motion function
Scott Lahteine 4 years ago
parent
commit
73fc0778b8
No account linked to committer's email address

+ 9
- 0
Marlin/src/core/debug_out.h View File

26
 //  (or not) in a given .cpp file
26
 //  (or not) in a given .cpp file
27
 //
27
 //
28
 
28
 
29
+#undef DEBUG_SECTION
29
 #undef DEBUG_PRINT_P
30
 #undef DEBUG_PRINT_P
30
 #undef DEBUG_ECHO_START
31
 #undef DEBUG_ECHO_START
31
 #undef DEBUG_ERROR_START
32
 #undef DEBUG_ERROR_START
53
 #undef DEBUG_DELAY
54
 #undef DEBUG_DELAY
54
 
55
 
55
 #if DEBUG_OUT
56
 #if DEBUG_OUT
57
+
58
+  #include "debug_section.h"
59
+  #define DEBUG_SECTION(N,S,D)    SectionLog N(PSTR(S),D)
60
+
56
   #define DEBUG_PRINT_P(P)        serialprintPGM(P)
61
   #define DEBUG_PRINT_P(P)        serialprintPGM(P)
57
   #define DEBUG_ECHO_START        SERIAL_ECHO_START
62
   #define DEBUG_ECHO_START        SERIAL_ECHO_START
58
   #define DEBUG_ERROR_START       SERIAL_ERROR_START
63
   #define DEBUG_ERROR_START       SERIAL_ERROR_START
78
   #define DEBUG_POS               SERIAL_POS
83
   #define DEBUG_POS               SERIAL_POS
79
   #define DEBUG_XYZ               SERIAL_XYZ
84
   #define DEBUG_XYZ               SERIAL_XYZ
80
   #define DEBUG_DELAY(ms)         serial_delay(ms)
85
   #define DEBUG_DELAY(ms)         serial_delay(ms)
86
+
81
 #else
87
 #else
88
+
89
+  #define DEBUG_SECTION(...)        NOOP
82
   #define DEBUG_PRINT_P(P)          NOOP
90
   #define DEBUG_PRINT_P(P)          NOOP
83
   #define DEBUG_ECHO_START()        NOOP
91
   #define DEBUG_ECHO_START()        NOOP
84
   #define DEBUG_ERROR_START()       NOOP
92
   #define DEBUG_ERROR_START()       NOOP
104
   #define DEBUG_POS(...)            NOOP
112
   #define DEBUG_POS(...)            NOOP
105
   #define DEBUG_XYZ(...)            NOOP
113
   #define DEBUG_XYZ(...)            NOOP
106
   #define DEBUG_DELAY(...)          NOOP
114
   #define DEBUG_DELAY(...)          NOOP
115
+
107
 #endif
116
 #endif
108
 
117
 
109
 #undef DEBUG_OUT
118
 #undef DEBUG_OUT

+ 49
- 0
Marlin/src/core/debug_section.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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
+#pragma once
23
+
24
+#include "serial.h"
25
+#include "../module/motion.h"
26
+
27
+class SectionLog {
28
+public:
29
+  SectionLog(PGM_P const msg=nullptr, bool inbug=true) {
30
+    the_msg = msg;
31
+    if ((debug = inbug)) echo_msg(PSTR(">>>"));
32
+  }
33
+
34
+  ~SectionLog() { if (debug) echo_msg(PSTR("<<<")); }
35
+
36
+private:
37
+  PGM_P the_msg;
38
+  bool debug;
39
+
40
+  void echo_msg(PGM_P const pre) {
41
+    serialprintPGM(pre);
42
+    if (the_msg) {
43
+      SERIAL_CHAR(' ');
44
+      serialprintPGM(the_msg);
45
+    }
46
+    SERIAL_CHAR(' ');
47
+    print_xyz(current_position);
48
+  }
49
+};

+ 7
- 14
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

462
             // Manually Probe Mesh in areas that can't be reached by the probe
462
             // Manually Probe Mesh in areas that can't be reached by the probe
463
             //
463
             //
464
             SERIAL_ECHOLNPGM("Manually probing unreachable points.");
464
             SERIAL_ECHOLNPGM("Manually probing unreachable points.");
465
-            do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
465
+            do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
466
 
466
 
467
             if (parser.seen('C') && !xy_seen) {
467
             if (parser.seen('C') && !xy_seen) {
468
 
468
 
780
       probe.stow();
780
       probe.stow();
781
       TERN_(HAS_LCD_MENU, ui.capture());
781
       TERN_(HAS_LCD_MENU, ui.capture());
782
 
782
 
783
-      #ifdef Z_AFTER_PROBING
784
-        probe.move_z_after_probing();
785
-      #endif
783
+      probe.move_z_after_probing();
786
 
784
 
787
       restore_ubl_active_state_and_leave();
785
       restore_ubl_active_state_and_leave();
788
 
786
 
858
       echo_and_take_a_measurement();
856
       echo_and_take_a_measurement();
859
 
857
 
860
       const float z2 = measure_point_with_encoder();
858
       const float z2 = measure_point_with_encoder();
861
-
862
       do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
859
       do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
863
 
860
 
864
       const float thickness = ABS(z1 - z2);
861
       const float thickness = ABS(z1 - z2);
899
         LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
896
         LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
900
 
897
 
901
         do_blocking_move_to(ppos);
898
         do_blocking_move_to(ppos);
902
-        do_blocking_move_to_z(z_clearance);
899
+        do_z_clearance(z_clearance);
903
 
900
 
904
         KEEPALIVE_STATE(PAUSED_FOR_USER);
901
         KEEPALIVE_STATE(PAUSED_FOR_USER);
905
         ui.capture();
902
         ui.capture();
915
 
912
 
916
         if (click_and_hold()) {
913
         if (click_and_hold()) {
917
           SERIAL_ECHOLNPGM("\nMesh only partially populated.");
914
           SERIAL_ECHOLNPGM("\nMesh only partially populated.");
918
-          do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
915
+          do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
919
           return restore_ubl_active_state_and_leave();
916
           return restore_ubl_active_state_and_leave();
920
         }
917
         }
921
 
918
 
940
 
937
 
941
     void abort_fine_tune() {
938
     void abort_fine_tune() {
942
       ui.return_to_status();
939
       ui.return_to_status();
943
-      do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
940
+      do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
944
       set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
941
       set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
945
     }
942
     }
946
 
943
 
1415
         }
1412
         }
1416
 
1413
 
1417
         probe.stow();
1414
         probe.stow();
1418
-        #ifdef Z_AFTER_PROBING
1419
-          probe.move_z_after_probing();
1420
-        #endif
1415
+        probe.move_z_after_probing();
1421
 
1416
 
1422
         if (abort_flag) {
1417
         if (abort_flag) {
1423
           SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
1418
           SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
1478
         }
1473
         }
1479
       }
1474
       }
1480
       probe.stow();
1475
       probe.stow();
1481
-      #ifdef Z_AFTER_PROBING
1482
-        probe.move_z_after_probing();
1483
-      #endif
1476
+      probe.move_z_after_probing();
1484
 
1477
 
1485
       if (abort_flag || finish_incremental_LSF(&lsf_results)) {
1478
       if (abort_flag || finish_incremental_LSF(&lsf_results)) {
1486
         SERIAL_ECHOPGM("Could not complete LSF!");
1479
         SERIAL_ECHOPGM("Could not complete LSF!");

+ 1
- 2
Marlin/src/gcode/bedlevel/G26.cpp View File

622
    */
622
    */
623
   set_bed_leveling_enabled(!parser.seen('D'));
623
   set_bed_leveling_enabled(!parser.seen('D'));
624
 
624
 
625
-  if (current_position.z < Z_CLEARANCE_BETWEEN_PROBES)
626
-    do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
625
+  do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
627
 
626
 
628
   #if DISABLED(NO_VOLUMETRICS)
627
   #if DISABLED(NO_VOLUMETRICS)
629
     bool volumetric_was_enabled = parser.volumetric_enabled;
628
     bool volumetric_was_enabled = parser.volumetric_enabled;

+ 3
- 6
Marlin/src/gcode/bedlevel/G35.cpp View File

75
  *               51 - Counter-Clockwise M5
75
  *               51 - Counter-Clockwise M5
76
  **/
76
  **/
77
 void GcodeSuite::G35() {
77
 void GcodeSuite::G35() {
78
-  if (DEBUGGING(LEVELING)) {
79
-    DEBUG_ECHOLNPGM(">>> G35");
80
-    log_machine_info();
81
-  }
78
+  DEBUG_SECTION(log_G35, "G35", DEBUGGING(LEVELING));
79
+
80
+  if (DEBUGGING(LEVELING)) log_machine_info();
82
 
81
 
83
   float z_measured[G35_PROBE_COUNT] = { 0 };
82
   float z_measured[G35_PROBE_COUNT] = { 0 };
84
 
83
 
181
 
180
 
182
   // Home Z after the alignment procedure
181
   // Home Z after the alignment procedure
183
   process_subcommands_now_P(PSTR("G28Z"));
182
   process_subcommands_now_P(PSTR("G28Z"));
184
-
185
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G35");
186
 }
183
 }
187
 
184
 
188
 #endif // ASSISTED_TRAMMING
185
 #endif // ASSISTED_TRAMMING

+ 5
- 9
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

172
   #if ENABLED(DEBUG_LEVELING_FEATURE)
172
   #if ENABLED(DEBUG_LEVELING_FEATURE)
173
     const uint8_t old_debug_flags = marlin_debug_flags;
173
     const uint8_t old_debug_flags = marlin_debug_flags;
174
     if (seenQ) marlin_debug_flags |= MARLIN_DEBUG_LEVELING;
174
     if (seenQ) marlin_debug_flags |= MARLIN_DEBUG_LEVELING;
175
-    if (DEBUGGING(LEVELING)) {
176
-      DEBUG_POS(">>> G29", current_position);
177
-      log_machine_info();
178
-    }
175
+    DEBUG_SECTION(log_G29, "G29", DEBUGGING(LEVELING));
176
+    if (DEBUGGING(LEVELING)) log_machine_info();
179
     marlin_debug_flags = old_debug_flags;
177
     marlin_debug_flags = old_debug_flags;
180
     if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
178
     if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
181
   #endif
179
   #endif
188
   if (axis_unhomed_error()) G29_RETURN(false);
186
   if (axis_unhomed_error()) G29_RETURN(false);
189
 
187
 
190
   if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
188
   if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
191
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Auto-level not needed, skip\n<<< G29");
189
+    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Auto-level not needed, skip");
192
     G29_RETURN(false);
190
     G29_RETURN(false);
193
   }
191
   }
194
 
192
 
416
     // Deploy certain probes before starting probing
414
     // Deploy certain probes before starting probing
417
     #if HAS_BED_PROBE
415
     #if HAS_BED_PROBE
418
       if (ENABLED(BLTOUCH))
416
       if (ENABLED(BLTOUCH))
419
-        do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
417
+        do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
420
       else if (probe.deploy()) {
418
       else if (probe.deploy()) {
421
         set_bed_leveling_enabled(abl_should_enable);
419
         set_bed_leveling_enabled(abl_should_enable);
422
         G29_RETURN(false);
420
         G29_RETURN(false);
884
   // Sync the planner from the current_position
882
   // Sync the planner from the current_position
885
   if (planner.leveling_active) sync_plan_position();
883
   if (planner.leveling_active) sync_plan_position();
886
 
884
 
887
-  #if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
885
+  #if HAS_BED_PROBE
888
     probe.move_z_after_probing();
886
     probe.move_z_after_probing();
889
   #endif
887
   #endif
890
 
888
 
900
 
898
 
901
   report_current_position();
899
   report_current_position();
902
 
900
 
903
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
904
-
905
   G29_RETURN(isnan(measured_z));
901
   G29_RETURN(isnan(measured_z));
906
 }
902
 }
907
 
903
 

+ 13
- 36
Marlin/src/gcode/calibrate/G28.cpp View File

115
 #if ENABLED(Z_SAFE_HOMING)
115
 #if ENABLED(Z_SAFE_HOMING)
116
 
116
 
117
   inline void home_z_safely() {
117
   inline void home_z_safely() {
118
+    DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING));
119
+
118
     // Disallow Z homing if X or Y homing is needed
120
     // Disallow Z homing if X or Y homing is needed
119
     if (axis_unhomed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return;
121
     if (axis_unhomed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return;
120
 
122
 
121
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("home_z_safely >>>");
122
-
123
     sync_plan_position();
123
     sync_plan_position();
124
 
124
 
125
     /**
125
     /**
146
       LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
146
       LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
147
       SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER);
147
       SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER);
148
     }
148
     }
149
-
150
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< home_z_safely");
151
   }
149
   }
152
 
150
 
153
 #endif // Z_SAFE_HOMING
151
 #endif // Z_SAFE_HOMING
197
  *
195
  *
198
  */
196
  */
199
 void GcodeSuite::G28() {
197
 void GcodeSuite::G28() {
198
+  DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
199
+  if (DEBUGGING(LEVELING)) log_machine_info();
200
 
200
 
201
-  if (DEBUGGING(LEVELING)) {
202
-    DEBUG_ECHOLNPGM(">>> G28");
203
-    log_machine_info();
204
-  }
205
-
206
-  #if ENABLED(LASER_MOVE_G28_OFF)
207
-    cutter.set_inline_enabled(false);       // turn off laser
208
-  #endif
201
+  TERN_(LASER_MOVE_G28_OFF, cutter.set_inline_enabled(false));  // turn off laser
209
 
202
 
210
   TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
203
   TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
211
 
204
 
220
       sync_plan_position();
213
       sync_plan_position();
221
       SERIAL_ECHOLNPGM("Simulated Homing");
214
       SERIAL_ECHOLNPGM("Simulated Homing");
222
       report_current_position();
215
       report_current_position();
223
-      if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
224
       return;
216
       return;
225
     }
217
     }
226
   #endif
218
   #endif
227
 
219
 
228
   // Home (O)nly if position is unknown
220
   // Home (O)nly if position is unknown
229
   if (!homing_needed() && parser.boolval('O')) {
221
   if (!homing_needed() && parser.boolval('O')) {
230
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip\n<<< G28");
222
+    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip");
231
     return;
223
     return;
232
   }
224
   }
233
 
225
 
313
                home_all = homeX == homeY && homeX == homeZ, // All or None
305
                home_all = homeX == homeY && homeX == homeZ, // All or None
314
                doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ;
306
                doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ;
315
 
307
 
316
-    destination = current_position;
317
-
318
     #if Z_HOME_DIR > 0  // If homing away from BED do Z first
308
     #if Z_HOME_DIR > 0  // If homing away from BED do Z first
319
 
309
 
320
       if (doZ) homeaxis(Z_AXIS);
310
       if (doZ) homeaxis(Z_AXIS);
322
     #endif
312
     #endif
323
 
313
 
324
     const float z_homing_height =
314
     const float z_homing_height =
325
-      (DISABLED(UNKNOWN_Z_NO_RAISE) || TEST(axis_known_position, Z_AXIS))
326
-        ? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
327
-        : 0;
315
+      ENABLED(UNKNOWN_Z_NO_RAISE) && TEST(axis_known_position, Z_AXIS)
316
+        ? 0
317
+        : (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT);
328
 
318
 
329
-    if (z_homing_height && (doX || doY || ENABLED(Z_SAFE_HOMING))) {
319
+    if (z_homing_height && (doX || doY || (ENABLED(Z_SAFE_HOMING) && doZ))) {
330
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
320
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
331
-      destination.z = z_homing_height + (TEST(axis_known_position, Z_AXIS) ? 0.0f : current_position.z);
332
-      if (destination.z > current_position.z) {
333
-        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) to ", destination.z);
334
-        do_blocking_move_to_z(destination.z);
335
-      }
321
+      if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) by ", z_homing_height);
322
+      do_z_clearance(z_homing_height, TEST(axis_known_position, Z_AXIS), DISABLED(UNKNOWN_Z_NO_RAISE));
336
     }
323
     }
337
 
324
 
338
     #if ENABLED(QUICK_HOME)
325
     #if ENABLED(QUICK_HOME)
387
 
374
 
388
         TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS));
375
         TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS));
389
 
376
 
390
-        #if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING)
391
-          #if Z_AFTER_HOMING > Z_AFTER_PROBING
392
-            do_blocking_move_to_z(Z_AFTER_HOMING);
393
-          #else
394
-            probe.move_z_after_probing();
395
-          #endif
396
-        #elif defined(Z_AFTER_HOMING)
397
-          do_blocking_move_to_z(Z_AFTER_HOMING);
398
-        #endif
377
+        probe.move_z_after_homing();
399
 
378
 
400
       } // doZ
379
       } // doZ
401
 
380
 
485
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
464
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
486
     SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
465
     SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
487
 
466
 
488
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
489
-
490
   #if HAS_L64XX
467
   #if HAS_L64XX
491
     // Set L6470 absolute position registers to counts
468
     // Set L6470 absolute position registers to counts
492
     // constexpr *might* move this to PROGMEM.
469
     // constexpr *might* move this to PROGMEM.

+ 2
- 6
Marlin/src/gcode/calibrate/G34_M422.cpp View File

56
  *   R<recalculate> points based on current probe offsets
56
  *   R<recalculate> points based on current probe offsets
57
  */
57
  */
58
 void GcodeSuite::G34() {
58
 void GcodeSuite::G34() {
59
-  if (DEBUGGING(LEVELING)) {
60
-    DEBUG_ECHOLNPGM(">>> G34");
61
-    log_machine_info();
62
-  }
59
+  DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING));
60
+  if (DEBUGGING(LEVELING)) log_machine_info();
63
 
61
 
64
   do { // break out on error
62
   do { // break out on error
65
 
63
 
367
     #endif
365
     #endif
368
 
366
 
369
   }while(0);
367
   }while(0);
370
-
371
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G34");
372
 }
368
 }
373
 
369
 
374
 /**
370
 /**

+ 1
- 1
Marlin/src/gcode/calibrate/G76_M871.cpp View File

104
   };
104
   };
105
 
105
 
106
   auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
106
   auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
107
-    do_blocking_move_to_z(5.0); // Raise nozzle before probing
107
+    do_z_clearance(5.0); // Raise nozzle before probing
108
     const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
108
     const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
109
     if (isnan(measured_z))
109
     if (isnan(measured_z))
110
       SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
110
       SERIAL_ECHOLNPGM("!Received NAN. Aborting.");

+ 1
- 2
Marlin/src/gcode/calibrate/M666.cpp View File

38
    * M666: Set delta endstop adjustment
38
    * M666: Set delta endstop adjustment
39
    */
39
    */
40
   void GcodeSuite::M666() {
40
   void GcodeSuite::M666() {
41
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> M666");
41
+    DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
42
     LOOP_XYZ(i) {
42
     LOOP_XYZ(i) {
43
       if (parser.seen(XYZ_CHAR(i))) {
43
       if (parser.seen(XYZ_CHAR(i))) {
44
         const float v = parser.value_linear_units();
44
         const float v = parser.value_linear_units();
46
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]);
46
         if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]);
47
       }
47
       }
48
     }
48
     }
49
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< M666");
50
   }
49
   }
51
 
50
 
52
 #elif HAS_EXTRA_ENDSTOPS
51
 #elif HAS_EXTRA_ENDSTOPS

+ 2
- 9
Marlin/src/gcode/control/T.cpp View File

48
  */
48
  */
49
 void GcodeSuite::T(const uint8_t tool_index) {
49
 void GcodeSuite::T(const uint8_t tool_index) {
50
 
50
 
51
-  if (DEBUGGING(LEVELING)) {
52
-    DEBUG_ECHOLNPAIR(">>> T(", tool_index, ")");
53
-    DEBUG_POS("BEFORE", current_position);
54
-  }
51
+  DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
52
+  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");
55
 
53
 
56
   // Count this command as movement / activity
54
   // Count this command as movement / activity
57
   reset_stepper_timeout();
55
   reset_stepper_timeout();
75
     );
73
     );
76
 
74
 
77
   #endif
75
   #endif
78
-
79
-  if (DEBUGGING(LEVELING)) {
80
-    DEBUG_POS("AFTER", current_position);
81
-    DEBUG_ECHOLNPGM("<<< T()");
82
-  }
83
 }
76
 }

+ 2
- 3
Marlin/src/gcode/probe/G30.cpp View File

57
 
57
 
58
   restore_feedrate_and_scaling();
58
   restore_feedrate_and_scaling();
59
 
59
 
60
-  #ifdef Z_AFTER_PROBING
61
-    if (raise_after == PROBE_PT_STOW) probe.move_z_after_probing();
62
-  #endif
60
+  if (raise_after == PROBE_PT_STOW)
61
+    probe.move_z_after_probing();
63
 
62
 
64
   report_current_position();
63
   report_current_position();
65
 }
64
 }

+ 1
- 3
Marlin/src/gcode/probe/M401_M402.cpp View File

41
  */
41
  */
42
 void GcodeSuite::M402() {
42
 void GcodeSuite::M402() {
43
   probe.stow();
43
   probe.stow();
44
-  #ifdef Z_AFTER_PROBING
45
-    probe.move_z_after_probing();
46
-  #endif
44
+  probe.move_z_after_probing();
47
   report_current_position();
45
   report_current_position();
48
 }
46
 }
49
 
47
 

+ 2
- 3
Marlin/src/module/delta.cpp View File

233
  * This is like quick_home_xy() but for 3 towers.
233
  * This is like quick_home_xy() but for 3 towers.
234
  */
234
  */
235
 void home_delta() {
235
 void home_delta() {
236
-  if (DEBUGGING(LEVELING)) DEBUG_POS(">>> home_delta", current_position);
236
+  DEBUG_SECTION(log_home_delta, "home_delta", DEBUGGING(LEVELING));
237
+
237
   // Init the current position of all carriages to 0,0,0
238
   // Init the current position of all carriages to 0,0,0
238
   current_position.reset();
239
   current_position.reset();
239
   destination.reset();
240
   destination.reset();
283
       line_to_current_position(homing_feedrate(Z_AXIS));
284
       line_to_current_position(homing_feedrate(Z_AXIS));
284
     }
285
     }
285
   #endif
286
   #endif
286
-
287
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< home_delta", current_position);
288
 }
287
 }
289
 
288
 
290
 #endif // DELTA
289
 #endif // DELTA

+ 11
- 6
Marlin/src/module/motion.cpp View File

387
  * Plan a move to (X, Y, Z) and set the current_position
387
  * Plan a move to (X, Y, Z) and set the current_position
388
  */
388
  */
389
 void do_blocking_move_to(const float rx, const float ry, const float rz, const feedRate_t &fr_mm_s/*=0.0*/) {
389
 void do_blocking_move_to(const float rx, const float ry, const float rz, const feedRate_t &fr_mm_s/*=0.0*/) {
390
-  if (DEBUGGING(LEVELING)) DEBUG_XYZ(">>> do_blocking_move_to", rx, ry, rz);
390
+  DEBUG_SECTION(log_move, "do_blocking_move_to", DEBUGGING(LEVELING));
391
+  if (DEBUGGING(LEVELING)) DEBUG_XYZ("> ", rx, ry, rz);
391
 
392
 
392
   const feedRate_t z_feedrate = fr_mm_s ?: homing_feedrate(Z_AXIS),
393
   const feedRate_t z_feedrate = fr_mm_s ?: homing_feedrate(Z_AXIS),
393
                   xy_feedrate = fr_mm_s ?: feedRate_t(XY_PROBE_FEEDRATE_MM_S);
394
                   xy_feedrate = fr_mm_s ?: feedRate_t(XY_PROBE_FEEDRATE_MM_S);
471
 
472
 
472
   #endif
473
   #endif
473
 
474
 
474
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< do_blocking_move_to");
475
-
476
   planner.synchronize();
475
   planner.synchronize();
477
 }
476
 }
478
 
477
 
507
   do_blocking_move_to(raw.x, raw.y, z, fr_mm_s);
506
   do_blocking_move_to(raw.x, raw.y, z, fr_mm_s);
508
 }
507
 }
509
 
508
 
509
+void do_z_clearance(const float &zclear, const bool z_known/*=true*/, const bool raise_on_unknown/*=true*/, const bool lower_allowed/*=false*/) {
510
+  const bool rel = raise_on_unknown && !z_known;
511
+  float zdest = zclear + (rel ? current_position.z : 0.0f);
512
+  if (!lower_allowed) NOLESS(zdest, current_position.z);
513
+  do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
514
+}
515
+
510
 //
516
 //
511
 // Prepare to do endstop or probe moves with custom feedrates.
517
 // Prepare to do endstop or probe moves with custom feedrates.
512
 //  - Save / restore current feedrate and multiplier
518
 //  - Save / restore current feedrate and multiplier
1272
  * Home an individual linear axis
1278
  * Home an individual linear axis
1273
  */
1279
  */
1274
 void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0) {
1280
 void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0) {
1281
+  DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING));
1275
 
1282
 
1276
   const feedRate_t real_fr_mm_s = fr_mm_s ?: homing_feedrate(axis);
1283
   const feedRate_t real_fr_mm_s = fr_mm_s ?: homing_feedrate(axis);
1277
 
1284
 
1278
   if (DEBUGGING(LEVELING)) {
1285
   if (DEBUGGING(LEVELING)) {
1279
-    DEBUG_ECHOPAIR(">>> do_homing_move(", axis_codes[axis], ", ", distance, ", ");
1286
+    DEBUG_ECHOPAIR("...(", axis_codes[axis], ", ", distance, ", ");
1280
     if (fr_mm_s)
1287
     if (fr_mm_s)
1281
       DEBUG_ECHO(fr_mm_s);
1288
       DEBUG_ECHO(fr_mm_s);
1282
     else
1289
     else
1349
     // Re-enable stealthChop if used. Disable diag1 pin on driver.
1356
     // Re-enable stealthChop if used. Disable diag1 pin on driver.
1350
     TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states));
1357
     TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states));
1351
   }
1358
   }
1352
-
1353
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< do_homing_move(", axis_codes[axis], ")");
1354
 }
1359
 }
1355
 
1360
 
1356
 /**
1361
 /**

+ 2
- 0
Marlin/src/module/motion.h View File

234
 void remember_feedrate_scaling_off();
234
 void remember_feedrate_scaling_off();
235
 void restore_feedrate_and_scaling();
235
 void restore_feedrate_and_scaling();
236
 
236
 
237
+void do_z_clearance(const float &zclear, const bool z_known=true, const bool raise_on_unknown=true, const bool lower_allowed=false);
238
+
237
 //
239
 //
238
 // Homing
240
 // Homing
239
 //
241
 //

+ 7
- 28
Marlin/src/module/probe.cpp View File

260
  * Raise Z to a minimum height to make room for a probe to move
260
  * Raise Z to a minimum height to make room for a probe to move
261
  */
261
  */
262
 void Probe::do_z_raise(const float z_raise) {
262
 void Probe::do_z_raise(const float z_raise) {
263
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::move_z(", z_raise, ")");
264
-
263
+  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::do_z_raise(", z_raise, ")");
265
   float z_dest = z_raise;
264
   float z_dest = z_raise;
266
   if (offset.z < 0) z_dest -= offset.z;
265
   if (offset.z < 0) z_dest -= offset.z;
267
-
268
-  NOMORE(z_dest, Z_MAX_POS);
269
-
270
-  if (z_dest > current_position.z)
271
-    do_blocking_move_to_z(z_dest);
266
+  do_z_clearance(z_dest);
272
 }
267
 }
273
 
268
 
274
 FORCE_INLINE void probe_specific_action(const bool deploy) {
269
 FORCE_INLINE void probe_specific_action(const bool deploy) {
410
   return false;
405
   return false;
411
 }
406
 }
412
 
407
 
413
-#ifdef Z_AFTER_PROBING
414
-  // After probing move to a preferred Z position
415
-  void Probe::move_z_after_probing() {
416
-    if (current_position.z != Z_AFTER_PROBING) {
417
-      do_blocking_move_to_z(Z_AFTER_PROBING);
418
-      current_position.z = Z_AFTER_PROBING;
419
-    }
420
-  }
421
-#endif
422
-
423
 /**
408
 /**
424
  * @brief Used by run_z_probe to do a single Z probe move.
409
  * @brief Used by run_z_probe to do a single Z probe move.
425
  *
410
  *
439
  * @return TRUE if the probe failed to trigger.
424
  * @return TRUE if the probe failed to trigger.
440
  */
425
  */
441
 bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
426
 bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
442
-  if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::probe_down_to_z", current_position);
427
+  DEBUG_SECTION(log_probe, "Probe::probe_down_to_z", DEBUGGING(LEVELING));
443
 
428
 
444
   #if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
429
   #if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
445
     thermalManager.wait_for_bed_heating();
430
     thermalManager.wait_for_bed_heating();
499
   // Tell the planner where we actually are
484
   // Tell the planner where we actually are
500
   sync_plan_position();
485
   sync_plan_position();
501
 
486
 
502
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< Probe::probe_down_to_z", current_position);
503
-
504
   return !probe_triggered;
487
   return !probe_triggered;
505
 }
488
 }
506
 
489
 
513
  * @return The Z position of the bed at the current XY or NAN on error.
496
  * @return The Z position of the bed at the current XY or NAN on error.
514
  */
497
  */
515
 float Probe::run_z_probe(const bool sanity_check/*=true*/) {
498
 float Probe::run_z_probe(const bool sanity_check/*=true*/) {
516
-
517
-  if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::run_z_probe", current_position);
499
+  DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));
518
 
500
 
519
   auto try_to_probe = [&](PGM_P const plbl, const float &z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) {
501
   auto try_to_probe = [&](PGM_P const plbl, const float &z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) {
520
     // Do a first probe at the fast speed
502
     // Do a first probe at the fast speed
527
         if (probe_fail) DEBUG_ECHOPGM(" No trigger.");
509
         if (probe_fail) DEBUG_ECHOPGM(" No trigger.");
528
         if (early_fail) DEBUG_ECHOPGM(" Triggered early.");
510
         if (early_fail) DEBUG_ECHOPGM(" Triggered early.");
529
         DEBUG_EOL();
511
         DEBUG_EOL();
530
-        DEBUG_POS("<<< run_z_probe", current_position);
531
       }
512
       }
532
     #else
513
     #else
533
       UNUSED(plbl);
514
       UNUSED(plbl);
651
 
632
 
652
   #endif
633
   #endif
653
 
634
 
654
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
655
-
656
   return measured_z;
635
   return measured_z;
657
 }
636
 }
658
 
637
 
666
  * - Return the probed Z position
645
  * - Return the probed Z position
667
  */
646
  */
668
 float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/, const bool sanity_check/*=true*/) {
647
 float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/, const bool sanity_check/*=true*/) {
648
+  DEBUG_SECTION(log_probe, "Probe::probe_at_point", DEBUGGING(LEVELING));
649
+
669
   if (DEBUGGING(LEVELING)) {
650
   if (DEBUGGING(LEVELING)) {
670
     DEBUG_ECHOLNPAIR(
651
     DEBUG_ECHOLNPAIR(
671
-      ">>> Probe::probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
652
+      "...(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
672
       ", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none",
653
       ", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none",
673
       ", ", int(verbose_level),
654
       ", ", int(verbose_level),
674
       ", ", probe_relative ? "probe" : "nozzle", "_relative)"
655
       ", ", probe_relative ? "probe" : "nozzle", "_relative)"
729
     #endif
710
     #endif
730
   }
711
   }
731
 
712
 
732
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< Probe::probe_at_point");
733
-
734
   return measured_z;
713
   return measured_z;
735
 }
714
 }
736
 
715
 

+ 14
- 3
Marlin/src/module/probe.h View File

79
 
79
 
80
     #endif
80
     #endif
81
 
81
 
82
-    #ifdef Z_AFTER_PROBING
83
-      static void move_z_after_probing();
84
-    #endif
82
+    static inline void move_z_after_probing() {
83
+      #ifdef Z_AFTER_PROBING
84
+        do_z_clearance(Z_AFTER_PROBING, true, true, true); // Move down still permitted
85
+      #endif
86
+    }
87
+    static inline void move_z_after_homing() {
88
+      #ifdef Z_AFTER_HOMING
89
+        do_z_clearance(Z_AFTER_HOMING, true, true, true);
90
+      #elif defined(Z_AFTER_PROBING)
91
+        move_z_after_probing();
92
+      #endif
93
+    }
85
     static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true);
94
     static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true);
86
     static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true) {
95
     static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true) {
87
       return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
96
       return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
89
 
98
 
90
   #else
99
   #else
91
 
100
 
101
+    FORCE_INLINE static void move_z_after_homing() {}
102
+
92
     static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
103
     static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
93
 
104
 
94
     static bool set_deployed(const bool) { return false; }
105
     static bool set_deployed(const bool) { return false; }

Loading…
Cancel
Save