瀏覽代碼

Add M211: Enable/Disable Software Endstops

Scott Lahteine 8 年之前
父節點
當前提交
280534c06f
共有 4 個檔案被更改,包括 84 行新增33 行删除
  1. 12
    5
      Marlin/Marlin.h
  2. 66
    28
      Marlin/Marlin_main.cpp
  3. 3
    0
      Marlin/language.h
  4. 3
    0
      Marlin/macros.h

+ 12
- 5
Marlin/Marlin.h 查看文件

@@ -245,8 +245,6 @@ void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return
245 245
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
246 246
 void clear_command_queue();
247 247
 
248
-void clamp_to_software_endstops(float target[3]);
249
-
250 248
 extern millis_t previous_cmd_ms;
251 249
 inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
252 250
 
@@ -275,8 +273,18 @@ extern volatile bool wait_for_heatup;
275 273
 extern float current_position[NUM_AXIS];
276 274
 extern float position_shift[3];
277 275
 extern float home_offset[3];
278
-extern float sw_endstop_min[3];
279
-extern float sw_endstop_max[3];
276
+
277
+// Software Endstops
278
+void update_software_endstops(AxisEnum axis);
279
+#if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
280
+  extern bool soft_endstops_enabled;
281
+  void clamp_to_software_endstops(float target[XYZ]);
282
+#else
283
+  #define soft_endstops_enabled false
284
+  #define clamp_to_software_endstops(x) NOOP
285
+#endif
286
+extern float soft_endstop_min[XYZ];
287
+extern float soft_endstop_max[XYZ];
280 288
 
281 289
 #define LOGICAL_POSITION(POS, AXIS) (POS + home_offset[AXIS] + position_shift[AXIS])
282 290
 #define RAW_POSITION(POS, AXIS)     (POS - home_offset[AXIS] - position_shift[AXIS])
@@ -379,7 +387,6 @@ extern uint8_t active_extruder;
379 387
   extern float mixing_factor[MIXING_STEPPERS];
380 388
 #endif
381 389
 
382
-void update_software_endstops(AxisEnum axis);
383 390
 void calculate_volumetric_multipliers();
384 391
 
385 392
 // Buzzer

+ 66
- 28
Marlin/Marlin_main.cpp 查看文件

@@ -205,6 +205,7 @@
205 205
  * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>
206 206
  * M209 - Turn Automatic Retract Detection on/off: S<bool> (For slicers that don't support G10/11).
207 207
           Every normal extrude-only move will be classified as retract depending on the direction.
208
+ * M211 - Enable, Disable, and/or Report software endstops: [S<bool>]
208 209
  * M218 - Set a tool offset: T<index> X<offset> Y<offset>
209 210
  * M220 - Set Feedrate Percentage: S<percent> ("FR" on your LCD)
210 211
  * M221 - Set Flow Percentage: S<percent>
@@ -332,9 +333,12 @@ float position_shift[3] = { 0 };
332 333
 // Set by M206, M428, or menu item. Saved to EEPROM.
333 334
 float home_offset[3] = { 0 };
334 335
 
335
-// Software Endstops. Default to configured limits.
336
-float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
337
-float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
336
+// Software Endstops are based on the configured limits.
337
+#if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
338
+  bool soft_endstops_enabled = true;
339
+#endif
340
+float soft_endstop_min[XYZ] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
341
+      soft_endstop_max[XYZ] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
338 342
 
339 343
 #if FAN_COUNT > 0
340 344
   int fanSpeeds[FAN_COUNT] = { 0 };
@@ -1477,21 +1481,21 @@ void update_software_endstops(AxisEnum axis) {
1477 1481
     if (axis == X_AXIS) {
1478 1482
       float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
1479 1483
       if (active_extruder != 0) {
1480
-        sw_endstop_min[X_AXIS] = X2_MIN_POS + offs;
1481
-        sw_endstop_max[X_AXIS] = dual_max_x + offs;
1484
+        soft_endstop_min[X_AXIS] = X2_MIN_POS + offs;
1485
+        soft_endstop_max[X_AXIS] = dual_max_x + offs;
1482 1486
         return;
1483 1487
       }
1484 1488
       else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
1485
-        sw_endstop_min[X_AXIS] = base_min_pos(X_AXIS) + offs;
1486
-        sw_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset) + offs;
1489
+        soft_endstop_min[X_AXIS] = base_min_pos(X_AXIS) + offs;
1490
+        soft_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset) + offs;
1487 1491
         return;
1488 1492
       }
