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

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

@@ -135,6 +135,15 @@ static void G33_cleanup(
135 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 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 148
   const bool _0p_calibration      = probe_points == 0,
140 149
              _1p_calibration      = probe_points == 1,
@@ -153,23 +162,13 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
153 162
              _7p_6_centre         = probe_points >= 5 && probe_points <= 7,
154 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 165
   LOOP_CAL_ALL(axis) z_at_pt[axis] = 0.0;
162 166
 
163 167
   if (!_0p_calibration) {
164 168
 
165 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 174
     if (_7p_calibration) { // probe extra center points
@@ -178,14 +177,9 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
178 177
       I_LOOP_CAL_PT(axis, start, steps) {
179 178
         const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
180 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 183
       z_at_pt[CEN] /= float(_7p_2_intermediates ? 7 : probe_points);
190 184
     }
191 185
 
@@ -206,14 +200,9 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
206 200
         for (int8_t circle = -offset; circle <= offset; circle++) {
207 201
           const float a = RADIANS(210 + (360 / NPP) *  (axis - 1)),
208 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 206
           // split probe point to neighbouring calibration points
218 207
           z_at_pt[uint8_t(round(axis - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
219 208
           z_at_pt[uint8_t(round(axis - interpol))           % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
@@ -243,7 +232,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
243 232
 
244 233
 #if HAS_BED_PROBE
245 234
 
246
-  static void G33_auto_tune() {
235
+  static bool G33_auto_tune() {
247 236
     float z_at_pt[NPP + 1]      = { 0.0 },
248 237
           z_at_pt_base[NPP + 1] = { 0.0 },
249 238
           z_temp, h_fac = 0.0, r_fac = 0.0, a_fac = 0.0, norm = 0.8;
@@ -257,7 +246,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
257 246
 
258 247
     SERIAL_PROTOCOLPGM("AUTO TUNE baseline");
259 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 250
     print_G33_results(z_at_pt_base, true, true);
262 251
 
263 252
     LOOP_XYZ(axis) {
@@ -272,7 +261,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
272 261
       SERIAL_CHAR(tolower(axis_codes[axis]));
273 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 265
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
277 266
       print_G33_results(z_at_pt, true, true);
278 267
       delta_endstop_adj[axis] += 1.0;
@@ -303,7 +292,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
303 292
       SERIAL_PROTOCOLPGM("Tuning R");
304 293
       SERIAL_PROTOCOL(zig_zag == -1 ? "-" : "+");
305 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 296
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
308 297
       print_G33_results(z_at_pt, true, true);
309 298
       delta_radius -= 1.0 * zig_zag;
@@ -330,7 +319,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
330 319
       SERIAL_CHAR(tolower(axis_codes[axis]));
331 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 323
       LOOP_CAL_ALL(axis) z_at_pt[axis] -= z_at_pt_base[axis];
335 324
       print_G33_results(z_at_pt, true, true);
336 325
 
@@ -365,6 +354,7 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
365 354
     SERIAL_EOL();
366 355
     SERIAL_PROTOCOLPGM("Copy these values to Configuration.h");
367 356
     SERIAL_EOL();
357
+    return true;
368 358
   }
369 359
 
370 360
 #endif // HAS_BED_PROBE
@@ -392,8 +382,9 @@ static float probe_G33_points(float z_at_pt[NPP + 1], const int8_t probe_points,
392 382
  *
393 383
  *   Vn  Verbose level:
394 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 389
  *   E   Engage the probe for each point
399 390
  */
@@ -406,12 +397,12 @@ void GcodeSuite::G33() {
406 397
   }
407 398
 
408 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 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 406
   if (calibration_precision < 0) {
416 407
     SERIAL_PROTOCOLLNPGM("?(C)alibration precision is implausible (>=0).");
417 408
     return;
@@ -519,6 +510,11 @@ void GcodeSuite::G33() {
519 510
     // Probe the points
520 511
 
521 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 519
     // Solve matrices
524 520
 
@@ -632,7 +628,7 @@ void GcodeSuite::G33() {
632 628
 
633 629
     // print report
634 630
 
635
-    if (verbose_level != 1)
631
+    if (verbose_level > 2)
636 632
       print_G33_results(z_at_pt, _tower_results, _opposite_results);
637 633
 
638 634
     if (verbose_level != 0) {                                    // !dry run
@@ -672,7 +668,8 @@ void GcodeSuite::G33() {
672 668
         SERIAL_PROTOCOL_F(zero_std_dev, 3);
673 669
         SERIAL_EOL();
674 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 675
     else {                                                       // dry run

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

@@ -30,7 +30,6 @@
30 30
 #if ENABLED(DELTA)
31 31
 
32 32
   #include "../../module/delta.h"
33
-
34 33
   /**
35 34
    * M665: Set delta configurations
36 35
    *
@@ -44,10 +43,7 @@
44 43
    *    Z = Rotate A and B by this angle
45 44
    */
46 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 47
     if (parser.seen('L')) delta_diagonal_rod             = parser.value_linear_units();
52 48
     if (parser.seen('R')) delta_radius                   = parser.value_linear_units();
53 49
     if (parser.seen('S')) delta_segments_per_second      = parser.value_float();

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

@@ -33,6 +33,15 @@
33 33
   #include "../../core/serial.h"
34 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 46
  * M290: Babystepping
38 47
  */
@@ -43,7 +52,7 @@ void GcodeSuite::M290() {
43 52
         const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2);
44 53
         thermalManager.babystep_axis((AxisEnum)a, offs * planner.axis_steps_per_mm[a]);
45 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 56
         #endif
48 57
       }
49 58
   #else
@@ -51,14 +60,10 @@ void GcodeSuite::M290() {
51 60
       const float offs = constrain(parser.value_axis_units(Z_AXIS), -2, 2);
52 61
       thermalManager.babystep_axis(Z_AXIS, offs * planner.axis_steps_per_mm[Z_AXIS]);
53 62
       #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
54
-        zprobe_zoffset += offs;
63
+        if (parser.boolval('P', true)) mod_zprobe_zoffset(offs);
55 64
       #endif
56 65
     }
57 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 69
 #endif // BABYSTEPPING

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

@@ -564,7 +564,7 @@ static float run_z_probe() {
564 564
     }
565 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,7 +576,7 @@ static float run_z_probe() {
576 576
  *   - Raise to the BETWEEN height
577 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 580
   #if ENABLED(DEBUG_LEVELING_FEATURE)
581 581
     if (DEBUGGING(LEVELING)) {
582 582
       SERIAL_ECHOPAIR(">>> probe_pt(", LOGICAL_X_POSITION(rx));
@@ -587,12 +587,14 @@ float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t
587 587
     }
588 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 599
   const float nz = 
598 600
     #if ENABLED(DELTA)
@@ -611,7 +613,7 @@ float probe_pt(const float &rx, const float &ry, const bool stow, const uint8_t
611 613
 
612 614
   float measured_z = NAN;
613 615
   if (!DEPLOY_PROBE()) {
614
-    measured_z = run_z_probe();
616
+    measured_z = run_z_probe() + zprobe_zoffset;
615 617
 
616 618
     if (!stow)
617 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,7 +32,7 @@
32 32
 #if HAS_BED_PROBE
33 33
   extern float zprobe_zoffset;
34 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 36
   #define DEPLOY_PROBE() set_probe_deployed(true)
37 37
   #define STOW_PROBE() set_probe_deployed(false)
38 38
 #else

Loading…
Cancel
Save