Browse Source

Fixes G29_with_retry behavior (#11045)

* Fix G29 (ABL) retry behavior
Colin Gilgenbach 7 years ago
parent
commit
0fff79c24b

+ 24
- 16
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -62,6 +62,12 @@
62 62
   #endif
63 63
 #endif
64 64
 
65
+#if ENABLED(G29_RETRY_AND_RECOVER)
66
+  #define G29_RETURN(b) return b;
67
+#else
68
+  #define G29_RETURN(b) return;
69
+#endif 
70
+
65 71
 /**
66 72
  * G29: Detailed Z probe, probes the bed at 3 or more points.
67 73
  *      Will fail if the printer has not been homed with G28.
@@ -136,7 +142,7 @@
136 142
  *     There's no extra effect if you have a fixed Z probe.
137 143
  *
138 144
  */
139
-void GcodeSuite::G29() {
145
+G29_TYPE GcodeSuite::G29() {
140 146
 
141 147
   #if ENABLED(DEBUG_LEVELING_FEATURE) || ENABLED(PROBE_MANUALLY)
142 148
     const bool seenQ = parser.seen('Q');
@@ -154,7 +160,7 @@ void GcodeSuite::G29() {
154 160
     }
155 161
     marlin_debug_flags = old_debug_flags;
156 162
     #if DISABLED(PROBE_MANUALLY)
157
-      if (seenQ) return;
163
+      if (seenQ) G29_RETURN(false);
158 164
     #endif
159 165
   #endif
160 166
 
@@ -174,7 +180,7 @@ void GcodeSuite::G29() {
174 180
               ;
175 181
 
176 182
   // Don't allow auto-leveling without homing first
177
-  if (axis_unhomed_error()) return;
183
+  if (axis_unhomed_error()) G29_RETURN(false);
178 184
 
179 185
   if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
180 186
     #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -183,7 +189,7 @@ void GcodeSuite::G29() {
183 189
         SERIAL_ECHOLNPGM("<<< G29");
184 190
       }
185 191
     #endif
186
-    return;
192
+    G29_RETURN(false);
187 193
   }
188 194
 
189 195
   // Define local vars 'static' for manual probing, 'auto' otherwise
@@ -285,14 +291,14 @@ void GcodeSuite::G29() {
285 291
         if (!leveling_is_valid()) {
286 292
           SERIAL_ERROR_START();
287 293
           SERIAL_ERRORLNPGM("No bilinear grid");
288
-          return;
294
+          G29_RETURN(false);
289 295
         }
290 296
 
291 297
         const float rz = parser.seenval('Z') ? RAW_Z_POSITION(parser.value_linear_units()) : current_position[Z_AXIS];
292 298
         if (!WITHIN(rz, -10, 10)) {
293 299
           SERIAL_ERROR_START();
294 300
           SERIAL_ERRORLNPGM("Bad Z value");
295
-          return;
301
+          G29_RETURN(false);
296 302
         }
297 303
 
298 304
         const float rx = RAW_X_POSITION(parser.linearval('X', NAN)),
@@ -316,7 +322,7 @@ void GcodeSuite::G29() {
316 322
           set_bed_leveling_enabled(abl_should_enable);
317 323
           if (abl_should_enable) report_current_position();
318 324
         }
319
-        return;
325
+        G29_RETURN(false);
320 326
       } // parser.seen('W')
321 327
 
322 328
     #else
@@ -328,13 +334,13 @@ void GcodeSuite::G29() {
328 334
     // Jettison bed leveling data
329 335
     if (!seen_w && parser.seen('J')) {
330 336
       reset_bed_level();
331
-      return;
337
+      G29_RETURN(false);
332 338
     }
333 339
 
334 340
     verbose_level = parser.intval('V');
335 341
     if (!WITHIN(verbose_level, 0, 4)) {
336 342
       SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-4).");
337
-      return;
343
+      G29_RETURN(false);
338 344
     }
339 345
 
340 346
     dryrun = parser.boolval('D')
@@ -355,11 +361,11 @@ void GcodeSuite::G29() {
355 361
 
356 362
       if (!WITHIN(abl_grid_points_x, 2, GRID_MAX_POINTS_X)) {
357 363
         SERIAL_PROTOCOLLNPGM("?Probe points (X) is implausible (2-" STRINGIFY(GRID_MAX_POINTS_X) ").");
358
-        return;
364
+        G29_RETURN(false);
359 365
       }
360 366
       if (!WITHIN(abl_grid_points_y, 2, GRID_MAX_POINTS_Y)) {
361 367
         SERIAL_PROTOCOLLNPGM("?Probe points (Y) is implausible (2-" STRINGIFY(GRID_MAX_POINTS_Y) ").");
362
-        return;
368
+        G29_RETURN(false);
363 369
       }
364 370
 
365 371
       abl_points = abl_grid_points_x * abl_grid_points_y;
@@ -392,7 +398,7 @@ void GcodeSuite::G29() {
392 398
         #endif
393 399
       ) {
394 400
         SERIAL_PROTOCOLLNPGM("? (L,R,F,B) out of bounds.");
395
-        return;
401
+        G29_RETURN(false);
396 402
       }
397 403
 
398 404
       // probe at the points of a lattice grid
@@ -417,7 +423,7 @@ void GcodeSuite::G29() {
417 423
       // Deploy the probe. Probe will raise if needed.
418 424
       if (DEPLOY_PROBE()) {
419 425
         set_bed_leveling_enabled(abl_should_enable);
420
-        return;
426
+        G29_RETURN(false);
421 427
       }
422 428
     #endif
423 429
 
@@ -494,7 +500,7 @@ void GcodeSuite::G29() {
494 500
         SERIAL_PROTOCOLLNPGM("idle");
495 501
     }
496 502
 
497
-    if (no_action) return;
503
+    if (no_action) G29_RETURN(false);
498 504
 
499 505
     if (abl_probe_index == 0) {
500 506
       // For the initial G29 S2 save software endstop state
@@ -584,7 +590,7 @@ void GcodeSuite::G29() {
584 590
           // If G29 is not completed, they will not be re-enabled
585 591
           soft_endstops_enabled = false;
586 592
         #endif
587
-        return;
593
+        G29_RETURN(false);
588 594
       }
589 595
       else {
590 596
 
@@ -610,7 +616,7 @@ void GcodeSuite::G29() {
610 616
           // If G29 is not completed, they will not be re-enabled
611 617
           soft_endstops_enabled = false;
612 618
         #endif
613
-        return;
619
+        G29_RETURN(false);
614 620
       }
615 621
       else {
616 622
 
@@ -990,6 +996,8 @@ void GcodeSuite::G29() {
990 996
   #endif
991 997
 
992 998
   report_current_position();
999
+  
1000
+  G29_RETURN(isnan(measured_z));
993 1001
 }
994 1002
 
995 1003
 #endif // OLDSCHOOL_ABL

+ 29
- 31
Marlin/src/gcode/gcode.cpp View File

@@ -61,11 +61,6 @@ bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
61 61
   float GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
62 62
 #endif
63 63
 
64
-#if HAS_LEVELING && ENABLED(G29_RETRY_AND_RECOVER)
65
-  #include "../feature/bedlevel/bedlevel.h"
66
-  #include "../module/planner.h"
67
-#endif
68
-
69 64
 /**
70 65
  * Set target_extruder from the T parameter or the active_extruder
71 66
  *
@@ -136,34 +131,37 @@ void GcodeSuite::dwell(millis_t time) {
136 131
  */
137 132
 #if HAS_LEVELING && ENABLED(G29_RETRY_AND_RECOVER)
138 133
 
134
+  #ifndef G29_MAX_RETRIES
135
+    #define G29_MAX_RETRIES 0
136
+  #endif
137
+   
139 138
   void GcodeSuite::G29_with_retry() {
140
-    set_bed_leveling_enabled(false);
141
-    for (uint8_t retries_left = G29_MAX_RETRIES;;) {
142
-      G29();
143
-      if (planner.leveling_active || !retries_left--) break;
144
-      #ifdef G29_ACTION_ON_RECOVER
145
-        SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_RECOVER);
146
-      #endif
147
-      #ifdef G29_RECOVER_COMMANDS
148
-        process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
149
-      #endif
150
-    }
151
-    if (planner.leveling_active) {
152
-      #ifdef G29_SUCCESS_COMMANDS
153
-        process_subcommands_now_P(PSTR(G29_SUCCESS_COMMANDS));
154
-      #endif
155
-    }
156
-    else {
157
-      #ifdef G29_FAILURE_COMMANDS
158
-        process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
159
-      #endif
160
-      #ifdef G29_ACTION_ON_FAILURE
161
-        SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_FAILURE);
162
-      #endif
163
-      #if ENABLED(G29_HALT_ON_FAILURE)
164
-        kill(PSTR(MSG_ERR_PROBING_FAILED));
165
-      #endif
139
+    uint8_t retries = G29_MAX_RETRIES;
140
+    while (G29()) { // G29 should return true for failed probes ONLY
141
+      if (retries--) {
142
+        #ifdef G29_ACTION_ON_RECOVER
143
+          SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_RECOVER);
144
+        #endif
145
+        #ifdef G29_RECOVER_COMMANDS
146
+          process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
147
+        #endif   
148
+      }
149
+      else {
150
+        #ifdef G29_FAILURE_COMMANDS
151
+          process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
152
+        #endif
153
+        #ifdef G29_ACTION_ON_FAILURE
154
+          SERIAL_ECHOLNPGM("//action:" G29_ACTION_ON_FAILURE);
155
+        #endif
156
+        #if ENABLED(G29_HALT_ON_FAILURE)
157
+          kill(PSTR(MSG_ERR_PROBING_FAILED));
158
+        #endif
159
+        return;
160
+      }
166 161
     }
162
+    #ifdef G29_SUCCESS_COMMANDS
163
+      process_subcommands_now_P(PSTR(G29_SUCCESS_COMMANDS));
164
+    #endif
167 165
   }
168 166
 
169 167
 #endif // HAS_LEVELING && G29_RETRY_AND_RECOVER

+ 4
- 1
Marlin/src/gcode/gcode.h View File

@@ -387,10 +387,13 @@ private:
387 387
   static void G28(const bool always_home_all);
388 388
 
389 389
   #if HAS_LEVELING
390
-    static void G29();
391 390
     #if ENABLED(G29_RETRY_AND_RECOVER)
392 391
       static void G29_with_retry();
392
+      #define G29_TYPE bool
393
+    #else
394
+      #define G29_TYPE void
393 395
     #endif
396
+    static G29_TYPE G29();
394 397
   #endif
395 398
 
396 399
   #if HAS_BED_PROBE

+ 4
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -936,6 +936,10 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
936 936
   #error "MESH_EDIT_GFX_OVERLAY requires AUTO_BED_LEVELING_UBL and a Graphical LCD."
937 937
 #endif
938 938
 
939
+#if ENABLED(G29_RETRY_AND_RECOVER) && HAS_LEVELING && !OLDSCHOOL_ABL
940
+  #error "G29_RETRY_AND_RECOVER currently only supports ABL"
941
+#endif
942
+
939 943
 /**
940 944
  * LCD_BED_LEVELING requirements
941 945
  */

Loading…
Cancel
Save