Kaynağa Gözat

G29 P2 & P4 bug fixes & improvements

Bob-the-Kuhn 7 yıl önce
ebeveyn
işleme
e5a27d9f36
1 değiştirilmiş dosya ile 103 ekleme ve 63 silme
  1. 103
    63
      Marlin/ubl_G29.cpp

+ 103
- 63
Marlin/ubl_G29.cpp Dosyayı Görüntüle

@@ -31,10 +31,14 @@
31 31
   #include "hex_print_routines.h"
32 32
   #include "configuration_store.h"
33 33
   #include "ultralcd.h"
34
+  #include "stepper.h"
34 35
 
35 36
   #include <math.h>
36 37
   #include "least_squares_fit.h"
37 38
 
39
+  extern float destination[XYZE];
40
+  extern float current_position[XYZE];
41
+
38 42
   void lcd_return_to_status();
39 43
   bool lcd_clicked();
40 44
   void lcd_implementation_clear();
@@ -317,6 +321,7 @@
317 321
 
318 322
   void __attribute__((optimize("O0"))) gcode_G29() {
319 323
 
324
+
320 325
     if (ubl.eeprom_start < 0) {
321 326
       SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
322 327
       SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
@@ -435,8 +440,8 @@
435 440
             // have Delta printers default to the center of the bed.
436 441
             // For now, until that is decided, it can be forced with the X
437 442
             // and Y parameters.
438
-            x_pos = X_PROBE_OFFSET_FROM_EXTRUDER > 0 ? X_MAX_POS : X_MIN_POS;
439
-            y_pos = Y_PROBE_OFFSET_FROM_EXTRUDER < 0 ? Y_MAX_POS : Y_MIN_POS;
443
+            x_pos = X_PROBE_OFFSET_FROM_EXTRUDER > 0 ? UBL_MESH_MAX_X : UBL_MESH_MIN_X;
444
+            y_pos = Y_PROBE_OFFSET_FROM_EXTRUDER < 0 ? UBL_MESH_MAX_Y : UBL_MESH_MIN_Y;
440 445
           }
441 446
 
442 447
           if (code_seen('C')) {
@@ -455,8 +460,9 @@
455 460
             }
456 461
           }
457 462
           manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M'));
458
-
459
-        } break;
463
+          SERIAL_PROTOCOLLNPGM("G29 P2 finished");
464
+          }
465
+          break;
460 466
 
461 467
         case 3: {
462 468
           //
@@ -900,6 +906,10 @@
900 906
   }
901 907
 
902 908
   float use_encoder_wheel_to_measure_point() {
909
+
910
+    while (ubl_lcd_clicked()) delay(50);;  // wait for user to release encoder wheel
911
+    delay(50);  // debounce
912
+
903 913
     KEEPALIVE_STATE(PAUSED_FOR_USER);
904 914
     while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
905 915
       idle();
@@ -917,15 +927,18 @@
917 927
     ubl.has_control_of_lcd_panel = true;
918 928
     ubl.save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
919 929
 
920
-    SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
921 930
     do_blocking_move_to_z(in_height);
922
-    do_blocking_move_to_xy((float(X_MAX_POS) - float(X_MIN_POS)) / 2.0, (float(Y_MAX_POS) - float(Y_MIN_POS)) / 2.0);
931
+    do_blocking_move_to_xy((float(UBL_MESH_MAX_X) - float(UBL_MESH_MIN_X)) / 2.0, (float(UBL_MESH_MAX_Y) - float(UBL_MESH_MIN_Y)) / 2.0);
923 932
       //, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])/2.0);
924 933
 
934
+    stepper.synchronize();
935
+    SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
936
+
937
+
925 938
     const float z1 = use_encoder_wheel_to_measure_point();
926 939
     do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
927
-    ubl.has_control_of_lcd_panel = false;
928 940
 
941
+    stepper.synchronize();
929 942
     SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
930 943
     const float z2 = use_encoder_wheel_to_measure_point();
931 944
     do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
@@ -935,6 +948,8 @@
935 948
       SERIAL_PROTOCOL_F(abs(z1 - z2), 6);
936 949
       SERIAL_PROTOCOLLNPGM("mm thick.");
937 950
     }
951
+    ubl.has_control_of_lcd_panel = false;
952
+
938 953
     ubl.restore_ubl_active_state_and_leave();
939 954
     return abs(z1 - z2);
940 955
   }
@@ -957,7 +972,7 @@
957 972
                   rawy = pgm_read_float(&(ubl.mesh_index_to_ypos[location.y_index]));
958 973
 
