Browse Source

Kinematic clamp_to_software_endstops

Scott Lahteine 7 years ago
parent
commit
893092ff7f
1 changed files with 38 additions and 21 deletions
  1. 38
    21
      Marlin/Marlin_main.cpp

+ 38
- 21
Marlin/Marlin_main.cpp View File

472
 #endif
472
 #endif
473
 
473
 
474
 // Software Endstops are based on the configured limits.
474
 // Software Endstops are based on the configured limits.
475
+float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
476
+      soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
475
 #if HAS_SOFTWARE_ENDSTOPS
477
 #if HAS_SOFTWARE_ENDSTOPS
476
   bool soft_endstops_enabled = true;
478
   bool soft_endstops_enabled = true;
479
+  #if IS_KINEMATIC
480
+    float soft_endstop_radius, soft_endstop_radius_2;
481
+  #endif
477
 #endif
482
 #endif
478
-float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
479
-      soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
480
 
483
 
481
 #if FAN_COUNT > 0
484
 #if FAN_COUNT > 0
482
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
485
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
1464
     #endif
1467
     #endif
1465
 
1468
 
1466
     #if ENABLED(DELTA)
1469
     #if ENABLED(DELTA)
1467
-      if (axis == Z_AXIS)
1468
-        delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1470
+      switch(axis) {
1471
+        case X_AXIS:
1472
+        case Y_AXIS:
1473
+          // Get a minimum radius for clamping
1474
+          soft_endstop_radius = MIN3(FABS(max(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
1475
+          soft_endstop_radius_2 = sq(soft_endstop_radius);
1476
+          break;
1477
+        case Z_AXIS:
1478
+          delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1479
+        default: break;
1480
+      }
1469
     #endif
1481
     #endif
1470
   }
1482
   }
1471
 
1483
 
12047
 
12059
 
12048
   /**
12060
   /**
12049
    * Constrain the given coordinates to the software endstops.
12061
    * Constrain the given coordinates to the software endstops.
12050
-   */
12051
-
12052
-  /**
12053
-   * Constrain the given coordinates to the software endstops.
12054
    *
12062
    *
12055
-   * NOTE: This will only apply to Z on DELTA and SCARA. XY is
12056
-   *       constrained to a circle on these kinematic systems.
12063
+   * For DELTA/SCARA the XY constraint is based on the smallest
12064
+   * radius within the set software endstops.
12057
    */
12065
    */
12058
   void clamp_to_software_endstops(float target[XYZ]) {
12066
   void clamp_to_software_endstops(float target[XYZ]) {
12059
     if (!soft_endstops_enabled) return;
12067
     if (!soft_endstops_enabled) return;
12060
-    #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
12061
-      NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
12062
-    #endif
12063
-    #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
12064
-      NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
12068
+    #if IS_KINEMATIC
12069
+      const float dist_2 = HYPOT2(target[X_AXIS], target[Y_AXIS]);
12070
+      if (dist_2 > soft_endstop_radius_2) {
12071
+        const float ratio = soft_endstop_radius / SQRT(dist_2); // 200 / 300 = 0.66
12072
+        target[X_AXIS] *= ratio;
12073
+        target[Y_AXIS] *= ratio;
12074
+      }
12075
+    #else
12076
+      #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
12077
+        NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
12078
+      #endif
12079
+      #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
12080
+        NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
12081
+      #endif
12082
+      #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
12083
+        NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
12084
+      #endif
12085
+      #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
12086
+        NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
12087
+      #endif
12065
     #endif
12088
     #endif
12066
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
12089
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
12067
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
12090
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
12068
     #endif
12091
     #endif
12069
-    #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
12070
-      NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
12071
-    #endif
12072
-    #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
12073
-      NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
12074
-    #endif
12075
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
12092
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
12076
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
12093
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
12077
     #endif
12094
     #endif

Loading…
Cancel
Save