Browse Source

Merge pull request #1556 from thinkyhead/enhanced_g29

Enhanced G29
Scott Lahteine 10 years ago
parent
commit
94fd8c7555
2 changed files with 323 additions and 175 deletions
  1. 3
    3
      Marlin/Configuration.h
  2. 320
    172
      Marlin/Marlin_main.cpp

+ 3
- 3
Marlin/Configuration.h View File

428
 
428
 
429
   // these are the offsets to the probe relative to the extruder tip (Hotend - Probe)
429
   // these are the offsets to the probe relative to the extruder tip (Hotend - Probe)
430
   // X and Y offsets must be integers
430
   // X and Y offsets must be integers
431
-  #define X_PROBE_OFFSET_FROM_EXTRUDER -25
432
-  #define Y_PROBE_OFFSET_FROM_EXTRUDER -29
433
-  #define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35
431
+  #define X_PROBE_OFFSET_FROM_EXTRUDER -25     // -left  +right
432
+  #define Y_PROBE_OFFSET_FROM_EXTRUDER -29     // -front +behind
433
+  #define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35  // -below (always!)
434
 
434
 
435
   #define Z_RAISE_BEFORE_HOMING 4       // (in mm) Raise Z before homing (G28) for Probe Clearance.
435
   #define Z_RAISE_BEFORE_HOMING 4       // (in mm) Raise Z before homing (G28) for Probe Clearance.
436
                                         // Be sure you have this distance over your Z_MAX_POS in case
436
                                         // Be sure you have this distance over your Z_MAX_POS in case

+ 320
- 172
Marlin/Marlin_main.cpp View File

1198
     #endif
1198
     #endif
1199
 }
1199
 }
1200
 
1200
 
1201
+enum ProbeAction { ProbeStay, ProbeEngage, ProbeRetract, ProbeEngageRetract };
1202
+
1201
 /// Probe bed height at position (x,y), returns the measured z value
1203
 /// Probe bed height at position (x,y), returns the measured z value
