Browse Source

Tweaks to motion.h reachable tests

Scott Lahteine 6 years ago
parent
commit
f0dbe61692
1 changed files with 12 additions and 15 deletions
  1. 12
    15
      Marlin/src/module/motion.h

+ 12
- 15
Marlin/src/module/motion.h View File

36
   #include "../module/scara.h"
36
   #include "../module/scara.h"
37
 #endif
37
 #endif
38
 
38
 
39
+// Error margin to work around float imprecision
40
+constexpr float slop = 0.0001;
41
+
39
 extern bool relative_mode;
42
 extern bool relative_mode;
40
 
43
 
41
 extern float current_position[XYZE],  // High-level current tool position
44
 extern float current_position[XYZE],  // High-level current tool position
265
 
268
 
266
 #else // CARTESIAN
269
 #else // CARTESIAN
267
 
270
 
268
-   // Return true if the given position is within the machine bounds.
271
+  // Return true if the given position is within the machine bounds.
269
   inline bool position_is_reachable(const float &rx, const float &ry) {
272
   inline bool position_is_reachable(const float &rx, const float &ry) {
273
+    if (!WITHIN(ry, Y_MIN_POS - slop, Y_MAX_POS + slop)) return false;
270
     #if ENABLED(DUAL_X_CARRIAGE)
274
     #if ENABLED(DUAL_X_CARRIAGE)
271
-      if (active_extruder == 0) {
272
-        // Add 0.001 margin to deal with float imprecision
273
-        return WITHIN(rx, X1_MIN_POS - 0.001f, X1_MAX_POS + 0.001f)
274
-            && WITHIN(ry,  Y_MIN_POS - 0.001f,  Y_MAX_POS + 0.001f);
275
-      } else {
276
-       // Add 0.001 margin to deal with float imprecision
277
-       return WITHIN(rx, X2_MIN_POS - 0.001f, X2_MAX_POS + 0.001f)
278
-           && WITHIN(ry,  Y_MIN_POS - 0.001f,  Y_MAX_POS + 0.001f);
279
-      }
275
+      if (active_extruder)
276
+        return WITHIN(rx, X2_MIN_POS - slop, X2_MAX_POS + slop);
277
+      else
278
+        return WITHIN(rx, X1_MIN_POS - slop, X1_MAX_POS + slop);
280
     #else
279
     #else
281
-      // Add 0.001 margin to deal with float imprecision
282
-      return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f)
283
-          && WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
280
+      return WITHIN(rx, X_MIN_POS - slop, X_MAX_POS + slop);
284
     #endif
281
     #endif
285
   }
282
   }
286
 
283
 
294
      */
291
      */
295
     inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
292
     inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
296
       return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
293
       return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
297
-          && WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f)
298
-          && WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f);
294
+          && WITHIN(rx, MIN_PROBE_X - slop, MAX_PROBE_X + slop)
295
+          && WITHIN(ry, MIN_PROBE_Y - slop, MAX_PROBE_Y + slop);
299
     }
296
     }
300
   #endif
297
   #endif
301
 
298
 

Loading…
Cancel
Save