959 974
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
960
-      if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) {
975
+      if (!WITHIN(rawx, UBL_MESH_MIN_X, UBL_MESH_MAX_X) || !WITHIN(rawy, UBL_MESH_MIN_Y, UBL_MESH_MAX_Y)) {
961 976
         SERIAL_ERROR_START;
962 977
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
963 978
         ubl.has_control_of_lcd_panel = false;
@@ -984,6 +999,10 @@
984 999
 
985 1000
       if (do_ubl_mesh_map) ubl.display_map(map_type);  // show user where we're probing
986 1001
 
1002
+
1003
+      while (ubl_lcd_clicked()) delay(50);;  // wait for user to release encoder wheel
1004
+      delay(50);  // debounce
1005
+
987 1006
       while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
988 1007
         idle();
989 1008
         if (ubl.encoder_diff) {
@@ -992,6 +1011,7 @@
992 1011
         }
993 1012
       }
994 1013
 
1014
+
995 1015
       const millis_t nxt = millis() + 1500L;
996 1016
       while (ubl_lcd_clicked()) {     // debounce and watch for abort
997 1017
         idle();
@@ -1038,6 +1058,7 @@
1038 1058
     y_flag = code_seen('Y') && code_has_value();
1039 1059
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
1040 1060
 
1061
+
1041 1062
     repeat_flag = code_seen('R');
1042 1063
     if (repeat_flag) {
1043 1064
       repetition_cnt = code_has_value() ? code_value_int() : (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y);
@@ -1436,33 +1457,52 @@
1436 1457
         goto FINE_TUNE_EXIT;
1437 1458
       }
1438 1459
 
1439
-      do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1440
-      do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1441
-
1442 1460
       float new_z = ubl.z_values[location.x_index][location.y_index];
1443 1461
 
1444
-      round_off = (int32_t)(new_z * 1000.0);    // we chop off the last digits just to be clean. We are rounding to the
1445
-      new_z = float(round_off) / 1000.0;
1462
+      if (!isnan(new_z)) {  //can't fine tune a point that hasn't been probed
1446 1463
 
1447
-      KEEPALIVE_STATE(PAUSED_FOR_USER);
1448
-      ubl.has_control_of_lcd_panel = true;
1464
+        do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1465
+        do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1449 1466
 
1450
-      if (do_ubl_mesh_map) ubl.display_map(map_type);  // show the user which point is being adjusted
1451 1467
 
1452
-      lcd_implementation_clear();
1453
-      lcd_mesh_edit_setup(new_z);
1454 1468
 
1455
-      do {
1456
-        new_z = lcd_mesh_edit();
1457
-        idle();
1458
-      } while (!ubl_lcd_clicked());
1459 1469
 
1460
-      lcd_return_to_status();
1461 1470
 
1462
-      ubl.has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked.
1463
-                                           // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
1464
-                                           // or here.
1465 1471
 
1472
+        round_off = (int32_t)(new_z * 1000.0);    // we chop off the last digits just to be clean. We are rounding to the
1473
+        new_z = float(round_off) / 1000.0;
1474
+
1475
+
1476
+
1477
+        KEEPALIVE_STATE(PAUSED_FOR_USER);
1478
+        ubl.has_control_of_lcd_panel = true;
1479
+
1480
+
1481
+        if (do_ubl_mesh_map) ubl.display_map(map_type);  // show the user which point is being adjusted
1482
+
1483
+
1484
+
1485
+        lcd_implementation_clear();
1486
+
1487
+        lcd_mesh_edit_setup(new_z);
1488
+
1489
+
1490
+
1491
+        do {
1492
+          new_z = lcd_mesh_edit();
1493
+          idle();
1494
+        } while (!ubl_lcd_clicked());
1495
+
1496
+
1497
+        lcd_return_to_status();
1498
+
1499
+
1500
+
1501
+
1502
+        ubl.has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked.
1503
+                                             // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
1504
+                                             // or here.
1505
+      }
1466 1506
       const millis_t nxt = millis() + 1500UL;
1467 1507
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1468 1508
         idle();
@@ -1630,10 +1670,10 @@
1630 1670
               SERIAL_ECHOPGM("   final >>>---> ");
1631 1671
               SERIAL_PROTOCOL_F( measured_z, 7);
1632 1672
               SERIAL_ECHOPGM("\n");
1633
-        }
1673
+            }
1634 1674
           #endif
1635 1675
           incremental_LSF(&lsf_results, x, y, measured_z);
1636
-      }
1676
+        }
1637 1677
 
1638 1678
         zig_zag = !zig_zag;
1639 1679
       }
@@ -1647,7 +1687,7 @@
1647 1687
       SERIAL_ECHOPGM("  D=");
1648 1688
       SERIAL_PROTOCOL_F( lsf_results.D, 7);
1649 1689
       SERIAL_CHAR('\n');
