瀏覽代碼

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 年之前
父節點
當前提交
dffe7b9072

+ 4
- 0
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp 查看文件

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

+ 6
- 10
Marlin/src/gcode/bedlevel/abl/G29.cpp 查看文件

201
     ABL_VAR int abl_probe_index;
201
     ABL_VAR int abl_probe_index;
202
   #endif
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
   #if ABL_GRID
204
   #if ABL_GRID
209
 
205
 
210
     #if ENABLED(PROBE_MANUALLY)
206
     #if ENABLED(PROBE_MANUALLY)
461
     // Abort current G29 procedure, go back to idle state
457
     // Abort current G29 procedure, go back to idle state
462
     if (seenA && g29_in_progress) {
458
     if (seenA && g29_in_progress) {
463
       SERIAL_ECHOLNPGM("Manual G29 aborted");
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
       set_bed_leveling_enabled(abl_should_enable);
461
       set_bed_leveling_enabled(abl_should_enable);
466
       g29_in_progress = false;
462
       g29_in_progress = false;
467
       TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
463
       TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
482
 
478
 
483
     if (abl_probe_index == 0) {
479
     if (abl_probe_index == 0) {
484
       // For the initial G29 S2 save software endstop state
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
       // Move close to the bed before the first point
482
       // Move close to the bed before the first point
487
       do_blocking_move_to_z(0);
483
       do_blocking_move_to_z(0);
488
     }
484
     }
552
         _manual_goto_xy(probePos); // Can be used here too!
548
         _manual_goto_xy(probePos); // Can be used here too!
553
         // Disable software endstops to allow manual adjustment
549
         // Disable software endstops to allow manual adjustment
554
         // If G29 is not completed, they will not be re-enabled
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
         G29_RETURN(false);
552
         G29_RETURN(false);
557
       }
553
       }
558
       else {
554
       else {
559
         // Leveling done! Fall through to G29 finishing code below
555
         // Leveling done! Fall through to G29 finishing code below
560
         SERIAL_ECHOLNPGM("Grid probing done.");
556
         SERIAL_ECHOLNPGM("Grid probing done.");
561
         // Re-enable software endstops, if needed
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
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
561
     #elif ENABLED(AUTO_BED_LEVELING_3POINT)
570
         _manual_goto_xy(probePos);
566
         _manual_goto_xy(probePos);
571
         // Disable software endstops to allow manual adjustment
567
         // Disable software endstops to allow manual adjustment
572
         // If G29 is not completed, they will not be re-enabled
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
         G29_RETURN(false);
570
         G29_RETURN(false);
575
       }
571
       }
576
       else {
572
       else {
578
         SERIAL_ECHOLNPGM("3-point probing done.");
574
         SERIAL_ECHOLNPGM("3-point probing done.");
579
 
575
 
580
         // Re-enable software endstops, if needed
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
         if (!dryrun) {
579
         if (!dryrun) {
584
           vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
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 查看文件

61
 void GcodeSuite::G29() {
61
 void GcodeSuite::G29() {
62
 
62
 
63
   static int mbl_probe_index = -1;
63
   static int mbl_probe_index = -1;
64
-  TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state);
65
 
64
 
66
   MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
65
   MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
67
   if (!WITHIN(state, 0, 5)) {
66
   if (!WITHIN(state, 0, 5)) {
98
       }
97
       }
99
       // For each G29 S2...
98
       // For each G29 S2...
100
       if (mbl_probe_index == 0) {
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
         // Move close to the bed before the first point
100
         // Move close to the bed before the first point
106
         do_blocking_move_to_z(0);
101
         do_blocking_move_to_z(0);
107
       }
102
       }
108
       else {
103
       else {
109
         // Save Z for the previous mesh position
104
         // Save Z for the previous mesh position
110
         mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
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
       // If there's another point to sample, move there with optional lift.
108
       // If there's another point to sample, move there with optional lift.
114
       if (mbl_probe_index < GRID_MAX_POINTS) {
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
         mbl.zigzag(mbl_probe_index++, ix, iy);
113
         mbl.zigzag(mbl_probe_index++, ix, iy);
122
         _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
114
         _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
123
       }
115
       }

+ 3
- 2
Marlin/src/gcode/calibrate/G28.cpp 查看文件

222
     return;
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
   // Disable the leveling matrix before homing
229
   // Disable the leveling matrix before homing
229
   #if HAS_LEVELING
230
   #if HAS_LEVELING

+ 3
- 1
Marlin/src/gcode/calibrate/G34.cpp 查看文件

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

+ 5
- 4
Marlin/src/gcode/calibrate/G425.cpp 查看文件

581
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE));
581
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE));
582
   #endif
582
   #endif
583
 
583
 
584
-  TEMPORARY_SOFT_ENDSTOP_STATE(false);
585
-  TEMPORARY_BED_LEVELING_STATE(false);
586
-
587
   if (homing_needed_error()) return;
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
   float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN;
590
   float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN;
592
 
591
 
593
   if (parser.seen('B'))
592
   if (parser.seen('B'))
612
   else
611
   else
613
     calibrate_all();
612
     calibrate_all();
614
 
613
 
614
+  SET_SOFT_ENDSTOP_LOOSE(false);
615
+
615
   #ifdef CALIBRATION_SCRIPT_POST
616
   #ifdef CALIBRATION_SCRIPT_POST
616
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST));
617
     GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST));
