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

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

@@ -0,0 +1,49 @@
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,7 +462,7 @@
462 462
             // Manually Probe Mesh in areas that can't be reached by the probe
463 463
             //
464 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 467
             if (parser.seen('C') && !xy_seen) {
468 468
 
@@ -780,9 +780,7 @@
780 780
       probe.stow();
781 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 785
       restore_ubl_active_state_and_leave();
788 786
 
@@ -858,7 +856,6 @@
858 856
       echo_and_take_a_measurement();
859 857
 
860 858
       const float z2 = measure_point_with_encoder();
861
-
862 859
       do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
863 860
 
864 861
       const float thickness = ABS(z1 - z2);
@@ -899,7 +896,7 @@
899 896
         LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
900 897
 
901 898
         do_blocking_move_to(ppos);
902
-        do_blocking_move_to_z(z_clearance);
899
+        do_z_clearance(z_clearance);
903 900
 
904 901
         KEEPALIVE_STATE(PAUSED_FOR_USER);
905 902
         ui.capture();
@@ -915,7 +912,7 @@
915 912
 
916 913
         if (click_and_hold()) {
917 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 916
           return restore_ubl_active_state_and_leave();
920 917
         }
921 918
 
@@ -940,7 +937,7 @@
940 937
 
941 938
     void abort_fine_tune() {
942 939
       ui.return_to_status();
943
-      do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
940
+      do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
944 941
       set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
945 942
     }
946 943
 
@@ -1415,9 +1412,7 @@
1415 1412
         }
1416 1413
 
1417 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 1417
         if (abort_flag) {
1423 1418
           SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
@@ -1478,9 +1473,7 @@
1478 1473
         }
1479 1474
       }