1202
-static float probe_pt(float x, float y, float z_before, int retract_action=0) {
1204
+static float probe_pt(float x, float y, float z_before, ProbeAction retract_action=ProbeEngageRetract) {
1203
   // move to right place
1205
   // move to right place
1204
   do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1206
   do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1205
   do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1207
   do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1206
 
1208
 
1207
-#ifndef Z_PROBE_SLED
1208
-   if ((retract_action==0) || (retract_action==1)) 
1209
-     engage_z_probe();   // Engage Z Servo endstop if available
1210
-#endif // Z_PROBE_SLED
1209
+  #ifndef Z_PROBE_SLED
1210
+    if (retract_action & ProbeEngage) engage_z_probe();
1211
+  #endif
1212
+
1211
   run_z_probe();
1213
   run_z_probe();
1212
   float measured_z = current_position[Z_AXIS];
1214
   float measured_z = current_position[Z_AXIS];
1213
-#ifndef Z_PROBE_SLED
1214
-  if ((retract_action==0) || (retract_action==3)) 
1215
-     retract_z_probe();
1216
-#endif // Z_PROBE_SLED
1215
+
1216
+  #ifndef Z_PROBE_SLED
1217
+    if (retract_action & ProbeRetract) retract_z_probe();
1218
+  #endif
1217
 
1219
 
1218
   SERIAL_PROTOCOLPGM(MSG_BED);
1220
   SERIAL_PROTOCOLPGM(MSG_BED);
1219
   SERIAL_PROTOCOLPGM(" x: ");
1221
   SERIAL_PROTOCOLPGM(" x: ");
1374
 #endif //FWRETRACT
1376
 #endif //FWRETRACT
1375
 
1377
 
1376
 #ifdef Z_PROBE_SLED
1378
 #ifdef Z_PROBE_SLED
1379
+
1380
+  #ifndef SLED_DOCKING_OFFSET
1381
+    #define SLED_DOCKING_OFFSET 0
1382
+  #endif
1383
+
1377
 //
1384
 //
1378
 // Method to dock/undock a sled designed by Charles Bell.
1385
 // Method to dock/undock a sled designed by Charles Bell.
1379
 //
1386
 //
1660
                                                 // Let's see if X and Y are homed and probe is inside bed area.
1667
                                                 // Let's see if X and Y are homed and probe is inside bed area.
1661
           if(code_seen(axis_codes[Z_AXIS])) {
1668
           if(code_seen(axis_codes[Z_AXIS])) {
1662
             if ( (axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]) \
1669
             if ( (axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]) \
1663
-              && (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER >= X_MIN_POS) \
1664
-              && (current_position[X_AXIS]+X_PROBE_OFFSET_FROM_EXTRUDER <= X_MAX_POS) \
1665
-              && (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER >= Y_MIN_POS) \
1666
-              && (current_position[Y_AXIS]+Y_PROBE_OFFSET_FROM_EXTRUDER <= Y_MAX_POS)) {
1670
+              && (current_position[X_AXIS] >= X_MIN_POS - X_PROBE_OFFSET_FROM_EXTRUDER) \
1671
+              && (current_position[X_AXIS] <= X_MAX_POS - X_PROBE_OFFSET_FROM_EXTRUDER) \
1672
+              && (current_position[Y_AXIS] >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) \
1673
+              && (current_position[Y_AXIS] <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER)) {
1667
 
1674
 
1668
               current_position[Z_AXIS] = 0;
1675
               current_position[Z_AXIS] = 0;
1669
               plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1676
               plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1717
       break;
1724
       break;
1718
 
1725
 
1719
 #ifdef ENABLE_AUTO_BED_LEVELING
1726
 #ifdef ENABLE_AUTO_BED_LEVELING
1727
+
1728
+    #if Z_MIN_PIN == -1
1729
+      #error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling!!! Z_MIN_PIN must point to a valid hardware pin."
1730
+    #endif
1731
+
1732
+   /**
1733
+    * Enhanced G29 Auto Bed Leveling Probe Routine
1734
+    * 
1735
+    * Parameters With AUTO_BED_LEVELING_GRID:
1736
+    *
1737
+    *  P  Set the size of the grid that will be probed (P x P points).
1738
+    *     Example: "G29 P4"
1739
+    *
1740
+    *  V  Set the verbose level (0-4). Example: "G29 V3"
1741
+    *
1742
+    *  T  Generate a Bed Topology Report. Example: "G29 P5 T" for a detailed report.
1743
+    *     This is useful for manual bed leveling and finding flaws in the bed (to
1744
+    *     assist with part placement).
1745
+    *
1746
+    *  F  Set the Front limit of the probing grid
1747
+    *  B  Set the Back limit of the probing grid
1748
+    *  L  Set the Left limit of the probing grid
1749
+    *  R  Set the Right limit of the probing grid
1750
+    *
1751
+    * Global Parameters:
1752
+    *
1753
+    * E/e By default G29 engages / disengages the probe for each point.
1754
+    *     Include "E" to engage and disengage the probe just once.
1755
+    *     There's no extra effect if you have a fixed probe.
1756
+    *     Usage: "G29 E" or "G29 e"
1757
+    *
1758
+    */
1759
+
1720
     case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
1760
     case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
1721
-    	     // Override probing area by providing [F]ront [B]ack [L]eft [R]ight Grid[P]oints values
1722
-        {
1723
-            #if Z_MIN_PIN == -1
1724
-            #error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin."
1725
-            #endif
1761
+    {
1762
+      // Use one of these defines to specify the origin
1763
+      // for a topographical map to be printed for your bed.
1764
+      #define ORIGIN_BACK_LEFT   1
1765
+      #define ORIGIN_FRONT_RIGHT 2
1766
+      #define ORIGIN_BACK_RIGHT  3
1767
+      #define ORIGIN_FRONT_LEFT  4
1768
+      #define TOPO_ORIGIN        ORIGIN_FRONT_LEFT
1769
+
1770
+      // Prevent user from running a G29 without first homing in X and Y
1771
+      if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS])) {
1772
+        LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1773
+        SERIAL_ECHO_START;
1774
+        SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1775
+        break; // abort G29, since we don't know where we are
1776
+      }
1726
 
1777
 
1727
-            // Prevent user from running a G29 without first homing in X and Y
1728
-            if (! (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) )
1729
-            {
1730
-                LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1731
-                SERIAL_ECHO_START;
1732
-                SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1733
-                break; // abort G29, since we don't know where we are
1734
-            }
1778
+      bool enhanced_g29 = code_seen('E') || code_seen('e');
1735
 
1779
 
1736
-#ifdef Z_PROBE_SLED
1737
-            dock_sled(false);
1738
-#endif // Z_PROBE_SLED
1739
-            st_synchronize();
1740
-            // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
1741
-            //vector_3 corrected_position = plan_get_position_mm();
1742
-            //corrected_position.debug("position before G29");
1743
-            plan_bed_level_matrix.set_to_identity();
1744
-            vector_3 uncorrected_position = plan_get_position();
1745
-            //uncorrected_position.debug("position durring G29");
1746
-            current_position[X_AXIS] = uncorrected_position.x;
1747
-            current_position[Y_AXIS] = uncorrected_position.y;
1748
-            current_position[Z_AXIS] = uncorrected_position.z;
1749
-            plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1750
-            setup_for_endstop_move();
1780
+      #ifdef AUTO_BED_LEVELING_GRID
1751
 
1781
 
1752
-            feedrate = homing_feedrate[Z_AXIS];
1753
-#ifdef AUTO_BED_LEVELING_GRID
1754
-            // probe at the points of a lattice grid
1755
-            int left_probe_bed_position=LEFT_PROBE_BED_POSITION;
1756
-            int right_probe_bed_position=RIGHT_PROBE_BED_POSITION;
1757
-            int back_probe_bed_position=BACK_PROBE_BED_POSITION;
1758
-            int front_probe_bed_position=FRONT_PROBE_BED_POSITION;
1759
-            int auto_bed_leveling_grid_points=AUTO_BED_LEVELING_GRID_POINTS;
1760
-            if (code_seen('L')) left_probe_bed_position=(int)code_value();
1761
-            if (code_seen('R')) right_probe_bed_position=(int)code_value();
1762
-            if (code_seen('B')) back_probe_bed_position=(int)code_value();
1763
-            if (code_seen('F')) front_probe_bed_position=(int)code_value();
1764
-            if (code_seen('P')) auto_bed_leveling_grid_points=(int)code_value();
1782
+        // Example Syntax:  G29 N4 V2 E T
1783
+        int verbose_level = 1;
1765
 
1784
 
1766
-            int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points-1);
1767
-            int yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points-1);
1785
+        bool topo_flag = code_seen('T') || code_seen('t');
1768
 
1786
 
1787
+        if (code_seen('V') || code_seen('v')) {
1788
+          verbose_level = code_value();
1789
+          if (verbose_level < 0 || verbose_level > 4) {
1790
+            SERIAL_PROTOCOLPGM("?(V)erbose Level is implausible (0-4).\n");
1791
+            break;
1792
+          }
1793
+          if (verbose_level > 0) {
1794
+            SERIAL_PROTOCOLPGM("G29 Enhanced Auto Bed Leveling Code V1.25:\n");
1795
+            SERIAL_PROTOCOLPGM("Full support at: http://3dprintboard.com/forum.php\n");
1796
+            if (verbose_level > 2) topo_flag = true;
1797
+          }
1798
+        }
1769
 
1799
 
1770
-            // solve the plane equation ax + by + d = z
1771
-            // A is the matrix with rows [x y 1] for all the probed points
1772
-            // B is the vector of the Z positions
1773
-            // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
1774
-            // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
1800
+        int auto_bed_leveling_grid_points = code_seen('P') ? code_value_long() : AUTO_BED_LEVELING_GRID_POINTS;
1801
+        if (auto_bed_leveling_grid_points < 2 || auto_bed_leveling_grid_points > AUTO_BED_LEVELING_GRID_POINTS) {
1802
+          SERIAL_PROTOCOLPGM("?Number of probed (P)oints is implausible (2 minimum).\n");
1803
+          break;
1804
+        }
1775
 
1805
 
1776
-            // "A" matrix of the linear system of equations
1777
-            double eqnAMatrix[auto_bed_leveling_grid_points*auto_bed_leveling_grid_points*3];
1806
+        // Define the possible boundaries for probing based on the set limits.
1807
+        // Code above (in G28) might have these limits wrong, or I am wrong here.
1808
+        #define MIN_PROBE_EDGE 10 // Edges of the probe square can be no less
1809
+        const int min_probe_x = max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER),
1810
+                  max_probe_x = min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER),
1811
+                  min_probe_y = max(Y_MIN_POS, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER),
1812
+                  max_probe_y = min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER);
1813
+
1814
+        int left_probe_bed_position = code_seen('L') ? code_value_long() : LEFT_PROBE_BED_POSITION,
1815
+            right_probe_bed_position = code_seen('R') ? code_value_long() : RIGHT_PROBE_BED_POSITION,
1816
+            front_probe_bed_position = code_seen('F') ? code_value_long() : FRONT_PROBE_BED_POSITION,
1817
+            back_probe_bed_position = code_seen('B') ? code_value_long() : BACK_PROBE_BED_POSITION;
1818
+
1819
+        bool left_out_l = left_probe_bed_position < min_probe_x,
1820
+             left_out_r = left_probe_bed_position > right_probe_bed_position - MIN_PROBE_EDGE,
1821
+             left_out = left_out_l || left_out_r,
1822
+             right_out_r = right_probe_bed_position > max_probe_x,
1823
+             right_out_l =right_probe_bed_position < left_probe_bed_position + MIN_PROBE_EDGE,
1824
+             right_out = right_out_l || right_out_r,
1825
+             front_out_f = front_probe_bed_position < min_probe_y,
1826
+             front_out_b = front_probe_bed_position > back_probe_bed_position - MIN_PROBE_EDGE,
1827
+             front_out = front_out_f || front_out_b,
1828
+             back_out_b = back_probe_bed_position > max_probe_y,
1829
+             back_out_f = back_probe_bed_position < front_probe_bed_position + MIN_PROBE_EDGE,
1830
+             back_out = back_out_f || back_out_b;
1831
+
1832
+        if (left_out || right_out || front_out || back_out) {
1833
+          if (left_out) {
1834
+            SERIAL_PROTOCOLPGM("?Probe (L)eft position out of range.\n");
1835
+            left_probe_bed_position = left_out_l ? min_probe_x : right_probe_bed_position - MIN_PROBE_EDGE;
1836
+          }
1837
+          if (right_out) {
1838
+            SERIAL_PROTOCOLPGM("?Probe (R)ight position out of range.\n");
1839
+            right_probe_bed_position = right_out_r ? max_probe_x : left_probe_bed_position + MIN_PROBE_EDGE;
1840
+          }
1841
+          if (front_out) {
1842
+            SERIAL_PROTOCOLPGM("?Probe (F)ront position out of range.\n");
1843
+            front_probe_bed_position = front_out_f ? min_probe_y : back_probe_bed_position - MIN_PROBE_EDGE;
1844
+          }
1845
+          if (back_out) {
1846
+            SERIAL_PROTOCOLPGM("?Probe (B)ack position out of range.\n");
1847
+            back_probe_bed_position = back_out_b ? max_probe_y : front_probe_bed_position + MIN_PROBE_EDGE;
1848
+          }
1849
+          break;
1850
+        }
1778
 
