Преглед изворни кода

Move reachable test to Probe class

Scott Lahteine пре 4 година
родитељ
комит
be62ab2d02

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Прегледај датотеку

@@ -1249,7 +1249,7 @@
1249 1249
         if (isnan(z_values[i][j])) {                  // Invalid mesh point?
1250 1250
 
1251 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 1253
             continue;
1254 1254
 
1255 1255
           found_a_NAN = true;
@@ -1316,7 +1316,7 @@
1316 1316
           // Also for round beds, there are grid points outside the bed the nozzle can't reach.
1317 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 1320
             continue;
1321 1321
 
1322 1322
           // Reachable. Check if it's the best_so_far location to the nozzle.

+ 2
- 12
Marlin/src/gcode/bedlevel/abl/G29.cpp Прегледај датотеку

@@ -417,17 +417,7 @@ G29_TYPE GcodeSuite::G29() {
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 421
         SERIAL_ECHOLNPGM("? (L,R,F,B) out of bounds.");
432 422
         G29_RETURN(false);
433 423
       }
@@ -704,7 +694,7 @@ G29_TYPE GcodeSuite::G29() {
704 694
 
705 695
           #if IS_KINEMATIC
706 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 698
           #endif
709 699
 
710 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 Прегледај датотеку

@@ -432,11 +432,11 @@ void GcodeSuite::M422() {
432 432
   };
433 433
 
434 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 436
       SERIAL_ECHOLNPGM("?(X) out of bounds.");
437 437
       return;
438 438
     }
439
-    if (!position_is_reachable_by_probe(pos)) {
439
+    if (!probe.can_reach(pos)) {
440 440
       SERIAL_ECHOLNPGM("?(Y) out of bounds.");
441 441
       return;
442 442
     }

+ 1
- 1
Marlin/src/gcode/calibrate/G76_M871.cpp Прегледај датотеку

@@ -116,7 +116,7 @@ void GcodeSuite::G76() {
116 116
       temp_comp.measure_point_x - probe.offset_xy.x,
117 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 120
       SERIAL_ECHOLNPGM("!Probe position unreachable - aborting.");
121 121
       return;
122 122
     }

+ 4
- 4
Marlin/src/gcode/calibrate/M48.cpp Прегледај датотеку

@@ -80,11 +80,11 @@ void GcodeSuite::M48() {
80 80
   xy_float_t next_pos = current_position;
81 81
 
82 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 88
     SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
89 89
     return;
90 90
   }
@@ -179,7 +179,7 @@ void GcodeSuite::M48() {
179 179
           #else
180 180
             // If we have gone out too far, we can do a simple fix and scale the numbers
181 181
             // back in closer to the origin.
182
-            while (!position_is_reachable_by_probe(next_pos)) {
182
+            while (!probe.can_reach(next_pos)) {
183 183
               next_pos *= 0.8f;
184 184
               if (verbose_level > 3)
185 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 Прегледај датотеку

@@ -43,7 +43,7 @@ void GcodeSuite::G30() {
43 43
   const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x),
44 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 48
   // Disable leveling so the planner won't mess with us
49 49
   #if HAS_LEVELING

+ 6
- 53
Marlin/src/module/motion.h Прегледај датотеку

@@ -30,10 +30,6 @@
30 30
 
31 31
 #include "../inc/MarlinConfig.h"
32 32
 
33
-#if HAS_BED_PROBE
34
-  #include "probe.h"
35
-#endif
36
-
37 33
 #if IS_SCARA
38 34
   #include "scara.h"
39 35
 #endif
@@ -58,7 +54,7 @@ FORCE_INLINE bool homing_needed() {
58 54
 }
59 55
 
60 56
 // Error margin to work around float imprecision
61
-constexpr float slop = 0.0001;
57
+constexpr float fslop = 0.0001;
62 58
 
63 59
 extern bool relative_mode;
64 60
 
@@ -306,7 +302,7 @@ void homeaxis(const AxisEnum axis);
306 302
   // Return true if the given point is within the printable area
307 303
   inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) {
308 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 306
     #elif IS_SCARA
311 307
       const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y);
312 308
       return (
@@ -322,67 +318,24 @@ void homeaxis(const AxisEnum axis);
322 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 321
 #else // CARTESIAN
347 322
 
348 323
   // Return true if the given position is within the machine bounds.
349 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 326
     #if ENABLED(DUAL_X_CARRIAGE)
352 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 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 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 333
     #endif
359 334
   }
360 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 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 340
  * Duplication mode
388 341
  */

+ 2
- 2
Marlin/src/module/probe.cpp Прегледај датотеку

@@ -89,7 +89,7 @@ Probe probe;
89 89
 xyz_pos_t Probe::offset; // Initialized by settings.load()
90 90
 
91 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 93
 #endif
94 94
 
95 95
 #if ENABLED(Z_PROBE_SLED)
@@ -727,7 +727,7 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
727 727
   // TODO: Adapt for SCARA, where the offset rotates
728 728
   xyz_pos_t npos = { rx, ry };
729 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 731
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable");
732 732
       return NAN;
733 733
     }

+ 49
- 0
Marlin/src/module/probe.h Прегледај датотеку

@@ -27,6 +27,8 @@
27 27
 
28 28
 #include "../inc/MarlinConfig.h"
29 29
 
30
+#include "motion.h"
31
+
30 32
 #if HAS_BED_PROBE
31 33
   enum ProbePtRaise : uint8_t {
32 34
     PROBE_PT_NONE,      // No raise or stow after run_z_probe
@@ -45,6 +47,39 @@ public:
45 47
 
46 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 83
     #ifdef Z_AFTER_PROBING
49 84
       static void move_z_after_probing();
50 85
     #endif
@@ -62,8 +97,22 @@ public:
62 97
 
63 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 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 116
   // Use offset_xy for read only access
68 117
   // More optimal the XY offset is known to always be zero.
69 118
   #if HAS_PROBE_XY_OFFSET

Loading…
Откажи
Сачувај