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

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

61
   float GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
61
   float GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
62
 #endif
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
  * Set target_extruder from the T parameter or the active_extruder
65
  * Set target_extruder from the T parameter or the active_extruder
71
  *
66
  *
136
  */
131
  */
137
 #if HAS_LEVELING && ENABLED(G29_RETRY_AND_RECOVER)
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
   void GcodeSuite::G29_with_retry() {
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
 #endif // HAS_LEVELING && G29_RETRY_AND_RECOVER
167
 #endif // HAS_LEVELING && G29_RETRY_AND_RECOVER

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

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

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

936
   #error "MESH_EDIT_GFX_OVERLAY requires AUTO_BED_LEVELING_UBL and a Graphical LCD."
936
   #error "MESH_EDIT_GFX_OVERLAY requires AUTO_BED_LEVELING_UBL and a Graphical LCD."
937
 #endif
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
  * LCD_BED_LEVELING requirements
944
  * LCD_BED_LEVELING requirements
941
  */
945
  */

Loading…
Cancel
Save