Browse Source

G29 P2 & P4 bug fixes & improvements

Bob-the-Kuhn 8 years ago
parent
commit
e5a27d9f36
1 changed files with 103 additions and 63 deletions
  1. 103
    63
      Marlin/ubl_G29.cpp

+ 103
- 63
Marlin/ubl_G29.cpp View File

31
   #include "hex_print_routines.h"
31
   #include "hex_print_routines.h"
32
   #include "configuration_store.h"
32
   #include "configuration_store.h"
33
   #include "ultralcd.h"
33
   #include "ultralcd.h"
34
+  #include "stepper.h"
34
 
35
 
35
   #include <math.h>
36
   #include <math.h>
36
   #include "least_squares_fit.h"
37
   #include "least_squares_fit.h"
37
 
38
 
39
+  extern float destination[XYZE];
40
+  extern float current_position[XYZE];
41
+
38
   void lcd_return_to_status();
42
   void lcd_return_to_status();
39
   bool lcd_clicked();
43
   bool lcd_clicked();
40
   void lcd_implementation_clear();
44
   void lcd_implementation_clear();
317
 
321
 
318
   void __attribute__((optimize("O0"))) gcode_G29() {
322
   void __attribute__((optimize("O0"))) gcode_G29() {
319
 
323
 
324
+
320
     if (ubl.eeprom_start < 0) {
325
     if (ubl.eeprom_start < 0) {
321
       SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
326
       SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
322
       SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
327
       SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
435
             // have Delta printers default to the center of the bed.
440
             // have Delta printers default to the center of the bed.
436
             // For now, until that is decided, it can be forced with the X
441
             // For now, until that is decided, it can be forced with the X
437
             // and Y parameters.
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
           if (code_seen('C')) {
447
           if (code_seen('C')) {
455
             }
460
             }
456
           }
461
           }
457
           manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M'));
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
         case 3: {
467
         case 3: {
462
           //
468
           //
900
   }
906
   }
901
 
907
 
902
   float use_encoder_wheel_to_measure_point() {
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
     KEEPALIVE_STATE(PAUSED_FOR_USER);
913
     KEEPALIVE_STATE(PAUSED_FOR_USER);
904
     while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
914
     while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
905
       idle();
915
       idle();
917
     ubl.has_control_of_lcd_panel = true;
927
     ubl.has_control_of_lcd_panel = true;
918
     ubl.save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
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
     do_blocking_move_to_z(in_height);
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
       //, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])/2.0);
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
     const float z1 = use_encoder_wheel_to_measure_point();
938
     const float z1 = use_encoder_wheel_to_measure_point();
926
     do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
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
     SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
942
     SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
930
     const float z2 = use_encoder_wheel_to_measure_point();
943
     const float z2 = use_encoder_wheel_to_measure_point();
931
     do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
944
     do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
935
       SERIAL_PROTOCOL_F(abs(z1 - z2), 6);
948
       SERIAL_PROTOCOL_F(abs(z1 - z2), 6);
936
       SERIAL_PROTOCOLLNPGM("mm thick.");
949
       SERIAL_PROTOCOLLNPGM("mm thick.");
937
     }
950
     }
951
+    ubl.has_control_of_lcd_panel = false;
952
+
938
     ubl.restore_ubl_active_state_and_leave();
953
     ubl.restore_ubl_active_state_and_leave();
939
     return abs(z1 - z2);
954
     return abs(z1 - z2);
940
   }
955
   }
957
                   rawy = pgm_read_float(&(ubl.mesh_index_to_ypos[location.y_index]));
972
                   rawy = pgm_read_float(&(ubl.mesh_index_to_ypos[location.y_index]));
958
 
973
 
959
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
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
         SERIAL_ERROR_START;
976
         SERIAL_ERROR_START;
962
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
977
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
963
         ubl.has_control_of_lcd_panel = false;
978
         ubl.has_control_of_lcd_panel = false;
984
 
999
 
985
       if (do_ubl_mesh_map) ubl.display_map(map_type);  // show user where we're probing
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
       while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
1006
       while (!ubl_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
988
         idle();
1007
         idle();
989
         if (ubl.encoder_diff) {
1008
         if (ubl.encoder_diff) {
992
         }
1011
         }
993
       }
1012
       }
