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
   #endif
383
   #endif
384
 
384
 
385
   #define HAS_Z_SERVO_ENDSTOP (defined(Z_ENDSTOP_SERVO_NR) && Z_ENDSTOP_SERVO_NR >= 0)
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
    * Sled Options
388
    * Sled Options

+ 44
- 63
Marlin/Marlin_main.cpp View File

750
   #endif
750
   #endif
751
 
751
 
752
   #if HAS_Z_SERVO_ENDSTOP
752
   #if HAS_Z_SERVO_ENDSTOP
753
-
754
-    endstops.enable_z_probe(false);
755
-
756
     /**
753
     /**
757
      * Set position of Z Servo Endstop
754
      * Set position of Z Servo Endstop
758
      *
755
      *
763
      *
760
      *
764
      */
761
      */
765
     STOW_Z_SERVO();
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
 
1661
 
1662
 #endif //HAS_BED_PROBE
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
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
1687
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
1665
 
1688
 
1666
   #if ENABLED(AUTO_BED_LEVELING_GRID)
1689
   #if ENABLED(AUTO_BED_LEVELING_GRID)
1861
 
1884
 
1862
     #if HAS_Z_SERVO_ENDSTOP
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
       // Engage Z Servo endstop if enabled
1890
       // Engage Z Servo endstop if enabled
1865
       DEPLOY_Z_SERVO();
1891
       DEPLOY_Z_SERVO();
1866
 
1892
 
1941
     #endif // Z_PROBE_ALLEN_KEY
1967
     #endif // Z_PROBE_ALLEN_KEY
1942
 
1968
 
1943
     #if ENABLED(FIX_MOUNTED_PROBE)
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
     #endif
1971
     #endif
1946
 
1972
 
1947
     endstops.enable_z_probe();
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
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1978
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1956
       if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position);
1979
       if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position);
1957
     #endif
1980
     #endif
1960
 
1983
 
1961
     #if HAS_Z_SERVO_ENDSTOP
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
       // Change the Z servo angle
1989
       // Change the Z servo angle
1972
       STOW_Z_SERVO();
1990
       STOW_Z_SERVO();
2034
           }
2052
           }
2035
           stop();
2053
           stop();
2036
         }
2054
         }
2037
-    #endif // Z_PROBE_ALLEN_KEY
2038
-
2039
-    #if ENABLED(FIX_MOUNTED_PROBE)
2055
+    #elif ENABLED(FIX_MOUNTED_PROBE)
2040
       // Nothing to do here. Just clear endstops.z_probe_enabled
2056
       // Nothing to do here. Just clear endstops.z_probe_enabled
2041
     #endif
2057
     #endif
2042
 
2058
 
2195
 
2211
 
2196
 #endif // AUTO_BED_LEVELING_FEATURE
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
 #if ENABLED(Z_PROBE_SLED) || ENABLED(Z_SAFE_HOMING) || ENABLED(AUTO_BED_LEVELING_FEATURE)
2214
 #if ENABLED(Z_PROBE_SLED) || ENABLED(Z_SAFE_HOMING) || ENABLED(AUTO_BED_LEVELING_FEATURE)
