Browse Source

Add loose soft endstop state, apply to UBL fine-tune (#19681)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Earle F. Philhower, III 3 years ago
parent
commit
dffe7b9072

+ 4
- 0
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

@@ -1009,6 +1009,8 @@
1009 1009
 
1010 1010
         lcd_mesh_edit_setup(new_z);
1011 1011
 
1012
+        SET_SOFT_ENDSTOP_LOOSE(true);
1013
+
1012 1014
         do {
1013 1015
           idle();
1014 1016
           new_z = lcd_mesh_edit();
@@ -1016,6 +1018,8 @@
1016 1018
           SERIAL_FLUSH();                                   // Prevent host M105 buffer overrun.
1017 1019
         } while (!ui.button_pressed());
1018 1020
 
1021
+        SET_SOFT_ENDSTOP_LOOSE(false);
1022
+
1019 1023
         if (!lcd_map_control) ui.return_to_status();        // Just editing a single point? Return to status
1020 1024
 
1021 1025
         if (click_and_hold(abort_fine_tune)) break;         // Button held down? Abort editing

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

@@ -201,10 +201,6 @@ G29_TYPE GcodeSuite::G29() {
201 201
     ABL_VAR int abl_probe_index;
202 202
   #endif
203 203
 
204
-  #if BOTH(HAS_SOFTWARE_ENDSTOPS, PROBE_MANUALLY)
205
-    ABL_VAR bool saved_soft_endstops_state = true;
206
-  #endif
207
-
208 204
   #if ABL_GRID
209 205
 
210 206
     #if ENABLED(PROBE_MANUALLY)
@@ -461,7 +457,7 @@ G29_TYPE GcodeSuite::G29() {
461 457
     // Abort current G29 procedure, go back to idle state
462 458
     if (seenA && g29_in_progress) {
463 459
       SERIAL_ECHOLNPGM("Manual G29 aborted");
464
-      TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
460
+      SET_SOFT_ENDSTOP_LOOSE(false);
465 461
       set_bed_leveling_enabled(abl_should_enable);
466 462
       g29_in_progress = false;
467 463
       TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
@@ -482,7 +478,7 @@ G29_TYPE GcodeSuite::G29() {
482 478
 
483 479
     if (abl_probe_index == 0) {
484 480
       // For the initial G29 S2 save software endstop state
485
-      TERN_(HAS_SOFTWARE_ENDSTOPS, saved_soft_endstops_state = soft_endstops_enabled);
481
+      SET_SOFT_ENDSTOP_LOOSE(true);
486 482
       // Move close to the bed before the first point
487 483
       do_blocking_move_to_z(0);
488 484
     }
@@ -552,14 +548,14 @@ G29_TYPE GcodeSuite::G29() {
552 548
         _manual_goto_xy(probePos); // Can be used here too!
553 549
         // Disable software endstops to allow manual adjustment
554 550
         // If G29 is not completed, they will not be re-enabled
555
-        TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false);
551
+        SET_SOFT_ENDSTOP_LOOSE(true);
556 552
         G29_RETURN(false);
557 553
       }
558 554
       else {
559 555
         // Leveling done! Fall through to G29 finishing code below
560 556
         SERIAL_ECHOLNPGM("Grid probing done.");
561 557
         // Re-enable software endstops, if needed
562
-        TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
558
+        SET_SOFT_ENDSTOP_LOOSE(false);
563 559
       }
564 560
 
565 561
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
@@ -570,7 +566,7 @@ G29_TYPE GcodeSuite::G29() {
570 566
         _manual_goto_xy(probePos);
571 567
         // Disable software endstops to allow manual adjustment
572 568
         // If G29 is not completed, they will not be re-enabled
573
-        TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false);
569
+        SET_SOFT_ENDSTOP_LOOSE(true);
574 570
         G29_RETURN(false);
575 571
       }
576 572
       else {
@@ -578,7 +574,7 @@ G29_TYPE GcodeSuite::G29() {
578 574
         SERIAL_ECHOLNPGM("3-point probing done.");
579 575
 
580 576
         // Re-enable software endstops, if needed
581
-        TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
577
+        SET_SOFT_ENDSTOP_LOOSE(false);
582 578
 
583 579
         if (!dryrun) {
584 580
           vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();

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

@@ -61,7 +61,6 @@ inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM("
61 61
 void GcodeSuite::G29() {
62 62
 
63 63
   static int mbl_probe_index = -1;
64
-  TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state);
65 64
 
66 65
   MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
67 66
   if (!WITHIN(state, 0, 5)) {
@@ -98,26 +97,19 @@ void GcodeSuite::G29() {
98 97
       }
99 98
       // For each G29 S2...
100 99
       if (mbl_probe_index == 0) {
101
-        #if HAS_SOFTWARE_ENDSTOPS
102
-          // For the initial G29 S2 save software endstop state
103
-          saved_soft_endstops_state = soft_endstops_enabled;
104
-        #endif
105 100
         // Move close to the bed before the first point
106 101
         do_blocking_move_to_z(0);
107 102
       }
108 103
       else {
109 104
         // Save Z for the previous mesh position
110 105
         mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
111
-        TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state);
106
+        SET_SOFT_ENDSTOP_LOOSE(false);
112 107
       }
113 108
       // If there's another point to sample, move there with optional lift.
114 109
       if (mbl_probe_index < GRID_MAX_POINTS) {
115
-        #if HAS_SOFTWARE_ENDSTOPS
116
-          // Disable software endstops to allow manual adjustment
117
-          // If G29 is not completed, they will not be re-enabled
118
-          soft_endstops_enabled = false;
119
-        #endif
120
-
110
+        // Disable software endstops to allow manual adjustment
111
+        // If G29 is left hanging without completion they won't be re-enabled!
112
+        SET_SOFT_ENDSTOP_LOOSE(true);
121 113
         mbl.zigzag(mbl_probe_index++, ix, iy);
122 114
         _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
123 115
       }

+ 3
- 2
Marlin/src/gcode/calibrate/G28.cpp View File

@@ -222,8 +222,9 @@ void GcodeSuite::G28() {
222 222
     return;
223 223
   }
224 224
 
225
-  // Wait for planner moves to finish!
226
-  planner.synchronize();
225
+  planner.synchronize();          // Wait for planner moves to finish!
226
+
227
+  SET_SOFT_ENDSTOP_LOOSE(false);  // Reset a leftover 'loose' motion state
227 228
 
228 229
   // Disable the leveling matrix before homing
229 230
   #if HAS_LEVELING

+ 3
- 1
Marlin/src/gcode/calibrate/G34.cpp View File

@@ -40,7 +40,7 @@ void GcodeSuite::G34() {
40 40
 
41 41
   if (homing_needed()) return;
42 42
 
43
-  TEMPORARY_SOFT_ENDSTOP_STATE(false);
43
+  SET_SOFT_ENDSTOP_LOOSE(true);
44 44
   TEMPORARY_BED_LEVELING_STATE(false);
45 45
   TemporaryGlobalEndstopsState unlock_z(false);
46 46
 
@@ -148,6 +148,8 @@ void GcodeSuite::G34() {
148 148
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands");
149 149
     gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST));
150 150
   #endif
151
+
152
+  SET_SOFT_ENDSTOP_LOOSE(false);
151 153
 }
152 154
 
153 155
 #endif // MECHANICAL_GANTRY_CALIBRATION

+ 5
- 4
Marlin/src/gcode/calibrate/G425.cpp View File

@@ -581,13 +581,12 @@ void GcodeSuite::G425() {
581 581
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE));
582 582
   #endif
583 583
 
584
-  TEMPORARY_SOFT_ENDSTOP_STATE(false);
585
-  TEMPORARY_BED_LEVELING_STATE(false);
586
-
587 584
   if (homing_needed_error()) return;
588 585
 
589
-  measurements_t m;
586
+  TEMPORARY_BED_LEVELING_STATE(false);
587
+  SET_SOFT_ENDSTOP_LOOSE(true);
590 588
 
589
+  measurements_t m;
591 590
   float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN;
592 591
 
593 592
   if (parser.seen('B'))
@@ -612,6 +611,8 @@ void GcodeSuite::G425() {
612 611
   else
613 612
     calibrate_all();
614 613
 
614
+  SET_SOFT_ENDSTOP_LOOSE(false);
615
+
615 616
   #ifdef CALIBRATION_SCRIPT_POST
616 617
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST));
617 618
   #endif

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

@@ -37,8 +37,8 @@ void GcodeSuite::M211() {
37 37
                   l_soft_max = soft_endstop.max.asLogical();
38 38
   SERIAL_ECHO_START();
39 39
   SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS);
40
-  if (parser.seen('S')) soft_endstops_enabled = parser.value_bool();
41
-  serialprint_onoff(soft_endstops_enabled);
40
+  if (parser.seen('S')) soft_endstop._enabled = parser.value_bool();
41
+  serialprint_onoff(soft_endstop._enabled);
42 42
   print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" "));
43 43
   print_xyz(l_soft_max, PSTR(STR_SOFT_MAX));
44 44
 }

+ 3
- 1
Marlin/src/gcode/feature/clean/G12.cpp View File

@@ -70,9 +70,11 @@ void GcodeSuite::G12() {
70 70
     TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active);
71 71
   #endif
72 72
 
73
-  TEMPORARY_SOFT_ENDSTOP_STATE(parser.boolval('E'));
73
+  SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E'));
74 74
 
75 75
   nozzle.clean(pattern, strokes, radius, objects, cleans);
76
+
77
+  SET_SOFT_ENDSTOP_LOOSE(false);
76 78
 }
