Browse Source

Simplify MBL movement, zigzag

Scott Lahteine 8 years ago
parent
commit
2129db581e
3 changed files with 75 additions and 38 deletions
  1. 35
    18
      Marlin/Marlin_main.cpp
  2. 12
    0
      Marlin/mesh_bed_leveling.h
  3. 28
    20
      Marlin/ultralcd.cpp

+ 35
- 18
Marlin/Marlin_main.cpp View File

@@ -2799,6 +2799,28 @@ inline void gcode_G28() {
2799 2799
 
2800 2800
   enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset };
2801 2801
 
2802
+  inline void _mbl_goto_xy(float x, float y) {
2803
+    saved_feedrate = feedrate;
2804
+    feedrate = homing_feedrate[X_AXIS];
2805
+
2806
+    #if MIN_Z_HEIGHT_FOR_HOMING > 0
2807
+      current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + MIN_Z_HEIGHT_FOR_HOMING;
2808
+      line_to_current_position();
2809
+    #endif
2810
+
2811
+    current_position[X_AXIS] = x + home_offset[X_AXIS];
2812
+    current_position[Y_AXIS] = y + home_offset[Y_AXIS];
2813
+    line_to_current_position();
2814
+
2815
+    #if MIN_Z_HEIGHT_FOR_HOMING > 0
2816
+      current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2817
+      line_to_current_position();
2818
+    #endif
2819
+
2820
+    feedrate = saved_feedrate;
2821
+    st_synchronize();
2822
+  }
2823
+
2802 2824
   /**
2803 2825
    * G29: Mesh-based Z probe, probes a grid and produces a
2804 2826
    *      mesh to compensate for variable bed height
@@ -2866,33 +2888,28 @@ inline void gcode_G28() {
2866 2888
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
2867 2889
           return;
2868 2890
         }
2891
+        // For each G29 S2...
2869 2892
         if (probe_point == 0) {
2870
-          // Set Z to a positive value before recording the first Z.
2871
-          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + home_offset[Z_AXIS];
2893
+          // For the intial G29 S2 make Z a positive value (e.g., 4.0)
2894
+          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2872 2895
           sync_plan_position();
2873 2896
         }
2874 2897
         else {
2875
-          // For others, save the Z of the previous point, then raise Z again.
2876
-          ix = (probe_point - 1) % (MESH_NUM_X_POINTS);
2877
-          iy = (probe_point - 1) / (MESH_NUM_X_POINTS);
2878
-          if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag
2879
-          mbl.set_z(ix, iy, current_position[Z_AXIS]);
2880
-          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + home_offset[Z_AXIS];
2881
-          plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS] / 60, active_extruder);
2882
-          st_synchronize();
2898
+          // For G29 S2 after adjusting Z.
2899
+          mbl.set_zigzag_z(probe_point - 1, current_position[Z_AXIS]);
2883 2900
         }
2884
-        // Is there another point to sample? Move there.
2901
+        // If there's another point to sample, move there with optional lift.
2885 2902
         if (probe_point < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
2886
-          ix = probe_point % (MESH_NUM_X_POINTS);
2887
-          iy = probe_point / (MESH_NUM_X_POINTS);
2888
-          if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag
2889
-          current_position[X_AXIS] = mbl.get_x(ix) + home_offset[X_AXIS];
2890
-          current_position[Y_AXIS] = mbl.get_y(iy) + home_offset[Y_AXIS];
2891
-          plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS] / 60, active_extruder);
2892
-          st_synchronize();
2903
+          mbl.zigzag(probe_point, ix, iy);
2904
+          _mbl_goto_xy(mbl.get_x(ix), mbl.get_y(iy));
2893 2905
           probe_point++;
2894 2906
         }
2895 2907
         else {
2908
+          // One last "return to the bed" (as originally coded) at completion
2909
+          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2910
+          line_to_current_position();
2911
+          st_synchronize();
2912
+
2896 2913
           // After recording the last point, activate the mbl and home
2897 2914
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2898 2915
           probe_point = -1;

+ 12
- 0
Marlin/mesh_bed_leveling.h View File

@@ -41,6 +41,18 @@
41 41
     float get_y(int i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42 42
     void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; }
43 43
 
44
+    inline void zigzag(int index, int &ix, int &iy) {
45
+      ix = index % (MESH_NUM_X_POINTS);
46
+      iy = index / (MESH_NUM_X_POINTS);
47
+      if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
48
+    }
49
+
50
+    void set_zigzag_z(int index, float z) {
51
+      int ix, iy;
52
+      zigzag(index, ix, iy);
53
+      set_z(ix, iy, z);
54
+    }
55
+
44 56
     int select_x_index(float x) {
45 57
       int i = 1;
46 58
       while (x > get_x(i) && i < MESH_NUM_X_POINTS - 1) i++;

+ 28
- 20
Marlin/ultralcd.cpp View File

@@ -887,6 +887,28 @@ void lcd_cooldown() {
887 887
    */
