Browse Source

Merge pull request #1736 from thinkyhead/fixup_homing

Fix G28 homing Y with X
Scott Lahteine 9 years ago
parent
commit
1e9999711c
1 changed files with 60 additions and 30 deletions
  1. 60
    30
      Marlin/Marlin_main.cpp

+ 60
- 30
Marlin/Marlin_main.cpp View File

1703
 #endif //FWRETRACT
1703
 #endif //FWRETRACT
1704
 
1704
 
1705
 /**
1705
 /**
1706
- * G28: Home all axes, one at a time
1706
+ * G28: Home all axes according to settings
1707
+ *
1708
+ * Parameters
1709
+ *
1710
+ *  None  Home to all axes with no parameters.
1711
+ *        With QUICK_HOME enabled XY will home together, then Z.
1712
+ *
1713
+ * Cartesian parameters
1714
+ *
1715
+ *  X   Home to the X endstop
1716
+ *  Y   Home to the Y endstop
1717
+ *  Z   Home to the Z endstop
1718
+ *
1719
+ * If numbers are included with XYZ set the position as with G92
1720
+ * Currently adds the home_offset, which may be wrong and removed soon.
1721
+ *
1722
+ *  Xn  Home X, setting X to n + home_offset[X_AXIS]
1723
+ *  Yn  Home Y, setting Y to n + home_offset[Y_AXIS]
1724
+ *  Zn  Home Z, setting Z to n + home_offset[Z_AXIS]
1707
  */
1725
  */