77 79
 
78 80
 #endif // NOZZLE_CLEAN_FEATURE

+ 5
- 23
Marlin/src/lcd/extui/ui_api.cpp View File

@@ -305,27 +305,9 @@ namespace ExtUI {
305 305
   }
306 306
 
307 307
   void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) {
308
-    // Start with no limits to movement
309
-    float min = current_position[axis] - 1000,
310
-          max = current_position[axis] + 1000;
311
-
312
-    // Limit to software endstops, if enabled
313
-    #if HAS_SOFTWARE_ENDSTOPS
314
-      if (soft_endstops_enabled) switch (axis) {
315
-        case X_AXIS:
316
-          TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
317
-          TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
318
-          break;
319
-        case Y_AXIS:
320
-          TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
321
-          TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
322
-          break;
323
-        case Z_AXIS:
324
-          TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
325
-          TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
326
-        default: break;
327
-      }
328
-    #endif // HAS_SOFTWARE_ENDSTOPS
308
+    // Get motion limit from software endstops, if any
309
+    float min, max;
310
+    soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max);
329 311
 
330 312
     // Delta limits XY based on the current offset from center
331 313
     // This assumes the center is 0,0
@@ -389,8 +371,8 @@ namespace ExtUI {
389 371
   }
390 372
 
391 373
   #if HAS_SOFTWARE_ENDSTOPS