1851
 
1779
-            // "B" vector of Z points
1780
-            double eqnBVector[auto_bed_leveling_grid_points*auto_bed_leveling_grid_points];
1852
+      #endif
1781
 
1853
 
1854
+      #ifdef Z_PROBE_SLED
1855
+        dock_sled(false); // engage (un-dock) the probe
1856
+      #endif
1782
 
1857
 
1858
+      st_synchronize();
1859
+      // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
1860
+      //vector_3 corrected_position = plan_get_position_mm();
1861
+      //corrected_position.debug("position before G29");
1862
+      plan_bed_level_matrix.set_to_identity();
1863
+      vector_3 uncorrected_position = plan_get_position();
1864
+      //uncorrected_position.debug("position durring G29");
1865
+      current_position[X_AXIS] = uncorrected_position.x;
1866
+      current_position[Y_AXIS] = uncorrected_position.y;
1867
+      current_position[Z_AXIS] = uncorrected_position.z;
1868
+      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1869
+      setup_for_endstop_move();
1783
 
1870
 
1784
-            int probePointCounter = 0;
1785
-            bool zig = true;
1871
+      feedrate = homing_feedrate[Z_AXIS];
1786
 
1872
 
1787
-            for (int yProbe=front_probe_bed_position; yProbe <= back_probe_bed_position; yProbe += yGridSpacing)
1873
+      #ifdef AUTO_BED_LEVELING_GRID
1874
+        // probe at the points of a lattice grid
1788
 