1480 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 1478
       if (abort_flag || finish_incremental_LSF(&lsf_results)) {
1486 1479
         SERIAL_ECHOPGM("Could not complete LSF!");

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

@@ -622,8 +622,7 @@ void GcodeSuite::G26() {
622 622
    */
623 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 627
   #if DISABLED(NO_VOLUMETRICS)
629 628
     bool volumetric_was_enabled = parser.volumetric_enabled;

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

@@ -75,10 +75,9 @@ static_assert(G35_PROBE_COUNT > 2, "TRAMMING_POINT_XY requires at least 3 XY pos
75 75
  *               51 - Counter-Clockwise M5
76 76
  **/
77 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 82
   float z_measured[G35_PROBE_COUNT] = { 0 };
84 83
 
@@ -181,8 +180,6 @@ void GcodeSuite::G35() {
181 180
 
182 181
   // Home Z after the alignment procedure
183 182
   process_subcommands_now_P(PSTR("G28Z"));
184
-
185
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G35");
186 183
 }
187 184
 
188 185
 #endif // ASSISTED_TRAMMING

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

@@ -172,10 +172,8 @@ G29_TYPE GcodeSuite::G29() {
172 172
   #if ENABLED(DEBUG_LEVELING_FEATURE)
173 173
     const uint8_t old_debug_flags = marlin_debug_flags;
174 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 177
     marlin_debug_flags = old_debug_flags;
180 178
     if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
181 179
   #endif
@@ -188,7 +186,7 @@ G29_TYPE GcodeSuite::G29() {
188 186
   if (axis_unhomed_error()) G29_RETURN(false);
189 187
 
190 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 190
     G29_RETURN(false);
193 191
   }
194 192
 
@@ -416,7 +414,7 @@ G29_TYPE GcodeSuite::G29() {
416 414
     // Deploy certain probes before starting probing
417 415
     #if HAS_BED_PROBE
418 416
       if (ENABLED(BLTOUCH))
419
-        do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
417
+        do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
420 418
       else if (probe.deploy()) {
421 419
         set_bed_leveling_enabled(abl_should_enable);
422 420
         G29_RETURN(false);
@@ -884,7 +882,7 @@ G29_TYPE GcodeSuite::G29() {
884 882
   // Sync the planner from the current_position
885 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 886
     probe.move_z_after_probing();
889 887
   #endif
890 888
 
@@ -900,8 +898,6 @@ G29_TYPE GcodeSuite::G29() {
900 898
 
901 899
   report_current_position();
902 900
 
903
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
904
-
905 901
   G29_RETURN(isnan(measured_z));
906 902
 }
907 903
 

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

@@ -115,11 +115,11 @@
115 115
 #if ENABLED(Z_SAFE_HOMING)
116 116
 
117 117
   inline void home_z_safely() {
118
+    DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING));
119
+
118 120
     // Disallow Z homing if X or Y homing is needed
119 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 123
     sync_plan_position();
124 124
 
125 125
     /**
@@ -146,8 +146,6 @@
146 146
       LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
147 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 151
 #endif // Z_SAFE_HOMING
@@ -197,15 +195,10 @@
197 195
  *
198 196
  */
199 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 203
   TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
211 204
 
@@ -220,14 +213,13 @@ void GcodeSuite::G28() {
220 213
       sync_plan_position();
221 214
       SERIAL_ECHOLNPGM("Simulated Homing");
222 215
       report_current_position();
223
-      if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
224 216
       return;
225 217
     }
226 218
   #endif
227 219
 
228 220
   // Home (O)nly if position is unknown
229 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 223
     return;
232 224
   }
233 225
 
@@ -313,8 +305,6 @@ void GcodeSuite::G28() {
313 305
                home_all = homeX == homeY && homeX == homeZ, // All or None
314 306
                doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ;
315 307
 
316
-    destination = current_position;
317
-
318 308
     #if Z_HOME_DIR > 0  // If homing away from BED do Z first
319 309
 
320 310
       if (doZ) homeaxis(Z_AXIS);
@@ -322,17 +312,14 @@ void GcodeSuite::G28() {
322 312
     #endif
323 313
 
324 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 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 325
     #if ENABLED(QUICK_HOME)
@@ -387,15 +374,7 @@ void GcodeSuite::G28() {
387 374
 
388 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 379
       } // doZ
401 380
 
@@ -485,8 +464,6 @@ void GcodeSuite::G28() {
485 464
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
486 465
     SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
487 466
 
488
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
489
-
490 467
   #if HAS_L64XX
491 468
     // Set L6470 absolute position registers to counts
492 469
     // constexpr *might* move this to PROGMEM.

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

@@ -56,10 +56,8 @@
56 56
  *   R<recalculate> points based on current probe offsets
57 57
  */
58 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 62
   do { // break out on error
65 63
 
@@ -367,8 +365,6 @@ void GcodeSuite::G34() {
367 365
     #endif
368 366
 
369 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,7 +104,7 @@ void GcodeSuite::G76() {
104 104
   };
105 105
 
106 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 108
     const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
109 109
     if (isnan(measured_z))
110 110
       SERIAL_ECHOLNPGM("!Received NAN. Aborting.");

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

@@ -38,7 +38,7 @@
38 38
    * M666: Set delta endstop adjustment
39 39
    */
40 40
   void GcodeSuite::M666() {
41
-    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> M666");
41
+    DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
42 42
     LOOP_XYZ(i) {
43 43
       if (parser.seen(XYZ_CHAR(i))) {
44 44
         const float v = parser.value_linear_units();
@@ -46,7 +46,6 @@
46 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 51
 #elif HAS_EXTRA_ENDSTOPS

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

@@ -48,10 +48,8 @@
48 48
  */
49 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 54
   // Count this command as movement / activity
57 55
   reset_stepper_timeout();
@@ -75,9 +73,4 @@ void GcodeSuite::T(const uint8_t tool_index) {
75 73
     );
76 74
 
77 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,9 +57,8 @@ void GcodeSuite::G30() {
57 57
 
58 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 63
   report_current_position();
65 64
 }

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

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

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

@@ -233,7 +233,8 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
233 233
  * This is like quick_home_xy() but for 3 towers.
234 234
  */
235 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 238
   // Init the current position of all carriages to 0,0,0
238 239
   current_position.reset();
239 240
   destination.reset();
@@ -283,8 +284,6 @@ void home_delta() {
283 284
       line_to_current_position(homing_feedrate(Z_AXIS));
284 285
     }
285 286
   #endif
286
-
287
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< home_delta", current_position);
288 287
 }
289 288
 
290 289
 #endif // DELTA

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

@@ -387,7 +387,8 @@ void _internal_move_to_destination(const feedRate_t &fr_mm_s/*=0.0f*/
387 387
  * Plan a move to (X, Y, Z) and set the current_position
388 388
  */
389 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 393
   const feedRate_t z_feedrate = fr_mm_s ?: homing_feedrate(Z_AXIS),
393 394
                   xy_feedrate = fr_mm_s ?: feedRate_t(XY_PROBE_FEEDRATE_MM_S);
@@ -471,8 +472,6 @@ void do_blocking_move_to(const float rx, const float ry, const float rz, const f
471 472
 
472 473
   #endif
473 474
 
474
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< do_blocking_move_to");
475
-
476 475
   planner.synchronize();
477 476
 }
478 477
 
@@ -507,6 +506,13 @@ void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRat
507 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 517
 // Prepare to do endstop or probe moves with custom feedrates.
512 518
 //  - Save / restore current feedrate and multiplier
@@ -1272,11 +1278,12 @@ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) {
1272 1278
  * Home an individual linear axis
1273 1279
  */
1274 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 1283
   const feedRate_t real_fr_mm_s = fr_mm_s ?: homing_feedrate(axis);
1277 1284
 
1278 1285
   if (DEBUGGING(LEVELING)) {
1279
-    DEBUG_ECHOPAIR(">>> do_homing_move(", axis_codes[axis], ", ", distance, ", ");
1286
+    DEBUG_ECHOPAIR("...(", axis_codes[axis], ", ", distance, ", ");
1280 1287
     if (fr_mm_s)
1281 1288
       DEBUG_ECHO(fr_mm_s);
1282 1289
     else
@@ -1349,8 +1356,6 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
1349 1356
     // Re-enable stealthChop if used. Disable diag1 pin on driver.
1350 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,6 +234,8 @@ void remember_feedrate_and_scaling();
234 234
 void remember_feedrate_scaling_off();
235 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 240
 // Homing
239 241
 //

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

@@ -260,15 +260,10 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
260 260
  * Raise Z to a minimum height to make room for a probe to move
261 261
  */
262 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 264
   float z_dest = z_raise;
266 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 269
 FORCE_INLINE void probe_specific_action(const bool deploy) {
@@ -410,16 +405,6 @@ bool Probe::set_deployed(const bool deploy) {
410 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 409
  * @brief Used by run_z_probe to do a single Z probe move.
425 410
  *
@@ -439,7 +424,7 @@ bool Probe::set_deployed(const bool deploy) {
439 424
  * @return TRUE if the probe failed to trigger.
440 425
  */
441 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 429
   #if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
445 430
     thermalManager.wait_for_bed_heating();
@@ -499,8 +484,6 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
499 484
   // Tell the planner where we actually are
500 485
   sync_plan_position();
501 486
 
502
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< Probe::probe_down_to_z", current_position);
503
-
504 487
   return !probe_triggered;
505 488
 }
506 489
 
@@ -513,8 +496,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
513 496
  * @return The Z position of the bed at the current XY or NAN on error.
514 497
  */
515 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 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 502
     // Do a first probe at the fast speed
@@ -527,7 +509,6 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
527 509
         if (probe_fail) DEBUG_ECHOPGM(" No trigger.");
528 510
         if (early_fail) DEBUG_ECHOPGM(" Triggered early.");
529 511
         DEBUG_EOL();
530
-        DEBUG_POS("<<< run_z_probe", current_position);
531 512
       }
532 513
     #else
533 514
       UNUSED(plbl);
@@ -651,8 +632,6 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
651 632
 
652 633
   #endif
653 634
 
654
-  if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
655
-
656 635
   return measured_z;
657 636
 }
658 637
 
@@ -666,9 +645,11 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
666 645
  * - Return the probed Z position
667 646
  */
668 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 650
   if (DEBUGGING(LEVELING)) {
670 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 653
       ", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none",
673 654
       ", ", int(verbose_level),
674 655
       ", ", probe_relative ? "probe" : "nozzle", "_relative)"
@@ -729,8 +710,6 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
729 710
     #endif
730 711
   }
731 712
 
732
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< Probe::probe_at_point");
733
-
734 713
   return measured_z;
735 714
 }
736 715
 

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

@@ -79,9 +79,18 @@ public:
79 79
 
80 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 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 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 96
       return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
@@ -89,6 +98,8 @@ public:
89 98
 
90 99
   #else
91 100
 
101
+    FORCE_INLINE static void move_z_after_homing() {}
102
+
92 103
     static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
93 104
 
94 105
     static bool set_deployed(const bool) { return false; }

Loading…
Cancel
Save