2222
   static void axis_unhomed_error(bool xyz=false) {
2215
   static void axis_unhomed_error(bool xyz=false) {
2223
     if (xyz) {
2216
     if (xyz) {
2313
     #if ENABLED(Z_PROBE_SLED)
2306
     #if ENABLED(Z_PROBE_SLED)
2314
       #define _Z_DEPLOY           (dock_sled(false))
2307
       #define _Z_DEPLOY           (dock_sled(false))
2315
       #define _Z_STOW             (dock_sled(true))
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
       #define _Z_DEPLOY           (deploy_z_probe())
2310
       #define _Z_DEPLOY           (deploy_z_probe())
2318
       #define _Z_STOW             (stow_z_probe())
2311
       #define _Z_STOW             (stow_z_probe())
2319
     #elif HAS_Z_SERVO_ENDSTOP
2312
     #elif HAS_Z_SERVO_ENDSTOP
2322
     #endif
2315
     #endif
2323
 
2316
 
2324
     // Homing Z towards the bed? Deploy the Z probe or endstop.
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
       if (axis == Z_AXIS && axis_home_dir < 0) {
2319
       if (axis == Z_AXIS && axis_home_dir < 0) {
2327
         #if ENABLED(DEBUG_LEVELING_FEATURE)
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
         #endif
2322
         #endif
2330
         _Z_DEPLOY;
2323
         _Z_DEPLOY;
2331
       }
2324
       }
2445
     axis_homed[axis] = true;
2438
     axis_homed[axis] = true;
2446
 
2439
 
2447
     // Put away the Z probe
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
       if (axis == Z_AXIS && axis_home_dir < 0) {
2442
       if (axis == Z_AXIS && axis_home_dir < 0) {
2450
         #if ENABLED(DEBUG_LEVELING_FEATURE)
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
         #endif
2445
         #endif
2453
         _Z_STOW;
2446
         _Z_STOW;
2454
       }
2447
       }
3474
 
3467
 
3475
     #if ENABLED(Z_PROBE_SLED)
3468
     #if ENABLED(Z_PROBE_SLED)
3476
       dock_sled(false); // engage (un-dock) the Z probe
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
       deploy_z_probe();
3471
       deploy_z_probe();
3479
     #endif
3472
     #endif
3480
 
3473
 
3727
 
3720
 
3728
     #if ENABLED(DELTA)
3721
     #if ENABLED(DELTA)
3729
       // Allen Key Probe for Delta
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
         stow_z_probe();
3724
         stow_z_probe();
3732
       #else
3725
       #else
3733
         raise_z_after_probing(); // for non Allen Key probes, such as simple mechanical probe
3726
         raise_z_after_probing(); // for non Allen Key probes, such as simple mechanical probe
3848
      * G30: Do a single Z probe at the current XY
3841
      * G30: Do a single Z probe at the current XY
3849
      */
3842
      */
3850
     inline void gcode_G30() {
3843
     inline void gcode_G30() {
3851
-      #if HAS_Z_SERVO_ENDSTOP
3852
-        raise_z_for_servo(Z_RAISE_BEFORE_PROBING);
3853
-      #endif
3854
       deploy_z_probe(); // Engage Z Servo endstop if available. Z_PROBE_SLED is missed here.
3844
       deploy_z_probe(); // Engage Z Servo endstop if available. Z_PROBE_SLED is missed here.
3855
 
3845
 
3856
       stepper.synchronize();
3846
       stepper.synchronize();
3869
 
3859
 
3870
       clean_up_after_endstop_move(); // Too early. must be done after the stowing.
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
       report_current_position();
3864
       report_current_position();
3878
     }
3865
     }
5989
    * M401: Engage Z Servo endstop if available
5976
    * M401: Engage Z Servo endstop if available
5990
    */
5977
    */
5991
   inline void gcode_M401() {
5978
   inline void gcode_M401() {
5992
-    #if HAS_Z_SERVO_ENDSTOP
5993
-      raise_z_for_servo(Z_RAISE_BEFORE_PROBING);
5994
-    #endif
5995
     deploy_z_probe();
5979
     deploy_z_probe();
5996
   }
5980
   }
5997
 
5981
 
5999
    * M402: Retract Z Servo endstop if enabled
5983
    * M402: Retract Z Servo endstop if enabled
6000
    */
5984
    */
6001
   inline void gcode_M402() {
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
 #endif // AUTO_BED_LEVELING_FEATURE && (HAS_Z_SERVO_ENDSTOP || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED
5989
 #endif // AUTO_BED_LEVELING_FEATURE && (HAS_Z_SERVO_ENDSTOP || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED

Loading…
Cancel
Save