888 888
 
889 889
   static int _lcd_level_bed_position;
890
+  static bool mbl_wait_for_move = false;
891
+
892
+  // Utility to go to the next mesh point
893
+  // A raise is added between points if MIN_Z_HEIGHT_FOR_HOMING is in use
894
+  // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
895
+  // Z position will be restored with the final action, a G28
896
+  inline void _mbl_goto_xy(float x, float y) {
897
+    mbl_wait_for_move = true;
898
+    #if MIN_Z_HEIGHT_FOR_HOMING > 0
899
+      current_position[Z_AXIS] += MIN_Z_HEIGHT_FOR_HOMING;
900
+      line_to_current(Z_AXIS);
901
+    #endif
902
+    current_position[X_AXIS] = x + home_offset[X_AXIS];
903
+    current_position[Y_AXIS] = y + home_offset[Y_AXIS];
904
+    line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
905
+    #if MIN_Z_HEIGHT_FOR_HOMING > 0
906
+      current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
907
+      line_to_current(Z_AXIS);
908
+    #endif
909
+    st_synchronize();
910
+    mbl_wait_for_move = false;
911
+  }
890 912
 
891 913
   /**
892 914
    * 5. MBL Wait for controller movement and clicks:
@@ -894,7 +916,6 @@ void lcd_cooldown() {
894 916
    *        - Click saves the Z, goes to the next mesh point
895 917
    */
896 918
   static void _lcd_level_bed_procedure() {
897
-    static bool mbl_wait_for_move = false;
898 919
     // Menu handlers may be called in a re-entrant fashion
899 920
     // if they call st_synchronize or plan_buffer_line. So
900 921
     // while waiting for a move we just ignore new input.
@@ -931,11 +952,7 @@ void lcd_cooldown() {
931 952
     if (LCD_CLICKED) {
932 953
       if (!debounce_click) {
933 954
         debounce_click = true; // ignore multiple "clicks" in a row
934
-        int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
935
-            iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
936
-        if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
937
-        mbl.set_z(ix, iy, current_position[Z_AXIS]);
938
-        _lcd_level_bed_position++;
955
+        mbl.set_zigzag_z(_lcd_level_bed_position++, current_position[Z_AXIS]);
939 956
         if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
940 957
           lcd_return_to_status();
941 958
           LCD_ALERTMESSAGEPGM(MSG_LEVEL_BED_DONE);
@@ -953,17 +970,9 @@ void lcd_cooldown() {
953 970
           #if ENABLED(NEWPANEL)
954 971
             lcd_quick_feedback();
955 972
           #endif
956
-          mbl_wait_for_move = true;
957
-          current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
958
-          line_to_current(Z_AXIS);
959
-          ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS);
960
-          iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
961
-          if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
962
-          current_position[X_AXIS] = mbl.get_x(ix);
963
-          current_position[Y_AXIS] = mbl.get_y(iy);
964
-          line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
965
-          st_synchronize();
966
-          mbl_wait_for_move = false;
973
+          int ix, iy;
974
+          mbl.zigzag(_lcd_level_bed_position, ix, iy);
975
+          _mbl_goto_xy(mbl.get_x(ix), mbl.get_y(iy));
967 976
           encoderPosition = 0;
968 977
         }
969 978
       }
@@ -980,12 +989,11 @@ void lcd_cooldown() {
980 989
   static void _lcd_level_bed_homing_done() {
981 990
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING), NULL);
982 991
     lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
992
+    if (mbl_wait_for_move) return;
983 993
     if (LCD_CLICKED) {
984 994
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
985 995
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
986
-      current_position[X_AXIS] = MESH_MIN_X;
987
-      current_position[Y_AXIS] = MESH_MIN_Y;
988
-      line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
996
+      _mbl_goto_xy(MESH_MIN_X, MESH_MIN_Y);
989 997
       _lcd_level_bed_position = 0;
990 998
       lcd_goto_menu(_lcd_level_bed_procedure, true);
991 999
     }

Loading…
Cancel
Save