Browse Source

Fix and improve software endstops (#13386)

Scott Lahteine 6 years ago
parent
commit
87162658c4
No account linked to committer's email address

+ 3
- 3
Marlin/src/feature/I2CPositionEncoder.cpp View File

@@ -328,8 +328,8 @@ bool I2CPositionEncoder::test_axis() {
328 328
 
329 329
   float startCoord[NUM_AXIS] = { 0 }, endCoord[NUM_AXIS] = { 0 };
330 330
 
331
-  const float startPosition = soft_endstop_min[encoderAxis] + 10,
332
-              endPosition = soft_endstop_max[encoderAxis] - 10,
331
+  const float startPosition = soft_endstop[encoderAxis].min + 10,
332
+              endPosition = soft_endstop[encoderAxis].max - 10,
333 333
               feedrate = FLOOR(MMM_TO_MMS((encoderAxis == Z_AXIS) ? HOMING_FEEDRATE_Z : HOMING_FEEDRATE_XY));
334 334
 
335 335
   ec = false;
@@ -390,7 +390,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
390 390
   ec = false;
391 391
 
392 392
   startDistance = 20;
393
-  endDistance = soft_endstop_max[encoderAxis] - 20;
393
+  endDistance = soft_endstop[encoderAxis].max - 20;
394 394
   travelDistance = endDistance - startDistance;
395 395
 
396 396
   LOOP_NA(i) {

+ 5
- 5
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -212,7 +212,7 @@ G29_TYPE GcodeSuite::G29() {
212 212
   #endif
213 213
 
214 214
   #if HAS_SOFTWARE_ENDSTOPS && ENABLED(PROBE_MANUALLY)
215
-    ABL_VAR bool enable_soft_endstops = true;
215
+    ABL_VAR bool saved_soft_endstops_state = true;
216 216
   #endif
217 217
 
218 218
   #if ABL_GRID
@@ -494,7 +494,7 @@ G29_TYPE GcodeSuite::G29() {
494 494
     if (seenA && g29_in_progress) {
495 495
       SERIAL_ECHOLNPGM("Manual G29 aborted");
496 496
       #if HAS_SOFTWARE_ENDSTOPS
497
-        soft_endstops_enabled = enable_soft_endstops;
497
+        soft_endstops_enabled = saved_soft_endstops_state;
498 498
       #endif
499 499
       set_bed_leveling_enabled(abl_should_enable);
500 500
       g29_in_progress = false;
@@ -519,7 +519,7 @@ G29_TYPE GcodeSuite::G29() {
519 519
     if (abl_probe_index == 0) {
520 520
       // For the initial G29 S2 save software endstop state
521 521
       #if HAS_SOFTWARE_ENDSTOPS
522
-        enable_soft_endstops = soft_endstops_enabled;
522
+        saved_soft_endstops_state = soft_endstops_enabled;
523 523
       #endif
524 524
       // Move close to the bed before the first point
525 525
       do_blocking_move_to_z(0);
@@ -617,7 +617,7 @@ G29_TYPE GcodeSuite::G29() {
617 617
 
618 618
         // Re-enable software endstops, if needed
619 619
         #if HAS_SOFTWARE_ENDSTOPS
620
-          soft_endstops_enabled = enable_soft_endstops;
620
+          soft_endstops_enabled = saved_soft_endstops_state;
621 621
         #endif
622 622
       }
623 623
 
@@ -641,7 +641,7 @@ G29_TYPE GcodeSuite::G29() {
641 641
 
642 642
         // Re-enable software endstops, if needed
643 643
         #if HAS_SOFTWARE_ENDSTOPS
644
-          soft_endstops_enabled = enable_soft_endstops;
644
+          soft_endstops_enabled = saved_soft_endstops_state;
645 645
         #endif
646 646
 
647 647
         if (!dryrun) {

+ 3
- 3
Marlin/src/gcode/bedlevel/mbl/G29.cpp View File

@@ -59,7 +59,7 @@ void GcodeSuite::G29() {
59 59
 
60 60
   static int mbl_probe_index = -1;
61 61
   #if HAS_SOFTWARE_ENDSTOPS
62
-    static bool enable_soft_endstops;
62
+    static bool saved_soft_endstops_state;
63 63
   #endif
64 64
 
65 65
   MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
@@ -99,7 +99,7 @@ void GcodeSuite::G29() {
99 99
       if (mbl_probe_index == 0) {
100 100
         #if HAS_SOFTWARE_ENDSTOPS
101 101
           // For the initial G29 S2 save software endstop state
102
-          enable_soft_endstops = soft_endstops_enabled;
102
+          saved_soft_endstops_state = soft_endstops_enabled;
103 103
         #endif
104 104
         // Move close to the bed before the first point
105 105
         do_blocking_move_to_z(0);
@@ -108,7 +108,7 @@ void GcodeSuite::G29() {
108 108
         // Save Z for the previous mesh position
109 109
         mbl.set_zigzag_z(mbl_probe_index - 1, current_position[Z_AXIS]);
110 110
         #if HAS_SOFTWARE_ENDSTOPS
111
-          soft_endstops_enabled = enable_soft_endstops;
111
+          soft_endstops_enabled = saved_soft_endstops_state;
112 112
         #endif
113 113
       }
114 114
       // If there's another point to sample, move there with optional lift.

+ 6
- 6
Marlin/src/gcode/control/M211.cpp View File

@@ -38,13 +38,13 @@ void GcodeSuite::M211() {
38 38
   if (parser.seen('S')) soft_endstops_enabled = parser.value_bool();
39 39
   serialprint_onoff(soft_endstops_enabled);
40 40
   SERIAL_ECHOPGM(MSG_SOFT_MIN);
41
-  SERIAL_ECHOPAIR(    MSG_X, LOGICAL_X_POSITION(soft_endstop_min[X_AXIS]));
42
-  SERIAL_ECHOPAIR(" " MSG_Y, LOGICAL_Y_POSITION(soft_endstop_min[Y_AXIS]));
43
-  SERIAL_ECHOPAIR(" " MSG_Z, LOGICAL_Z_POSITION(soft_endstop_min[Z_AXIS]));
41
+  SERIAL_ECHOPAIR(    MSG_X, LOGICAL_X_POSITION(soft_endstop[X_AXIS].min));
42
+  SERIAL_ECHOPAIR(" " MSG_Y, LOGICAL_Y_POSITION(soft_endstop[Y_AXIS].min));
43
+  SERIAL_ECHOPAIR(" " MSG_Z, LOGICAL_Z_POSITION(soft_endstop[Z_AXIS].min));
44 44
   SERIAL_ECHOPGM(MSG_SOFT_MAX);
45
-  SERIAL_ECHOPAIR(    MSG_X, LOGICAL_X_POSITION(soft_endstop_max[X_AXIS]));
46
-  SERIAL_ECHOPAIR(" " MSG_Y, LOGICAL_Y_POSITION(soft_endstop_max[Y_AXIS]));
47
-  SERIAL_ECHOLNPAIR(" " MSG_Z, LOGICAL_Z_POSITION(soft_endstop_max[Z_AXIS]));
45
+  SERIAL_ECHOPAIR(    MSG_X, LOGICAL_X_POSITION(soft_endstop[X_AXIS].max));
46
+  SERIAL_ECHOPAIR(" " MSG_Y, LOGICAL_Y_POSITION(soft_endstop[Y_AXIS].max));
47
+  SERIAL_ECHOLNPAIR(" " MSG_Z, LOGICAL_Z_POSITION(soft_endstop[Z_AXIS].max));
48 48
 }
49 49
 
50 50
 #endif

+ 1
- 1
Marlin/src/gcode/feature/camera/M240.cpp View File

@@ -127,7 +127,7 @@ void GcodeSuite::M240() {
127 127
        parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position[Y_AXIS],
128 128
       (parser.seenval('Z') ? parser.value_linear_units() : photo_position[Z_AXIS]) + current_position[Z_AXIS]
129 129
     };
130
-    clamp_to_software_endstops(raw);
130
+    apply_motion_limits(raw);
131 131
     do_blocking_move_to(raw, fr_mm_s);
132 132
 
133 133
     #ifdef PHOTO_SWITCH_POSITION

+ 1
- 1
Marlin/src/gcode/motion/G2_G3.cpp View File

@@ -190,7 +190,7 @@ void plan_arc(
190 190
     #endif
191 191
     raw[E_AXIS] += extruder_per_segment;
192 192
 
193
-    clamp_to_software_endstops(raw);
193
+    apply_motion_limits(raw);
194 194
 
195 195
     #if HAS_LEVELING && !PLANNER_LEVELING
196 196
       planner.apply_leveling(raw);

+ 11
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -2121,3 +2121,14 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
2121 2121
     #error "Both SERVICE_NAME_3 and SERVICE_INTERVAL_3 are required."
2122 2122
   #endif
2123 2123
 #endif
2124
+
2125
+/**
2126
+ * Require soft endstops for certain setups
2127
+ */
2128
+#if DISABLED(MIN_SOFTWARE_ENDSTOPS) || DISABLED(MAX_SOFTWARE_ENDSTOPS)
2129
+  #if ENABLED(DUAL_X_CARRIAGE)
2130
+    #error "DUAL_X_CARRIAGE requires both MIN_ and MAX_SOFTWARE_ENDSTOPS."
2131
+  #elif HAS_HOTEND_OFFSET
2132
+    #error "MIN_ and MAX_SOFTWARE_ENDSTOPS are both required with offset hotends."
2133
+  #endif
2134
+#endif

+ 6
- 6
Marlin/src/lcd/extensible_ui/ui_api.cpp View File

@@ -213,26 +213,26 @@ namespace ExtUI {
213 213
       if (soft_endstops_enabled) switch (axis) {
214 214
         case X_AXIS:
215 215
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
216
-            min = soft_endstop_min[X_AXIS];
216
+            min = soft_endstop[X_AXIS].min;
217 217
           #endif
218 218
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
219
-            max = soft_endstop_max[X_AXIS];
219
+            max = soft_endstop[X_AXIS].max;
220 220
           #endif
221 221
           break;
222 222
         case Y_AXIS:
223 223
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
224
-            min = soft_endstop_min[Y_AXIS];
224
+            min = soft_endstop[Y_AXIS].min;
225 225
           #endif
226 226
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
227
-            max = soft_endstop_max[Y_AXIS];
227
+            max = soft_endstop[Y_AXIS].max;
228 228
           #endif
229 229
           break;
230 230
         case Z_AXIS:
231 231
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
232
-            min = soft_endstop_min[Z_AXIS];
232
+            min = soft_endstop[Z_AXIS].min;
233 233
           #endif
234 234
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
235
-            max = soft_endstop_max[Z_AXIS];
235
+            max = soft_endstop[Z_AXIS].max;
236 236
           #endif
237 237
         default: break;
238 238
       }

+ 6
- 6
Marlin/src/lcd/menu/menu_motion.cpp View File

@@ -86,26 +86,26 @@ static void _lcd_move_xyz(PGM_P name, AxisEnum axis) {
86 86
       if (soft_endstops_enabled) switch (axis) {
87 87
         case X_AXIS:
88 88
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
89
-            min = soft_endstop_min[X_AXIS];
89
+            min = soft_endstop[X_AXIS].min;
90 90
           #endif
91 91
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
92
-            max = soft_endstop_max[X_AXIS];
92
+            max = soft_endstop[X_AXIS].max;
93 93
           #endif
94 94
           break;
95 95
         case Y_AXIS:
96 96
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
97
-            min = soft_endstop_min[Y_AXIS];
97
+            min = soft_endstop[Y_AXIS].min;
98 98
           #endif
99 99
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
100
-            max = soft_endstop_max[Y_AXIS];
100
+            max = soft_endstop[Y_AXIS].max;
101 101
           #endif
102 102
           break;
103 103
         case Z_AXIS:
104 104
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
105
-            min = soft_endstop_min[Z_AXIS];
105
+            min = soft_endstop[Z_AXIS].min;
106 106
           #endif
107 107
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
108
-            max = soft_endstop_max[Z_AXIS];
108
+            max = soft_endstop[Z_AXIS].max;
109 109
           #endif
110 110
         default: break;
111 111
       }

+ 72
- 75
Marlin/src/module/motion.cpp View File

@@ -149,13 +149,13 @@ float cartes[XYZ];
149 149
   #endif
150 150
 
151 151
   #if HAS_SOFTWARE_ENDSTOPS
152
-    float soft_endstop_radius, soft_endstop_radius_2;
152
+    float delta_max_radius, delta_max_radius_2;
153 153
   #elif IS_SCARA
154
-    constexpr float soft_endstop_radius = SCARA_PRINTABLE_RADIUS,
155
-                    soft_endstop_radius_2 = sq(SCARA_PRINTABLE_RADIUS);
154
+    constexpr float delta_max_radius = SCARA_PRINTABLE_RADIUS,
155
+                    delta_max_radius_2 = sq(SCARA_PRINTABLE_RADIUS);
156 156
   #else // DELTA
157
-    constexpr float soft_endstop_radius = DELTA_PRINTABLE_RADIUS,
158
-                    soft_endstop_radius_2 = sq(DELTA_PRINTABLE_RADIUS);
157
+    constexpr float delta_max_radius = DELTA_PRINTABLE_RADIUS,
158
+                    delta_max_radius_2 = sq(DELTA_PRINTABLE_RADIUS);
159 159
   #endif
160 160
 
161 161
 #endif
@@ -460,8 +460,7 @@ void clean_up_after_endstop_or_probe_move() {
460 460
   bool soft_endstops_enabled = true;
461 461
 
462 462
   // Software Endstops are based on the configured limits.
463
-  float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
464
-        soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
463
+  axis_limits_t soft_endstop[XYZ] = { { X_MIN_BED, X_MAX_BED }, { Y_MIN_BED, Y_MAX_BED }, { Z_MIN_POS, Z_MAX_POS } };
465 464
 
466 465
   /**
467 466
    * Software endstops can be used to monitor the open end of
@@ -487,26 +486,27 @@ void clean_up_after_endstop_or_probe_move() {
487 486
 
488 487
         if (new_tool_index != 0) {
489 488
           // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
490
-          soft_endstop_min[X_AXIS] = X2_MIN_POS;
491
-          soft_endstop_max[X_AXIS] = dual_max_x;
489
+          soft_endstop[X_AXIS].min = X2_MIN_POS;
490
+          soft_endstop[X_AXIS].max = dual_max_x;
492 491
         }
493 492
         else if (dxc_is_duplicating()) {
494 493
           // In Duplication Mode, T0 can move as far left as X1_MIN_POS
495 494
           // but not so far to the right that T1 would move past the end
496
-          soft_endstop_min[X_AXIS] = X1_MIN_POS;
497
-          soft_endstop_max[X_AXIS] = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
495
+          soft_endstop[X_AXIS].min = X1_MIN_POS;
496
+          soft_endstop[X_AXIS].max = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
498 497
         }
499 498
         else {
500 499
           // In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
501
-          soft_endstop_min[X_AXIS] = X1_MIN_POS;
502
-          soft_endstop_max[X_AXIS] = X1_MAX_POS;
500
+          soft_endstop[X_AXIS].min = X1_MIN_POS;
501
+          soft_endstop[X_AXIS].max = X1_MAX_POS;
503 502
         }
503
+
504 504
       }
505 505
 
506 506
     #elif ENABLED(DELTA)
507 507
 
508
-      soft_endstop_min[axis] = base_min_pos(axis);
509
-      soft_endstop_max[axis] = (axis == Z_AXIS ? delta_height
508
+      soft_endstop[axis].min = base_min_pos(axis);
509
+      soft_endstop[axis].max = (axis == Z_AXIS ? delta_height
510 510
       #if HAS_BED_PROBE
511 511
         - zprobe_zoffset
512 512
       #endif
@@ -516,11 +516,11 @@ void clean_up_after_endstop_or_probe_move() {
516 516
         case X_AXIS:
517 517
         case Y_AXIS:
518 518
           // Get a minimum radius for clamping
519
-          soft_endstop_radius = MIN(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
520
-          soft_endstop_radius_2 = sq(soft_endstop_radius);
519
+          delta_max_radius = MIN(ABS(MAX(soft_endstop[X_AXIS].min, soft_endstop[Y_AXIS].min)), soft_endstop[X_AXIS].max, soft_endstop[Y_AXIS].max);
520
+          delta_max_radius_2 = sq(delta_max_radius);
521 521
           break;
522 522
         case Z_AXIS:
523
-          delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
523
+          delta_clip_start_height = soft_endstop[axis].max - delta_safe_distance_from_top();
524 524
         default: break;
525 525
       }
526 526
 
@@ -531,84 +531,81 @@ void clean_up_after_endstop_or_probe_move() {
531 531
       // retain the same physical limit when other tools are selected.
532 532
       if (old_tool_index != new_tool_index) {
533 533
         const float offs = hotend_offset[axis][new_tool_index] - hotend_offset[axis][old_tool_index];
534
-        soft_endstop_min[axis] += offs;
535
-        soft_endstop_max[axis] += offs;
534
+        soft_endstop[axis].min += offs;
535
+        soft_endstop[axis].max += offs;
536 536
       }
537 537
       else {
538 538
         const float offs = hotend_offset[axis][active_extruder];
539
-        soft_endstop_min[axis] = base_min_pos(axis) + offs;
540
-        soft_endstop_max[axis] = base_max_pos(axis) + offs;
539
+        soft_endstop[axis].min = base_min_pos(axis) + offs;
540
+        soft_endstop[axis].max = base_max_pos(axis) + offs;
541 541
       }
542 542
 
543 543
     #else
544 544
 
545
-      soft_endstop_min[axis] = base_min_pos(axis);
546
-      soft_endstop_max[axis] = base_max_pos(axis);
545
+      soft_endstop[axis].min = base_min_pos(axis);
546
+      soft_endstop[axis].max = base_max_pos(axis);
547 547
 
548 548
     #endif
549 549
 
550
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
551
-      if (DEBUGGING(LEVELING)) {
552
-        SERIAL_ECHOPAIR("For ", axis_codes[axis]);
553
-        SERIAL_ECHOPAIR(" axis:\n soft_endstop_min = ", soft_endstop_min[axis]);
554
-        SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
555
-      }
556
-    #endif
557
-  }
550
+  #if ENABLED(DEBUG_LEVELING_FEATURE)
551
+    if (DEBUGGING(LEVELING))
552
+      SERIAL_ECHOLNPAIR("Axis ", axis_codes[axis], " min:", soft_endstop[axis].min, " max:", soft_endstop[axis].max);
553
+  #endif
554
+}
558 555
 
559
-#endif // HAS_SOFTWARE_ENDSTOPS
556
+  /**
557
+   * Constrain the given coordinates to the software endstops.
558
+   *
559
+   * For DELTA/SCARA the XY constraint is based on the smallest
560
+   * radius within the set software endstops.
561
+   */
562
+  void apply_motion_limits(float target[XYZ]) {
560 563
 
561
-/**
562
- * Constrain the given coordinates to the software endstops.
563
- *
564
- * For DELTA/SCARA the XY constraint is based on the smallest
565
- * radius within the set software endstops.
566
- */
567
-void clamp_to_software_endstops(float target[XYZ]) {
564
+    if (!soft_endstops_enabled) return;
568 565
 
569
-  if (!soft_endstops_enabled) return;
566
+    #if IS_KINEMATIC
567
+
568
+      #if HAS_HOTEND_OFFSET && ENABLED(DELTA)
569
+        // The effector center position will be the target minus the hotend offset.
570
+        const float offx = hotend_offset[X_AXIS][active_extruder], offy = hotend_offset[Y_AXIS][active_extruder];
571
+      #else
572
+        // SCARA needs to consider the angle of the arm through the entire move, so for now use no tool offset.
573
+        constexpr float offx = 0, offy = 0;
574
+      #endif
570 575
 
571
-  #if IS_KINEMATIC
576
+      const float dist_2 = HYPOT2(target[X_AXIS] - offx, target[Y_AXIS] - offy);
577
+      if (dist_2 > delta_max_radius_2) {
578
+        const float ratio = (delta_max_radius) / SQRT(dist_2); // 200 / 300 = 0.66
579
+        target[X_AXIS] *= ratio;
580
+        target[Y_AXIS] *= ratio;
581
+      }
572 582
 
573
-    #if HAS_HOTEND_OFFSET && ENABLED(DELTA)
574
-      // The effector center position will be the target minus the hotend offset.
575
-      const float offx = hotend_offset[X_AXIS][active_extruder], offy = hotend_offset[Y_AXIS][active_extruder];
576 583
     #else
577
-      // SCARA needs to consider the angle of the arm through the entire move, so for now use no tool offset.
578
-      constexpr float offx = 0, offy = 0;
579
-    #endif
580
-
581
-    const float dist_2 = HYPOT2(target[X_AXIS] - offx, target[Y_AXIS] - offy);
582
-    if (dist_2 > soft_endstop_radius_2) {
583
-      const float ratio = (soft_endstop_radius) / SQRT(dist_2); // 200 / 300 = 0.66
584
-      target[X_AXIS] *= ratio;
585
-      target[Y_AXIS] *= ratio;
586
-    }
587 584
 
588
-  #else
585
+      #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_X)
586
+        NOLESS(target[X_AXIS], soft_endstop[X_AXIS].min);
587
+      #endif
588
+      #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_X)
589
+        NOMORE(target[X_AXIS], soft_endstop[X_AXIS].max);
590
+      #endif
591
+      #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
592
+        NOLESS(target[Y_AXIS], soft_endstop[Y_AXIS].min);
593
+      #endif
594
+      #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
595
+        NOMORE(target[Y_AXIS], soft_endstop[Y_AXIS].max);
596
+      #endif
589 597
 
590
-    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_X)
591
-      NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
592 598
     #endif
593
-    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_X)
594
-      NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
595
-    #endif
596
-    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
597
-      NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
599
+
600
+    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
601
+      NOLESS(target[Z_AXIS], soft_endstop[Z_AXIS].min);
598 602
     #endif
599
-    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
600
-      NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
603
+    #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
604
+      NOMORE(target[Z_AXIS], soft_endstop[Z_AXIS].max);
601 605
     #endif
606
+  }
602 607
 
603
-  #endif
604
-
605
-  #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
606
-    NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
607
-  #endif
608
-  #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
609
-    NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
610
-  #endif
611
-}
608
+#endif // HAS_SOFTWARE_ENDSTOPS
612 609
 
613 610
 #if !UBL_SEGMENTED
614 611
 #if IS_KINEMATIC
@@ -995,7 +992,7 @@ void clamp_to_software_endstops(float target[XYZ]) {
995 992
  * before calling or cold/lengthy extrusion may get missed.
996 993
  */
997 994
 void prepare_move_to_destination() {
998
-  clamp_to_software_endstops(destination);
995
+  apply_motion_limits(destination);
999 996
 
1000 997
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
1001 998
 

+ 6
- 6
Marlin/src/module/motion.h View File

@@ -118,23 +118,23 @@ XYZ_DEFS(signed char, home_dir, HOME_DIR);
118 118
   constexpr float hotend_offset[XYZ][HOTENDS] = { { 0 }, { 0 }, { 0 } };
119 119
 #endif
120 120
 
121
+typedef struct { float min, max; } axis_limits_t;
121 122
 #if HAS_SOFTWARE_ENDSTOPS
122 123
   extern bool soft_endstops_enabled;
123
-  extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
124
+  extern axis_limits_t soft_endstop[XYZ];
125
+  void apply_motion_limits(float target[XYZ]);
124 126
   void update_software_endstops(const AxisEnum axis
125 127
     #if HAS_HOTEND_OFFSET
126 128
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
127 129
     #endif
128 130
   );
129 131
 #else
130
-  constexpr bool soft_endstops_enabled = true;
131
-  constexpr float soft_endstop_min[XYZ] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
132
-                  soft_endstop_max[XYZ] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
132
+  constexpr bool soft_endstops_enabled = false;
133
+  //constexpr axis_limits_t soft_endstop[XYZ] = { { X_MIN_POS, X_MAX_POS }, { Y_MIN_POS, Y_MAX_POS }, { Z_MIN_POS, Z_MAX_POS } };
134
+  #define apply_motion_limits(V)    NOOP
133 135
   #define update_software_endstops(...) NOOP
134 136
 #endif
135 137
 
136
-void clamp_to_software_endstops(float target[XYZ]);
137
-
138 138
 void report_current_position();
139 139
 
140 140
 inline void set_current_from_destination() { COPY(current_position, destination); }

+ 1
- 1
Marlin/src/module/planner_bezier.cpp View File

@@ -188,7 +188,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
188 188
     // not linear in the distance.
189 189
     bez_target[Z_AXIS] = interp(position[Z_AXIS], target[Z_AXIS], t);
190 190
     bez_target[E_AXIS] = interp(position[E_AXIS], target[E_AXIS], t);
191
-    clamp_to_software_endstops(bez_target);
191
+    apply_motion_limits(bez_target);
192 192
 
193 193
     #if HAS_LEVELING && !PLANNER_LEVELING
194 194
       float pos[XYZE] = { bez_target[X_AXIS], bez_target[Y_AXIS], bez_target[Z_AXIS], bez_target[E_AXIS] };

+ 3
- 3
Marlin/src/module/tool_change.cpp View File

@@ -739,7 +739,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
739 739
           #endif
740 740
           current_position[Z_AXIS] += toolchange_settings.z_raise;
741 741
           #if HAS_SOFTWARE_ENDSTOPS
742
-            NOMORE(current_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
742
+            NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
743 743
           #endif
744 744
           planner.buffer_line(current_position, feedrate_mm_s, active_extruder);
745 745
         #endif
@@ -771,7 +771,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
771 771
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
772 772
         current_position[Z_AXIS] += MAX(-zdiff, 0.0) + toolchange_settings.z_raise;
773 773
         #if HAS_SOFTWARE_ENDSTOPS
774
-          NOMORE(current_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
774
+          NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
775 775
         #endif
776 776
         if (!no_move) fast_line_to_current(Z_AXIS);
777 777
         move_nozzle_servo(tmp_extruder);
@@ -840,7 +840,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
840 840
         #endif
841 841
 
842 842
         // Prevent a move outside physical bounds
843
-        clamp_to_software_endstops(destination);
843
+        apply_motion_limits(destination);
844 844
 
845 845
         // Move back to the original (or tweaked) position
846 846
         do_blocking_move_to(destination);

Loading…
Cancel
Save