Browse Source

Make use of the good features of a sled probe for all probes.

Move and extend axis_unhomed test to deploy/stow_z_probe().
Move and extend position store/restore to deploy/stow_z_probe().

Now all kinds of probes can use the 'E' parameter in G29/M48.
Allen key probes can be used now for grid and 3-point levelling.

Deploying the Allen Key probe uses big moves in z direction.
Too dangerous for an unhomed z-axis.
Throw a compile time error when we try to configure an
Allen Key probe homing to z-min and having no other z-min-endstop.
AnHardt 9 years ago
parent
commit
16c83d203b
2 changed files with 49 additions and 108 deletions
  1. 45
    101
      Marlin/Marlin_main.cpp
  2. 4
    7
      Marlin/SanityCheck.h

+ 45
- 101
Marlin/Marlin_main.cpp View File

1735
 
1735
 
1736
 #endif //HAS_BED_PROBE
1736
 #endif //HAS_BED_PROBE
1737
 
1737
 
1738
-#if ENABLED(Z_PROBE_SLED) || ENABLED(Z_SAFE_HOMING) || HAS_PROBING_PROCEDURE
1738
+#if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || ENABLED(Z_SAFE_HOMING) || HAS_PROBING_PROCEDURE
1739
   static bool axis_unhomed_error(const bool x, const bool y, const bool z) {
1739
   static bool axis_unhomed_error(const bool x, const bool y, const bool z) {
1740
     const bool xx = x && !axis_homed[X_AXIS],
1740
     const bool xx = x && !axis_homed[X_AXIS],
1741
                yy = y && !axis_homed[Y_AXIS],
1741
                yy = y && !axis_homed[Y_AXIS],
1783
       }
1783
       }
1784
     #endif
1784
     #endif
1785
 
1785
 
1786
-    if (axis_unhomed_error(true, false, false)) return;
1787
-
1788
-    float oldXpos = current_position[X_AXIS]; // save x position
1789
-
1790
     // Dock sled a bit closer to ensure proper capturing
1786
     // Dock sled a bit closer to ensure proper capturing
1791
     do_blocking_move_to_x(X_MAX_POS + SLED_DOCKING_OFFSET - ((stow) ? 1 : 0));
1787
     do_blocking_move_to_x(X_MAX_POS + SLED_DOCKING_OFFSET - ((stow) ? 1 : 0));
1792
     digitalWrite(SLED_PIN, !stow); // switch solenoid
1788
     digitalWrite(SLED_PIN, !stow); // switch solenoid
1793
 
1789
 
1794
-    do_blocking_move_to_x(oldXpos); // return to position before docking
1795
-
1796
   }
1790
   }
1797
 
1791
 
1798
 #endif // Z_PROBE_SLED
1792
 #endif // Z_PROBE_SLED
1964
     #endif
1958
     #endif
1965
   #endif
1959
   #endif
1966
 
1960
 
1967
-  static void deploy_z_probe() {
1961
+  #define DEPLOY_PROBE() set_probe_deployed( true )
1962
+  #define STOW_PROBE() set_probe_deployed( false )
1963
+
1964
+  // returns false for ok and true for failure
1965
+  static bool set_probe_deployed(bool deploy) {
1968
 
1966
 
1969
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1967
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1970
-      if (DEBUGGING(LEVELING)) DEBUG_POS("deploy_z_probe", current_position);
1968
+      if (DEBUGGING(LEVELING)) {
1969
+        DEBUG_POS("set_probe_deployed", current_position);
1970
+        SERIAL_ECHOPAIR("deploy: ", deploy);
1971
+      }
1971
     #endif
1972
     #endif
1972
 
1973
 
1973
-    if (endstops.z_probe_enabled) return;
1974
+    if (endstops.z_probe_enabled == deploy) return false;
1974
 
1975
 
1975
     // Make room for probe
1976
     // Make room for probe
1976
     do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW);
1977
     do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW);
1977
 
1978
 
