瀏覽代碼

Debug messages for homing and leveling

Scott Lahteine 10 年之前
父節點
當前提交
194f98ff95
共有 1 個檔案被更改,包括 306 行新增6 行删除
  1. 306
    6
      Marlin/Marlin_main.cpp

+ 306
- 6
Marlin/Marlin_main.cpp 查看文件

@@ -1033,6 +1033,19 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
1033 1033
 
1034 1034
 #endif //DUAL_X_CARRIAGE
1035 1035
 
1036
+#ifdef DEBUG_LEVELING
1037
+  void print_xyz(const char *prefix, const float x, const float y, const float z) {
1038
+    SERIAL_ECHO(prefix);
1039
+    SERIAL_ECHOPAIR(": (", x);
1040
+    SERIAL_ECHOPAIR(", ", y);
1041
+    SERIAL_ECHOPAIR(", ", z);
1042
+    SERIAL_ECHOLNPGM(")");
1043
+  }
1044
+  void print_xyz(const char *prefix, const float xyz[]) {
1045
+    print_xyz(prefix, xyz[X_AXIS], xyz[Y_AXIS], xyz[Z_AXIS]);
1046
+  }
1047
+#endif
1048
+
1036 1049
 static void set_axis_is_at_home(AxisEnum axis) {
1037 1050
 
1038 1051
   #if ENABLED(DUAL_X_CARRIAGE)
@@ -1098,6 +1111,12 @@ static void set_axis_is_at_home(AxisEnum axis) {
1098 1111
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1099 1112
       if (axis == Z_AXIS) current_position[Z_AXIS] -= zprobe_zoffset;
1100 1113
     #endif
1114
+
1115
+    #ifdef DEBUG_LEVELING
1116
+      SERIAL_ECHOPAIR("set_axis_is_at_home ", (unsigned long)axis);
1117
+      SERIAL_ECHOPAIR(" > (home_offset[axis]==", home_offset[axis]);
1118
+      print_xyz(") > current_position", current_position);
1119
+    #endif
1101 1120
   }
1102 1121
 }
1103 1122
 
@@ -1143,6 +1162,9 @@ static void setup_for_endstop_move() {
1143 1162
   saved_feedrate_multiplier = feedrate_multiplier;
1144 1163
   feedrate_multiplier = 100;
1145 1164
   refresh_cmd_timeout();
1165
+  #ifdef DEBUG_LEVELING
1166
+    SERIAL_ECHOLNPGM("setup_for_endstop_move > enable_endstops(true)");
1167
+  #endif
1146 1168
   enable_endstops(true);
1147 1169
 }
1148 1170
 
@@ -1153,6 +1175,9 @@ static void setup_for_endstop_move() {
1153 1175
      * Calculate delta, start a line, and set current_position to destination
1154 1176
      */
1155 1177
     void prepare_move_raw() {
1178
+      #ifdef DEBUG_LEVELING
1179
+        print_xyz("prepare_move_raw > destination", destination);
1180
+      #endif
1156 1181
       refresh_cmd_timeout();
1157 1182
       calculate_delta(destination);
1158 1183
       plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], (feedrate/60)*(feedrate_multiplier/100.0), active_extruder);
@@ -1180,6 +1205,10 @@ static void setup_for_endstop_move() {
1180 1205
         current_position[Y_AXIS] = corrected_position.y;
1181 1206
         current_position[Z_AXIS] = corrected_position.z;
1182 1207
 
1208
+        #ifdef DEBUG_LEVELING
1209
+          print_xyz("set_bed_level_equation_lsq > current_position", current_position);
1210
+        #endif
1211
+
1183 1212
         sync_plan_position();
1184 1213
       }
1185 1214
 
@@ -1209,6 +1238,10 @@ static void setup_for_endstop_move() {
1209 1238
       current_position[Y_AXIS] = corrected_position.y;
1210 1239
       current_position[Z_AXIS] = corrected_position.z;
1211 1240
 
1241
+      #ifdef DEBUG_LEVELING
1242
+        print_xyz("set_bed_level_equation_3pts > current_position", current_position);
1243
+      #endif
1244
+
1212 1245
       sync_plan_position();
1213 1246
     }
1214 1247
 
