Browse Source

Move reachable test to Probe class

Scott Lahteine 5 years ago
parent
commit
be62ab2d02

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

1249
         if (isnan(z_values[i][j])) {                  // Invalid mesh point?
1249
         if (isnan(z_values[i][j])) {                  // Invalid mesh point?
1250
 
1250
 
1251
           // Skip points the probe can't reach
1251
           // Skip points the probe can't reach
1252
-          if (!position_is_reachable_by_probe(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
1252
+          if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
1253
             continue;
1253
             continue;
1254
 
1254
 
1255
           found_a_NAN = true;
1255
           found_a_NAN = true;
1316
           // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1316
           // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1317
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1317
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1318
 
1318
 
1319
-          if (probe_relative ? !position_is_reachable_by_probe(mpos) : !position_is_reachable(mpos))
1319
+          if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
1320
             continue;
1320
             continue;
1321
 
1321
 
1322
           // Reachable. Check if it's the best_so_far location to the nozzle.
1322
           // Reachable. Check if it's the best_so_far location to the nozzle.

+ 2
- 12
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

417
         );
417
         );
418
       }
418
       }
419
 
419
 
420
-      if (
421
-        #if IS_SCARA || ENABLED(DELTA)
422
-             !position_is_reachable_by_probe(probe_position_lf.x, 0)
423
-          || !position_is_reachable_by_probe(probe_position_rb.x, 0)
424
-          || !position_is_reachable_by_probe(0, probe_position_lf.y)
425
-          || !position_is_reachable_by_probe(0, probe_position_rb.y)
426
-        #else
427
-             !position_is_reachable_by_probe(probe_position_lf)
428
-          || !position_is_reachable_by_probe(probe_position_rb)
429
-        #endif
430
-      ) {
420
+      if (!probe.good_bounds(probe_position_lf, probe_position_rb)) {
431
         SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
421
         SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
432
         G29_RETURN(false);
422
         G29_RETURN(false);
433
       }
423
       }
704
 
694
 
705
           #if IS_KINEMATIC
695
           #if IS_KINEMATIC
706
             // Avoid probing outside the round or hexagonal area
696
             // Avoid probing outside the round or hexagonal area
707
-            if (!position_is_reachable_by_probe(probePos)) continue;
697
+            if (!probe.can_reach(probePos)) continue;
708
           #endif
698
           #endif
709
 
699
 
710
           if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), ".");
700
           if (verbose_level) SERIAL_ECHOLNPAIR("Probing mesh point ", int(pt_index), "/", int(GRID_MAX_POINTS), ".");

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

432
   };
432
   };
433
 
433
 
434
   if (is_probe_point) {
434
   if (is_probe_point) {
435
-    if (!position_is_reachable_by_probe(pos.x, Y_CENTER)) {
435
+    if (!probe.can_reach(pos.x, Y_CENTER)) {
436
       SERIAL_ECHOLNPGM("?(X) out of bounds.");
436
       SERIAL_ECHOLNPGM("?(X) out of bounds.");
437
       return;
437
       return;
438
     }
438
     }
439
-    if (!position_is_reachable_by_probe(pos)) {
439
+    if (!probe.can_reach(pos)) {
440
       SERIAL_ECHOLNPGM("?(Y) out of bounds.");
440
       SERIAL_ECHOLNPGM("?(Y) out of bounds.");
441
       return;
441
       return;
442
     }
442
     }

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

116
       temp_comp.measure_point_x - probe.offset_xy.x,
116
       temp_comp.measure_point_x - probe.offset_xy.x,
117
       temp_comp.measure_point_y - probe.offset_xy.y
117
       temp_comp.measure_point_y - probe.offset_xy.y
118
     );
118
     );
119
-    if (!position_is_reachable_by_probe(destination)) {
119
+    if (!probe.can_reach(destination)) {
120
       SERIAL_ECHOLNPGM("!Probe position unreachable - aborting.");
120
       SERIAL_ECHOLNPGM("!Probe position unreachable - aborting.");
121
       return;
121
       return;
122
     }
122
     }

+ 4
- 4
Marlin/src/gcode/calibrate/M48.cpp View File

80
   xy_float_t next_pos = current_position;
80
   xy_float_t next_pos = current_position;
81
 
81
 
82
   const xy_pos_t probe_pos = {
82
   const xy_pos_t probe_pos = {
83
-    parser.linearval('X', next_pos.x + probe.offset_xy.x),
84
-    parser.linearval('Y', next_pos.y + probe.offset_xy.y)
83
+    parser.linearval('X', next_pos.x + probe.offset_xy.x),  // If no X use the probe's current X position
84
+    parser.linearval('Y', next_pos.y + probe.offset_xy.y)   // If no Y, ditto
85
   };
85
   };
86
 
86
 
87
-  if (!position_is_reachable_by_probe(probe_pos)) {
87
+  if (!probe.can_reach(probe_pos)) {
88
     SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
88
     SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
89
     return;
89
     return;
90
   }
90
   }
179
           #else