1489 1493
     }
1490 1494
     else
1491 1495
   #endif
1492 1496
   {
1493
-    sw_endstop_min[axis] = base_min_pos(axis) + offs;
1494
-    sw_endstop_max[axis] = base_max_pos(axis) + offs;
1497
+    soft_endstop_min[axis] = base_min_pos(axis) + offs;
1498
+    soft_endstop_max[axis] = base_max_pos(axis) + offs;
1495 1499
   }
1496 1500
 
1497 1501
   #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -1499,16 +1503,15 @@ void update_software_endstops(AxisEnum axis) {
1499 1503
       SERIAL_ECHOPAIR("For ", axis_codes[axis]);
1500 1504
       SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
1501 1505
       SERIAL_ECHOPAIR("\n position_shift = ", position_shift[axis]);
1502
-      SERIAL_ECHOPAIR("\n sw_endstop_min = ", sw_endstop_min[axis]);
1503
-      SERIAL_ECHOPAIR("\n sw_endstop_max = ", sw_endstop_max[axis]);
1506
+      SERIAL_ECHOPAIR("\n soft_endstop_min = ", soft_endstop_min[axis]);
1507
+      SERIAL_ECHOPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
1504 1508
       SERIAL_EOL;
1505 1509
     }
1506 1510
   #endif
1507 1511
 
1508 1512
   #if ENABLED(DELTA)
1509
-    if (axis == Z_AXIS) {
1510
-      delta_clip_start_height = sw_endstop_max[axis] - delta_safe_distance_from_top();
1511
-    }
1513
+    if (axis == Z_AXIS)
1514
+      delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1512 1515
   #endif
1513 1516
 
1514 1517
 }
@@ -1574,8 +1577,8 @@ static void set_axis_is_at_home(AxisEnum axis) {
1574 1577
        * SCARA home positions are based on configuration since the actual
1575 1578
        * limits are determined by the inverse kinematic transform.
1576 1579
        */
1577
-      sw_endstop_min[axis] = base_min_pos(axis); // + (delta[axis] - base_home_pos(axis));
1578
-      sw_endstop_max[axis] = base_max_pos(axis); // + (delta[axis] - base_home_pos(axis));
1580
+      soft_endstop_min[axis] = base_min_pos(axis); // + (delta[axis] - base_home_pos(axis));
1581
+      soft_endstop_max[axis] = base_max_pos(axis); // + (delta[axis] - base_home_pos(axis));
1579 1582
     }
1580 1583
     else
1581 1584
   #endif