1875
 
1789
-            {
1790
-              int xProbe, xInc;
1791
-              if (zig)
1792
-              {
1793
-                xProbe = left_probe_bed_position;
1794
-                //xEnd = right_probe_bed_position;
1795
-                xInc = xGridSpacing;
1796
-                zig = false;
1797
-              } else // zag
1798
-              {
1799
-                xProbe = right_probe_bed_position;
1800
-                //xEnd = left_probe_bed_position;
1801
-                xInc = -xGridSpacing;
1802
-                zig = true;
1803
-              }
1876
+        int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points - 1);
1877
+        int yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points - 1);
1804
 
1878
 
1805
-              for (int xCount=0; xCount < auto_bed_leveling_grid_points; xCount++)
1806
-              {
1807
-                float z_before;
1808
-                if (probePointCounter == 0)
1809
-                {
1810
-                  // raise before probing
1811
-                  z_before = Z_RAISE_BEFORE_PROBING;
1812
-                } else
1813
-                {
1814
-                  // raise extruder
1815
-                  z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
1816
-                }
1817
-
1818
-                float measured_z;
1819
-                //Enhanced G29 - Do not retract servo between probes
1820
-                if (code_seen('E') || code_seen('e') )
1821
-                   {
1822
-                   if ((yProbe==FRONT_PROBE_BED_POSITION) && (xCount==0))
1823
-                       {
1824
-                        measured_z = probe_pt(xProbe, yProbe, z_before,1);
1825
-                       } else if ((yProbe==FRONT_PROBE_BED_POSITION + (yGridSpacing * (AUTO_BED_LEVELING_GRID_POINTS-1))) && (xCount == AUTO_BED_LEVELING_GRID_POINTS-1))
1826
-                         {
1827
-                         measured_z = probe_pt(xProbe, yProbe, z_before,3);
1828
-                         } else {
1829
-                           measured_z = probe_pt(xProbe, yProbe, z_before,2);
1830
-                         }
1831
-                    } else {
1832
-                    measured_z = probe_pt(xProbe, yProbe, z_before);
1833
-                    }
1834
-
1835
-                eqnBVector[probePointCounter] = measured_z;
1836
-
1837
-                eqnAMatrix[probePointCounter + 0*auto_bed_leveling_grid_points*auto_bed_leveling_grid_points] = xProbe;
1838
-                eqnAMatrix[probePointCounter + 1*auto_bed_leveling_grid_points*auto_bed_leveling_grid_points] = yProbe;
1839
-                eqnAMatrix[probePointCounter + 2*auto_bed_leveling_grid_points*auto_bed_leveling_grid_points] = 1;
1840
-                probePointCounter++;
1841
-                xProbe += xInc;
1842
-              }
1879
+        // solve the plane equation ax + by + d = z
1880
+        // A is the matrix with rows [x y 1] for all the probed points
1881
+        // B is the vector of the Z positions
1882
+        // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
1883
+        // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
1884
+
1885
+        int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points;
1886
+
1887
+        double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
1888
+               eqnBVector[abl2],     // "B" vector of Z points
1889
+               mean = 0.0;
1890
+
1891
+        int probePointCounter = 0;
1892
+        bool zig = true;
1893
+
1894
+        for (int yProbe = front_probe_bed_position; yProbe <= back_probe_bed_position; yProbe += yGridSpacing) {
1895
+          int xProbe, xInc;
1896
+
1897
+          if (zig)
1898
+            xProbe = left_probe_bed_position, xInc = xGridSpacing;
1899
+          else
1900
+            xProbe = right_probe_bed_position, xInc = -xGridSpacing;
1901
+
1902
+          // If topo_flag is set then don't zig-zag. Just scan in one direction.
1903
+          // This gets the probe points in more readable order.
1904
+          if (!topo_flag) zig = !zig;
1905
+
1906
+          for (int xCount = 0; xCount < auto_bed_leveling_grid_points; xCount++) {
1907
+            // raise extruder
1908
+            float z_before = probePointCounter == 0 ? Z_RAISE_BEFORE_PROBING : current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS,
1909
+                  measured_z;
1910
+
1911
+            // Enhanced G29 - Do not retract servo between probes
1912
+            ProbeAction act;
1913
+            if (enhanced_g29) {
1914
+              if (yProbe == front_probe_bed_position && xCount == 0)
1915
+                act = ProbeEngage;
1916
+              else if (yProbe == front_probe_bed_position + (yGridSpacing * (auto_bed_leveling_grid_points - 1)) && xCount == auto_bed_leveling_grid_points - 1)
1917
+                act = ProbeRetract;
1918
+              else
1919
+                act = ProbeStay;
1843
             }
1920
             }
1844
-            clean_up_after_endstop_move();
1921
+            else
1922
+              act = ProbeEngageRetract;
1845
 
1923
 
1846
-            // solve lsq problem
1847
-            double *plane_equation_coefficients = qr_solve(auto_bed_leveling_grid_points*auto_bed_leveling_grid_points, 3, eqnAMatrix, eqnBVector);
1924
+            measured_z = probe_pt(xProbe, yProbe, z_before, act);
1848
 
1925
 
1849
-            SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
1850
-            SERIAL_PROTOCOL(plane_equation_coefficients[0]);
1851
-            SERIAL_PROTOCOLPGM(" b: ");
1852
-            SERIAL_PROTOCOL(plane_equation_coefficients[1]);
1853
-            SERIAL_PROTOCOLPGM(" d: ");
1854
-            SERIAL_PROTOCOLLN(plane_equation_coefficients[2]);
1926
+            mean += measured_z;
1855
 
1927
 
1928
+            eqnBVector[probePointCounter] = measured_z;
1929
+            eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
1930
+            eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
1931
+            eqnAMatrix[probePointCounter + 2 * abl2] = 1;
1856
 
1932
 
1857
-            set_bed_level_equation_lsq(plane_equation_coefficients);
1933
+            probePointCounter++;
1934
+            xProbe += xInc;
1858
 
1935
 
1859
-            free(plane_equation_coefficients);
1936
+          } //xProbe
1860
 
