Browse Source

Merge pull request #8169 from thinkyhead/bf2_kinematic_soft_endstops

[2.0.x] Kinematic clamp_to_software_endstops
Scott Lahteine 7 years ago
parent
commit
1f38761da2
No account linked to committer's email address
1 changed files with 37 additions and 15 deletions
  1. 37
    15
      Marlin/src/module/motion.cpp

+ 37
- 15
Marlin/src/module/motion.cpp View File

@@ -454,29 +454,42 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
454 454
   // Software Endstops are based on the configured limits.
455 455
   bool soft_endstops_enabled = true;
456 456
 
457
+  #if IS_KINEMATIC
458
+    float soft_endstop_radius, soft_endstop_radius_2;
459
+  #endif
460
+
457 461
   /**
458 462
    * Constrain the given coordinates to the software endstops.
459 463
    *
460
-   * NOTE: This will only apply to Z on DELTA and SCARA. XY is
461
-   *       constrained to a circle on these kinematic systems.
464
+   * For DELTA/SCARA the XY constraint is based on the smallest
465
+   * radius within the set software endstops.
462 466
    */
463 467
   void clamp_to_software_endstops(float target[XYZ]) {
464 468
     if (!soft_endstops_enabled) return;
465
-    #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
466
-      NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
467
-    #endif
468
-    #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
469
-      NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
469
+    #if IS_KINEMATIC
470
+      const float dist_2 = HYPOT2(target[X_AXIS], target[Y_AXIS]);
471
+      if (dist_2 > soft_endstop_radius_2) {
472
+        const float ratio = soft_endstop_radius / SQRT(dist_2); // 200 / 300 = 0.66
473
+        target[X_AXIS] *= ratio;
474
+        target[Y_AXIS] *= ratio;
475
+      }
476
+    #else
477
+      #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
478
+        NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
479
+      #endif
480
+      #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
481
+        NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
482
+      #endif
483
+      #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
484
+        NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
485
+      #endif
486
+      #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
487
+        NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
488
+      #endif
470 489
     #endif
471 490
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
472 491
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
473 492
     #endif
474
-    #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
475
-      NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
476
-    #endif
477
-    #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
478
-      NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
479
-    #endif
480 493
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
481 494
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
482 495
     #endif
@@ -1259,8 +1272,17 @@ void homeaxis(const AxisEnum axis) {
1259 1272
     #endif
1260 1273
 
1261 1274
     #if ENABLED(DELTA)
1262
-      if (axis == Z_AXIS)
1263
-        delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1275
+      switch(axis) {
1276
+        case X_AXIS:
1277
+        case Y_AXIS:
1278
+          // Get a minimum radius for clamping
1279
+          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]);
1280
+          soft_endstop_radius_2 = sq(soft_endstop_radius);
1281
+          break;
1282
+        case Z_AXIS:
1283
+          delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1284
+        default: break;
1285
+      }
1264 1286
     #endif
1265 1287
   }
1266 1288
 

Loading…
Cancel
Save