392
-    bool getSoftEndstopState() { return soft_endstops_enabled; }
393
-    void setSoftEndstopState(const bool value) { soft_endstops_enabled = value; }
374
+    bool getSoftEndstopState() { return soft_endstop._enabled; }
375
+    void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; }
394 376
   #endif
395 377
 
396 378
   #if HAS_TRINAMIC_CONFIG

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

@@ -57,28 +57,9 @@
57 57
 static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
58 58
   if (ui.use_click()) return ui.goto_previous_screen_no_defer();
59 59
   if (ui.encoderPosition && !ui.manual_move.processing) {
60
-
61
-    // Start with no limits to movement
62
-    float min = current_position[axis] - 1000,
63
-          max = current_position[axis] + 1000;
64
-
65
-    // Limit to software endstops, if enabled
66
-    #if HAS_SOFTWARE_ENDSTOPS
67
-      if (soft_endstops_enabled) switch (axis) {
68
-        case X_AXIS:
69
-          TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
70
-          TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
71
-          break;
72
-        case Y_AXIS:
73
-          TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
74
-          TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
75
-          break;
76
-        case Z_AXIS:
77
-          TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
78
-          TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
79
-        default: break;
80
-      }
81
-    #endif // HAS_SOFTWARE_ENDSTOPS
60
+    // Get motion limit from software endstops, if any
61
+    float min, max;
62
+    soft_endstop.get_manual_axis_limits(axis, min, max);
82 63
 
83 64
     // Delta limits XY based on the current offset from center
84 65
     // This assumes the center is 0,0
@@ -238,7 +219,7 @@ void menu_move() {
238 219
   BACK_ITEM(MSG_MOTION);
239 220
 
240 221
   #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
241
-    EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
222
+    EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
242 223
   #endif
243 224
 
244 225
   if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {

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

@@ -48,16 +48,12 @@
48 48
 float z_offset_backup, calculated_z_offset;
49 49
 
50 50
 TERN_(HAS_LEVELING, bool leveling_was_active);
51
-TERN_(HAS_SOFTWARE_ENDSTOPS, bool store_soft_endstops_enabled);
52 51
 
53 52
 void prepare_for_calibration() {
54 53
   z_offset_backup = probe.offset.z;
55 54
 
56 55
   // Disable soft endstops for free Z movement
57
-  #if HAS_SOFTWARE_ENDSTOPS
58
-    store_soft_endstops_enabled = soft_endstops_enabled;
59
-    soft_endstops_enabled = false;
60
-  #endif
56
+  SET_SOFT_ENDSTOP_LOOSE(true);
61 57
 
62 58
   // Disable leveling for raw planner motion
63 59
   #if HAS_LEVELING
@@ -68,7 +64,7 @@ void prepare_for_calibration() {
68 64
 
69 65
 void set_offset_and_go_back(const float &z) {
70 66
   probe.offset.z = z;
71
-  TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = store_soft_endstops_enabled);
67
+  SET_SOFT_ENDSTOP_LOOSE(false);
72 68
   TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
73 69
   ui.goto_previous_screen_no_defer();
74 70
 }

+ 3
- 21
Marlin/src/lcd/tft/ui_480x320.cpp View File

@@ -813,27 +813,9 @@ static void moveAxis(AxisEnum axis, const int8_t direction) {
813 813
   }
814 814
 
815 815
   if (!ui.manual_move.processing) {
816
-    // Start with no limits to movement
817
-    float min = current_position[axis] - 1000,
818
-          max = current_position[axis] + 1000;
819
-
820
-    // Limit to software endstops, if enabled
821
-    #if HAS_SOFTWARE_ENDSTOPS
822
-      if (soft_endstops_enabled) switch (axis) {
823
-        case X_AXIS:
824
-          TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x);
825
-          TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x);
826
-          break;
827
-        case Y_AXIS:
828
-          TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y);
829
-          TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y);
830
-          break;
831
-        case Z_AXIS:
832
-          TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z);
833
-          TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z);
834
-        default: break;
835
-      }
836
-    #endif // HAS_SOFTWARE_ENDSTOPS
816
+    // Get motion limit from software endstops, if any
817
+    float min, max;
818
+    soft_endstop.get_manual_axis_limits(axis, min, max);
837 819
 