1937
 
1861
-#else // AUTO_BED_LEVELING_GRID not defined
1938
+        } //yProbe
1862
 
1939
 
1863
-            // Probe at 3 arbitrary points
1864
-            // Enhanced G29
1865
-            
1866
-            float z_at_pt_1, z_at_pt_2, z_at_pt_3;
1867
-            
1868
-            if (code_seen('E') || code_seen('e')) {
1869
-              // probe 1               
1870
-              z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING,1);
1871
-              // probe 2
1872
-              z_at_pt_2 = probe_pt(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS,2);
1873
-              // probe 3
1874
-              z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS,3); 
1875
-            }
1876
-            else {
1877
-              // probe 1
1878
-              z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING);
1879
-              // probe 2
1880
-              z_at_pt_2 = probe_pt(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1881
-              // probe 3
1882
-              z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1883
-            }
1884
-            clean_up_after_endstop_move();
1885
-            set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
1940
+        clean_up_after_endstop_move();
1886
 
1941
 
1942
+        // solve lsq problem
1943
+        double *plane_equation_coefficients = qr_solve(abl2, 3, eqnAMatrix, eqnBVector);
1944
+
1945
+        mean /= abl2;
1946
+
1947
+        if (verbose_level) {
1948
+          SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
1949
+          SERIAL_PROTOCOL(plane_equation_coefficients[0]);
1950
+          SERIAL_PROTOCOLPGM(" b: ");
1951
+          SERIAL_PROTOCOL(plane_equation_coefficients[1]);
1952
+          SERIAL_PROTOCOLPGM(" d: ");
1953
+          SERIAL_PROTOCOLLN(plane_equation_coefficients[2]);
1954
+          if (verbose_level > 2) {
1955
+            SERIAL_PROTOCOLPGM("Mean of sampled points: ");
1956
+            SERIAL_PROTOCOL_F(mean, 6);
1957
+            SERIAL_PROTOCOLPGM(" \n");
1958
+          }
1959
+        }
1887
 