@@ -1221,6 +1254,10 @@ static void setup_for_endstop_move() {
1221 1254
       float start_z = current_position[Z_AXIS];
1222 1255
       long start_steps = st_get_position(Z_AXIS);
1223 1256
     
1257
+      #ifdef DEBUG_LEVELING
1258
+        SERIAL_ECHOLNPGM("run_z_probe (DELTA) 1");
1259
+      #endif
1260
+
1224 1261
       // move down slowly until you find the bed
1225 1262
       feedrate = homing_feedrate[Z_AXIS] / 4;
1226 1263
       destination[Z_AXIS] = -10;
@@ -1232,6 +1269,11 @@ static void setup_for_endstop_move() {
1232 1269
       long stop_steps = st_get_position(Z_AXIS);
1233 1270
       float mm = start_z - float(start_steps - stop_steps) / axis_steps_per_unit[Z_AXIS];
1234 1271
       current_position[Z_AXIS] = mm;
1272
+
1273
+      #ifdef DEBUG_LEVELING
1274
+        print_xyz("run_z_probe (DELTA) 2 > current_position", current_position);
1275
+      #endif
1276
+
1235 1277
       sync_plan_position_delta();
1236 1278
       
1237 1279
     #else // !DELTA
@@ -1265,6 +1307,10 @@ static void setup_for_endstop_move() {
1265 1307
       // Get the current stepper position after bumping an endstop
1266 1308
       current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1267 1309
       sync_plan_position();
1310
+
1311
+      #ifdef DEBUG_LEVELING
1312
+        print_xyz("run_z_probe > current_position", current_position);
1313
+      #endif
1268 1314
       
1269 1315
     #endif // !DELTA
1270 1316
   }
@@ -1276,6 +1322,10 @@ static void setup_for_endstop_move() {
1276 1322
   static void do_blocking_move_to(float x, float y, float z) {
1277 1323
     float oldFeedRate = feedrate;
1278 1324
 
1325
+    #ifdef DEBUG_LEVELING
1326
+      print_xyz("do_blocking_move_to", x, y, z);
1327
+    #endif
1328
+
1279 1329
     #if ENABLED(DELTA)
1280 1330
 
1281 1331
       feedrate = XY_TRAVEL_SPEED;
@@ -1312,6 +1362,9 @@ static void setup_for_endstop_move() {
1312 1362
 
1313 1363
   static void clean_up_after_endstop_move() {
1314 1364
     #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
1365
+      #if ENABLED(DEBUG_LEVELING)
1366
+        SERIAL_ECHOLNPGM("clean_up_after_endstop_move > ENDSTOPS_ONLY_FOR_HOMING > enable_endstops(false)");
1367
+      #endif
1315 1368
       enable_endstops(false);
1316 1369
     #endif
1317 1370
     feedrate = saved_feedrate;
@@ -1321,6 +1374,10 @@ static void setup_for_endstop_move() {
1321 1374
 
1322 1375
   static void deploy_z_probe() {
1323 1376
 
1377
+    #ifdef DEBUG_LEVELING
1378
+      print_xyz("deploy_z_probe > current_position", current_position);
1379
+    #endif
1380
+
1324 1381
     #if HAS_SERVO_ENDSTOPS
1325 1382
 
1326 1383
       // Engage Z Servo endstop if enabled
@@ -1411,6 +1468,10 @@ static void setup_for_endstop_move() {
1411 1468
 
1412 1469
   static void stow_z_probe(bool doRaise=true) {
1413 1470
 
1471
+    #ifdef DEBUG_LEVELING
1472
+      print_xyz("stow_z_probe > current_position", current_position);
1473
+    #endif
1474
+
1414 1475
     #if HAS_SERVO_ENDSTOPS
1415 1476
 
1416 1477
       // Retract Z Servo endstop if enabled
@@ -1418,6 +1479,12 @@ static void setup_for_endstop_move() {
1418 1479
 
1419 1480
         #if Z_RAISE_AFTER_PROBING > 0
1420 1481
           if (doRaise) {
1482
+            #ifdef DEBUG_LEVELING
1483
+              SERIAL_ECHOPAIR("Raise Z (after) by ", (float)Z_RAISE_AFTER_PROBING);
1484
+              SERIAL_EOL;
1485
+              SERIAL_ECHOPAIR("> SERVO_ENDSTOPS > do_blocking_move_to_z ", current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING);
1486
+              SERIAL_EOL;
1487
+            #endif
1421 1488
             do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1422 1489
             st_synchronize();
1423 1490
           }
@@ -1506,19 +1573,51 @@ static void setup_for_endstop_move() {
1506 1573
 
1507 1574
   // Probe bed height at position (x,y), returns the measured z value
1508 1575
   static float probe_pt(float x, float y, float z_before, ProbeAction probe_action=ProbeDeployAndStow, int verbose_level=1) {
1576
+
1577
+    #ifdef DEBUG_LEVELING
1578
+      SERIAL_ECHOLNPGM("probe_pt >>>");
1579
+      SERIAL_ECHOPAIR("> ProbeAction:", (unsigned long)probe_action);
1580
+      SERIAL_EOL;
1581
+      print_xyz("> current_position", current_position);
1582
+    #endif
1583
+
1584
+    #ifdef DEBUG_LEVELING
1585
+      SERIAL_ECHOPAIR("Z Raise to z_before ", z_before);
1586
+      SERIAL_EOL;
1587
+      SERIAL_ECHOPAIR("> do_blocking_move_to_z ", z_before);
1588
+      SERIAL_EOL;
1589
+    #endif
1590
+
1509 1591
     // Move Z up to the z_before height, then move the Z probe to the given XY
1510 1592
     do_blocking_move_to_z(z_before); // this also updates current_position
1593
+
1594
+    #ifdef DEBUG_LEVELING
1595
+      SERIAL_ECHOPAIR("> do_blocking_move_to_xy ", x - X_PROBE_OFFSET_FROM_EXTRUDER);
1596
+      SERIAL_ECHOPAIR(", ", y - Y_PROBE_OFFSET_FROM_EXTRUDER);
1597
+      SERIAL_EOL;
1598
+    #endif
1599
+
1511 1600
     do_blocking_move_to_xy(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER); // this also updates current_position
1512 1601
 
1513 1602
     #if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
1514
-      if (probe_action & ProbeDeploy) deploy_z_probe();
1603
+      if (probe_action & ProbeDeploy) {
1604
+        #ifdef DEBUG_LEVELING
1605
+          SERIAL_ECHOLNPGM("> ProbeDeploy");
1606
+        #endif
1607
+        deploy_z_probe();
1608
+      }
1515 1609
     #endif
1516 1610
 
1517 1611
     run_z_probe();
1518 1612
     float measured_z = current_position[Z_AXIS];
1519 1613
 
1520 1614
     #if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
1521
-      if (probe_action & ProbeStow) stow_z_probe();
1615
+      if (probe_action & ProbeStow) {
1616
+        #ifdef DEBUG_LEVELING
1617
+          SERIAL_ECHOLNPGM("> ProbeStow (stow_z_probe will do Z Raise)");
1618
+        #endif
1619
+        stow_z_probe();
1620
+      }
1522 1621
     #endif
1523 1622
 
1524 1623
     if (verbose_level > 2) {
@@ -1530,6 +1629,11 @@ static void setup_for_endstop_move() {
1530 1629
       SERIAL_PROTOCOL_F(measured_z, 3);
1531 1630
       SERIAL_EOL;
1532 1631
     }
1632
+
1633
+    #ifdef DEBUG_LEVELING
1634
+      SERIAL_ECHOLNPGM("<<< probe_pt");
1635
+    #endif
1636
+
1533 1637
     return measured_z;
1534 1638
   }
1535 1639
 
@@ -1585,6 +1689,9 @@ static void setup_for_endstop_move() {
1585 1689
 
1586 1690
     // Reset calibration results to zero.
1587 1691
     void reset_bed_level() {
1692
+      #ifdef DEBUG_LEVELING
1693
+        SERIAL_ECHOLNPGM("reset_bed_level");
1694
+      #endif
1588 1695
       for (int y = 0; y < AUTO_BED_LEVELING_GRID_POINTS; y++) {
1589 1696
         for (int x = 0; x < AUTO_BED_LEVELING_GRID_POINTS; x++) {
1590 1697
           bed_level[x][y] = 0.0;
@@ -1620,6 +1727,10 @@ static void setup_for_endstop_move() {
1620 1727
    * offset[in]   The additional distance to move to adjust docking location
1621 1728
    */
1622 1729
   static void dock_sled(bool dock, int offset=0) {
1730
+    #ifdef DEBUG_LEVELING
1731
+      SERIAL_ECHOPAIR("dock_sled", dock);
1732
+      SERIAL_EOL;
1733
+    #endif
1623 1734
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
1624 1735
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1625 1736
       SERIAL_ECHO_START;
@@ -1654,6 +1765,11 @@ static void setup_for_endstop_move() {
1654 1765
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1655 1766
 
1656 1767
 static void homeaxis(AxisEnum axis) {
1768
+  #ifdef DEBUG_LEVELING
1769
+    SERIAL_ECHOPAIR(">>> homeaxis(", (unsigned long)axis);
1770
+    SERIAL_CHAR(')');
1771
+    SERIAL_EOL;
1772
+  #endif
1657 1773
   #define HOMEAXIS_DO(LETTER) \
1658 1774
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
1659 1775
 
@@ -1706,6 +1822,9 @@ static void homeaxis(AxisEnum axis) {
1706 1822
     current_position[axis] = 0;
1707 1823
     sync_plan_position();
1708 1824
 
1825
+    #ifdef DEBUG_LEVELING
1826
+      SERIAL_ECHOLNPGM("> enable_endstops(false)");
1827
+    #endif
1709 1828
     enable_endstops(false); // Disable endstops while moving away
1710 1829
 
1711 1830
     // Move away from the endstop by the axis HOME_BUMP_MM
@@ -1713,6 +1832,9 @@ static void homeaxis(AxisEnum axis) {
1713 1832
     line_to_destination();
1714 1833
     st_synchronize();
1715 1834
 
1835
+    #ifdef DEBUG_LEVELING
1836
+      SERIAL_ECHOLNPGM("> enable_endstops(true)");
1837
+    #endif
1716 1838
     enable_endstops(true); // Enable endstops for next homing move
1717 1839
 
1718 1840
     // Slow down the feedrate for the next move
@@ -1723,6 +1845,10 @@ static void homeaxis(AxisEnum axis) {
1723 1845
     line_to_destination();
1724 1846
     st_synchronize();
1725 1847
 
1848
+    #ifdef DEBUG_LEVELING
1849
+      print_xyz("> TRIGGER ENDSTOP > current_position", current_position);
1850
+    #endif
1851
+
1726 1852
     #if ENABLED(Z_DUAL_ENDSTOPS)
1727 1853
       if (axis == Z_AXIS) {
1728 1854
         float adj = fabs(z_endstop_adj);
@@ -1751,19 +1877,39 @@ static void homeaxis(AxisEnum axis) {
1751 1877
     #if ENABLED(DELTA)
1752 1878
       // retrace by the amount specified in endstop_adj
1753 1879
       if (endstop_adj[axis] * axis_home_dir < 0) {
1880
+        #ifdef DEBUG_LEVELING
1881
+          SERIAL_ECHOLNPGM("> enable_endstops(false)");
1882
+        #endif
1754 1883
         enable_endstops(false); // Disable endstops while moving away
1755 1884
         sync_plan_position();
1756 1885
         destination[axis] = endstop_adj[axis];
1886
+        #ifdef DEBUG_LEVELING
1887
+          SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]);
1888
+          print_xyz(" > destination", destination);
1889
+        #endif
1757 1890
         line_to_destination();
1758 1891
         st_synchronize();
1892
+        #ifdef DEBUG_LEVELING
1893
+          SERIAL_ECHOLNPGM("> enable_endstops(true)");
1894
+        #endif
1759 1895
         enable_endstops(true); // Enable endstops for next homing move
1760 1896
       }
1897
+      #ifdef DEBUG_LEVELING
1898
+        else {
1899
+          SERIAL_ECHOPAIR("> endstop_adj * axis_home_dir = ", endstop_adj[axis] * axis_home_dir);
1900
+          SERIAL_EOL;
1901
+        }
1902
+      #endif
1761 1903
     #endif
1762 1904
 
1763 1905
     // Set the axis position to its home position (plus home offsets)
1764 1906
     set_axis_is_at_home(axis);
1765 1907
     sync_plan_position();
1766 1908
 
1909
+    #ifdef DEBUG_LEVELING
1910
+      print_xyz("> AFTER set_axis_is_at_home > current_position", current_position);
1911
+    #endif
1912
+
1767 1913
     destination[axis] = current_position[axis];
1768 1914
     feedrate = 0.0;
1769 1915
     endstops_hit_on_purpose(); // clear endstop hit flags
@@ -1780,7 +1926,12 @@ static void homeaxis(AxisEnum axis) {
1780 1926
 
1781 1927
       // Deploy a Z probe if there is one, and homing towards the bed
1782 1928
       if (axis == Z_AXIS) {
1783
-        if (axis_home_dir < 0) stow_z_probe();
1929
+        if (axis_home_dir < 0) {
1930
+          #ifdef DEBUG_LEVELING
1931
+            SERIAL_ECHOLNPGM("> SERVO_LEVELING > stow_z_probe");
1932
+          #endif
1933
+          stow_z_probe();
1934
+        }
1784 1935
       }
1785 1936
       else
1786 1937
 
@@ -1789,12 +1940,22 @@ static void homeaxis(AxisEnum axis) {
1789 1940
     {
1790 1941
       #if HAS_SERVO_ENDSTOPS
1791 1942
         // Retract Servo endstop if enabled
1792
-        if (servo_endstop_id[axis] >= 0)
1943
+        if (servo_endstop_id[axis] >= 0) {
1944
+          #ifdef DEBUG_LEVELING
1945
+            SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
1946
+          #endif
1793 1947
           servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
1948
+        }
1794 1949
       #endif
1795 1950
     }
1796 1951
 
1797 1952
   }
1953
+
1954
+  #ifdef DEBUG_LEVELING
1955
+    SERIAL_ECHOPAIR("<<< homeaxis(", (unsigned long)axis);
1956
+    SERIAL_CHAR(')');
1957
+    SERIAL_EOL;
1958
+  #endif
1798 1959
 }
1799 1960
 
1800 1961
 #if ENABLED(FWRETRACT)
@@ -1996,6 +2157,10 @@ inline void gcode_G4() {
1996 2157
  */
1997 2158
 inline void gcode_G28() {
1998 2159
 
2160
+  #ifdef DEBUG_LEVELING
2161
+    SERIAL_ECHOLNPGM("gcode_G28 >>>");
2162
+  #endif
2163
+
1999 2164
   // Wait for planner moves to finish!
2000 2165
   st_synchronize();
2001 2166
 
@@ -2044,6 +2209,10 @@ inline void gcode_G28() {
2044 2209
 
2045 2210
     sync_plan_position_delta();
2046 2211
 
2212
+    #ifdef DEBUG_LEVELING
2213
+      print_xyz("(DELTA) > current_position", current_position);
2214
+    #endif
2215
+
2047 2216
   #else // NOT DELTA
2048 2217
 
2049 2218
     bool  homeX = code_seen(axis_codes[X_AXIS]),
@@ -2057,12 +2226,20 @@ inline void gcode_G28() {
2057 2226
       #if Z_HOME_DIR > 0  // If homing away from BED do Z first
2058 2227
 
2059 2228
         HOMEAXIS(Z);
2229
+        #ifdef DEBUG_LEVELING
2230
+          print_xyz("> HOMEAXIS(Z) > current_position", current_position);
2231
+        #endif
2060 2232
 
2061 2233
       #elif DISABLED(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
2062 2234
 
2063 2235
         // Raise Z before homing any other axes
2064 2236
         // (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
2065 2237
         destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
2238
+        #ifdef DEBUG_LEVELING
2239
+          SERIAL_ECHOPAIR("Raise Z (before homing) by ", (float)Z_RAISE_BEFORE_HOMING);
2240
+          SERIAL_EOL;
2241
+          print_xyz("> (home_all_axis || homeZ) > destination", destination);
2242
+        #endif
2066 2243
         feedrate = max_feedrate[Z_AXIS] * 60;
2067 2244
         line_to_destination();
2068 2245
         st_synchronize();
@@ -2099,6 +2276,10 @@ inline void gcode_G28() {
2099 2276
         set_axis_is_at_home(Y_AXIS);
2100 2277
         sync_plan_position();
2101 2278
 
2279
+        #ifdef DEBUG_LEVELING
2280
+          print_xyz("> QUICK_HOME > current_position 1", current_position);
2281
+        #endif
2282
+
2102 2283
         destination[X_AXIS] = current_position[X_AXIS];
2103 2284
         destination[Y_AXIS] = current_position[Y_AXIS];
2104 2285
         line_to_destination();
@@ -2111,6 +2292,10 @@ inline void gcode_G28() {
2111 2292
         #if DISABLED(SCARA)
2112 2293
           current_position[Z_AXIS] = destination[Z_AXIS];
2113 2294
         #endif
2295
+
2296
+        #ifdef DEBUG_LEVELING
2297
+          print_xyz("> QUICK_HOME > current_position 2", current_position);
2298
+        #endif
2114 2299
       }
2115 2300
 
2116 2301
     #endif // QUICK_HOME
@@ -2137,11 +2322,19 @@ inline void gcode_G28() {
2137 2322
       #else
2138 2323
         HOMEAXIS(X);
2139 2324
       #endif
2325
+      #ifdef DEBUG_LEVELING
2326
+        print_xyz("> homeX", current_position);
2327
+      #endif
2140 2328
     }
2141 2329
 
2142 2330
     #if DISABLED(HOME_Y_BEFORE_X)
2143 2331
       // Home Y
2144
-      if (home_all_axis || homeY) HOMEAXIS(Y);
2332
+      if (home_all_axis || homeY) {
2333
+        HOMEAXIS(Y);
2334
+        #ifdef DEBUG_LEVELING
2335
+          print_xyz("> homeY", current_position);
2336
+        #endif
2337
+      }
2145 2338
     #endif
2146 2339
 
2147 2340
     // Home Z last if homing towards the bed
@@ -2151,6 +2344,10 @@ inline void gcode_G28() {
2151 2344
 
2152 2345
         #if ENABLED(Z_SAFE_HOMING)
2153 2346
 
2347
+          #ifdef DEBUG_LEVELING
2348
+            SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>");
2349
+          #endif
2350
+
2154 2351
           if (home_all_axis) {
2155 2352
 
2156 2353
             current_position[Z_AXIS] = 0;
@@ -2165,6 +2362,14 @@ inline void gcode_G28() {
2165 2362
             destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
2166 2363
             destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
2167 2364
             feedrate = XY_TRAVEL_SPEED;
2365
+
2366
+            #ifdef DEBUG_LEVELING
2367
+              SERIAL_ECHOPAIR("Raise Z (before homing) by ", (float)Z_RAISE_BEFORE_HOMING);
2368
+              SERIAL_EOL;
2369
+              print_xyz("> home_all_axis > current_position", current_position);
2370
+              print_xyz("> home_all_axis > destination", destination);
2371
+            #endif
2372
+
2168 2373
             // This could potentially move X, Y, Z all together
2169 2374
             line_to_destination();
2170 2375
             st_synchronize();
@@ -2197,6 +2402,14 @@ inline void gcode_G28() {
2197 2402
                 // NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
2198 2403
                 destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
2199 2404
                 feedrate = max_feedrate[Z_AXIS] * 60;  // feedrate (mm/m) = max_feedrate (mm/s)
2405
+
2406
+                #ifdef DEBUG_LEVELING
2407
+                  SERIAL_ECHOPAIR("Raise Z (before homing) by ", (float)Z_RAISE_BEFORE_HOMING);
2408
+                  SERIAL_EOL;
2409
+                  print_xyz("> homeZ > current_position", current_position);
2410
+                  print_xyz("> homeZ > destination", destination);
2411
+                #endif
2412
+
2200 2413
                 line_to_destination();
2201 2414
                 st_synchronize();
2202 2415
 
@@ -2217,12 +2430,20 @@ inline void gcode_G28() {
2217 2430
 
2218 2431
           } // !home_all_axes && homeZ
2219 2432
 
2433
+          #ifdef DEBUG_LEVELING
2434
+            SERIAL_ECHOLNPGM("<<< Z_SAFE_HOMING");
2435
+          #endif
2436
+
2220 2437
         #else // !Z_SAFE_HOMING
2221 2438
 
2222 2439
           HOMEAXIS(Z);
2223 2440
 
2224 2441
         #endif // !Z_SAFE_HOMING
2225 2442
 
2443
+        #ifdef DEBUG_LEVELING
2444
+          print_xyz("> (home_all_axis || homeZ) > final", current_position);
2445
+        #endif
2446
+
2226 2447
       } // home_all_axis || homeZ
2227 2448
 
2228 2449
     #endif // Z_HOME_DIR < 0
@@ -2236,6 +2457,9 @@ inline void gcode_G28() {
2236 2457
   #endif
2237 2458
 
2238 2459
   #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
2460
+    #ifdef DEBUG_LEVELING
2461
+      SERIAL_ECHOLNPGM("ENDSTOPS_ONLY_FOR_HOMING enable_endstops(false)");
2462
+    #endif
2239 2463
     enable_endstops(false);
2240 2464
   #endif
2241 2465
 
@@ -2251,6 +2475,9 @@ inline void gcode_G28() {
2251 2475
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2252 2476
       sync_plan_position();
2253 2477
       mbl.active = 1;
2478
+      #ifdef DEBUG_LEVELING
2479
+        print_xyz("mbl_was_active > current_position", current_position);
2480
+      #endif
2254 2481
     }
2255 2482
   #endif
2256 2483
 
@@ -2258,6 +2485,11 @@ inline void gcode_G28() {
2258 2485
   feedrate_multiplier = saved_feedrate_multiplier;
2259 2486
   refresh_cmd_timeout();
2260 2487
   endstops_hit_on_purpose(); // clear endstop hit flags
2488
+
2489
+  #ifdef DEBUG_LEVELING
2490
+    SERIAL_ECHOLNPGM("<<< gcode_G28");
2491
+  #endif
2492
+
2261 2493
 }
2262 2494
 
2263 2495
 #if ENABLED(MESH_BED_LEVELING)
@@ -2443,6 +2675,10 @@ inline void gcode_G28() {
2443 2675
    */
2444 2676
   inline void gcode_G29() {
2445 2677
 
2678
+    #ifdef DEBUG_LEVELING
2679
+      SERIAL_ECHOLNPGM("gcode_G29 >>>");
2680
+    #endif
2681
+
2446 2682
     // Don't allow auto-leveling without homing first
2447 2683
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
2448 2684
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
@@ -2601,6 +2837,19 @@ inline void gcode_G28() {
2601 2837
           float measured_z,
2602 2838
                 z_before = probePointCounter ? Z_RAISE_BETWEEN_PROBINGS + current_position[Z_AXIS] : Z_RAISE_BEFORE_PROBING;
2603 2839
 
2840
+          if (probePointCounter) {
2841
+            #ifdef DEBUG_LEVELING
2842
+              SERIAL_ECHOPAIR("z_before = (between) ", (float)(Z_RAISE_BETWEEN_PROBINGS + current_position[Z_AXIS]));
2843
+              SERIAL_EOL;
2844
+            #endif
2845
+          }
2846
+          else {
2847
+            #ifdef DEBUG_LEVELING
2848
+              SERIAL_ECHOPAIR("z_before = (before) ", (float)Z_RAISE_BEFORE_PROBING);
2849
+              SERIAL_EOL;
2850
+            #endif
2851
+          }
2852
+
2604 2853
           #if ENABLED(DELTA)
2605 2854
             // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
2606 2855
             float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe);
@@ -2638,6 +2887,10 @@ inline void gcode_G28() {
2638 2887
         } //xProbe
2639 2888
       } //yProbe
2640 2889
 
2890
+      #ifdef DEBUG_LEVELING
2891
+        print_xyz("> probing complete > current_position", current_position);
2892
+      #endif
2893
+
2641 2894
       clean_up_after_endstop_move();
2642 2895
 
2643 2896
       #if ENABLED(DELTA)
@@ -2734,6 +2987,10 @@ inline void gcode_G28() {
2734 2987
 
2735 2988
     #else // !AUTO_BED_LEVELING_GRID
2736 2989
 
2990
+      #ifdef DEBUG_LEVELING
2991
+        SERIAL_ECHOLNPGM("> 3-point Leveling");
2992
+      #endif
2993
+
2737 2994
       // Actions for each probe
2738 2995
       ProbeAction p1, p2, p3;
2739 2996
       if (deploy_probe_for_each_reading)
@@ -2763,6 +3020,13 @@ inline void gcode_G28() {
2763 3020
               z_tmp = current_position[Z_AXIS],
2764 3021
               real_z = st_get_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
2765 3022
 
3023
+        #ifdef DEBUG_LEVELING
3024
+          SERIAL_ECHOPAIR("> BEFORE apply_rotation_xyz > z_tmp  = ", z_tmp);
3025
+          SERIAL_EOL;
3026
+          SERIAL_ECHOPAIR("> BEFORE apply_rotation_xyz > real_z = ", real_z);
3027
+          SERIAL_EOL;
3028
+        #endif
3029
+
2766 3030
         apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); // Apply the correction sending the Z probe offset
2767 3031
 
2768 3032
         // Get the current Z position and send it to the planner.
@@ -2781,6 +3045,11 @@ inline void gcode_G28() {
2781 3045
         //      adjust for inaccurate endstops, not for reasonably accurate probes. If it were
2782 3046
         //      added here, it could be seen as a compensating factor for the Z probe.
2783 3047
         //
3048
+        #ifdef DEBUG_LEVELING
3049
+          SERIAL_ECHOPAIR("> AFTER apply_rotation_xyz > z_tmp  = ", z_tmp);
3050
+          SERIAL_EOL;
3051
+        #endif
3052
+
2784 3053
         current_position[Z_AXIS] = -zprobe_zoffset + (z_tmp - real_z)
2785 3054
           #if HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED)
2786 3055
              + Z_RAISE_AFTER_PROBING
@@ -2788,6 +3057,10 @@ inline void gcode_G28() {
2788 3057
           ;
2789 3058
         // current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home"
2790 3059
         sync_plan_position();
3060
+
3061
+        #ifdef DEBUG_LEVELING
3062
+          print_xyz("> corrected Z in G29", current_position);
3063
+        #endif
2791 3064
       }
2792 3065
     #endif // !DELTA
2793 3066
 
@@ -2798,9 +3071,18 @@ inline void gcode_G28() {
2798 3071
     #endif
2799 3072
 
2800 3073
     #ifdef Z_PROBE_END_SCRIPT
3074
+      #ifdef DEBUG_LEVELING
3075
+        SERIAL_ECHO("Z Probe End Script: ");
3076
+        SERIAL_ECHOLNPGM(Z_PROBE_END_SCRIPT);
3077
+      #endif
2801 3078
       enqueuecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2802 3079
       st_synchronize();
2803 3080
     #endif
3081
+
3082
+    #ifdef DEBUG_LEVELING
3083
+      SERIAL_ECHOLNPGM("<<< gcode_G29");
3084
+    #endif
3085
+
2804 3086
   }
2805 3087
 
2806 3088
   #if DISABLED(Z_PROBE_SLED)
@@ -4095,11 +4377,23 @@ inline void gcode_M206() {
4095 4377
    * M666: Set delta endstop adjustment
4096 4378
    */
4097 4379
   inline void gcode_M666() {
4380
+    #ifdef DEBUG_LEVELING
4381
+      SERIAL_ECHOLNPGM(">>> gcode_M666");
4382
+    #endif
4098 4383
     for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4099 4384
       if (code_seen(axis_codes[i])) {
4100 4385
         endstop_adj[i] = code_value();
4386
+        #ifdef DEBUG_LEVELING
4387
+          SERIAL_ECHOPGM("endstop_adj[");
4388
+          SERIAL_ECHO(axis_codes[i]);
4389
+          SERIAL_ECHOPAIR("] = ", endstop_adj[i]);
4390
+          SERIAL_EOL;
4391
+        #endif
4101 4392
       }
4102 4393
     }
4394
+    #ifdef DEBUG_LEVELING
4395
+      SERIAL_ECHOLNPGM("<<< gcode_M666");
4396
+    #endif
4103 4397
   }
4104 4398
 #elif ENABLED(Z_DUAL_ENDSTOPS) // !DELTA && ENABLED(Z_DUAL_ENDSTOPS)
4105 4399
   /**
@@ -5801,7 +6095,13 @@ void clamp_to_software_endstops(float target[3]) {
5801 6095
     float negative_z_offset = 0;
5802 6096
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
5803 6097
       if (zprobe_zoffset < 0) negative_z_offset += zprobe_zoffset;
5804
-      if (home_offset[Z_AXIS] < 0) negative_z_offset += home_offset[Z_AXIS];
6098
+      if (home_offset[Z_AXIS] < 0) {
6099
+        #ifdef DEBUG_LEVELING
6100
+          SERIAL_ECHOPAIR("> clamp_to_software_endstops > Add home_offset[Z_AXIS]:", home_offset[Z_AXIS]);
6101
+          SERIAL_EOL;
6102
+        #endif
6103
+        negative_z_offset += home_offset[Z_AXIS];
6104
+      }
5805 6105
     #endif
5806 6106
     NOLESS(target[Z_AXIS], min_pos[Z_AXIS] + negative_z_offset);
5807 6107
   }

Loading…
取消
儲存