994
 
1013
 
1014
+
995
       const millis_t nxt = millis() + 1500L;
1015
       const millis_t nxt = millis() + 1500L;
996
       while (ubl_lcd_clicked()) {     // debounce and watch for abort
1016
       while (ubl_lcd_clicked()) {     // debounce and watch for abort
997
         idle();
1017
         idle();
1038
     y_flag = code_seen('Y') && code_has_value();
1058
     y_flag = code_seen('Y') && code_has_value();
1039
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
1059
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
1040
 
1060
 
1061
+
1041
     repeat_flag = code_seen('R');
1062
     repeat_flag = code_seen('R');
1042
     if (repeat_flag) {
1063
     if (repeat_flag) {
1043
       repetition_cnt = code_has_value() ? code_value_int() : (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y);
1064
       repetition_cnt = code_has_value() ? code_value_int() : (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y);
1436
         goto FINE_TUNE_EXIT;
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
       float new_z = ubl.z_values[location.x_index][location.y_index];
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
       const millis_t nxt = millis() + 1500UL;
1506
       const millis_t nxt = millis() + 1500UL;
1467
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1507
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1468
         idle();
1508
         idle();
1630
               SERIAL_ECHOPGM("   final >>>---> ");
1670
               SERIAL_ECHOPGM("   final >>>---> ");
1631
               SERIAL_PROTOCOL_F( measured_z, 7);
1671
               SERIAL_PROTOCOL_F( measured_z, 7);
1632
               SERIAL_ECHOPGM("\n");
1672
               SERIAL_ECHOPGM("\n");
1633
-        }
1673
+            }
1634
           #endif
1674
           #endif
1635
           incremental_LSF(&lsf_results, x, y, measured_z);
1675
           incremental_LSF(&lsf_results, x, y, measured_z);
1636
-      }
1676
+        }
1637
 
1677
 
1638
         zig_zag = !zig_zag;
1678
         zig_zag = !zig_zag;
1639
       }
1679
       }
1647
       SERIAL_ECHOPGM("  D=");
1687
       SERIAL_ECHOPGM("  D=");
1648
       SERIAL_PROTOCOL_F( lsf_results.D, 7);
1688
       SERIAL_PROTOCOL_F( lsf_results.D, 7);
1649
       SERIAL_CHAR('\n');
1689
       SERIAL_CHAR('\n');
1650
-        }
1690
+    }
1651
 
1691
 
1652
     normal = vector_3( lsf_results.A, lsf_results.B, 1.0000);
1692
     normal = vector_3( lsf_results.A, lsf_results.B, 1.0000);
1653
     normal = normal.get_normal();
1693
     normal = normal.get_normal();
1660
       SERIAL_ECHOPGM(",");
1700
       SERIAL_ECHOPGM(",");
1661
       SERIAL_PROTOCOL_F( normal.z, 7);
1701
       SERIAL_PROTOCOL_F( normal.z, 7);
1662
       SERIAL_ECHOPGM("]\n");
1702
       SERIAL_ECHOPGM("]\n");
1663
-      }
1703
+    }
1664
 
1704
 
1665
     rotation = matrix_3x3::create_look_at( vector_3( lsf_results.A,  lsf_results.B, 1));
1705
     rotation = matrix_3x3::create_look_at( vector_3( lsf_results.A,  lsf_results.B, 1));
1666
 
1706
 
1667
     for (i = 0; i < GRID_MAX_POINTS_X; i++) {
1707
     for (i = 0; i < GRID_MAX_POINTS_X; i++) {
1668
       for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
1708
       for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
1669
         float x_tmp, y_tmp, z_tmp;
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
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1744
     #if ENABLED(DEBUG_LEVELING_FEATURE)
1705
       if (DEBUGGING(LEVELING)) {
1745
       if (DEBUGGING(LEVELING)) {
1723
         SERIAL_CHAR('\n');
1763
         SERIAL_CHAR('\n');
1724
       }
1764
       }
1725
     #endif
1765
     #endif
1726
-            return;
1727
-          }
1766
+    return;
1767
+  }
1728
 
1768
 
1729
 #endif // AUTO_BED_LEVELING_UBL
1769
 #endif // AUTO_BED_LEVELING_UBL

Loading…
Cancel
Save