1960
 
1888
-#endif // AUTO_BED_LEVELING_GRID
1889
-            st_synchronize();
1961
+        if (topo_flag) {
1890
 
1962
 
1891
-            // The following code correct the Z height difference from z-probe position and hotend tip position.
1892
-            // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
1893
-            // When the bed is uneven, this height must be corrected.
1894
-            real_z = float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS];  //get the real Z (since the auto bed leveling is already correcting the plane)
1895
-            x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER;
1896
-            y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
1897
-            z_tmp = current_position[Z_AXIS];
1963
+          int xx, yy;
1898
 
1964
 
1899
-            apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
1900
-            current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
1901
-            plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1902
-#ifdef Z_PROBE_SLED
1903
-            dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel.
1904
-#endif // Z_PROBE_SLED
1965
+          SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n");
1966
+          #if TOPO_ORIGIN == ORIGIN_FRONT_LEFT
1967
+            for (yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--)
1968
+          #else
1969
+            for (yy = 0; yy < auto_bed_leveling_grid_points; yy++)
1970
+          #endif
1971
+            {
1972
+              #if TOPO_ORIGIN == ORIGIN_BACK_RIGHT
1973
+                for (xx = auto_bed_leveling_grid_points - 1; xx >= 0; xx--)
1974
+              #else
1975
+                for (xx = 0; xx < auto_bed_leveling_grid_points; xx++)
1976
+              #endif
1977
+                {
1978
+                  int ind =
1979
+                    #if TOPO_ORIGIN == ORIGIN_BACK_RIGHT || TOPO_ORIGIN == ORIGIN_FRONT_LEFT
1980
+                      yy * auto_bed_leveling_grid_points + xx
1981
+                    #elif TOPO_ORIGIN == ORIGIN_BACK_LEFT
1982
+                      xx * auto_bed_leveling_grid_points + yy
1983
+                    #elif TOPO_ORIGIN == ORIGIN_FRONT_RIGHT
1984
+                      abl2 - xx * auto_bed_leveling_grid_points - yy - 1
1985
+                    #endif
1986
+                  ;
1987
+                  float diff = eqnBVector[ind] - mean;
1988
+                  if (diff >= 0.0)
1989
+                    SERIAL_PROTOCOLPGM(" +");   // Watch column alignment in Pronterface
1990
+                  else
1991
+                    SERIAL_PROTOCOLPGM(" -");
1992
+                  SERIAL_PROTOCOL_F(diff, 5);
1993
+                } // xx
1994
+                SERIAL_PROTOCOLPGM("\n");
1995
+            } // yy
1996
+            SERIAL_PROTOCOLPGM("\n");
1997
+
1998
+        } //topo_flag
1999
+
2000
+
2001
+        set_bed_level_equation_lsq(plane_equation_coefficients);
2002
+        free(plane_equation_coefficients);
2003
+
2004
+      #else // !AUTO_BED_LEVELING_GRID
2005
+
2006
+        // Probe at 3 arbitrary points
2007
+        float z_at_pt_1, z_at_pt_2, z_at_pt_3;
2008
+
2009
+        if (enhanced_g29) {
2010
+          // Basic Enhanced G29
2011
+          z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING, ProbeEngage);
2012
+          z_at_pt_2 = probe_pt(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS, ProbeStay);
2013
+          z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS, ProbeRetract);
1905
         }
