Browse Source

Merge pull request #4096 from thinkyhead/rc_always_raise_servo

Always raise Z (if needed) for servo deploy/stow
Scott Lahteine 8 years ago
parent
commit
524f6d9bd6
2 changed files with 44 additions and 64 deletions
  1. 0
    1
      Marlin/Conditionals.h
  2. 44
    63
      Marlin/Marlin_main.cpp

+ 0
- 1
Marlin/Conditionals.h View File

@@ -383,7 +383,6 @@
383 383
   #endif
384 384
 
385 385
   #define HAS_Z_SERVO_ENDSTOP (defined(Z_ENDSTOP_SERVO_NR) && Z_ENDSTOP_SERVO_NR >= 0)
386
-  #define SERVO_LEVELING (ENABLED(AUTO_BED_LEVELING_FEATURE) && HAS_Z_SERVO_ENDSTOP)
387 386
 
388 387
   /**
389 388
    * Sled Options

+ 44
- 63
Marlin/Marlin_main.cpp View File

@@ -750,9 +750,6 @@ void servo_init() {
750 750
   #endif
751 751
 
752 752
   #if HAS_Z_SERVO_ENDSTOP
753
-
754
-    endstops.enable_z_probe(false);
755
-
756 753
     /**
757 754
      * Set position of Z Servo Endstop
758 755
      *
@@ -763,8 +760,11 @@ void servo_init() {
763 760
      *
764 761
      */
765 762
     STOW_Z_SERVO();
766
-  #endif // HAS_Z_SERVO_ENDSTOP
763
+  #endif
767 764
 
765
+  #if HAS_BED_PROBE
766
+    endstops.enable_z_probe(false);
767
+  #endif
768 768
 }
769 769
 
770 770
 /**
@@ -1661,6 +1661,29 @@ static void setup_for_endstop_move() {
1661 1661
 
1662 1662
 #endif //HAS_BED_PROBE
1663 1663
 
1664
+#if HAS_Z_SERVO_ENDSTOP
1665
+
1666
+  /**
1667
+   * Raise Z to a minimum height to make room for a servo to move
1668
+   *
1669
+   * zprobe_zoffset: Negative of the Z height where the probe engages
1670
+   *         z_dest: The before / after probing raise distance
1671
+   *
1672
+   * The zprobe_zoffset is negative for a switch below the nozzle, so
1673
+   * multiply by Z_HOME_DIR (-1) to move enough away from the bed.
1674
+   */
1675
+  void raise_z_for_servo(float z_dest) {
1676
+    z_dest += home_offset[Z_AXIS];
1677
+
1678
+    if ((Z_HOME_DIR) < 0 && zprobe_zoffset < 0)
1679
+      z_dest -= zprobe_zoffset;
1680
+
1681
+    if (z_dest > current_position[Z_AXIS])
1682
+      do_blocking_move_to_z(z_dest); // also updates current_position
1683
+  }
1684
+
1685
+#endif
1686
+
1664 1687
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
1665 1688
 
1666 1689
   #if ENABLED(AUTO_BED_LEVELING_GRID)