1978
-    #ifdef _TRIGGERED_WHEN_STOWED_TEST
1979
-      // If endstop is already false, the Z probe is deployed
1980
-      if (_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions.
1981
-                                        // Would a goto be less ugly?
1982
-      //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity
1983
-      // for a triggered when stowed manual probe.
1984
-    #endif
1985
-
1986
     #if ENABLED(Z_PROBE_SLED)
1979
     #if ENABLED(Z_PROBE_SLED)
1987
-
1988
-      dock_sled(false);
1989
-
1990
-    #elif HAS_Z_SERVO_ENDSTOP
1991
-
1992
-      // Engage Z Servo endstop if enabled
1993
-      DEPLOY_Z_SERVO();
1994
-
1980
+      if (axis_unhomed_error(true, false, false)) { stop(); return true; }
1995
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1981
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1996
-
1997
-      run_deploy_moves_script();
1998
-
1999
-    #else
2000
-
2001
-      // Nothing to be done. Just enable_z_probe below...
2002
-
1982
+      if (axis_unhomed_error(true, true,  true )) { stop(); return true; }
2003
     #endif
1983
     #endif
2004
 
1984
 
2005
-    #ifdef _TRIGGERED_WHEN_STOWED_TEST
2006
-      }; // opened before the probe specific actions
2007
-
2008
-      if (_TRIGGERED_WHEN_STOWED_TEST) {
2009
-        if (IsRunning()) {
2010
-          SERIAL_ERROR_START;
2011
-          SERIAL_ERRORLNPGM("Z-Probe failed");
2012
-          LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2013
-        }
2014
-        stop();
2015
-      }
2016
-    #endif
2017
-
2018
-    endstops.enable_z_probe();
2019
-  }
2020
-
2021
-  static void stow_z_probe() {
2022
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
2023
-      if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position);
2024
-    #endif
2025
-
2026
-    if (!endstops.z_probe_enabled) return;
2027
-
2028
-    // Make more room for the servo
2029
-    do_probe_raise(_Z_RAISE_PROBE_DEPLOY_STOW);
1985
+    float oldXpos = current_position[X_AXIS]; // save x position
1986
+    float oldYpos = current_position[Y_AXIS]; // save y position
2030
 
1987
 
2031
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
1988
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
2032
       // If endstop is already false, the Z probe is deployed
1989
       // If endstop is already false, the Z probe is deployed
2033
-      if (!_TRIGGERED_WHEN_STOWED_TEST) { // closed after the probe specific actions.
2034
-                                        // Would a goto be less ugly?
1990
+      if (_TRIGGERED_WHEN_STOWED_TEST == deploy) { // closed after the probe specific actions.
1991
+                                                   // Would a goto be less ugly?
2035
       //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity
1992
       //while (!_TRIGGERED_WHEN_STOWED_TEST) { idle(); // would offer the opportunity
2036
       // for a triggered when stowed manual probe.
1993
       // for a triggered when stowed manual probe.
1994
+    #endif
2037
 
1995
 
2038
-      #if ENABLED(Z_PROBE_SLED)
2039
-
2040
-      dock_sled(true);
2041
-
1996
+    #if ENABLED(Z_PROBE_SLED)
1997
+      dock_sled(!deploy);
2042
     #elif HAS_Z_SERVO_ENDSTOP
1998
     #elif HAS_Z_SERVO_ENDSTOP
2043
-
2044
-      // Change the Z servo angle
2045
-      STOW_Z_SERVO();
2046
-
1999
+      servo[Z_ENDSTOP_SERVO_NR].move(z_servo_angle[((deploy) ? 0 : 1)]);
2047
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
2000
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
2048
-
2049
-      run_stow_moves_script();
2050
-
2051
-    #else
2052
-
2053
-      // Nothing to do here. Just clear endstops.z_probe_enabled
2054
-
2001
+      if (!deploy) run_stow_moves_script();
2002
+      else run_deploy_moves_script();
2003
+     #else
2004
+      // Nothing to be done. Just enable_z_probe below...
2055
     #endif
2005
     #endif
2056
 
2006
 
2057
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
2007
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
2058
       }; // opened before the probe specific actions
2008
       }; // opened before the probe specific actions