2014
         }
1906
-        break;
2015
+        else {
2016
+          z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING);
2017
+          z_at_pt_2 = probe_pt(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
2018
+          z_at_pt_3 = probe_pt(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
2019
+        }
2020
+        clean_up_after_endstop_move();
2021
+        set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
2022
+
2023
+      #endif // !AUTO_BED_LEVELING_GRID
2024
+
2025
+      st_synchronize();
2026
+
2027
+      if (verbose_level > 0)
2028
+        plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:");
2029
+
2030
+      // The following code correct the Z height difference from z-probe position and hotend tip position.
2031
+      // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
2032
+      // When the bed is uneven, this height must be corrected.
2033
+      real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS];  //get the real Z (since the auto bed leveling is already correcting the plane)
2034
+      x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER;
2035
+      y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
2036
+      z_tmp = current_position[Z_AXIS];
2037
+
2038
+      apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
2039
+      current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
2040
+      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2041
+
2042
+      #ifdef Z_PROBE_SLED
2043
+        dock_sled(true, -SLED_DOCKING_OFFSET); // dock the probe, correcting for over-travel
2044
+      #endif
2045
+    }
2046
+    break;
2047
+
1907
 #ifndef Z_PROBE_SLED
2048
 #ifndef Z_PROBE_SLED
