Selaa lähdekoodia

Debug messages for homing and leveling

Scott Lahteine 10 vuotta sitten
vanhempi
commit
194f98ff95
1 muutettua tiedostoa jossa 306 lisäystä ja 6 poistoa
  1. 306
    6
      Marlin/Marlin_main.cpp

+ 306
- 6
Marlin/Marlin_main.cpp Näytä tiedosto

1033
 
1033
 
1034
 #endif //DUAL_X_CARRIAGE
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
 static void set_axis_is_at_home(AxisEnum axis) {
1049
 static void set_axis_is_at_home(AxisEnum axis) {
1037
 
1050
 
1038
   #if ENABLED(DUAL_X_CARRIAGE)
1051
   #if ENABLED(DUAL_X_CARRIAGE)
1098
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1111
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1099
       if (axis == Z_AXIS) current_position[Z_AXIS] -= zprobe_zoffset;
1112
       if (axis == Z_AXIS) current_position[Z_AXIS] -= zprobe_zoffset;
1100
     #endif
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
   saved_feedrate_multiplier = feedrate_multiplier;
1162
   saved_feedrate_multiplier = feedrate_multiplier;
1144
   feedrate_multiplier = 100;
1163
   feedrate_multiplier = 100;
1145
   refresh_cmd_timeout();
1164
   refresh_cmd_timeout();
1165
+  #ifdef DEBUG_LEVELING
1166
+    SERIAL_ECHOLNPGM("setup_for_endstop_move > enable_endstops(true)");
1167
+  #endif
1146
   enable_endstops(true);
1168
   enable_endstops(true);
1147
 }
1169
 }
1148
 
1170
 
1153
      * Calculate delta, start a line, and set current_position to destination
1175
      * Calculate delta, start a line, and set current_position to destination
1154
      */
1176
      */
1155
     void prepare_move_raw() {
1177
     void prepare_move_raw() {
1178
+      #ifdef DEBUG_LEVELING
1179
+        print_xyz("prepare_move_raw > destination", destination);
1180
+      #endif
1156
       refresh_cmd_timeout();
1181
       refresh_cmd_timeout();
1157
       calculate_delta(destination);
1182
       calculate_delta(destination);
1158
       plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], (feedrate/60)*(feedrate_multiplier/100.0), active_extruder);
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
         current_position[Y_AXIS] = corrected_position.y;
1205
         current_position[Y_AXIS] = corrected_position.y;
1181
         current_position[Z_AXIS] = corrected_position.z;
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
         sync_plan_position();
1212
         sync_plan_position();
1184
       }
1213
       }
1185
 
1214
 
1209
       current_position[Y_AXIS] = corrected_position.y;
1238
       current_position[Y_AXIS] = corrected_position.y;
1210
       current_position[Z_AXIS] = corrected_position.z;
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
       sync_plan_position();
1245
       sync_plan_position();
1213
     }
1246
     }
1214
 
1247
 
1221
       float start_z = current_position[Z_AXIS];
1254
       float start_z = current_position[Z_AXIS];
1222
       long start_steps = st_get_position(Z_AXIS);
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
       // move down slowly until you find the bed
1261
       // move down slowly until you find the bed
1225
       feedrate = homing_feedrate[Z_AXIS] / 4;
1262
       feedrate = homing_feedrate[Z_AXIS] / 4;
1226
       destination[Z_AXIS] = -10;
1263
       destination[Z_AXIS] = -10;
1232
       long stop_steps = st_get_position(Z_AXIS);
1269
       long stop_steps = st_get_position(Z_AXIS);
1233
       float mm = start_z - float(start_steps - stop_steps) / axis_steps_per_unit[Z_AXIS];
1270
       float mm = start_z - float(start_steps - stop_steps) / axis_steps_per_unit[Z_AXIS];
1234
       current_position[Z_AXIS] = mm;
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
       sync_plan_position_delta();
1277
       sync_plan_position_delta();
1236
       
1278
       
1237
     #else // !DELTA
1279
     #else // !DELTA
1265
       // Get the current stepper position after bumping an endstop
1307
       // Get the current stepper position after bumping an endstop
1266
       current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1308
       current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1267
       sync_plan_position();
1309
       sync_plan_position();
1310
+
1311
+      #ifdef DEBUG_LEVELING
1312
+        print_xyz("run_z_probe > current_position", current_position);
1313
+      #endif
1268
       
1314
       
1269
     #endif // !DELTA