2059
-      if (!_TRIGGERED_WHEN_STOWED_TEST) {
2009
+
2010
+      if (_TRIGGERED_WHEN_STOWED_TEST == deploy) {
2060
         if (IsRunning()) {
2011
         if (IsRunning()) {
2061
           SERIAL_ERROR_START;
2012
           SERIAL_ERROR_START;
2062
-          SERIAL_ERRORLNPGM("Z-Probe failed!");
2013
+          SERIAL_ERRORLNPGM("Z-Probe failed");
2063
           LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2014
           LCD_ALERTMESSAGEPGM("Err: ZPROBE");
2064
         }
2015
         }
2065
         stop();
2016
         stop();
2067
       }
2018
       }
2068
     #endif
2019
     #endif
2069
 
2020
 
2070
-    endstops.enable_z_probe(false);
2021
+    do_blocking_move_to(oldXpos, oldYpos, current_position[Z_AXIS]); // return to position before deploy
2022
+    endstops.enable_z_probe( deploy );
2023
+    return false;
2071
   }
2024
   }
2072
 
2025
 
2073
   // Do a single Z probe and return with current_position[Z_AXIS]
2026
   // Do a single Z probe and return with current_position[Z_AXIS]
2200
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2153
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2201
       if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2154
       if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2202
     #endif
2155
     #endif
2203
-    deploy_z_probe();
2156
+    if (DEPLOY_PROBE()) return NAN;
2204
 
2157
 
2205
     float measured_z = run_z_probe();
2158
     float measured_z = run_z_probe();
2206
 
2159
 
2208
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2161
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2209
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2162
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2210
       #endif
2163
       #endif
2211
-      stow_z_probe();
2164
+      if (STOW_PROBE()) return NAN;
2212
     }
2165
     }
2213
     else {
2166
     else {
2214
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2167
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2416
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2369
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2417
           if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2370
           if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2418
         #endif
2371
         #endif
2419
-        deploy_z_probe();
2372
+        if (DEPLOY_PROBE()) return;
2420
       }
2373
       }
2421
     #endif
2374
     #endif
2422
 
2375
 
2543
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2496
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2544
           if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2497
           if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2545
         #endif
2498
         #endif
2546
-        stow_z_probe();
2499
+        if (STOW_PROBE()) return;
2547
       }
2500
       }
2548
     #endif
2501
     #endif
2549
 
2502
 
3457
     }
3410
     }
3458
 
3411
 
3459
     bool dryrun = code_seen('D');
3412
     bool dryrun = code_seen('D');
3460
-
3461
-    #if ENABLED(Z_PROBE_ALLEN_KEY)
3462
-      const bool stow_probe_after_each = false;
3463
-    #else
3464
-      bool stow_probe_after_each = code_seen('E');
3465
-    #endif
3413
+    bool stow_probe_after_each = code_seen('E');
3466
 
3414
 
3467
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3415
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3468
 
3416
 
3561
 
3509
 
3562
     setup_for_endstop_or_probe_move();
3510
     setup_for_endstop_or_probe_move();
3563
 
3511
 
3564
-    // Deploy the probe. Servo will raise if needed.
3565
-    deploy_z_probe();
3512
+    // Deploy the probe. Probe will raise if needed.
3513
+    if (DEPLOY_PROBE()) return;
3566
 
3514
 
3567
     bed_leveling_in_progress = true;
3515
     bed_leveling_in_progress = true;
3568
 
3516
 
3667
     #endif // !AUTO_BED_LEVELING_GRID
3615
     #endif // !AUTO_BED_LEVELING_GRID
3668
 
3616
 
3669
     // Raise to _Z_RAISE_PROBE_DEPLOY_STOW. Stow the probe.
3617
     // Raise to _Z_RAISE_PROBE_DEPLOY_STOW. Stow the probe.
3670
-    stow_z_probe();
3618
+    if (STOW_PROBE()) return;
3671
 
3619
 
3672
     // Restore state after probing
3620
     // Restore state after probing
