Browse Source

Add M211: Enable/Disable Software Endstops

Scott Lahteine 8 years ago
parent
commit
280534c06f
4 changed files with 84 additions and 33 deletions
  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 View File

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
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
 void clear_command_queue();
246
 void clear_command_queue();
247
 
247
 
248
-void clamp_to_software_endstops(float target[3]);
249
-
250
 extern millis_t previous_cmd_ms;
248
 extern millis_t previous_cmd_ms;
251
 inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
249
 inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
252
 
250
 
275
 extern float current_position[NUM_AXIS];
273
 extern float current_position[NUM_AXIS];
276
 extern float position_shift[3];
274
 extern float position_shift[3];
277
 extern float home_offset[3];
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
 #define LOGICAL_POSITION(POS, AXIS) (POS + home_offset[AXIS] + position_shift[AXIS])
289
 #define LOGICAL_POSITION(POS, AXIS) (POS + home_offset[AXIS] + position_shift[AXIS])
282
 #define RAW_POSITION(POS, AXIS)     (POS - home_offset[AXIS] - position_shift[AXIS])
290
 #define RAW_POSITION(POS, AXIS)     (POS - home_offset[AXIS] - position_shift[AXIS])
379
   extern float mixing_factor[MIXING_STEPPERS];
387
   extern float mixing_factor[MIXING_STEPPERS];
380
 #endif
388
 #endif
381
 
389
 
382
-void update_software_endstops(AxisEnum axis);
383
 void calculate_volumetric_multipliers();
390
 void calculate_volumetric_multipliers();
384
 
391
 
385
 // Buzzer
392
 // Buzzer

+ 66
- 28
Marlin/Marlin_main.cpp View File

205
  * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>
205
  * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>
206
  * M209 - Turn Automatic Retract Detection on/off: S<bool> (For slicers that don't support G10/11).
206
  * M209 - Turn Automatic Retract Detection on/off: S<bool> (For slicers that don't support G10/11).
207
           Every normal extrude-only move will be classified as retract depending on the direction.
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
  * M218 - Set a tool offset: T<index> X<offset> Y<offset>
209
  * M218 - Set a tool offset: T<index> X<offset> Y<offset>
209
  * M220 - Set Feedrate Percentage: S<percent> ("FR" on your LCD)
210
  * M220 - Set Feedrate Percentage: S<percent> ("FR" on your LCD)
210
  * M221 - Set Flow Percentage: S<percent>
211
  * M221 - Set Flow Percentage: S<percent>
332
 // Set by M206, M428, or menu item. Saved to EEPROM.
333
 // Set by M206, M428, or menu item. Saved to EEPROM.
333
 float home_offset[3] = { 0 };
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
 #if FAN_COUNT > 0
343
 #if FAN_COUNT > 0
340
   int fanSpeeds[FAN_COUNT] = { 0 };
344
   int fanSpeeds[FAN_COUNT] = { 0 };
1477
     if (axis == X_AXIS) {
1481
     if (axis == X_AXIS) {
1478
       float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
1482
       float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
1479
       if (active_extruder != 0) {
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
         return;
1486
         return;
1483
       }
1487
       }
1484
       else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
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
         return;
1491
         return;
1488
       }
1492
       }
1489
     }
1493
     }
1490
     else
1494
     else
1491
   #endif
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
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1501
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1499
       SERIAL_ECHOPAIR("For ", axis_codes[axis]);
1503
       SERIAL_ECHOPAIR("For ", axis_codes[axis]);
1500
       SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
1504
       SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
1501
       SERIAL_ECHOPAIR("\n position_shift = ", position_shift[axis]);
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
       SERIAL_EOL;
1508
       SERIAL_EOL;
1505
     }
1509
     }
1506
   #endif
1510
   #endif
1507
 
1511
 
1508
   #if ENABLED(DELTA)
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
   #endif
1515
   #endif
1513
 
1516
 
1514
 }
1517
 }
1574
        * SCARA home positions are based on configuration since the actual
1577
        * SCARA home positions are based on configuration since the actual
1575
        * limits are determined by the inverse kinematic transform.
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
     else
1583
     else
1581
   #endif
1584
   #endif
5572
 
5575
 
5573
 #endif // FWRETRACT
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
 #if HOTENDS > 1
5605
 #if HOTENDS > 1
5576
 
5606
 
5577
   /**
5607
   /**
6175
   bool err = false;
6205
   bool err = false;
6176
   LOOP_XYZ(i) {
6206
   LOOP_XYZ(i) {
6177
     if (axis_homed[i]) {
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
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6209
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6180
       if (diff > -20 && diff < 20) {
6210
       if (diff > -20 && diff < 20) {
6181
         set_home_offset((AxisEnum)i, home_offset[i] - diff);
6211
         set_home_offset((AxisEnum)i, home_offset[i] - diff);
7495
           break;
7525
           break;
7496
       #endif // FWRETRACT
7526
       #endif // FWRETRACT
7497
 
7527
 
7528
+      case 211: // M211 - Enable, Disable, and/or Report software endstops
7529
+        gcode_M211();
7530
+        break;
7531
+
7498
       #if HOTENDS > 1
7532
       #if HOTENDS > 1
7499
         case 218: // M218 - Set a tool offset: T<index> X<offset> Y<offset>
7533
         case 218: // M218 - Set a tool offset: T<index> X<offset> Y<offset>
7500
           gcode_M218();
7534
           gcode_M218();
7749
   SERIAL_EOL;
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
 #if ENABLED(DELTA)
7803
 #if ENABLED(DELTA)
7766
 
7804
 

+ 3
- 0
Marlin/language.h View File

157
 #define MSG_ENDSTOP_OPEN                    "open"
157
 #define MSG_ENDSTOP_OPEN                    "open"
158
 #define MSG_HOTEND_OFFSET                   "Hotend offsets:"
158
 #define MSG_HOTEND_OFFSET                   "Hotend offsets:"
159
 #define MSG_DUPLICATION_MODE                "Duplication mode: "
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
 #define MSG_SD_CANT_OPEN_SUBDIR             "Cannot open subdir "
164
 #define MSG_SD_CANT_OPEN_SUBDIR             "Cannot open subdir "
162
 #define MSG_SD_INIT_FAIL                    "SD init fail"
165
 #define MSG_SD_INIT_FAIL                    "SD init fail"

+ 3
- 0
Marlin/macros.h View File

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

Loading…
Cancel
Save