@@ -5572,6 +5575,33 @@ inline void gcode_M206() {
5572 5575
 
5573 5576
 #endif // FWRETRACT
5574 5577
 
5578
+/**
5579
+ * M211: Enable, Disable, and/or Report software endstops
5580
+ *
5581
+ * Usage: M211 S1 to enable, M211 S0 to disable, M211 alone for report
5582
+ */
5583
+inline void gcode_M211() {
5584
+  SERIAL_ECHO_START;
5585
+  #if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
5586
+    if (code_seen('S')) soft_endstops_enabled = code_value_bool();
5587
+  #endif
5588
+  #if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
5589
+    SERIAL_ECHOPGM(MSG_SOFT_ENDSTOPS ": ");
5590
+    serialprintPGM(soft_endstops_enabled ? PSTR(MSG_ON) : PSTR(MSG_OFF));
5591
+  #else
5592
+    SERIAL_ECHOPGM(MSG_SOFT_ENDSTOPS ": " MSG_OFF);
5593
+  #endif
5594
+  SERIAL_ECHOPGM("  " MSG_SOFT_MIN ": ");
5595
+  SERIAL_ECHOPAIR(    MSG_X, soft_endstop_min[X_AXIS]);
5596
+  SERIAL_ECHOPAIR(" " MSG_Y, soft_endstop_min[Y_AXIS]);
5597
+  SERIAL_ECHOPAIR(" " MSG_Z, soft_endstop_min[Z_AXIS]);
5598
+  SERIAL_ECHOPGM("  " MSG_SOFT_MAX ": ");
5599
+  SERIAL_ECHOPAIR(    MSG_X, soft_endstop_max[X_AXIS]);
5600
+  SERIAL_ECHOPAIR(" " MSG_Y, soft_endstop_max[Y_AXIS]);
5601
+  SERIAL_ECHOPAIR(" " MSG_Z, soft_endstop_max[Z_AXIS]);
5602
+  SERIAL_EOL;
5603
+}
5604
+
5575 5605
 #if HOTENDS > 1
5576 5606
 
5577 5607
   /**
@@ -6175,7 +6205,7 @@ inline void gcode_M428() {
6175 6205
   bool err = false;
6176 6206
   LOOP_XYZ(i) {
6177 6207
     if (axis_homed[i]) {
6178
-      float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) * 0.5) ? base_home_pos(i) : 0,
6208
+      float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos(i) : 0,
6179 6209
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6180 6210
       if (diff > -20 && diff < 20) {
6181 6211
         set_home_offset((AxisEnum)i, home_offset[i] - diff);
@@ -7495,6 +7525,10 @@ void process_next_command() {
7495 7525
           break;
7496 7526
       #endif // FWRETRACT
7497 7527
 
7528
+      case 211: // M211 - Enable, Disable, and/or Report software endstops
7529
+        gcode_M211();
7530
+        break;
7531
+
7498 7532
       #if HOTENDS > 1
7499 7533
         case 218: // M218 - Set a tool offset: T<index> X<offset> Y<offset>
7500 7534
           gcode_M218();
@@ -7749,18 +7783,22 @@ void ok_to_send() {
7749 7783
   SERIAL_EOL;
7750 7784
 }
7751 7785
 
7752
-void clamp_to_software_endstops(float target[3]) {
7753
-  if (min_software_endstops) {
7754
-    NOLESS(target[X_AXIS], sw_endstop_min[X_AXIS]);
7755
-    NOLESS(target[Y_AXIS], sw_endstop_min[Y_AXIS]);
7756
-    NOLESS(target[Z_AXIS], sw_endstop_min[Z_AXIS]);
7757
-  }
7758
-  if (max_software_endstops) {
7759
-    NOMORE(target[X_AXIS], sw_endstop_max[X_AXIS]);
7760
-    NOMORE(target[Y_AXIS], sw_endstop_max[Y_AXIS]);
7761
-    NOMORE(target[Z_AXIS], sw_endstop_max[Z_AXIS]);
7786
+#if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
7787
+
7788
+  void clamp_to_software_endstops(float target[XYZ]) {
7789
+    #if ENABLED(min_software_endstops)
7790
+      NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
7791
+      NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
7792
+      NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
7793
+    #endif
7794
+    #if ENABLED(max_software_endstops)
7795
+      NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
7796
+      NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
7797
+      NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
7798
+    #endif
7762 7799
   }
7763
-}
7800
+
7801
+#endif
7764 7802
 
7765 7803
 #if ENABLED(DELTA)
7766 7804
 

+ 3
- 0
Marlin/language.h 查看文件

@@ -157,6 +157,9 @@
157 157
 #define MSG_ENDSTOP_OPEN                    "open"
158 158
 #define MSG_HOTEND_OFFSET                   "Hotend offsets:"
159 159
 #define MSG_DUPLICATION_MODE                "Duplication mode: "
160
+#define MSG_SOFT_ENDSTOPS                   "Soft endstops"
161
+#define MSG_SOFT_MIN                        "Min"
162
+#define MSG_SOFT_MAX                        "Max"
160 163
 
161 164
 #define MSG_SD_CANT_OPEN_SUBDIR             "Cannot open subdir "
162 165
 #define MSG_SD_INIT_FAIL                    "SD init fail"

+ 3
- 0
Marlin/macros.h 查看文件

@@ -24,6 +24,9 @@
24 24
 #define MACROS_H
25 25
 
26 26
 #define NUM_AXIS 4
27
+#define XYZE 4
28
+#define ABC  3
29
+#define XYZ  3
27 30
 
28 31
 #define FORCE_INLINE __attribute__((always_inline)) inline
29 32
 

Loading…
取消
儲存