3673
     clean_up_after_endstop_or_probe_move();
3621
     clean_up_after_endstop_or_probe_move();
3874
     /**
3822
     /**
3875
      * G31: Deploy the Z probe
3823
      * G31: Deploy the Z probe
3876
      */
3824
      */
3877
-    inline void gcode_G31() { deploy_z_probe(); }
3825
+    inline void gcode_G31() { DEPLOY_PROBE(); }
3878
 
3826
 
3879
     /**
3827
     /**
3880
      * G32: Stow the Z probe
3828
      * G32: Stow the Z probe
3881
      */
3829
      */
3882
-    inline void gcode_G32() { stow_z_probe(); }
3830
+    inline void gcode_G32() { STOW_PROBE(); }
3883
 
3831
 
3884
   #endif // Z_PROBE_SLED
3832
   #endif // Z_PROBE_SLED
3885
 
3833
 
4220
     float  X_current = current_position[X_AXIS],
4168
     float  X_current = current_position[X_AXIS],
4221
            Y_current = current_position[Y_AXIS];
4169
            Y_current = current_position[Y_AXIS];
4222
 
4170
 
4223
-    #if ENABLED(Z_PROBE_ALLEN_KEY)
4224
-      const bool stow_probe_after_each = false;
4225
-    #else
4226
-      bool stow_probe_after_each = code_seen('E');
4227
-    #endif
4171
+    bool stow_probe_after_each = code_seen('E');
4228
 
4172
 
4229
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
4173
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
4230
     #if DISABLED(DELTA)
4174
     #if DISABLED(DELTA)
4391
 
4335
 
4392
     } // End of probe loop
4336
     } // End of probe loop
4393
 
4337
 
4394
-    stow_z_probe();
4338
+    if (STOW_PROBE()) return;
4395
 
4339
 
4396
     if (verbose_level > 0) {
4340
     if (verbose_level > 0) {
4397
       SERIAL_PROTOCOLPGM("Mean: ");
4341
       SERIAL_PROTOCOLPGM("Mean: ");
5967
   /**
5911
   /**
5968
    * M401: Engage Z Servo endstop if available
5912
    * M401: Engage Z Servo endstop if available
5969
    */
5913
    */
5970
-  inline void gcode_M401() { deploy_z_probe(); }
5914
+  inline void gcode_M401() { DEPLOY_PROBE(); }
5971
 
5915
 
5972
   /**
5916
   /**
5973
    * M402: Retract Z Servo endstop if enabled
5917
    * M402: Retract Z Servo endstop if enabled
5974
    */
5918
    */
5975
-  inline void gcode_M402() { stow_z_probe(); }
5919
+  inline void gcode_M402() { STOW_PROBE(); }
5976
 
5920
 
5977
 #endif // HAS_BED_PROBE
5921
 #endif // HAS_BED_PROBE
5978
 
5922
 

+ 4
- 7
Marlin/SanityCheck.h View File

425
 #endif
425
 #endif
426
 
426
 
427
 /**
427
 /**
428
- * Allen Key Z probe requires Delta and Auto Bed Leveling grid
428
+ * Allen Key
429
+ * Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis.
429
  */
430
  */
430
-#if ENABLED(Z_PROBE_ALLEN_KEY)
431
-  #if !ENABLED(DELTA)
432
-    #error "Z_PROBE_ALLEN_KEY is only usable with DELTA."
433
-  #elif ENABLED(MESH_BED_LEVELING) || (ENABLED(AUTO_BED_LEVELING_FEATURE) && !ENABLED(AUTO_BED_LEVELING_GRID))
434
-    #error "Z_PROBE_ALLEN_KEY can only use AUTO_BED_LEVELING_GRID leveling."
435
-  #endif
431
+#if ENABLED(Z_PROBE_ALLEN_KEY) && (Z_HOME_DIR < 0) && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
432
+  #error "You can't home to a z min endstop with a Z_PROBE_ALLEN_KEY"
436
 #endif
433
 #endif
437
 
434
 
438
 /**
435
 /**

Loading…
Cancel
Save