ソースを参照

Homing fixes

- Prevent `Z_SAFE_HOMING` from homing Z twice in some cases
- Allow `G28` with XYZ values of 0 to explicitly set the position
- Don’t add `home_offset` when setting XYZ explicitly in `G28`
- Add `code_has_value` function to check for the presence of a numeric
value (could just test for space or nul to allow other types of values)
Scott Lahteine 10年前
コミット
ac2b23f574
1個のファイルの変更89行の追加74行の削除
  1. 89
    74
      Marlin/Marlin_main.cpp

+ 89
- 74
Marlin/Marlin_main.cpp ファイルの表示

@@ -850,6 +850,11 @@ void get_command()
850 850
 
851 851
 }
852 852
 
853
+float code_has_value() {
854
+  char c = *(strchr_pointer + 1);
855
+  return (c >= '0' && c <= '9') || c == '-' || c == '+' || c == '.';
856
+}
857
+
853 858
 float code_value() {
854 859
   float ret;
855 860
   char *e = strchr(strchr_pointer, 'E');
@@ -1814,21 +1819,24 @@ inline void gcode_G28() {
1814 1819
 
1815 1820
     home_all_axis = !(homeX || homeY || homeZ) || (homeX && homeY && homeZ);
1816 1821
 
1817
-    #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
1822
+    if (home_all_axis || homeZ) {
1818 1823
 
1819
-      if (home_all_axis || homeZ) HOMEAXIS(Z);
1824
+      #if Z_HOME_DIR > 0  // If homing away from BED do Z first
1820 1825
 
1821
-    #elif !defined(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
1826
+        HOMEAXIS(Z);
1822 1827
 
1823
-      // Raise Z before homing any other axes
1824
-      if (home_all_axis || homeZ) {
1825
-        destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1828
+      #elif !defined(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
1829
+
1830
+        // Raise Z before homing any other axes
1831
+        // (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
1832
+        destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
1826 1833
         feedrate = max_feedrate[Z_AXIS] * 60;
1827 1834
         line_to_destination();
1828 1835
         st_synchronize();
1829
-      }
1830 1836
 
1831
-    #endif
1837
+      #endif
1838
+
1839
+    } // home_all_axis || homeZ
1832 1840
 
1833 1841
     #ifdef QUICK_HOME
1834 1842
 
@@ -1897,97 +1905,104 @@ inline void gcode_G28() {
1897 1905
     if (home_all_axis || homeY) HOMEAXIS(Y);
1898 1906
 
1899 1907
     // Set the X position, if included
1900
-    // Adds the home_offset as well, which may be wrong
1901
-    if (code_seen(axis_codes[X_AXIS])) {
1902
-      float v = code_value();
1903
-      if (v) current_position[X_AXIS] = v
1904
-        #ifndef SCARA
1905
-          + home_offset[X_AXIS]
1906
-        #endif
1907
-      ;
1908
-    }
1908
+    if (code_seen(axis_codes[X_AXIS]) && code_has_value())
1909
+      current_position[X_AXIS] = code_value();
1909 1910
 
1910 1911
     // Set the Y position, if included
1911
-    // Adds the home_offset as well, which may be wrong
1912
-    if (code_seen(axis_codes[Y_AXIS])) {
1913
-      float v = code_value();
1914
-      if (v) current_position[Y_AXIS] = v
1915
-        #ifndef SCARA
1916
-          + home_offset[Y_AXIS]
1917
-        #endif
1918
-      ;
1919
-    }
1912
+    if (code_seen(axis_codes[Y_AXIS]) && code_has_value())
1913
+      current_position[Y_AXIS] = code_value();
1920 1914
 
1921 1915
     // Home Z last if homing towards the bed
1922 1916
     #if Z_HOME_DIR < 0
1923 1917
 
1924
-      #ifndef Z_SAFE_HOMING
1918
+      if (home_all_axis || homeZ) {
1925 1919
 
1926
-        if (home_all_axis || homeZ) HOMEAXIS(Z);
1920
+        #ifdef Z_SAFE_HOMING
1927 1921
 
1928
-      #else // Z_SAFE_HOMING
1922
+          if (home_all_axis) {
1929 1923
 
1930
-        if (home_all_axis) {
1931
-          destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER);
1932
-          destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
1933
-          destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1934
-          feedrate = XY_TRAVEL_SPEED;
1935
-          current_position[Z_AXIS] = 0;
1924
+            current_position[Z_AXIS] = 0;
1925
+            sync_plan_position();
1936 1926
 
1937
-          sync_plan_position();
1938
-          line_to_destination();
1939
-          st_synchronize();
1940
-          current_position[X_AXIS] = destination[X_AXIS];
1941
-          current_position[Y_AXIS] = destination[Y_AXIS];
1927
+            //
1928
+            // Set the probe (or just the nozzle) destination to the safe homing point
1929
+            //
1930
+            // NOTE: If current_position[X_AXIS] or current_position[Y_AXIS] were set above
1931
+            // then this may not work as expected.
1932
+            destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER);
1933
+            destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
1934
+            destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1935
+            feedrate = XY_TRAVEL_SPEED;
1936
+            // This could potentially move X, Y, Z all together
1937
+            line_to_destination();
1938
+            st_synchronize();
1942 1939
 
1943
-          HOMEAXIS(Z);
1944
-        }
1940
+            // Set current X, Y is the Z_SAFE_HOMING_POINT minus PROBE_OFFSET_FROM_EXTRUDER
1941
+            current_position[X_AXIS] = destination[X_AXIS];
1942
+            current_position[Y_AXIS] = destination[Y_AXIS];
1945 1943
 
1946
-        // Let's see if X and Y are homed and probe is inside bed area.
1947
-        if (homeZ) {
1948
-
1949
-          if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
1950
-
1951
-            float cpx = current_position[X_AXIS], cpy = current_position[Y_AXIS];
1952
-            if (   cpx >= X_MIN_POS - X_PROBE_OFFSET_FROM_EXTRUDER
1953
-                && cpx <= X_MAX_POS - X_PROBE_OFFSET_FROM_EXTRUDER
1954
-                && cpy >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER
1955
-                && cpy <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) {
1956
-              current_position[Z_AXIS] = 0;
1957
-              plan_set_position(cpx, cpy, 0, current_position[E_AXIS]);
1958
-              destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1959
-              feedrate = max_feedrate[Z_AXIS] * 60;  // max_feedrate is in mm/s. line_to_destination is feedrate/60.
1960
-              line_to_destination();
1961
-              st_synchronize();
1962
-              HOMEAXIS(Z);
1963
-            }
1964
-            else {
1944
+            // Home the Z axis
1945
+            HOMEAXIS(Z);
1946
+          }
1947
+
1948
+          else if (homeZ) { // Don't need to Home Z twice
1949
+
1950
+            // Let's see if X and Y are homed
1951
+            if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
1952
+
1953
+              // Make sure the probe is within the physical limits
1954
+              // NOTE: This doesn't necessarily ensure the probe is also within the bed!
1955
+              float cpx = current_position[X_AXIS], cpy = current_position[Y_AXIS];
1956
+              if (   cpx >= X_MIN_POS - X_PROBE_OFFSET_FROM_EXTRUDER
1957
+                  && cpx <= X_MAX_POS - X_PROBE_OFFSET_FROM_EXTRUDER
1958
+                  && cpy >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER
1959
+                  && cpy <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) {
1960
+                // Set the plan current position to X, Y, 0
1961
+                current_position[Z_AXIS] = 0;
1962
+                plan_set_position(cpx, cpy, 0, current_position[E_AXIS]); // = sync_plan_position
1963
+
1964
+                // Set Z destination away from bed and raise the axis
1965
+                // NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
1966
+                destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
1967
+                feedrate = max_feedrate[Z_AXIS] * 60;  // feedrate (mm/m) = max_feedrate (mm/s)
1968
+                line_to_destination();
1969
+                st_synchronize();
1970
+
1971
+                // Home the Z axis
1972
+                HOMEAXIS(Z);
1973
+              }
1974
+              else {
1965 1975
                 LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
1966 1976
                 SERIAL_ECHO_START;
1967 1977
                 SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
1978
+              }
1968 1979
             }
1969
-          }
1970
-          else {
1971
-            LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1972
-            SERIAL_ECHO_START;
1973
-            SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1974
-          }
1975
-        }
1980
+            else {
1981
+              LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1982
+              SERIAL_ECHO_START;
1983
+              SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1984
+            }
1985
+
1986
+          } // !home_all_axes && homeZ
1976 1987
 
1977
-      #endif // Z_SAFE_HOMING
1988
+        #else // !Z_SAFE_HOMING
1989
+
1990
+          HOMEAXIS(Z);
1991
+
1992
+        #endif // !Z_SAFE_HOMING
1993
+
1994
+      } // home_all_axis || homeZ
1978 1995
 
1979 1996
     #endif // Z_HOME_DIR < 0
1980 1997
 
1981 1998
     // Set the Z position, if included
1982
-    // Adds the home_offset as well, which may be wrong
1983
-    if (code_seen(axis_codes[Z_AXIS])) {
1984
-      float v = code_value();
1985
-      if (v) current_position[Z_AXIS] = v + home_offset[Z_AXIS];
1986
-    }
1999
+    if (code_seen(axis_codes[Z_AXIS]) && code_has_value())
2000
+      current_position[Z_AXIS] = code_value();
1987 2001
 
1988 2002
     #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0)
1989 2003
       if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset;  // Add Z_Probe offset (the distance is negative)
1990 2004
     #endif
2005
+
1991 2006
     sync_plan_position();
1992 2007
 
1993 2008
   #endif // else DELTA

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