179
           #else
180
             // If we have gone out too far, we can do a simple fix and scale the numbers
180
             // If we have gone out too far, we can do a simple fix and scale the numbers
181
             // back in closer to the origin.
181
             // back in closer to the origin.
182
-            while (!position_is_reachable_by_probe(next_pos)) {
182
+            while (!probe.can_reach(next_pos)) {
183
               next_pos *= 0.8f;
183
               next_pos *= 0.8f;
184
               if (verbose_level > 3)
184
               if (verbose_level > 3)
185
                 SERIAL_ECHOLNPAIR_P(PSTR("Moving inward: X"), next_pos.x, SP_Y_STR, next_pos.y);
185
                 SERIAL_ECHOLNPAIR_P(PSTR("Moving inward: X"), next_pos.x, SP_Y_STR, next_pos.y);

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

43
   const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x),
43
   const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x),
44
                          parser.linearval('Y', current_position.y + probe.offset_xy.y) };
44
                          parser.linearval('Y', current_position.y + probe.offset_xy.y) };
45
 
45
 
46
-  if (!position_is_reachable_by_probe(pos)) return;
46
+  if (!probe.can_reach(pos)) return;
47
 
47
 
48
   // Disable leveling so the planner won't mess with us
48
   // Disable leveling so the planner won't mess with us
49
   #if HAS_LEVELING
49
   #if HAS_LEVELING

+ 6
- 53
Marlin/src/module/motion.h View File

30
 
30
 
31
 #include "../inc/MarlinConfig.h"
31
 #include "../inc/MarlinConfig.h"
32
 
32
 
33
-#if HAS_BED_PROBE
34
-  #include "probe.h"
35
-#endif
36
-
37
 #if IS_SCARA
33
 #if IS_SCARA
38
   #include "scara.h"
34
   #include "scara.h"
39
 #endif
35
 #endif
58
 }
54
 }
59
 
55
 
60
 // Error margin to work around float imprecision
56
 // Error margin to work around float imprecision
61
-constexpr float slop = 0.0001;
57
+constexpr float fslop = 0.0001;
62
 
58
 
63
 extern bool relative_mode;
59
 extern bool relative_mode;
64
 
60
 
306
   // Return true if the given point is within the printable area
302
   // Return true if the given point is within the printable area
307
   inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
303
   inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
308
     #if ENABLED(DELTA)
304
     #if ENABLED(DELTA)
309
-      return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + slop);
305
+      return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop);
310
     #elif IS_SCARA
306
     #elif IS_SCARA
311
       const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
307
       const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
312
       return (
308
       return (
322
     return position_is_reachable(pos.x, pos.y, inset);
318
     return position_is_reachable(pos.x, pos.y, inset);
323
   }
319
   }
324
 
320
 
325
-  #if HAS_BED_PROBE
326
-
327
-    #if HAS_PROBE_XY_OFFSET
328
-
329
-      // Return true if the both nozzle and the probe can reach the given point.
330
-      // Note: This won't work on SCARA since the probe offset rotates with the arm.
331
-      inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
332
-        return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y)
333
-               && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
334
-      }
335
-
336
-    #else
337
-
338
-      FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) {
339
-        return position_is_reachable(rx, ry, MIN_PROBE_EDGE);
340
-      }
341
-
342
-    #endif
343
-
344
-  #endif // HAS_BED_PROBE
345
-
346
 #else // CARTESIAN
321
 #else // CARTESIAN
347
 
322
 
348
   // Return true if the given position is within the machine bounds.
323
   // Return true if the given position is within the machine bounds.
349
   inline bool position_is_reachable(const float &rx, const float &ry) {
324
   inline bool position_is_reachable(const float &rx, const float &ry) {
350
-    if (!WITHIN(ry, Y_MIN_POS - slop, Y_MAX_POS + slop)) return false;
325
+    if (!WITHIN(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false;
351
     #if ENABLED(DUAL_X_CARRIAGE)
326
     #if ENABLED(DUAL_X_CARRIAGE)
352
       if (active_extruder)
327
       if (active_extruder)
353
-        return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop);
328
+        return WITHIN(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop);
354
       else
329
       else
355
-        return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop);
330
+        return WITHIN(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop);
356
     #else
331
     #else
357
-      return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop);
332
+      return WITHIN(rx, X_MIN_POS - fslop, X_MAX_POS + fslop);
358
     #endif
333
     #endif
359
   }
334
   }
360
   inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }
335
   inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); }
361
 
336
 
362
-  #if HAS_BED_PROBE
363
-
364
-    /**
365
-     * Return whether the given position is within the bed, and whether the nozzle
366
-     * can reach the position required to put the probe at the given position.
367
-     *
368
-     * Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
369
-     *          nozzle must be be able to reach +10,-10.
370
-     */
371
-    inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
372
-      return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y)
373
-          && WITHIN(rx, probe.min_x() - slop, probe.max_x() + slop)
374
-          && WITHIN(ry, probe.min_y() - slop, probe.max_y() + slop);
375
-    }
376
-
377
-  #endif // HAS_BED_PROBE
378
-
379
 #endif // CARTESIAN