617
   #endif
618
   #endif

+ 2
- 2
Marlin/src/gcode/control/M211.cpp 查看文件

37
                   l_soft_max = soft_endstop.max.asLogical();
37
                   l_soft_max = soft_endstop.max.asLogical();
38
   SERIAL_ECHO_START();
38
   SERIAL_ECHO_START();
39
   SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS);
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
   print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" "));
42
   print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" "));
43
   print_xyz(l_soft_max, PSTR(STR_SOFT_MAX));
43
   print_xyz(l_soft_max, PSTR(STR_SOFT_MAX));
44
 }
44
 }

+ 3
- 1
Marlin/src/gcode/feature/clean/G12.cpp 查看文件

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

+ 5
- 23
Marlin/src/lcd/extui/ui_api.cpp 查看文件

305
   }
305
   }
306
 
306
 
307
   void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) {
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
     // Delta limits XY based on the current offset from center
312
     // Delta limits XY based on the current offset from center
331
     // This assumes the center is 0,0
313
     // This assumes the center is 0,0
389
   }
371
   }
390
 
372
 
391
   #if HAS_SOFTWARE_ENDSTOPS
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
   #endif
376
   #endif
395
 
377
 
396
   #if HAS_TRINAMIC_CONFIG
378
   #if HAS_TRINAMIC_CONFIG

+ 4
- 23
Marlin/src/lcd/menu/menu_motion.cpp 查看文件

57
 static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
57
 static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
58
   if (ui.use_click()) return ui.goto_previous_screen_no_defer();
58
   if (ui.use_click()) return ui.goto_previous_screen_no_defer();
59
   if (ui.encoderPosition && !ui.manual_move.processing) {
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
     // Delta limits XY based on the current offset from center
64
     // Delta limits XY based on the current offset from center
84
     // This assumes the center is 0,0
65
     // This assumes the center is 0,0
238
   BACK_ITEM(MSG_MOTION);
219
   BACK_ITEM(MSG_MOTION);
239
 
220
 
240
   #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
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
   #endif
223
   #endif
243
 
224
 
244
   if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
225
   if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {

+ 2
- 6
Marlin/src/lcd/menu/menu_probe_offset.cpp 查看文件

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

+ 3
- 21
Marlin/src/lcd/tft/ui_480x320.cpp 查看文件

813
   }
813
   }
814
 
814
 
815
   if (!ui.manual_move.processing) {
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
     // Delta limits XY based on the current offset from center
820
     // Delta limits XY based on the current offset from center
839
     // This assumes the center is 0,0
821
     // This assumes the center is 0,0

+ 1
- 1
Marlin/src/libs/nozzle.cpp 查看文件

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

+ 12
- 9
Marlin/src/module/motion.cpp 查看文件

534
 
534
 
535
 #if HAS_SOFTWARE_ENDSTOPS
535
 #if HAS_SOFTWARE_ENDSTOPS
536
 
536
 
537
-  bool soft_endstops_enabled = true;
538
-
539
   // Software Endstops are based on the configured limits.
537
   // Software Endstops are based on the configured limits.
540
-  axis_limits_t soft_endstop = {
538
+  soft_endstops_t soft_endstop = {
541
     { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
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
 
623
 
625
     #endif
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
    * Constrain the given coordinates to the software endstops.
631
    * Constrain the given coordinates to the software endstops.
636
    */
635
    */
637
   void apply_motion_limits(xyz_pos_t &target) {
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
     #if IS_KINEMATIC
640
     #if IS_KINEMATIC
642
 
641
 
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
 #if !UBL_SEGMENTED
696
 #if !UBL_SEGMENTED
694
 
697
 

+ 47
- 12
Marlin/src/module/motion.h 查看文件

148
   constexpr xyz_pos_t hotend_offset[1] = { { 0 } };
148
   constexpr xyz_pos_t hotend_offset[1] = { { 0 } };
149
 #endif
149
 #endif
150
 
150
 
151
-typedef struct { xyz_pos_t min, max; } axis_limits_t;
152
 #if HAS_SOFTWARE_ENDSTOPS
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
   void apply_motion_limits(xyz_pos_t &target);
182
   void apply_motion_limits(xyz_pos_t &target);
156
   void update_software_endstops(const AxisEnum axis
183
   void update_software_endstops(const AxisEnum axis
157
     #if HAS_HOTEND_OFFSET
184
     #if HAS_HOTEND_OFFSET
158
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
185
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
159
     #endif
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
   #define update_software_endstops(...) NOOP
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
 void report_real_position();
207
 void report_real_position();
173
 void report_current_position();
208
 void report_current_position();

+ 2
- 6
Marlin/src/module/tool_change.cpp 查看文件

1017
         // Raise by a configured distance to avoid workpiece, except with
1017
         // Raise by a configured distance to avoid workpiece, except with
1018
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
1018
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
1019
         if (!no_move) {
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
           // Check if Z has space to compensate at least z_offset, and if not, just abort now
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
           if (newz > maxz) return;
1024
           if (newz > maxz) return;
1029
 
1025
 
1030
           current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz);
1026
           current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz);

Loading…
取消
儲存