1650
-        }
1690
+    }
1651 1691
 
1652 1692
     normal = vector_3( lsf_results.A, lsf_results.B, 1.0000);
1653 1693
     normal = normal.get_normal();
@@ -1660,46 +1700,46 @@
1660 1700
       SERIAL_ECHOPGM(",");
1661 1701
       SERIAL_PROTOCOL_F( normal.z, 7);
1662 1702
       SERIAL_ECHOPGM("]\n");
1663
-      }
1703
+    }
1664 1704
 
1665 1705
     rotation = matrix_3x3::create_look_at( vector_3( lsf_results.A,  lsf_results.B, 1));
1666 1706
 
1667 1707
     for (i = 0; i < GRID_MAX_POINTS_X; i++) {
1668 1708
       for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
1669 1709
         float x_tmp, y_tmp, z_tmp;
1670
-          x_tmp = pgm_read_float(&(ubl.mesh_index_to_xpos[i]));
1671
-          y_tmp = pgm_read_float(&(ubl.mesh_index_to_ypos[j]));
1672
-          z_tmp = ubl.z_values[i][j];
1673
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
1674
-            if (DEBUGGING(LEVELING)) {
1675
-              SERIAL_ECHOPGM("before rotation = [");
1676
-              SERIAL_PROTOCOL_F( x_tmp, 7);
1677
-              SERIAL_ECHOPGM(",");
1678
-              SERIAL_PROTOCOL_F( y_tmp, 7);
1679
-              SERIAL_ECHOPGM(",");
1680
-              SERIAL_PROTOCOL_F( z_tmp, 7);
1681
-              SERIAL_ECHOPGM("]   ---> ");
1682
-              safe_delay(20);
1683
-        }
1684
-          #endif
1685
-          apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
1686
-          #if ENABLED(DEBUG_LEVELING_FEATURE)
1687
-            if (DEBUGGING(LEVELING)) {
1688
-              SERIAL_ECHOPGM("after rotation = [");
1689
-              SERIAL_PROTOCOL_F( x_tmp, 7);
1690
-              SERIAL_ECHOPGM(",");
1691
-              SERIAL_PROTOCOL_F( y_tmp, 7);
1692
-              SERIAL_ECHOPGM(",");
1693
-              SERIAL_PROTOCOL_F( z_tmp, 7);
1694
-              SERIAL_ECHOPGM("]\n");
1695
-              safe_delay(55);
1696
-      }
1710
+        x_tmp = pgm_read_float(&(ubl.mesh_index_to_xpos[i]));
1711
+        y_tmp = pgm_read_float(&(ubl.mesh_index_to_ypos[j]));
1712
+        z_tmp = ubl.z_values[i][j];
1713
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
1714
+          if (DEBUGGING(LEVELING)) {
1715
+            SERIAL_ECHOPGM("before rotation = [");
1716
+            SERIAL_PROTOCOL_F( x_tmp, 7);
1717
+            SERIAL_ECHOPGM(",");
1718
+            SERIAL_PROTOCOL_F( y_tmp, 7);
1719
+            SERIAL_ECHOPGM(",");
1720
+            SERIAL_PROTOCOL_F( z_tmp, 7);
1721
+            SERIAL_ECHOPGM("]   ---> ");
1722
+            safe_delay(20);
1723
+          }
1724
+        #endif
1725
+        apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
1726
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
1727
+          if (DEBUGGING(LEVELING)) {
1728
+            SERIAL_ECHOPGM("after rotation = [");
1729
+            SERIAL_PROTOCOL_F( x_tmp, 7);
1730
+            SERIAL_ECHOPGM(",");
1731
+            SERIAL_PROTOCOL_F( y_tmp, 7);
1732
+            SERIAL_ECHOPGM(",");
1733
+            SERIAL_PROTOCOL_F( z_tmp, 7);
1734
+            SERIAL_ECHOPGM("]\n");
1735
+            safe_delay(55);
1736
+          }
1697 1737
 
1698
-      #endif
1738
+        #endif
1699 1739
 
1700
-          ubl.z_values[i][j] += z_tmp - lsf_results.D;
1701
-        }
1702
-        }
1740
+        ubl.z_values[i][j] += z_tmp - lsf_results.D;
1741
+      }
1742
+    }
1703 1743
 
1704 1744
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1705 1745
       if (DEBUGGING(LEVELING)) {
@@ -1723,7 +1763,7 @@
1723 1763
         SERIAL_CHAR('\n');
1724 1764
       }
1725 1765
     #endif
1726
-            return;
1727
-          }
1766
+    return;
1767
+  }
1728 1768
 
1729 1769
 #endif // AUTO_BED_LEVELING_UBL

Loading…
İptal
Kaydet