1908
     case 30: // G30 Single Z Probe
2049
     case 30: // G30 Single Z Probe
1909
         {
2050
         {
2036
         enable_e0();
2177
         enable_e0();
2037
         enable_e1();
2178
         enable_e1();
2038
         enable_e2();
2179
         enable_e2();
2180
+        enable_e3();
2039
       break;
2181
       break;
2040
 
2182
 
2041
 #ifdef SDSUPPORT
2183
 #ifdef SDSUPPORT
2744
         disable_e0();
2886
         disable_e0();
2745
         disable_e1();
2887
         disable_e1();
2746
         disable_e2();
2888
         disable_e2();
2889
+        disable_e3();
2747
         finishAndDisableSteppers();
2890
         finishAndDisableSteppers();
2748
         fanSpeed = 0;
2891
         fanSpeed = 0;
2749
         delay(1000); // Wait a little before to switch off
2892
         delay(1000); // Wait a little before to switch off
2780
           disable_e0();
2923
           disable_e0();
2781
           disable_e1();
2924
           disable_e1();
2782
           disable_e2();
2925
           disable_e2();
2926
+          disable_e3();
2783
           finishAndDisableSteppers();
2927
           finishAndDisableSteppers();
2784
         }
2928
         }
2785
         else
2929
         else
2793
               disable_e0();
2937
               disable_e0();
2794
               disable_e1();
2938
               disable_e1();
2795
               disable_e2();
2939
               disable_e2();
2940
+              disable_e3();
2796
             }
2941
             }
2797
           #endif
2942
           #endif
2798
         }
2943
         }
3731
         disable_e0();
3876
         disable_e0();
3732
         disable_e1();
3877
         disable_e1();
3733
         disable_e2();
3878
         disable_e2();
3879
+        disable_e3();
3734
         delay(100);
3880
         delay(100);
3735
         LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
3881
         LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
3736
         uint8_t cnt=0;
3882
         uint8_t cnt=0;
4479
         disable_e0();
4625
         disable_e0();
4480
         disable_e1();
4626
         disable_e1();
4481
         disable_e2();
4627
         disable_e2();
4628
+        disable_e3();
4482
       }
4629
       }
4483
     }
4630
     }
4484
   }
4631
   }
4584
   disable_e0();
4731
   disable_e0();
4585
   disable_e1();
4732
   disable_e1();
4586
   disable_e2();
4733
   disable_e2();
4734
+  disable_e3();
4587
 
4735
 
4588
 #if defined(PS_ON_PIN) && PS_ON_PIN > -1
4736
 #if defined(PS_ON_PIN) && PS_ON_PIN > -1
4589
   pinMode(PS_ON_PIN,INPUT);
4737
   pinMode(PS_ON_PIN,INPUT);

Loading…
Cancel
Save