1315
     #endif // !DELTA
1270
   }
1316
   }
1276
   static void do_blocking_move_to(float x, float y, float z) {
1322
   static void do_blocking_move_to(float x, float y, float z) {
1277
     float oldFeedRate = feedrate;
1323
     float oldFeedRate = feedrate;
1278
 
1324
 
1325
+    #ifdef DEBUG_LEVELING
1326
+      print_xyz("do_blocking_move_to", x, y, z);
1327
+    #endif
1328
+
1279
     #if ENABLED(DELTA)
1329
     #if ENABLED(DELTA)
1280
 
1330
 
1281
       feedrate = XY_TRAVEL_SPEED;
1331
       feedrate = XY_TRAVEL_SPEED;
1312
 
1362
 
1313
   static void clean_up_after_endstop_move() {
1363
   static void clean_up_after_endstop_move() {
1314
     #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
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
       enable_endstops(false);
1368
       enable_endstops(false);
1316
     #endif
1369
     #endif
1317
     feedrate = saved_feedrate;
1370
     feedrate = saved_feedrate;
1321
 
1374
 
1322
   static void deploy_z_probe() {
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
     #if HAS_SERVO_ENDSTOPS
1381
     #if HAS_SERVO_ENDSTOPS
1325
 
1382
 
1326
       // Engage Z Servo endstop if enabled
1383
       // Engage Z Servo endstop if enabled
1411
 
1468
 
1412
   static void stow_z_probe(bool doRaise=true) {
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
     #if HAS_SERVO_ENDSTOPS
1475
     #if HAS_SERVO_ENDSTOPS
1415
 
1476
 
1416
       // Retract Z Servo endstop if enabled
1477
       // Retract Z Servo endstop if enabled
1418
 
1479
 
1419
         #if Z_RAISE_AFTER_PROBING > 0
1480
         #if Z_RAISE_AFTER_PROBING > 0
1420
           if (doRaise) {
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
             do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1488
             do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1422
             st_synchronize();
1489
             st_synchronize();
1423
           }
1490
           }
1506
 
1573
 
1507
   // Probe bed height at position (x,y), returns the measured z value
1574
   // Probe bed height at position (x,y), returns the measured z value
1508
   static float probe_pt(float x, float y, float z_before, ProbeAction probe_action=ProbeDeployAndStow, int verbose_level=1) {
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
     // Move Z up to the z_before height, then move the Z probe to the given XY
1591
     // Move Z up to the z_before height, then move the Z probe to the given XY
1510
     do_blocking_move_to_z(z_before); // this also updates current_position
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
     do_blocking_move_to_xy(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER); // this also updates current_position
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
     #if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
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
     #endif
1609
     #endif
1516
 
1610
 
1517
     run_z_probe();
1611
     run_z_probe();
1518
     float measured_z = current_position[Z_AXIS];
1612
     float measured_z = current_position[Z_AXIS];
1519
 
1613
 
1520
     #if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
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
     #endif
1621
     #endif
1523
 
1622
 
1524
     if (verbose_level > 2) {
1623
     if (verbose_level > 2) {
1530
       SERIAL_PROTOCOL_F(measured_z, 3);
1629
       SERIAL_PROTOCOL_F(measured_z, 3);
1531
       SERIAL_EOL;
1630
       SERIAL_EOL;
1532
     }
1631
     }
1632
+
1633
+    #ifdef DEBUG_LEVELING
1634
+      SERIAL_ECHOLNPGM("<<< probe_pt");
1635
+    #endif
1636
+
1533
     return measured_z;
1637
     return measured_z;
1534
   }
1638
   }
1535
 
1639
 
1585
 
1689
 
1586
     // Reset calibration results to zero.
1690
     // Reset calibration results to zero.
1587
     void reset_bed_level() {
1691
     void reset_bed_level() {
1692
+      #ifdef DEBUG_LEVELING
1693
+        SERIAL_ECHOLNPGM("reset_bed_level");
1694
+      #endif
1588
       for (int y = 0; y < AUTO_BED_LEVELING_GRID_POINTS; y++) {
1695
       for (int y = 0; y < AUTO_BED_LEVELING_GRID_POINTS; y++) {
1589
         for (int x = 0; x < AUTO_BED_LEVELING_GRID_POINTS; x++) {
1696
         for (int x = 0; x < AUTO_BED_LEVELING_GRID_POINTS; x++) {
1590
           bed_level[x][y] = 0.0;
1697
           bed_level[x][y] = 0.0;
1620
    * offset[in]   The additional distance to move to adjust docking location
1727
    * offset[in]   The additional distance to move to adjust docking location
1621
    */
1728
    */
1622
   static void dock_sled(bool dock, int offset=0) {
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
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
1734
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
1624
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1735
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1625
       SERIAL_ECHO_START;
1736
       SERIAL_ECHO_START;
1654
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1765
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1655
 
1766
 
1656
 static void homeaxis(AxisEnum axis) {
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
   #define HOMEAXIS_DO(LETTER) \
1773
   #define HOMEAXIS_DO(LETTER) \
1658
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
1774
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
1659
 
1775
 
1706
     current_position[axis] = 0;
1822
     current_position[axis] = 0;
1707
     sync_plan_position();
1823
     sync_plan_position();
1708
 
1824
 
1825
+    #ifdef DEBUG_LEVELING
1826
+      SERIAL_ECHOLNPGM("> enable_endstops(false)");
1827
+    #endif
1709
     enable_endstops(false); // Disable endstops while moving away
1828
     enable_endstops(false); // Disable endstops while moving away
1710
 
1829
 
1711
     // Move away from the endstop by the axis HOME_BUMP_MM
1830
     // Move away from the endstop by the axis HOME_BUMP_MM
1713
     line_to_destination();
1832
     line_to_destination();
1714
     st_synchronize();
1833
     st_synchronize();
1715
 
1834
 
1835
+    #ifdef DEBUG_LEVELING
1836
+      SERIAL_ECHOLNPGM("> enable_endstops(true)");
1837
+    #endif
1716
     enable_endstops(true); // Enable endstops for next homing move
1838
     enable_endstops(true); // Enable endstops for next homing move
1717
 
1839
 
1718
     // Slow down the feedrate for the next move
1840
     // Slow down the feedrate for the next move
1723
     line_to_destination();
1845
     line_to_destination();
1724
     st_synchronize();
1846
     st_synchronize();
1725
 
1847
 
1848
+    #ifdef DEBUG_LEVELING
1849
+      print_xyz("> TRIGGER ENDSTOP > current_position", current_position);
1850
+    #endif
1851
+
1726
     #if ENABLED(Z_DUAL_ENDSTOPS)
1852
     #if ENABLED(Z_DUAL_ENDSTOPS)
1727
       if (axis == Z_AXIS) {
1853
       if (axis == Z_AXIS) {
1728
         float adj = fabs(z_endstop_adj);
1854
         float adj = fabs(z_endstop_adj);
1751
     #if ENABLED(DELTA)
1877
     #if ENABLED(DELTA)
1752
       // retrace by the amount specified in endstop_adj
1878
       // retrace by the amount specified in endstop_adj
1753
       if (endstop_adj[axis] * axis_home_dir < 0) {
1879
       if (endstop_adj[axis] * axis_home_dir < 0) {
1880
+        #ifdef DEBUG_LEVELING
1881
+          SERIAL_ECHOLNPGM("> enable_endstops(false)");
1882
+        #endif
1754
         enable_endstops(false); // Disable endstops while moving away
1883
         enable_endstops(false); // Disable endstops while moving away
1755
         sync_plan_position();
1884
         sync_plan_position();
1756
         destination[axis] = endstop_adj[axis];
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
         line_to_destination();
1890
         line_to_destination();
1758
         st_synchronize();
1891
         st_synchronize();
1892
+        #ifdef DEBUG_LEVELING
1893
+          SERIAL_ECHOLNPGM("> enable_endstops(true)");
1894
+        #endif
1759
         enable_endstops(true); // Enable endstops for next homing move
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
     #endif
1903
     #endif
1762
 
1904
 
1763
     // Set the axis position to its home position (plus home offsets)
1905
     // Set the axis position to its home position (plus home offsets)
1764
     set_axis_is_at_home(axis);
1906
     set_axis_is_at_home(axis);
1765
     sync_plan_position();
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
     destination[axis] = current_position[axis];
1913
     destination[axis] = current_position[axis];
1768
     feedrate = 0.0;
1914
     feedrate = 0.0;
1769
     endstops_hit_on_purpose(); // clear endstop hit flags
1915
     endstops_hit_on_purpose(); // clear endstop hit flags
1780
 
1926
 
1781
       // Deploy a Z probe if there is one, and homing towards the bed
1927
       // Deploy a Z probe if there is one, and homing towards the bed
1782
       if (axis == Z_AXIS) {
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
       else
1936
       else
1786
 
1937
 
1789
     {
1940
     {
1790
       #if HAS_SERVO_ENDSTOPS
1941
       #if HAS_SERVO_ENDSTOPS
1791
         // Retract Servo endstop if enabled
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
           servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
1947
           servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
1948
+        }
1794
       #endif
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
 #if ENABLED(FWRETRACT)
1961
 #if ENABLED(FWRETRACT)
1996
  */
2157
  */
1997
 inline void gcode_G28() {
2158
 inline void gcode_G28() {
1998
 
2159
 
2160
+  #ifdef DEBUG_LEVELING
2161
+    SERIAL_ECHOLNPGM("gcode_G28 >>>");
2162
+  #endif
2163
+
1999
   // Wait for planner moves to finish!
2164
   // Wait for planner moves to finish!
2000
   st_synchronize();
2165
   st_synchronize();
2001
 
2166
 
2044
 
2209
 
2045
     sync_plan_position_delta();
2210
     sync_plan_position_delta();
2046
 
2211
 
2212
+    #ifdef DEBUG_LEVELING
2213
+      print_xyz("(DELTA) > current_position", current_position);
2214
+    #endif
2215
+
2047
   #else // NOT DELTA
2216
   #else // NOT DELTA
2048
 
2217
 
2049
     bool  homeX = code_seen(axis_codes[X_AXIS]),
2218
     bool  homeX = code_seen(axis_codes[X_AXIS]),
2057
       #if Z_HOME_DIR > 0  // If homing away from BED do Z first
2226
       #if Z_HOME_DIR > 0  // If homing away from BED do Z first
2058
 
2227
 
2059
         HOMEAXIS(Z);
2228
         HOMEAXIS(Z);
2229
+        #ifdef DEBUG_LEVELING
2230
+          print_xyz("> HOMEAXIS(Z) > current_position", current_position);
2231
+        #endif
2060
 
2232
 
2061
       #elif DISABLED(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
2233
       #elif DISABLED(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
2062
 
2234
 
2063
         // Raise Z before homing any other axes
2235
         // Raise Z before homing any other axes
2064
         // (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
2236
         // (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
2065
         destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
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
         feedrate = max_feedrate[Z_AXIS] * 60;
2243
         feedrate = max_feedrate[Z_AXIS] * 60;
2067
         line_to_destination();
2244
         line_to_destination();
2068
         st_synchronize();
2245
         st_synchronize();
2099
         set_axis_is_at_home(Y_AXIS);
2276
         set_axis_is_at_home(Y_AXIS);
2100
         sync_plan_position();
2277
         sync_plan_position();
2101
 
2278
 
2279
+        #ifdef DEBUG_LEVELING
2280
+          print_xyz("> QUICK_HOME > current_position 1", current_position);
2281
+        #endif
2282
+
2102
         destination[X_AXIS] = current_position[X_AXIS];
2283
         destination[X_AXIS] = current_position[X_AXIS];
2103
         destination[Y_AXIS] = current_position[Y_AXIS];
2284
         destination[Y_AXIS] = current_position[Y_AXIS];
2104
         line_to_destination();
2285
         line_to_destination();
2111
         #if DISABLED(SCARA)
2292
         #if DISABLED(SCARA)
2112
           current_position[Z_AXIS] = destination[Z_AXIS];
2293
           current_position[Z_AXIS] = destination[Z_AXIS];
2113
         #endif
2294
         #endif
2295
+
2296
+        #ifdef DEBUG_LEVELING
2297
+          print_xyz("> QUICK_HOME > current_position 2", current_position);
2298
+        #endif
2114
       }
2299
       }
2115
 
2300
 
2116
     #endif // QUICK_HOME
2301
     #endif // QUICK_HOME
2137
       #else
2322
       #else
2138
         HOMEAXIS(X);
2323
         HOMEAXIS(X);
2139
       #endif
2324
       #endif
2325
+      #ifdef DEBUG_LEVELING
2326
+        print_xyz("> homeX", current_position);
2327
+      #endif
2140
     }
2328
     }
2141
 
2329
 
2142
     #if DISABLED(HOME_Y_BEFORE_X)
2330
     #if DISABLED(HOME_Y_BEFORE_X)
2143
       // Home Y
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
     #endif
2338
     #endif
2146
 
2339
 
2147
     // Home Z last if homing towards the bed
2340
     // Home Z last if homing towards the bed
2151
 
2344
 
2152
         #if ENABLED(Z_SAFE_HOMING)
2345
         #if ENABLED(Z_SAFE_HOMING)
2153
 
2346
 
2347
+          #ifdef DEBUG_LEVELING
2348
+            SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>");
2349
+          #endif
2350
+
2154
           if (home_all_axis) {
2351
           if (home_all_axis) {
2155
 
2352
 
2156
             current_position[Z_AXIS] = 0;
2353
             current_position[Z_AXIS] = 0;
2165
             destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
2362
             destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
2166
             destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
2363
             destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
2167
             feedrate = XY_TRAVEL_SPEED;
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
             // This could potentially move X, Y, Z all together
2373
             // This could potentially move X, Y, Z all together
2169
             line_to_destination();
2374
             line_to_destination();
2170
             st_synchronize();
2375
             st_synchronize();
2197
                 // NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
2402
                 // NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
2198
                 destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
2403
                 destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);
2199
                 feedrate = max_feedrate[Z_AXIS] * 60;  // feedrate (mm/m) = max_feedrate (mm/s)
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
                 line_to_destination();
2413
                 line_to_destination();
2201
                 st_synchronize();
2414
                 st_synchronize();
2202
 
2415
 
2217
 
2430
 
2218
           } // !home_all_axes && homeZ
2431
           } // !home_all_axes && homeZ
2219
 
2432
 
2433
+          #ifdef DEBUG_LEVELING
2434
+            SERIAL_ECHOLNPGM("<<< Z_SAFE_HOMING");
2435
+          #endif
2436
+
2220
         #else // !Z_SAFE_HOMING
2437
         #else // !Z_SAFE_HOMING
2221
 
2438
 
2222
           HOMEAXIS(Z);
2439
           HOMEAXIS(Z);
2223
 
2440
 
2224
         #endif // !Z_SAFE_HOMING
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
       } // home_all_axis || homeZ
2447
       } // home_all_axis || homeZ
2227
 
2448
 
2228
     #endif // Z_HOME_DIR < 0
2449
     #endif // Z_HOME_DIR < 0
2236
   #endif
2457
   #endif
2237
 
2458
 
2238
   #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
2459
   #if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
2460
+    #ifdef DEBUG_LEVELING
2461
+      SERIAL_ECHOLNPGM("ENDSTOPS_ONLY_FOR_HOMING enable_endstops(false)");
2462
+    #endif
2239
     enable_endstops(false);
2463
     enable_endstops(false);
2240
   #endif
2464
   #endif
2241
 
2465
 
2251
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2475
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2252
       sync_plan_position();
2476
       sync_plan_position();
2253
       mbl.active = 1;
2477
       mbl.active = 1;
2478
+      #ifdef DEBUG_LEVELING
2479
+        print_xyz("mbl_was_active > current_position", current_position);
2480
+      #endif
2254
     }
2481
     }
2255
   #endif
2482
   #endif
2256
 
2483
 
2258
   feedrate_multiplier = saved_feedrate_multiplier;
2485
   feedrate_multiplier = saved_feedrate_multiplier;
2259
   refresh_cmd_timeout();
2486
   refresh_cmd_timeout();
2260
   endstops_hit_on_purpose(); // clear endstop hit flags
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
 #if ENABLED(MESH_BED_LEVELING)
2495
 #if ENABLED(MESH_BED_LEVELING)
2443
    */
2675
    */
2444
   inline void gcode_G29() {
2676
   inline void gcode_G29() {
2445
 
2677
 
2678
+    #ifdef DEBUG_LEVELING
2679
+      SERIAL_ECHOLNPGM("gcode_G29 >>>");
2680
+    #endif
2681
+
2446
     // Don't allow auto-leveling without homing first
2682
     // Don't allow auto-leveling without homing first
2447
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
2683
     if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
2448
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
2684
       LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
2601
           float measured_z,
2837
           float measured_z,
2602
                 z_before = probePointCounter ? Z_RAISE_BETWEEN_PROBINGS + current_position[Z_AXIS] : Z_RAISE_BEFORE_PROBING;
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
           #if ENABLED(DELTA)
2853
           #if ENABLED(DELTA)
2605
             // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
2854
             // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
2606
             float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe);
2855
             float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe);
2638
         } //xProbe
2887
         } //xProbe
2639
       } //yProbe
2888
       } //yProbe
2640
 
2889
 
2890
+      #ifdef DEBUG_LEVELING
2891
+        print_xyz("> probing complete > current_position", current_position);
2892
+      #endif
2893
+
2641
       clean_up_after_endstop_move();
2894
       clean_up_after_endstop_move();
2642
 
2895
 
2643
       #if ENABLED(DELTA)
2896
       #if ENABLED(DELTA)
2734
 
2987
 
2735
     #else // !AUTO_BED_LEVELING_GRID
2988
     #else // !AUTO_BED_LEVELING_GRID
2736
 
2989
 
2990
+      #ifdef DEBUG_LEVELING
2991
+        SERIAL_ECHOLNPGM("> 3-point Leveling");
2992
+      #endif
2993
+
2737
       // Actions for each probe
2994
       // Actions for each probe
2738
       ProbeAction p1, p2, p3;
2995
       ProbeAction p1, p2, p3;
2739
       if (deploy_probe_for_each_reading)
2996
       if (deploy_probe_for_each_reading)
2763
               z_tmp = current_position[Z_AXIS],
3020
               z_tmp = current_position[Z_AXIS],
2764
               real_z = st_get_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
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
         apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); // Apply the correction sending the Z probe offset
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
         // Get the current Z position and send it to the planner.
3032
         // Get the current Z position and send it to the planner.
2781
         //      adjust for inaccurate endstops, not for reasonably accurate probes. If it were
3045
         //      adjust for inaccurate endstops, not for reasonably accurate probes. If it were
2782
         //      added here, it could be seen as a compensating factor for the Z probe.
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
         current_position[Z_AXIS] = -zprobe_zoffset + (z_tmp - real_z)
3053
         current_position[Z_AXIS] = -zprobe_zoffset + (z_tmp - real_z)
2785
           #if HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED)
3054
           #if HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED)
2786
              + Z_RAISE_AFTER_PROBING
3055
              + Z_RAISE_AFTER_PROBING
2788
           ;
3057
           ;
2789
         // current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home"
3058
         // current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home"
2790
         sync_plan_position();
3059
         sync_plan_position();
3060
+
3061
+        #ifdef DEBUG_LEVELING
3062
+          print_xyz("> corrected Z in G29", current_position);
3063
+        #endif
2791
       }
3064
       }
2792
     #endif // !DELTA
3065
     #endif // !DELTA
2793
 
3066
 
2798
     #endif
3071
     #endif
2799
 
3072
 
2800
     #ifdef Z_PROBE_END_SCRIPT
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
       enqueuecommands_P(PSTR(Z_PROBE_END_SCRIPT));
3078
       enqueuecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2802
       st_synchronize();
3079
       st_synchronize();
2803
     #endif
3080
     #endif
3081
+
3082
+    #ifdef DEBUG_LEVELING
3083
+      SERIAL_ECHOLNPGM("<<< gcode_G29");
3084
+    #endif
3085
+
2804
   }
3086
   }
2805
 
3087
 
2806
   #if DISABLED(Z_PROBE_SLED)
3088
   #if DISABLED(Z_PROBE_SLED)
4095
    * M666: Set delta endstop adjustment
4377
    * M666: Set delta endstop adjustment
4096
    */
4378
    */
4097
   inline void gcode_M666() {
4379
   inline void gcode_M666() {
4380
+    #ifdef DEBUG_LEVELING
4381
+      SERIAL_ECHOLNPGM(">>> gcode_M666");
4382
+    #endif
4098
     for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4383
     for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4099
       if (code_seen(axis_codes[i])) {
4384
       if (code_seen(axis_codes[i])) {
4100
         endstop_adj[i] = code_value();
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
 #elif ENABLED(Z_DUAL_ENDSTOPS) // !DELTA && ENABLED(Z_DUAL_ENDSTOPS)
4398
 #elif ENABLED(Z_DUAL_ENDSTOPS) // !DELTA && ENABLED(Z_DUAL_ENDSTOPS)
4105
   /**
4399
   /**
5801
     float negative_z_offset = 0;
6095
     float negative_z_offset = 0;
5802
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
6096
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
5803
       if (zprobe_zoffset < 0) negative_z_offset += zprobe_zoffset;
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
     #endif
6105
     #endif
5806
     NOLESS(target[Z_AXIS], min_pos[Z_AXIS] + negative_z_offset);
6106
     NOLESS(target[Z_AXIS], min_pos[Z_AXIS] + negative_z_offset);
5807
   }
6107
   }

Loading…
Peruuta
Tallenna