838 820
     // Delta limits XY based on the current offset from center
839 821
     // This assumes the center is 0,0

+ 1
- 1
Marlin/src/libs/nozzle.cpp View File

@@ -161,7 +161,7 @@ Nozzle nozzle;
161 161
         LIMIT(   end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \
162 162
       }while(0)
163 163
 
164
-      if (soft_endstops_enabled) {
164
+      if (soft_endstop.enabled()) {
165 165
 
166 166
         LIMIT_AXIS(x);
167 167
         LIMIT_AXIS(y);

+ 12
- 9
Marlin/src/module/motion.cpp View File

@@ -534,12 +534,11 @@ void restore_feedrate_and_scaling() {
534 534
 
535 535
 #if HAS_SOFTWARE_ENDSTOPS
536 536
 
537
-  bool soft_endstops_enabled = true;
538
-
539 537
   // Software Endstops are based on the configured limits.
540
-  axis_limits_t soft_endstop = {
538
+  soft_endstops_t soft_endstop = {
541 539
     { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
542
-    { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }
540
+    { X_MAX_POS, Y_MAX_POS, Z_MAX_POS },
541
+    { true, false }
543 542
   };
544 543
 
545 544
   /**
@@ -624,9 +623,9 @@ void restore_feedrate_and_scaling() {
624 623
 
625 624
     #endif
626 625
 
627
-  if (DEBUGGING(LEVELING))
628
-    SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]);
629
-}
626
+    if (DEBUGGING(LEVELING))
627
+      SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]);
628
+  }
630 629
 
631 630
   /**
632 631
    * Constrain the given coordinates to the software endstops.
@@ -636,7 +635,7 @@ void restore_feedrate_and_scaling() {
636 635
    */
637 636
   void apply_motion_limits(xyz_pos_t &target) {
638 637
 
639
-    if (!soft_endstops_enabled) return;
638
+    if (!soft_endstop._enabled) return;
640 639
 
641 640
     #if IS_KINEMATIC
642 641
 
@@ -688,7 +687,11 @@ void restore_feedrate_and_scaling() {
688 687
     }
689 688
   }
690 689
 
691
-#endif // HAS_SOFTWARE_ENDSTOPS
690
+#else // !HAS_SOFTWARE_ENDSTOPS
691
+
692
+  soft_endstops_t soft_endstop;
693
+
694
+#endif // !HAS_SOFTWARE_ENDSTOPS
692 695
 
693 696
 #if !UBL_SEGMENTED
694 697
 

+ 47
- 12
Marlin/src/module/motion.h View File

@@ -148,26 +148,61 @@ inline float home_bump_mm(const AxisEnum axis) {
148 148
   constexpr xyz_pos_t hotend_offset[1] = { { 0 } };
149 149
 #endif
150 150
 
151
-typedef struct { xyz_pos_t min, max; } axis_limits_t;
152 151
 #if HAS_SOFTWARE_ENDSTOPS
153
-  extern bool soft_endstops_enabled;
154
-  extern axis_limits_t soft_endstop;
152
+
153
+  typedef struct {
154
+    xyz_pos_t min, max;
155
+    struct {
156
+      bool _enabled:1;
157
+      bool _loose:1;
158
+    };
159
+    bool enabled() { return _enabled && !_loose; }
160
+    void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) {
161
+      amin = -100000; amax = 100000; // "No limits"
162
+      #if HAS_SOFTWARE_ENDSTOPS
163
+        if (enabled()) switch (axis) {
164
+          case X_AXIS:
165
+            TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x);
166
+            TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x);
167
+            break;
168
+          case Y_AXIS:
169
+            TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y);
170
+            TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y);
171
+            break;
172
+          case Z_AXIS:
173
+            TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z);
174
+            TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z);
175
+          default: break;
176
+        }
177
+      #endif
178
+    }
179
+  } soft_endstops_t;
180
+
181
+  extern soft_endstops_t soft_endstop;
155 182
   void apply_motion_limits(xyz_pos_t &target);
