ソースを参照

Move z safe homing to its own function

Scott Lahteine 8年前
コミット
b4034915f8
2個のファイルの変更57行の追加69行の削除
  1. 54
    69
      Marlin/Marlin_main.cpp
  2. 3
    0
      Marlin/language_en.h

+ 54
- 69
Marlin/Marlin_main.cpp ファイルの表示

@@ -2749,6 +2749,57 @@ inline void gcode_G4() {
2749 2749
 
2750 2750
 #endif // DELTA
2751 2751
 
2752
+#if ENABLED(Z_SAFE_HOMING)
2753
+
2754
+  inline void home_z_safely() {
2755
+
2756
+    // Disallow Z homing if X or Y are unknown
2757
+    if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
2758
+      LCD_MESSAGEPGM(MSG_ERR_Z_HOMING);
2759
+      SERIAL_ECHO_START;
2760
+      SERIAL_ECHOLNPGM(MSG_ERR_Z_HOMING);
2761
+      return;
2762
+    }
2763
+
2764
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
2765
+      if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Z_SAFE_HOMING >>>");
2766
+    #endif
2767
+
2768
+    SYNC_PLAN_POSITION_KINEMATIC();
2769
+
2770
+    /**
2771
+     * Move the Z probe (or just the nozzle) to the safe homing point
2772
+     */
2773
+    float cpx = Z_SAFE_HOMING_X_POINT, cpy = Z_SAFE_HOMING_Y_POINT;
2774
+    #if HAS_BED_PROBE
2775
+      cpx -= X_PROBE_OFFSET_FROM_EXTRUDER;
2776
+      cpy -= Y_PROBE_OFFSET_FROM_EXTRUDER;
2777
+    #endif
2778
+
2779
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
2780
+      if (DEBUGGING(LEVELING)) {
2781
+        SERIAL_ECHOPAIR("Z_SAFE_HOMING X:", cpx);
2782
+        SERIAL_ECHOLNPAIR(" Y:", cpy);
2783
+      }
2784
+    #endif
2785
+
2786
+    if (cpx >= X_MIN_POS && cpx <= X_MAX_POS && cpy >= Y_MIN_POS && cpy <= Y_MAX_POS) {
2787
+      do_blocking_move_to_xy(LOGICAL_X_POSITION(destination[X_AXIS]), LOGICAL_Y_POSITION(destination[Y_AXIS]));
2788
+      HOMEAXIS(Z);
2789
+    }
2790
+    else {
2791
+      LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
2792
+      SERIAL_ECHO_START;
2793
+      SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
2794
+    }
2795
+
2796
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
2797
+      if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< Z_SAFE_HOMING");
2798
+    #endif
2799
+  }
2800
+
2801
+#endif // Z_SAFE_HOMING
2802
+
2752 2803
 /**
2753 2804
  * G28: Home all axes according to settings
2754 2805
  *
@@ -2824,7 +2875,6 @@ inline void gcode_G28() {
2824 2875
   #endif
2825 2876
   endstops.enable(true); // Enable endstops for next homing move
2826 2877
 
2827
-
2828 2878
   #if ENABLED(DELTA)
2829 2879
 
2830 2880
     home_delta();
@@ -2915,81 +2965,16 @@ inline void gcode_G28() {
2915 2965
 
2916 2966
     // Home Z last if homing towards the bed
2917 2967
     #if Z_HOME_DIR < 0
2918
-
2919 2968
       if (home_all_axis || homeZ) {
2920
-
2921 2969
         #if ENABLED(Z_SAFE_HOMING)
2922
-
2923
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
2924
-            if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>");
2925
-          #endif
2926
-
2927
-          if (home_all_axis) {
2928
-
2929
-            /**
2930
-             * At this point we already have Z at Z_HOMING_HEIGHT height
2931
-             * No need to move Z any more as this height should already be safe
2932
-             * enough to reach Z_SAFE_HOMING XY positions.
2933
-             * Just make sure the planner is in sync.
2934
-             */
2935
-            SYNC_PLAN_POSITION_KINEMATIC();
2936
-
2937
-            /**
2938
-             * Move the Z probe (or just the nozzle) to the safe homing point
2939
-             */
2940
-            destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - (X_PROBE_OFFSET_FROM_EXTRUDER));
2941
-            destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - (Y_PROBE_OFFSET_FROM_EXTRUDER));
2942
-            destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
2943
-
2944
-            #if ENABLED(DEBUG_LEVELING_FEATURE)
2945
-              if (DEBUGGING(LEVELING)) DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", destination);
2946
-            #endif
2947
-
2948
-            // Move in the XY plane
2949
-            do_blocking_move_to_xy(destination[X_AXIS], destination[Y_AXIS]);
2950
-          }
2951
-
2952
-          // Let's see if X and Y are homed
2953
-          if (axis_unhomed_error(true, true, false)) return;
2954
-
2955
-          /**
2956
-           * Make sure the Z probe is within the physical limits
2957
-           * NOTE: This doesn't necessarily ensure the Z probe is also
2958
-           * within the bed!
2959
-           */
2960
-          float cpx = RAW_CURRENT_POSITION(X_AXIS), cpy = RAW_CURRENT_POSITION(Y_AXIS);
2961
-          if (   cpx >= X_MIN_POS - (X_PROBE_OFFSET_FROM_EXTRUDER)
2962
-              && cpx <= X_MAX_POS - (X_PROBE_OFFSET_FROM_EXTRUDER)
2963
-              && cpy >= Y_MIN_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER)
2964
-              && cpy <= Y_MAX_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER)) {
2965
-
2966
-            // Home the Z axis
2967
-            HOMEAXIS(Z);
2968
-          }
2969
-          else {
2970
-            LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
2971
-            SERIAL_ECHO_START;
2972
-            SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
2973
-          }
2974
-
2975
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
2976
-            if (DEBUGGING(LEVELING)) {
2977
-              SERIAL_ECHOLNPGM("<<< Z_SAFE_HOMING");
2978
-            }
2979
-          #endif
2980
-
2981
-        #else // !Z_SAFE_HOMING
2982
-
2970
+          home_z_safely();
2971
+        #else
2983 2972
           HOMEAXIS(Z);
2984
-
2985
-        #endif // !Z_SAFE_HOMING
2986
-
2973
+        #endif
2987 2974
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2988 2975
           if (DEBUGGING(LEVELING)) DEBUG_POS("> (home_all_axis || homeZ) > final", current_position);
2989 2976
         #endif
2990
-
2991 2977
       } // home_all_axis || homeZ
2992
-
2993 2978
     #endif // Z_HOME_DIR < 0
2994 2979
 
2995 2980
     SYNC_PLAN_POSITION_KINEMATIC();

+ 3
- 0
Marlin/language_en.h ファイルの表示

@@ -408,6 +408,9 @@
408 408
 #ifndef MSG_ERR_MINTEMP_BED
409 409
   #define MSG_ERR_MINTEMP_BED                 "Err: MINTEMP BED"
410 410
 #endif
411
+#ifndef MSG_ERR_Z_HOMING
412
+  #define MSG_ERR_Z_HOMING                    "G28 Z Forbidden"
413
+#endif
411 414
 #ifndef MSG_HALTED
412 415
   #define MSG_HALTED                          "PRINTER HALTED"
413 416
 #endif

読み込み中…
キャンセル
保存