@@ -1861,6 +1884,9 @@ static void setup_for_endstop_move() {
1861 1884
 
1862 1885
     #if HAS_Z_SERVO_ENDSTOP
1863 1886
 
1887
+      // Make room for Z Servo
1888
+      raise_z_for_servo(Z_RAISE_BEFORE_PROBING);
1889
+
1864 1890
       // Engage Z Servo endstop if enabled
1865 1891
       DEPLOY_Z_SERVO();
1866 1892
 
@@ -1941,17 +1967,14 @@ static void setup_for_endstop_move() {
1941 1967
     #endif // Z_PROBE_ALLEN_KEY
1942 1968
 
1943 1969
     #if ENABLED(FIX_MOUNTED_PROBE)
1944
-      // Noting to be done. Just set endstops.z_probe_enabled
1970
+      // Nothing to be done. Just enable_z_probe below...
1945 1971
     #endif
1946 1972
 
1947 1973
     endstops.enable_z_probe();
1948 1974
 
1949 1975
   }
1950 1976
 
1951
-  static void stow_z_probe(bool doRaise = true) {
1952
-    #if !(HAS_Z_SERVO_ENDSTOP && (Z_RAISE_AFTER_PROBING > 0))
1953
-      UNUSED(doRaise);
1954
-    #endif
1977
+  static void stow_z_probe() {
1955 1978
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1956 1979
       if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position);
1957 1980
     #endif
@@ -1960,13 +1983,8 @@ static void setup_for_endstop_move() {
1960 1983
 
1961 1984
     #if HAS_Z_SERVO_ENDSTOP
1962 1985
 
1963
-      // Retract Z Servo endstop if enabled
1964
-      #if Z_RAISE_AFTER_PROBING > 0
1965
-        if (doRaise) {
1966
-          raise_z_after_probing(); // this also updates current_position
1967
-          stepper.synchronize();
1968
-        }
1969
-      #endif
1986
+      // Make room for the servo
1987
+      raise_z_for_servo(Z_RAISE_AFTER_PROBING);
1970 1988
 
1971 1989
       // Change the Z servo angle
1972 1990
       STOW_Z_SERVO();
@@ -2034,9 +2052,7 @@ static void setup_for_endstop_move() {
2034 2052
           }
2035 2053
           stop();
2036 2054
         }
2037
-    #endif // Z_PROBE_ALLEN_KEY
2038
-
2039
-    #if ENABLED(FIX_MOUNTED_PROBE)
2055
+    #elif ENABLED(FIX_MOUNTED_PROBE)
2040 2056
       // Nothing to do here. Just clear endstops.z_probe_enabled
2041 2057
     #endif
2042 2058
 
@@ -2195,29 +2211,6 @@ static void setup_for_endstop_move() {
2195 2211
 
2196 2212
 #endif // AUTO_BED_LEVELING_FEATURE
2197 2213
 
2198
-#if HAS_Z_SERVO_ENDSTOP
2199
-
2200
-  /**
2201
-   * Raise Z to a minimum height to make room for a servo to move
2202
-   *
2203
-   * zprobe_zoffset: Negative of the Z height where the probe engages
2204
-   *         z_dest: The before / after probing raise distance
2205
-   *
2206
-   * The zprobe_zoffset is negative for a switch below the nozzle, so
2207
-   * multiply by Z_HOME_DIR (-1) to move enough away from the bed.
2208
-   */
2209
-  void raise_z_for_servo(float z_dest) {
2210
-    z_dest += home_offset[Z_AXIS];
2211
-
2212
-    if ((Z_HOME_DIR) < 0 && zprobe_zoffset < 0)
2213
-      z_dest -= zprobe_zoffset;
2214
-
2215
-    if (z_dest > current_position[Z_AXIS])
2216
-      do_blocking_move_to_z(z_dest); // also updates current_position
2217
-  }
2218
-
2219
-#endif
2220
-
2221 2214
 #if ENABLED(Z_PROBE_SLED) || ENABLED(Z_SAFE_HOMING) || ENABLED(AUTO_BED_LEVELING_FEATURE)
2222 2215
   static void axis_unhomed_error(bool xyz=false) {
2223 2216
     if (xyz) {
@@ -2313,7 +2306,7 @@ static void homeaxis(AxisEnum axis) {
2313 2306
     #if ENABLED(Z_PROBE_SLED)
2314 2307
       #define _Z_DEPLOY           (dock_sled(false))
2315 2308
       #define _Z_STOW             (dock_sled(true))
2316
-    #elif SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE)
2309
+    #elif ENABLED(AUTO_BED_LEVELING_FEATURE) && (HAS_Z_SERVO_ENDSTOP || ENABLED(FIX_MOUNTED_PROBE))
2317 2310
       #define _Z_DEPLOY           (deploy_z_probe())
2318 2311
       #define _Z_STOW             (stow_z_probe())
2319 2312
     #elif HAS_Z_SERVO_ENDSTOP
@@ -2322,10 +2315,10 @@ static void homeaxis(AxisEnum axis) {
2322 2315
     #endif
2323 2316
 
2324 2317
     // Homing Z towards the bed? Deploy the Z probe or endstop.
2325
-    #if ENABLED(Z_PROBE_SLED) || SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE) || HAS_Z_SERVO_ENDSTOP
2318
+    #if HAS_Z_SERVO_ENDSTOP || ENABLED(Z_PROBE_SLED) || ENABLED(FIX_MOUNTED_PROBE)
2326 2319
       if (axis == Z_AXIS && axis_home_dir < 0) {
2327 2320
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2328
-          if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> SERVO_LEVELING > " STRINGIFY(_Z_DEPLOY));
2321
+          if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > " STRINGIFY(_Z_DEPLOY));
2329 2322
         #endif
2330 2323
         _Z_DEPLOY;
2331 2324
       }
@@ -2445,10 +2438,10 @@ static void homeaxis(AxisEnum axis) {
2445 2438
     axis_homed[axis] = true;
2446 2439
 
2447 2440
     // Put away the Z probe
2448
-    #if ENABLED(Z_PROBE_SLED) || SERVO_LEVELING || ENABLED(FIX_MOUNTED_PROBE) || HAS_Z_SERVO_ENDSTOP
2441
+    #if HAS_Z_SERVO_ENDSTOP || ENABLED(Z_PROBE_SLED) || ENABLED(FIX_MOUNTED_PROBE)
2449 2442
       if (axis == Z_AXIS && axis_home_dir < 0) {
2450 2443
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2451
-          if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> SERVO_LEVELING > " STRINGIFY(_Z_STOW));
2444
+          if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > " STRINGIFY(_Z_STOW));
2452 2445
         #endif
2453 2446
         _Z_STOW;
2454 2447
       }
@@ -3474,7 +3467,7 @@ inline void gcode_G28() {
3474 3467
 
3475 3468
     #if ENABLED(Z_PROBE_SLED)
3476 3469
       dock_sled(false); // engage (un-dock) the Z probe
3477
-    #elif ENABLED(FIX_MOUNTED_PROBE) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_ALLEN_KEY) || (ENABLED(DELTA) && SERVO_LEVELING)
3470
+    #elif ENABLED(FIX_MOUNTED_PROBE) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_ALLEN_KEY) || (ENABLED(DELTA) && HAS_Z_SERVO_ENDSTOP)
3478 3471
       deploy_z_probe();
3479 3472
     #endif
3480 3473
 
@@ -3727,7 +3720,7 @@ inline void gcode_G28() {
3727 3720
 
3728 3721
     #if ENABLED(DELTA)
3729 3722
       // Allen Key Probe for Delta
3730
-      #if ENABLED(Z_PROBE_ALLEN_KEY) || SERVO_LEVELING
3723
+      #if ENABLED(Z_PROBE_ALLEN_KEY) || HAS_Z_SERVO_ENDSTOP
3731 3724
         stow_z_probe();
3732 3725
       #else
3733 3726
         raise_z_after_probing(); // for non Allen Key probes, such as simple mechanical probe
@@ -3848,9 +3841,6 @@ inline void gcode_G28() {
3848 3841
      * G30: Do a single Z probe at the current XY
3849 3842
      */
3850 3843
     inline void gcode_G30() {
3851
-      #if HAS_Z_SERVO_ENDSTOP
3852
-        raise_z_for_servo(Z_RAISE_BEFORE_PROBING);
3853
-      #endif
3854 3844
       deploy_z_probe(); // Engage Z Servo endstop if available. Z_PROBE_SLED is missed here.
3855 3845
 
3856 3846
       stepper.synchronize();
@@ -3869,10 +3859,7 @@ inline void gcode_G28() {
3869 3859
 
3870 3860
       clean_up_after_endstop_move(); // Too early. must be done after the stowing.
3871 3861
 
3872
-      #if HAS_Z_SERVO_ENDSTOP
3873
-        raise_z_for_servo(Z_RAISE_AFTER_PROBING);
3874
-      #endif
3875
-      stow_z_probe(false); // Retract Z Servo endstop if available. Z_PROBE_SLED is missed here.
3862
+      stow_z_probe(); // Retract Z Servo endstop if available. Z_PROBE_SLED is missed here.
3876 3863
 
3877 3864
       report_current_position();
3878 3865
     }
@@ -5989,9 +5976,6 @@ inline void gcode_M400() { stepper.synchronize(); }
5989 5976
    * M401: Engage Z Servo endstop if available
5990 5977
    */
5991 5978
   inline void gcode_M401() {
5992
-    #if HAS_Z_SERVO_ENDSTOP
5993
-      raise_z_for_servo(Z_RAISE_BEFORE_PROBING);
5994
-    #endif
5995 5979
     deploy_z_probe();
5996 5980
   }
5997 5981
 
@@ -5999,10 +5983,7 @@ inline void gcode_M400() { stepper.synchronize(); }
5999 5983
    * M402: Retract Z Servo endstop if enabled
6000 5984
    */
6001 5985
   inline void gcode_M402() {
6002
-    #if HAS_Z_SERVO_ENDSTOP
6003
-      raise_z_for_servo(Z_RAISE_AFTER_PROBING);
6004
-    #endif
6005
-    stow_z_probe(false);
5986
+    stow_z_probe();
6006 5987
   }
6007 5988
 
6008 5989
 #endif // AUTO_BED_LEVELING_FEATURE && (HAS_Z_SERVO_ENDSTOP || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED

Loading…
Cancel
Save