156 183
   void update_software_endstops(const AxisEnum axis
157 184
     #if HAS_HOTEND_OFFSET
158 185
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
159 186
     #endif
160 187
   );
161
-  #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
162
-#else
163
-  constexpr bool soft_endstops_enabled = false;
164
-  //constexpr axis_limits_t soft_endstop = {
165
-  //  { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
166
-  //  { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } };
167
-  #define apply_motion_limits(V)    NOOP
188
+  #define SET_SOFT_ENDSTOP_LOOSE(loose) (soft_endstop._loose = loose)
189
+
190
+#else // !HAS_SOFTWARE_ENDSTOPS
191
+
192
+  typedef struct {
193
+    bool enabled() { return false; }
194
+    void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) {
195
+      // No limits
196
+      amin = current_position[axis] - 1000;
197
+      amax = current_position[axis] + 1000;
198
+    }
199
+  } soft_endstops_t;
200
+  extern soft_endstops_t soft_endstop;
201
+  #define apply_motion_limits(V)        NOOP
168 202
   #define update_software_endstops(...) NOOP
169
-  #define TEMPORARY_SOFT_ENDSTOP_STATE(...) NOOP
170
-#endif
203
+  #define SET_SOFT_ENDSTOP_LOOSE()      NOOP
204
+
205
+#endif // !HAS_SOFTWARE_ENDSTOPS
171 206
 
172 207
 void report_real_position();
173 208
 void report_current_position();

+ 2
- 6
Marlin/src/module/tool_change.cpp View File

@@ -1017,14 +1017,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
1017 1017
         // Raise by a configured distance to avoid workpiece, except with
1018 1018
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
1019 1019
         if (!no_move) {
1020
-          #if HAS_SOFTWARE_ENDSTOPS
1021
-            const float maxz = _MIN(soft_endstop.max.z, Z_MAX_POS);
1022
-          #else
1023
-            constexpr float maxz = Z_MAX_POS;
1024
-          #endif
1020
+          const float newz = current_position.z + _MAX(-diff.z, 0.0);
1025 1021
 
1026 1022
           // Check if Z has space to compensate at least z_offset, and if not, just abort now
1027
-          const float newz = current_position.z + _MAX(-diff.z, 0.0);
1023
+          const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS);
1028 1024
           if (newz > maxz) return;
1029 1025
 
1030 1026
           current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz);

Loading…
Cancel
Save