소스 검색

Merge pull request #8169 from thinkyhead/bf2_kinematic_soft_endstops

[2.0.x] Kinematic clamp_to_software_endstops
Scott Lahteine 7 년 전
부모
커밋
1f38761da2
No account linked to committer's email address
1개의 변경된 파일37개의 추가작업 그리고 15개의 파일을 삭제
  1. 37
    15
      Marlin/src/module/motion.cpp

+ 37
- 15
Marlin/src/module/motion.cpp 파일 보기

454
   // Software Endstops are based on the configured limits.
454
   // Software Endstops are based on the configured limits.
455
   bool soft_endstops_enabled = true;
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
    * Constrain the given coordinates to the software endstops.
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
   void clamp_to_software_endstops(float target[XYZ]) {
467
   void clamp_to_software_endstops(float target[XYZ]) {
464
     if (!soft_endstops_enabled) return;
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
     #endif
489
     #endif
471
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
490
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
472
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
491
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
473
     #endif
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
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
493
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
481
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
494
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
482
     #endif
495
     #endif
1259
     #endif
1272
     #endif
1260
 
1273
 
1261
     #if ENABLED(DELTA)
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
     #endif
1286
     #endif
1265
   }
1287
   }
1266
 
1288
 

Loading…
취소
저장