337
 #endif // CARTESIAN
380
 
338
 
381
-#if !HAS_BED_PROBE
382
-  FORCE_INLINE bool position_is_reachable_by_probe(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
383
-#endif
384
-FORCE_INLINE bool position_is_reachable_by_probe(const xy_pos_t &pos) { return position_is_reachable_by_probe(pos.x, pos.y); }
385
-
386
 /**
339
 /**
387
  * Duplication mode
340
  * Duplication mode
388
  */
341
  */

+ 2
- 2
Marlin/src/module/probe.cpp View File

89
 xyz_pos_t Probe::offset; // Initialized by settings.load()
89
 xyz_pos_t Probe::offset; // Initialized by settings.load()
90
 
90
 
91
 #if HAS_PROBE_XY_OFFSET
91
 #if HAS_PROBE_XY_OFFSET
92
-  const xyz_pos_t &Probe::offset_xy = probe.offset;
92
+  const xyz_pos_t &Probe::offset_xy = Probe::offset;
93
 #endif
93
 #endif
94
 
94
 
95
 #if ENABLED(Z_PROBE_SLED)
95
 #if ENABLED(Z_PROBE_SLED)
727
   // TODO: Adapt for SCARA, where the offset rotates
727
   // TODO: Adapt for SCARA, where the offset rotates
728
   xyz_pos_t npos = { rx, ry };
728
   xyz_pos_t npos = { rx, ry };
729
   if (probe_relative) {                                     // The given position is in terms of the probe
729
   if (probe_relative) {                                     // The given position is in terms of the probe
730
-    if (!position_is_reachable_by_probe(npos)) {
730
+    if (!can_reach(npos)) {
731
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
731
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
732
       return NAN;
732
       return NAN;
733
     }
733
     }

+ 49
- 0
Marlin/src/module/probe.h View File

27
 
27
 
28
 #include "../inc/MarlinConfig.h"
28
 #include "../inc/MarlinConfig.h"
29
 
29
 
30
+#include "motion.h"
31
+
30
 #if HAS_BED_PROBE
32
 #if HAS_BED_PROBE
31
   enum ProbePtRaise : uint8_t {
33
   enum ProbePtRaise : uint8_t {
32
     PROBE_PT_NONE,      // No raise or stow after run_z_probe
34
     PROBE_PT_NONE,      // No raise or stow after run_z_probe
45
 
47
 
46
     static bool set_deployed(const bool deploy);
48
     static bool set_deployed(const bool deploy);
47
 
49
 
50
+
51
+    #if IS_KINEMATIC
52
+
53
+      #if HAS_PROBE_XY_OFFSET
54
+        // Return true if the both nozzle and the probe can reach the given point.
55
+        // Note: This won't work on SCARA since the probe offset rotates with the arm.
56
+        static inline bool can_reach(const float &rx, const float &ry) {
57
+          return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
58
+              && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));       // Can the nozzle also go near there?
59
+        }
60
+      #else
61
+        FORCE_INLINE static bool can_reach(const float &rx, const float &ry) {
62
+          return position_is_reachable(rx, ry, MIN_PROBE_EDGE);
63
+        }
64
+      #endif
65
+
66
+    #else
67
+
68
+      /**
69
+       * Return whether the given position is within the bed, and whether the nozzle
70
+       * can reach the position required to put the probe at the given position.
71
+       *
72
+       * Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
73
+       *          nozzle must be be able to reach +10,-10.
74
+       */
75
+      static inline bool can_reach(const float &rx, const float &ry) {
76
+        return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
77
+            && WITHIN(rx, min_x() - fslop, max_x() + fslop)
78
+            && WITHIN(ry, min_y() - fslop, max_y() + fslop);
79
+      }
80
+
81
+    #endif
82
+
48
     #ifdef Z_AFTER_PROBING
83
     #ifdef Z_AFTER_PROBING
49
       static void move_z_after_probing();
84
       static void move_z_after_probing();
50
     #endif
85
     #endif
62
 
97
 
63
     static bool set_deployed(const bool) { return false; }
98
     static bool set_deployed(const bool) { return false; }
64
 
99
 
100
+    FORCE_INLINE static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
101
+
65
   #endif
102
   #endif
66
 
103
 
104
+  FORCE_INLINE static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
105
+
106
+  FORCE_INLINE static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
107
+    return (
108
+      #if IS_KINEMATIC
109
+         can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
110
+      #else
111
+         can_reach(lf) && can_reach(rb)
112
+      #endif
113
+    );
114
+  }
115
+
67
   // Use offset_xy for read only access
116
   // Use offset_xy for read only access
68
   // More optimal the XY offset is known to always be zero.
117
   // More optimal the XY offset is known to always be zero.
69
   #if HAS_PROBE_XY_OFFSET
118
   #if HAS_PROBE_XY_OFFSET

Loading…
Cancel
Save