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
 
328
 
329
   float startCoord[NUM_AXIS] = { 0 }, endCoord[NUM_AXIS] = { 0 };
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
               feedrate = FLOOR(MMM_TO_MMS((encoderAxis == Z_AXIS) ? HOMING_FEEDRATE_Z : HOMING_FEEDRATE_XY));
333
               feedrate = FLOOR(MMM_TO_MMS((encoderAxis == Z_AXIS) ? HOMING_FEEDRATE_Z : HOMING_FEEDRATE_XY));
334
 
334
 
335
   ec = false;
335
   ec = false;
390
   ec = false;
390
   ec = false;
391
 
391
 
392
   startDistance = 20;
392
   startDistance = 20;
393
-  endDistance = soft_endstop_max[encoderAxis] - 20;
393
+  endDistance = soft_endstop[encoderAxis].max - 20;
394
   travelDistance = endDistance - startDistance;
394
   travelDistance = endDistance - startDistance;
395
 
395
 
396
   LOOP_NA(i) {
396
   LOOP_NA(i) {

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

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

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

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

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

38
   if (parser.seen('S')) soft_endstops_enabled = parser.value_bool();
38
   if (parser.seen('S')) soft_endstops_enabled = parser.value_bool();
39
   serialprint_onoff(soft_endstops_enabled);
39
   serialprint_onoff(soft_endstops_enabled);
40
   SERIAL_ECHOPGM(MSG_SOFT_MIN);
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
   SERIAL_ECHOPGM(MSG_SOFT_MAX);
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
 #endif
50
 #endif

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

127
        parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position[Y_AXIS],
127
        parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : photo_position[Y_AXIS],
128
       (parser.seenval('Z') ? parser.value_linear_units() : photo_position[Z_AXIS]) + current_position[Z_AXIS]
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
     do_blocking_move_to(raw, fr_mm_s);
131
     do_blocking_move_to(raw, fr_mm_s);
132
 
132
 
133
     #ifdef PHOTO_SWITCH_POSITION
133
     #ifdef PHOTO_SWITCH_POSITION

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

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

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

2121
     #error "Both SERVICE_NAME_3 and SERVICE_INTERVAL_3 are required."
2121
     #error "Both SERVICE_NAME_3 and SERVICE_INTERVAL_3 are required."
2122
   #endif
2122
   #endif
2123
 #endif
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
       if (soft_endstops_enabled) switch (axis) {
213
       if (soft_endstops_enabled) switch (axis) {
214
         case X_AXIS:
214
         case X_AXIS:
215
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
215
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
216
-            min = soft_endstop_min[X_AXIS];
216
+            min = soft_endstop[X_AXIS].min;
217
           #endif
217
           #endif
218
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
218
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
219
-            max = soft_endstop_max[X_AXIS];
219
+            max = soft_endstop[X_AXIS].max;
220
           #endif
220
           #endif
221
           break;
221
           break;
222
         case Y_AXIS:
222
         case Y_AXIS:
223
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
223
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
224
-            min = soft_endstop_min[Y_AXIS];
224
+            min = soft_endstop[Y_AXIS].min;
225
           #endif
225
           #endif
226
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
226
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
227
-            max = soft_endstop_max[Y_AXIS];
227
+            max = soft_endstop[Y_AXIS].max;
228
           #endif
228
           #endif
229
           break;
229
           break;
230
         case Z_AXIS:
230
         case Z_AXIS:
231
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
231
           #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
232
-            min = soft_endstop_min[Z_AXIS];
232
+            min = soft_endstop[Z_AXIS].min;
233
           #endif
233
           #endif
234
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
234
           #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
235
-            max = soft_endstop_max[Z_AXIS];
235
+            max = soft_endstop[Z_AXIS].max;
236
           #endif
236
           #endif
237
         default: break;
237
         default: break;
238
       }
238
       }

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

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

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

149
   #endif
149
   #endif
150
 
150
 
151
   #if HAS_SOFTWARE_ENDSTOPS
151
   #if HAS_SOFTWARE_ENDSTOPS
152
-    float soft_endstop_radius, soft_endstop_radius_2;
152
+    float delta_max_radius, delta_max_radius_2;
153
   #elif IS_SCARA
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
   #else // DELTA
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
   #endif
159
   #endif
160
 
160
 
161
 #endif
161
 #endif
460
   bool soft_endstops_enabled = true;
460
   bool soft_endstops_enabled = true;
461
 
461
 
462
   // Software Endstops are based on the configured limits.
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
    * Software endstops can be used to monitor the open end of
466
    * Software endstops can be used to monitor the open end of
487
 
486
 
488
         if (new_tool_index != 0) {
487
         if (new_tool_index != 0) {
489
           // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
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
         else if (dxc_is_duplicating()) {
492
         else if (dxc_is_duplicating()) {
494
           // In Duplication Mode, T0 can move as far left as X1_MIN_POS
493
           // In Duplication Mode, T0 can move as far left as X1_MIN_POS
495
           // but not so far to the right that T1 would move past the end
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
         else {
498
         else {
500
           // In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
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
     #elif ENABLED(DELTA)
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
       #if HAS_BED_PROBE
510
       #if HAS_BED_PROBE
511
         - zprobe_zoffset
511
         - zprobe_zoffset
512
       #endif
512
       #endif
516
         case X_AXIS:
516
         case X_AXIS:
517
         case Y_AXIS:
517
         case Y_AXIS:
518
           // Get a minimum radius for clamping
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
           break;
521
           break;
522
         case Z_AXIS:
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
         default: break;
524
         default: break;
525
       }
525
       }
526
 
526
 
531
       // retain the same physical limit when other tools are selected.
531
       // retain the same physical limit when other tools are selected.
532
       if (old_tool_index != new_tool_index) {
532
       if (old_tool_index != new_tool_index) {
533
         const float offs = hotend_offset[axis][new_tool_index] - hotend_offset[axis][old_tool_index];
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
       else {
537
       else {
538
         const float offs = hotend_offset[axis][active_extruder];
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
     #else
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
     #endif
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
     #else
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
     #endif
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
     #endif
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
     #endif
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
 #if !UBL_SEGMENTED
610
 #if !UBL_SEGMENTED
614
 #if IS_KINEMATIC
611
 #if IS_KINEMATIC
995
  * before calling or cold/lengthy extrusion may get missed.
992
  * before calling or cold/lengthy extrusion may get missed.
996
  */
993
  */
997
 void prepare_move_to_destination() {
994
 void prepare_move_to_destination() {
998
-  clamp_to_software_endstops(destination);
995
+  apply_motion_limits(destination);
999
 
996
 
1000
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
997
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
1001
 
998
 

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

118
   constexpr float hotend_offset[XYZ][HOTENDS] = { { 0 }, { 0 }, { 0 } };
118
   constexpr float hotend_offset[XYZ][HOTENDS] = { { 0 }, { 0 }, { 0 } };
119
 #endif
119
 #endif
120
 
120
 
121
+typedef struct { float min, max; } axis_limits_t;
121
 #if HAS_SOFTWARE_ENDSTOPS
122
 #if HAS_SOFTWARE_ENDSTOPS
122
   extern bool soft_endstops_enabled;
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
   void update_software_endstops(const AxisEnum axis
126
   void update_software_endstops(const AxisEnum axis
125
     #if HAS_HOTEND_OFFSET
127
     #if HAS_HOTEND_OFFSET
126
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
128
       , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0
127
     #endif
129
     #endif
128
   );
130
   );
129
 #else
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
   #define update_software_endstops(...) NOOP
135
   #define update_software_endstops(...) NOOP
134
 #endif
136
 #endif
135
 
137
 
136
-void clamp_to_software_endstops(float target[XYZ]);
137
-
138
 void report_current_position();
138
 void report_current_position();
139
 
139
 
140
 inline void set_current_from_destination() { COPY(current_position, destination); }
140
 inline void set_current_from_destination() { COPY(current_position, destination); }

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

188
     // not linear in the distance.
188
     // not linear in the distance.
189
     bez_target[Z_AXIS] = interp(position[Z_AXIS], target[Z_AXIS], t);
189
     bez_target[Z_AXIS] = interp(position[Z_AXIS], target[Z_AXIS], t);
190
     bez_target[E_AXIS] = interp(position[E_AXIS], target[E_AXIS], t);
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
     #if HAS_LEVELING && !PLANNER_LEVELING
193
     #if HAS_LEVELING && !PLANNER_LEVELING
194
       float pos[XYZE] = { bez_target[X_AXIS], bez_target[Y_AXIS], bez_target[Z_AXIS], bez_target[E_AXIS] };
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
           #endif
739
           #endif
740
           current_position[Z_AXIS] += toolchange_settings.z_raise;
740
           current_position[Z_AXIS] += toolchange_settings.z_raise;
741
           #if HAS_SOFTWARE_ENDSTOPS
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
           #endif
743
           #endif
744
           planner.buffer_line(current_position, feedrate_mm_s, active_extruder);
744
           planner.buffer_line(current_position, feedrate_mm_s, active_extruder);
745
         #endif
745
         #endif
771
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
771
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
772
         current_position[Z_AXIS] += MAX(-zdiff, 0.0) + toolchange_settings.z_raise;
772
         current_position[Z_AXIS] += MAX(-zdiff, 0.0) + toolchange_settings.z_raise;
773
         #if HAS_SOFTWARE_ENDSTOPS
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
         #endif
775
         #endif
776
         if (!no_move) fast_line_to_current(Z_AXIS);
776
         if (!no_move) fast_line_to_current(Z_AXIS);
777
         move_nozzle_servo(tmp_extruder);
777
         move_nozzle_servo(tmp_extruder);
840
         #endif
840
         #endif
841
 
841
 
842
         // Prevent a move outside physical bounds
842
         // Prevent a move outside physical bounds
843
-        clamp_to_software_endstops(destination);
843
+        apply_motion_limits(destination);
844
 
844
 
845
         // Move back to the original (or tweaked) position
845
         // Move back to the original (or tweaked) position
846
         do_blocking_move_to(destination);
846
         do_blocking_move_to(destination);

Loading…
Cancel
Save