1708
 inline void gcode_G28() {
1726
 inline void gcode_G28() {
1709
   #ifdef ENABLE_AUTO_BED_LEVELING
1727
   #ifdef ENABLE_AUTO_BED_LEVELING
1726
 
1744
 
1727
   enable_endstops(true);
1745
   enable_endstops(true);
1728
 
1746
 
1729
-  for (int i = X_AXIS; i < NUM_AXIS; i++) destination[i] = current_position[i];
1747
+  for (int i = 0; i < NUM_AXIS; i++) destination[i] = current_position[i]; // includes E_AXIS
1730
 
1748
 
1731
   feedrate = 0.0;
1749
   feedrate = 0.0;
1732
 
1750
 
1757
 
1775
 
1758
   #else // NOT DELTA
1776
   #else // NOT DELTA
1759
 
1777
 
1760
-    home_all_axis = !(code_seen(axis_codes[X_AXIS]) || code_seen(axis_codes[Y_AXIS]) || code_seen(axis_codes[Z_AXIS]));
1778
+    bool  homeX = code_seen(axis_codes[X_AXIS]),
1779
+          homeY = code_seen(axis_codes[Y_AXIS]),
1780
+          homeZ = code_seen(axis_codes[Z_AXIS]);
1781
+
1782
+    home_all_axis = !homeX && !homeY && !homeZ; // No parameters means home all axes
1761
 
1783
 
1762
     #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
1784
     #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
1763
-      if (home_all_axis || code_seen(axis_codes[Z_AXIS])) {
1764
-        HOMEAXIS(Z);
1765
-      }
1785
+      if (home_all_axis || homeZ) HOMEAXIS(Z);
1766
     #endif
1786
     #endif
1767
 
1787
 
1768
     #ifdef QUICK_HOME
1788
     #ifdef QUICK_HOME
1769
-      if (home_all_axis || code_seen(axis_codes[X_AXIS] && code_seen(axis_codes[Y_AXIS]))) {  //first diagonal move
1789
+      if (home_all_axis || (homeX && homeY)) {  //first diagonal move
1770
         current_position[X_AXIS] = current_position[Y_AXIS] = 0;
1790
         current_position[X_AXIS] = current_position[Y_AXIS] = 0;
1771
 
1791
 
1772
-        #ifndef DUAL_X_CARRIAGE
1773
-          int x_axis_home_dir = home_dir(X_AXIS);
1774
-        #else
1792
+        #ifdef DUAL_X_CARRIAGE
1775
           int x_axis_home_dir = x_home_dir(active_extruder);
1793
           int x_axis_home_dir = x_home_dir(active_extruder);
1776
           extruder_duplication_enabled = false;
1794
           extruder_duplication_enabled = false;
1795
+        #else
1796
+          int x_axis_home_dir = home_dir(X_AXIS);
1777
         #endif
1797
         #endif
1778
 
1798
 
1779
         sync_plan_position();
1799
         sync_plan_position();
1807
       }
1827
       }
1808
     #endif //QUICK_HOME
1828
     #endif //QUICK_HOME
1809
 
1829
 
1810
-    if ((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
1830
+    // Home X
1831
+    if (home_all_axis || homeX) {
1811
       #ifdef DUAL_X_CARRIAGE
1832
       #ifdef DUAL_X_CARRIAGE
1812
         int tmp_extruder = active_extruder;
1833
         int tmp_extruder = active_extruder;
1813
         extruder_duplication_enabled = false;
1834
         extruder_duplication_enabled = false;
1825
       #endif
1846
       #endif
1826
     }
1847
     }
1827
 
1848
 
1828
-    if (home_all_axis || code_seen(axis_codes[Y_AXIS])) HOMEAXIS(Y);
1849
+    // Home Y
1850
+    if (home_all_axis || homeY) HOMEAXIS(Y);
1829
 
1851
 
1852
+    // Set the X position, if included
1853
+    // Adds the home_offset as well, which may be wrong
1830
     if (code_seen(axis_codes[X_AXIS])) {
1854
     if (code_seen(axis_codes[X_AXIS])) {
1831
-      if (code_value_long() != 0) {
1832
-          current_position[X_AXIS] = code_value()
1833
-            #ifndef SCARA
1834
-              + home_offset[X_AXIS]
1835
-            #endif
1836
-          ;
1837
-      }
1855
+      float v = code_value();
1856
+      if (v) current_position[X_AXIS] = v
1857
+        #ifndef SCARA
1858
+          + home_offset[X_AXIS]
1859
+        #endif
1860
+      ;
1838
     }
1861
     }
1839
 
1862
 
1840
-    if (code_seen(axis_codes[Y_AXIS]) && code_value_long() != 0) {
1841
-      current_position[Y_AXIS] = code_value()
1863
+    // Set the Y position, if included
1864
+    // Adds the home_offset as well, which may be wrong
1865
+    if (code_seen(axis_codes[Y_AXIS])) {
1866
+      float v = code_value();
1867
+      if (v) current_position[Y_AXIS] = v
1842
         #ifndef SCARA
1868
         #ifndef SCARA
1843
           + home_offset[Y_AXIS]
1869
           + home_offset[Y_AXIS]
1844
         #endif
1870
         #endif
1845
       ;
1871
       ;
1846
     }
1872
     }
1847
 
1873
 
1848
-    #if Z_HOME_DIR < 0                      // If homing towards BED do Z last
1874
+    // Home Z last if homing towards the bed
1875
+    #if Z_HOME_DIR < 0
1849
 
1876
 
1850
       #ifndef Z_SAFE_HOMING
1877
       #ifndef Z_SAFE_HOMING
1851
 
1878
 
1852
-        if (home_all_axis || code_seen(axis_codes[Z_AXIS])) {
1879
+        if (home_all_axis || homeZ) {
1880
+          // Raise Z before homing Z? Shouldn't this happen before homing X or Y?
1853
           #if defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
1881
           #if defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
1854
             destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1882
             destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1855
             feedrate = max_feedrate[Z_AXIS];
1883
             feedrate = max_feedrate[Z_AXIS];
1878
         }
1906
         }
1879
 
1907
 
1880
         // Let's see if X and Y are homed and probe is inside bed area.
1908
         // Let's see if X and Y are homed and probe is inside bed area.
1881
-        if (code_seen(axis_codes[Z_AXIS])) {
1909
+        if (homeZ) {
1882
 
1910
 
1883
           if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
1911
           if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
1884
 
1912
 
1912
 
1940
 
1913
     #endif // Z_HOME_DIR < 0
1941
     #endif // Z_HOME_DIR < 0
1914
 
1942
 
1915
-
1916
-    if (code_seen(axis_codes[Z_AXIS]) && code_value_long() != 0)
1917
-      current_position[Z_AXIS] = code_value() + home_offset[Z_AXIS];
1943
+    // Set the Z position, if included
1944
+    // Adds the home_offset as well, which may be wrong
1945
+    if (code_seen(axis_codes[Z_AXIS])) {
1946
+      float v = code_value();
1947
+      if (v) current_position[Z_AXIS] = v + home_offset[Z_AXIS];
1948
+    }
1918
 
1949
 
1919
     #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0)
1950
     #if defined(ENABLE_AUTO_BED_LEVELING) && (Z_HOME_DIR < 0)
1920
-      if (home_all_axis || code_seen(axis_codes[Z_AXIS]))
1921
-        current_position[Z_AXIS] += zprobe_zoffset;  //Add Z_Probe offset (the distance is negative)
1951
+      if (home_all_axis || homeZ) current_position[Z_AXIS] += zprobe_zoffset;  // Add Z_Probe offset (the distance is negative)
1922
     #endif
1952
     #endif
1923
     sync_plan_position();
1953
     sync_plan_position();
1924
 
1954
 
2741
    *     E = Engage probe for each reading
2771
    *     E = Engage probe for each reading
2742
    *     L = Number of legs of movement before probe
2772
    *     L = Number of legs of movement before probe
2743
    *  
2773
    *  
2744
-   * This function assumes the bed has been homed.  Specificaly, that a G28 command
2774
+   * This function assumes the bed has been homed.  Specifically, that a G28 command
2745
    * as been issued prior to invoking the M48 Z-Probe repeatability measurement function.
2775
    * as been issued prior to invoking the M48 Z-Probe repeatability measurement function.
2746
    * Any information generated by a prior G29 Bed leveling command will be lost and need to be
2776
    * Any information generated by a prior G29 Bed leveling command will be lost and need to be
2747
    * regenerated.
2777
    * regenerated.

Loading…
Cancel
Save