Browse Source

Merge pull request #8558 from LVD-AC/2.0.x]-probe-error-handling

[2.0.x] G33 probe error handling
Scott Lahteine 7 years ago
parent
commit
a9adc2c2f6
No account linked to committer's email address

+ 1
- 1
Marlin/src/core/macros.h View File

96
 
96
 
97
 // Macros for bit masks
97
 // Macros for bit masks
98
 #ifndef _BV
98
 #ifndef _BV
99
-  #define _BV(B) (1UL<<(B))
99
+  #define _BV(n)  (1<<(n))
100
 #endif
100
 #endif
101
 #define TEST(n,b) (((n)&_BV(b))!=0)
101
 #define TEST(n,b) (((n)&_BV(b))!=0)
102
 #define SBI(n,b) (n |= _BV(b))
102
 #define SBI(n,b) (n |= _BV(b))

+ 37
- 40
Marlin/src/gcode/calibrate/G33.cpp View File

135
   #endif
135
   #endif
136
 }
136
 }
137
 
137
 
138
+inline float calibration_probe(const float nx, const float ny, const bool stow) {
139
+  #if HAS_BED_PROBE
140
+    return probe_pt(nx, ny, stow, 0, false);
141
+  #else
142
+    UNUSED(stow);
143
+    return lcd_probe_pt(nx, ny);
144
+  #endif
145
+}
146
+
138
 static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points, const bool towers_set, const bool stow_after_each) {
147
 static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points, const bool towers_set, const bool stow_after_each) {
139
   const bool _0p_calibration      = probe_points == 0,
148
   const bool _0p_calibration      = probe_points == 0,
140
              _1p_calibration      = probe_points == 1,
149
              _1p_calibration      = probe_points == 1,
153
              _7p_6_centre         = probe_points >= 5 && probe_points <= 7,
162
              _7p_6_centre         = probe_points >= 5 && probe_points <= 7,
154
              _7p_9_centre         = probe_points >= 8;
163
              _7p_9_centre         = probe_points >= 8;
155
 
164
 
156
-  #if HAS_BED_PROBE
157
-    const float dx = (X_PROBE_OFFSET_FROM_EXTRUDER),
158
-                dy = (Y_PROBE_OFFSET_FROM_EXTRUDER);
159
-  #endif
160
-
161
   LOOP_CAL_ALL(axis) z_at_pt[axis] = 0.0;
165
   LOOP_CAL_ALL(axis) z_at_pt[axis] = 0.0;
162
 
166
 
163
   if (!_0p_calibration) {
167
   if (!_0p_calibration) {
164
 
168
 
165
     if (!_7p_no_intermediates && !_7p_4_intermediates && !_7p_11_intermediates) { // probe the center
169
     if (!_7p_no_intermediates && !_7p_4_intermediates && !_7p_11_intermediates) { // probe the center
166
-      z_at_pt[CEN] +=
167
-        #if HAS_BED_PROBE
168
-          probe_pt(dx, dy, stow_after_each, 1, false)
169
-        #else
170
-          lcd_probe_pt(0, 0)
171
-        #endif
172
-      ;
170
+      z_at_pt[CEN] += calibration_probe(0, 0, stow_after_each);
171
+      if (isnan(z_at_pt[CEN])) return NAN;
173
     }
172
     }
174
 
173
 
175
     if (_7p_calibration) { // probe extra center points
174
     if (_7p_calibration) { // probe extra center points
178
       I_LOOP_CAL_PT(axis, start, steps) {
177
       I_LOOP_CAL_PT(axis, start, steps) {
179
         const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
178
         const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
180
                     r = delta_calibration_radius * 0.1;
179
                     r = delta_calibration_radius * 0.1;
181
-        z_at_pt[CEN] +=
182
-          #if HAS_BED_PROBE
183
-            probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1, false)
184
-          #else
185
-            lcd_probe_pt(cos(a) * r, sin(a) * r)
186
-          #endif
187
-        ;
188
-      }
180
+        z_at_pt[CEN] += calibration_probe(cos(a) * r, sin(a) * r, stow_after_each);
181
+        if (isnan(z_at_pt[CEN])) return NAN;
182
+     }
189
       z_at_pt[CEN] /= float(_7p_2_intermediates ? 7 : probe_points);
183
       z_at_pt[CEN] /= float(_7p_2_intermediates ? 7 : probe_points);
190
     }
184
     }
191
 
185
 
206
         for (int8_t circle = -offset; circle <= offset; circle++) {
200
         for (int8_t circle = -offset; circle <= offset; circle++) {
207
           const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
201
           const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
208
                       r = delta_calibration_radius * (1 + 0.1 * (zig_zag ? circle : - circle)),
202
                       r = delta_calibration_radius * (1 + 0.1 * (zig_zag ? circle : - circle)),
209
-                      interpol = FMOD(axis, 1);
210
-          const float z_temp =
211
-            #if HAS_BED_PROBE
212
-              probe_pt(cos(a) * r + dx, sin(a) * r + dy, stow_after_each, 1, false)
213
-            #else
214
-              lcd_probe_pt(cos(a) * r, sin(a) * r)
215
-            #endif
216
-          ;
203
+                      interpol = fmod(axis, 1);
204
+          const float z_temp = calibration_probe(cos(a) * r, sin(a) * r, stow_after_each);
205
+          if (isnan(z_temp)) return NAN;
217
           // split probe point to neighbouring calibration points
206
           // split probe point to neighbouring calibration points
218
           z_at_pt[uint8_t(round(axis - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
207
           z_at_pt[uint8_t(round(axis - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
219
           z_at_pt[uint8_t(round(axis - interpol))           % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
208
           z_at_pt[uint8_t(round(axis - interpol))           % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
243
 
232
 
244
 #if HAS_BED_PROBE
233
 #if HAS_BED_PROBE
245
 
234
 
246
-  static void G33_auto_tune() {
235
+  static bool G33_auto_tune() {
247
     float z_at_pt[NPP + 1]      = { 0.0 },
236
     float z_at_pt[NPP + 1]      = { 0.0 },
248
           z_at_pt_base[NPP + 1] = { 0.0 },
237
           z_at_pt_base[NPP + 1] = { 0.0 },
249
           z_temp, h_fac = 0.0, r_fac = 0.0, a_fac = 0.0, norm = 0.8;
238
           z_temp, h_fac = 0.0, r_fac = 0.0, a_fac = 0.0, norm = 0.8;
257
 
246
 
258
     SERIAL_PROTOCOLPGM("AUTO TUNE baseline");
247
     SERIAL_PROTOCOLPGM("AUTO TUNE baseline");
259
     SERIAL_EOL();
248
     SERIAL_EOL();
260
-    probe_G33_points(z_at_pt_base, 3, true, false);
249
+    if (isnan(probe_G33_points(z_at_pt_base, 3, true, false))) return false;
261
     print_G33_results(z_at_pt_base, true, true);
250
     print_G33_results(z_at_pt_base, true, true);
262
 
251
 
263
     LOOP_XYZ(axis) {
252
     LOOP_XYZ(axis) {
272
       SERIAL_CHAR(tolower(axis_codes[axis]));
261
       SERIAL_CHAR(tolower(axis_codes[axis]));
273
       SERIAL_EOL();
262
       SERIAL_EOL();
274
 
263
 
275
-      probe_G33_points(z_at_pt, 3, true, false);
264
+      if (isnan(probe_G33_points(z_at_pt, 3, true, false))) return false;
276
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
265
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
277
       print_G33_results(z_at_pt, true, true);
266
       print_G33_results(z_at_pt, true, true);
278
       delta_endstop_adj[axis] += 1.0;
267
       delta_endstop_adj[axis] += 1.0;
303
       SERIAL_PROTOCOLPGM("Tuning R");
292
       SERIAL_PROTOCOLPGM("Tuning R");
304
       SERIAL_PROTOCOL(zig_zag == -1 ? "-" : "+");
293
       SERIAL_PROTOCOL(zig_zag == -1 ? "-" : "+");
305
       SERIAL_EOL();
294
       SERIAL_EOL();
306
-      probe_G33_points(z_at_pt, 3, true, false);
295
+      if (isnan(probe_G33_points(z_at_pt, 3, true, false))) return false;
307
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
296
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
308
       print_G33_results(z_at_pt, true, true);
297
       print_G33_results(z_at_pt, true, true);
309
       delta_radius -= 1.0 * zig_zag;
298
       delta_radius -= 1.0 * zig_zag;
330
       SERIAL_CHAR(tolower(axis_codes[axis]));
319
       SERIAL_CHAR(tolower(axis_codes[axis]));
331
       SERIAL_EOL();
320
       SERIAL_EOL();
332
 
321
 
333
-      probe_G33_points(z_at_pt, 3, true, false);
322
+      if (isnan(probe_G33_points(z_at_pt, 3, true, false))) return false;
334
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
323
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
335
       print_G33_results(z_at_pt, true, true);
324
       print_G33_results(z_at_pt, true, true);
336
 
325
 
365
     SERIAL_EOL();
354
     SERIAL_EOL();
366
     SERIAL_PROTOCOLPGM("Copy these values to Configuration.h");
355
     SERIAL_PROTOCOLPGM("Copy these values to Configuration.h");
367
     SERIAL_EOL();
356
     SERIAL_EOL();
357
+    return true;
368
   }
358
   }
369
 
359
 
370
 #endif // HAS_BED_PROBE
360
 #endif // HAS_BED_PROBE
392
  *
382
  *
393
  *   Vn  Verbose level:
383
  *   Vn  Verbose level:
394
  *      V0  Dry-run mode. Report settings and probe results. No calibration.
384
  *      V0  Dry-run mode. Report settings and probe results. No calibration.
395
- *      V1  Report settings
396
- *      V2  Report settings and probe results
385
+ *      V1  Report start and end settings only
386
+ *      V2  Report settings at each iteration
387
+ *      V3  Report settings and probe results
397
  *
388
  *
398
  *   E   Engage the probe for each point
389
  *   E   Engage the probe for each point
399
  */
390
  */
406
   }
397
   }
407
 
398
 
408
   const int8_t verbose_level = parser.byteval('V', 1);
399
   const int8_t verbose_level = parser.byteval('V', 1);
409
-  if (!WITHIN(verbose_level, 0, 2)) {
410
-    SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-2).");
400
+  if (!WITHIN(verbose_level, 0, 3)) {
401
+    SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-3).");
411
     return;
402
     return;
412
   }
403
   }
413
 
404
 
414
-  const float calibration_precision = parser.floatval('C');
405
+  const float calibration_precision = parser.floatval('C', 0.0);
415
   if (calibration_precision < 0) {
406
   if (calibration_precision < 0) {
416
     SERIAL_PROTOCOLLNPGM("?(C)alibration precision is implausible (>=0).");
407
     SERIAL_PROTOCOLLNPGM("?(C)alibration precision is implausible (>=0).");
417
     return;
408
     return;
519
     // Probe the points
510
     // Probe the points
520
 
511
 
521
     zero_std_dev = probe_G33_points(z_at_pt, probe_points, towers_set, stow_after_each);
512
     zero_std_dev = probe_G33_points(z_at_pt, probe_points, towers_set, stow_after_each);
513
+    if (isnan(zero_std_dev)) {
514
+      SERIAL_PROTOCOLPGM("Correct delta_radius with M665 R or end-stops with M666 X Y Z");
515
+      SERIAL_EOL();
516
+      return G33_CLEANUP();
517
+    }
522
 
518
 
523
     // Solve matrices
519
     // Solve matrices
524
 
520
 
632
 
628
 
633
     // print report
629
     // print report
634
 
630
 
635
-    if (verbose_level != 1)
631
+    if (verbose_level > 2)
636
       print_G33_results(z_at_pt, _tower_results, _opposite_results);
632
       print_G33_results(z_at_pt, _tower_results, _opposite_results);
637
 
633
 
638
     if (verbose_level != 0) {                                    // !dry run
634
     if (verbose_level != 0) {                                    // !dry run
672
         SERIAL_PROTOCOL_F(zero_std_dev, 3);
668
         SERIAL_PROTOCOL_F(zero_std_dev, 3);
673
         SERIAL_EOL();
669
         SERIAL_EOL();
674
         lcd_setstatus(mess);
670
         lcd_setstatus(mess);
675
-        print_G33_settings(_endstop_results, _angle_results);
671
+        if (verbose_level > 1)
672
+          print_G33_settings(_endstop_results, _angle_results);
676
       }
673
       }
677
     }
674
     }
678
     else {                                                       // dry run
675
     else {                                                       // dry run

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

30
 #if ENABLED(DELTA)
30
 #if ENABLED(DELTA)
31
 
31
 
32
   #include "../../module/delta.h"
32
   #include "../../module/delta.h"
33
-
34
   /**
33
   /**
35
    * M665: Set delta configurations
34
    * M665: Set delta configurations
36
    *
35
    *
44
    *    Z = Rotate A and B by this angle
43
    *    Z = Rotate A and B by this angle
45
    */
44
    */
46
   void GcodeSuite::M665() {
45
   void GcodeSuite::M665() {
47
-    if (parser.seen('H')) {
48
-      delta_height = parser.value_linear_units();
49
-      update_software_endstops(Z_AXIS);
50
-    }
46
+    if (parser.seen('H')) delta_height                   = parser.value_linear_units();
51
     if (parser.seen('L')) delta_diagonal_rod             = parser.value_linear_units();
47
     if (parser.seen('L')) delta_diagonal_rod             = parser.value_linear_units();
52
     if (parser.seen('R')) delta_radius                   = parser.value_linear_units();
48
     if (parser.seen('R')) delta_radius                   = parser.value_linear_units();
53
     if (parser.seen('S')) delta_segments_per_second      = parser.value_float();
49
     if (parser.seen('S')) delta_segments_per_second      = parser.value_float();

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

33
   #include "../../core/serial.h"
33
   #include "../../core/serial.h"
34
 #endif
34
 #endif
35
 
35
 
36
+
37
+#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
38
+  FORCE_INLINE void mod_zprobe_zoffset(const float &offs) {
39
+    zprobe_zoffset += offs;
40
+    SERIAL_ECHO_START();
41
+    SERIAL_ECHOLNPAIR(MSG_PROBE_Z_OFFSET ": ", zprobe_zoffset);
42
+  }
43
+#endif
44
+
36
 /**
45
 /**
37
  * M290: Babystepping
46
  * M290: Babystepping
38
  */
47
  */
43
         const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2);
52
         const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2);
44
         thermalManager.babystep_axis((AxisEnum)a, offs * planner.axis_steps_per_mm[a]);
53
         thermalManager.babystep_axis((AxisEnum)a, offs * planner.axis_steps_per_mm[a]);
45
         #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
54
         #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
46
-          if (a == Z_AXIS) zprobe_zoffset += offs;
55
+          if (a == Z_AXIS && parser.boolval('P', true)) mod_zprobe_zoffset(offs);
47
         #endif
56
         #endif
48
       }
57
       }
49
   #else
58
   #else
51
       const float offs = constrain(parser.value_axis_units(Z_AXIS), -2, 2);
60
       const float offs = constrain(parser.value_axis_units(Z_AXIS), -2, 2);
52
       thermalManager.babystep_axis(Z_AXIS, offs * planner.axis_steps_per_mm[Z_AXIS]);
61
       thermalManager.babystep_axis(Z_AXIS, offs * planner.axis_steps_per_mm[Z_AXIS]);
53
       #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
62
       #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
54
-        zprobe_zoffset += offs;
63
+        if (parser.boolval('P', true)) mod_zprobe_zoffset(offs);
55
       #endif
64
       #endif
56
     }
65
     }
57
   #endif
66
   #endif
58
-  #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
59
-    SERIAL_ECHO_START();
60
-    SERIAL_ECHOLNPAIR(MSG_PROBE_Z_OFFSET ": ", zprobe_zoffset);
61
-  #endif
62
 }
67
 }
63
 
68
 
64
 #endif // BABYSTEPPING
69
 #endif // BABYSTEPPING

+ 11
- 9
Marlin/src/module/probe.cpp View File

564
     }
564
     }
565
   #endif
565
   #endif
566
 
566
 
567
-  return current_position[Z_AXIS] + zprobe_zoffset;
567
+  return current_position[Z_AXIS];
568
 }
568
 }
569
 
569
 
570
 /**
570
 /**
576
  *   - Raise to the BETWEEN height
576
  *   - Raise to the BETWEEN height
577
  * - Return the probed Z position
577
  * - Return the probed Z position
578
  */
578
  */
579
-float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t verbose_level, const bool printable/*=true*/) {
579
+float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t verbose_level, const bool probe_relative/*=true*/) {
580
   #if ENABLED(DEBUG_LEVELING_FEATURE)
580
   #if ENABLED(DEBUG_LEVELING_FEATURE)
581
     if (DEBUGGING(LEVELING)) {
581
     if (DEBUGGING(LEVELING)) {
582
       SERIAL_ECHOPAIR(">>> probe_pt(", LOGICAL_X_POSITION(rx));
582
       SERIAL_ECHOPAIR(">>> probe_pt(", LOGICAL_X_POSITION(rx));
587
     }
587
     }
588
   #endif
588
   #endif
589
 
589
 
590
-  const float nx = rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ny = ry - (Y_PROBE_OFFSET_FROM_EXTRUDER);
591
-
592
-  if (!printable
593
-    ? !position_is_reachable(nx, ny)
594
-    : !position_is_reachable_by_probe(rx, ry)
595
-  ) return NAN;
590
+  // TODO: Adapt for SCARA, where the offset rotates
591
+  float nx = rx, ny = ry;
592
+  if (probe_relative) {
593
+    if (!position_is_reachable_by_probe(rx, ry)) return NAN;  // The given position is in terms of the probe
594
+    nx -= (X_PROBE_OFFSET_FROM_EXTRUDER);                     // Get the nozzle position
595
+    ny -= (Y_PROBE_OFFSET_FROM_EXTRUDER);
596
+  }
597
+  else if (!position_is_reachable(nx, ny)) return NAN;        // The given position is in terms of the nozzle
596
 
598
 
597
   const float nz = 
599
   const float nz = 
598
     #if ENABLED(DELTA)
600
     #if ENABLED(DELTA)
611
 
613
 
612
   float measured_z = NAN;
614
   float measured_z = NAN;
613
   if (!DEPLOY_PROBE()) {
615
   if (!DEPLOY_PROBE()) {
614
-    measured_z = run_z_probe();
616
+    measured_z = run_z_probe() + zprobe_zoffset;
615
 
617
 
616
     if (!stow)
618
     if (!stow)
617
       do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
619
       do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST));

+ 1
- 1
Marlin/src/module/probe.h View File

32
 #if HAS_BED_PROBE
32
 #if HAS_BED_PROBE
33
   extern float zprobe_zoffset;
33
   extern float zprobe_zoffset;
34
   bool set_probe_deployed(const bool deploy);
34
   bool set_probe_deployed(const bool deploy);
35
-  float probe_pt(const float &rx, const float &ry, const bool, const uint8_t, const bool printable=true);
35
+  float probe_pt(const float &rx, const float &ry, const bool, const uint8_t, const bool probe_relative=true);
36
   #define DEPLOY_PROBE() set_probe_deployed(true)
36
   #define DEPLOY_PROBE() set_probe_deployed(true)
37
   #define STOW_PROBE() set_probe_deployed(false)
37
   #define STOW_PROBE() set_probe_deployed(false)
38
 #else
38
 #else

Loading…
Cancel
Save