Parcourir la source

Kinematic clamp_to_software_endstops

Scott Lahteine il y a 6 ans
Parent
révision
893092ff7f
1 fichiers modifiés avec 38 ajouts et 21 suppressions
  1. 38
    21
      Marlin/Marlin_main.cpp

+ 38
- 21
Marlin/Marlin_main.cpp Voir le fichier

@@ -472,11 +472,14 @@ float filament_size[EXTRUDERS], volumetric_multiplier[EXTRUDERS];
472 472
 #endif
473 473
 
474 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 477
 #if HAS_SOFTWARE_ENDSTOPS
476 478
   bool soft_endstops_enabled = true;
479
+  #if IS_KINEMATIC
480
+    float soft_endstop_radius, soft_endstop_radius_2;
481
+  #endif
477 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 484
 #if FAN_COUNT > 0
482 485
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
@@ -1464,8 +1467,17 @@ bool get_target_extruder_from_command(const uint16_t code) {
1464 1467
     #endif
1465 1468
 
1466 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 1481
     #endif
1470 1482
   }
1471 1483
 
@@ -12047,31 +12059,36 @@ void ok_to_send() {
12047 12059
 
12048 12060
   /**
12049 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 12066
   void clamp_to_software_endstops(float target[XYZ]) {
12059 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 12088
     #endif
12066 12089
     #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
12067 12090
       NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
12068 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 12092
     #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
12076 12093
       NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
12077 12094
     #endif

Chargement…
Annuler
Enregistrer