Browse Source

Merge pull request #3488 from thinkyhead/rc_more_manual_level_fix

Mesh Bed Leveling – Add lift between probes, comments, cleanup
Scott Lahteine 9 years ago
parent
commit
5da7de8431
4 changed files with 90 additions and 49 deletions
  1. 37
    20
      Marlin/Marlin_main.cpp
  2. 1
    1
      Marlin/configuration_store.cpp
  3. 13
    1
      Marlin/mesh_bed_leveling.h
  4. 39
    27
      Marlin/ultralcd.cpp

+ 37
- 20
Marlin/Marlin_main.cpp View File

2465
    */
2465
    */
2466
   #if ENABLED(MESH_BED_LEVELING)
2466
   #if ENABLED(MESH_BED_LEVELING)
2467
     uint8_t mbl_was_active = mbl.active;
2467
     uint8_t mbl_was_active = mbl.active;
2468
-    mbl.active = 0;
2468
+    mbl.active = false;
2469
   #endif
2469
   #endif
2470
 
2470
 
2471
   setup_for_endstop_move();
2471
   setup_for_endstop_move();
2799
 
2799
 
2800
   enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset };
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
    * G29: Mesh-based Z probe, probes a grid and produces a
2825
    * G29: Mesh-based Z probe, probes a grid and produces a
2804
    *      mesh to compensate for variable bed height
2826
    *      mesh to compensate for variable bed height
2866
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
2888
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
2867
           return;
2889
           return;
2868
         }
2890
         }
2891
+        // For each G29 S2...
2869
         if (probe_point == 0) {
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
           sync_plan_position();
2895
           sync_plan_position();
2873
         }
2896
         }
2874
         else {
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
         if (probe_point < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
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
           probe_point++;
2905
           probe_point++;
2894
         }
2906
         }
2895
         else {
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
           // After recording the last point, activate the mbl and home
2913
           // After recording the last point, activate the mbl and home
2897
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2914
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2898
           probe_point = -1;
2915
           probe_point = -1;
2899
-          mbl.active = 1;
2916
+          mbl.active = true;
2900
           enqueue_and_echo_commands_P(PSTR("G28"));
2917
           enqueue_and_echo_commands_P(PSTR("G28"));
2901
         }
2918
         }
2902
         break;
2919
         break;

+ 1
- 1
Marlin/configuration_store.cpp View File

551
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
551
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
552
 
552
 
553
   #if ENABLED(MESH_BED_LEVELING)
553
   #if ENABLED(MESH_BED_LEVELING)
554
-    mbl.active = 0;
554
+    mbl.active = false;
555
   #endif
555
   #endif
556
 
556
 
557
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
557
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)

+ 13
- 1
Marlin/mesh_bed_leveling.h View File

29
 
29
 
30
   class mesh_bed_leveling {
30
   class mesh_bed_leveling {
31
   public:
31
   public:
32
-    uint8_t active;
32
+    bool active;
33
     float z_offset;
33
     float z_offset;
34
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
34
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
35
 
35
 
41
     float get_y(int i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
41
     float get_y(int i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
42
     void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; }
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
     int select_x_index(float x) {
56
     int select_x_index(float x) {
45
       int i = 1;
57
       int i = 1;
46
       while (x > get_x(i) && i < MESH_NUM_X_POINTS - 1) i++;
58
       while (x > get_x(i) && i < MESH_NUM_X_POINTS - 1) i++;

+ 39
- 27
Marlin/ultralcd.cpp View File

887
    */
887
    */
888
 
888
 
889
   static int _lcd_level_bed_position;
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
-   * MBL Wait for controller movement and clicks:
893
-   *   - Movement adjusts the Z axis
894
-   *   - Click saves the Z and goes to the next mesh point
914
+   * 5. MBL Wait for controller movement and clicks:
915
+   *        - Movement adjusts the Z axis
916
+   *        - Click saves the Z, goes to the next mesh point
895
    */
917
    */
896
   static void _lcd_level_bed_procedure() {
918
   static void _lcd_level_bed_procedure() {
897
-    static bool mbl_wait_for_move = false;
898
     // Menu handlers may be called in a re-entrant fashion
919
     // Menu handlers may be called in a re-entrant fashion
899
     // if they call st_synchronize or plan_buffer_line. So
920
     // if they call st_synchronize or plan_buffer_line. So
900
     // while waiting for a move we just ignore new input.
921
     // while waiting for a move we just ignore new input.
931
     if (LCD_CLICKED) {
952
     if (LCD_CLICKED) {
932
       if (!debounce_click) {
953
       if (!debounce_click) {
933
         debounce_click = true; // ignore multiple "clicks" in a row
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
         if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
956
         if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
940
           lcd_return_to_status();
957
           lcd_return_to_status();
941
           LCD_ALERTMESSAGEPGM(MSG_LEVEL_BED_DONE);
958
           LCD_ALERTMESSAGEPGM(MSG_LEVEL_BED_DONE);
946
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
963
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
947
           line_to_current(Z_AXIS);
964
           line_to_current(Z_AXIS);
948
           st_synchronize();
965
           st_synchronize();
949
-          mbl.active = 1;
966
+          mbl.active = true;
950
           enqueue_and_echo_commands_P(PSTR("G28"));
967
           enqueue_and_echo_commands_P(PSTR("G28"));
951
         }
968
         }
952
         else {
969
         else {
953
           #if ENABLED(NEWPANEL)
970
           #if ENABLED(NEWPANEL)
954
             lcd_quick_feedback();
971
             lcd_quick_feedback();
955
           #endif
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
           encoderPosition = 0;
976
           encoderPosition = 0;
968
         }
977
         }
969
       }
978
       }
973
     }
982
     }
974
   }
983
   }
975
 
984
 
985
+  /**
986
+   * 4. MBL Display "Click to Begin", wait for click
987
+   *        Move to the first probe position
988
+   */
976
   static void _lcd_level_bed_homing_done() {
989
   static void _lcd_level_bed_homing_done() {
977
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING), NULL);
990
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING), NULL);
978
     lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
991
     lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
992
+    if (mbl_wait_for_move) return;
979
     if (LCD_CLICKED) {
993
     if (LCD_CLICKED) {
980
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
994
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
981
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
995
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
982
-      current_position[X_AXIS] = MESH_MIN_X;
983
-      current_position[Y_AXIS] = MESH_MIN_Y;
984
-      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);
985
       _lcd_level_bed_position = 0;
997
       _lcd_level_bed_position = 0;
986
       lcd_goto_menu(_lcd_level_bed_procedure, true);
998
       lcd_goto_menu(_lcd_level_bed_procedure, true);
987
     }
999
     }
988
   }
1000
   }
989
 
1001
 
990
   /**
1002
   /**
991
-   * MBL Move to mesh starting point
1003
+   * 3. MBL Display "Hoing XYZ" - Wait for homing to finish
992
    */
1004
    */
993
   static void _lcd_level_bed_homing() {
1005
   static void _lcd_level_bed_homing() {
994
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
1006
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
998
   }
1010
   }
999
 
1011
 
1000
   /**
1012
   /**
1001
-   * MBL Continue Bed Leveling...
1013
+   * 2. MBL Continue Bed Leveling...
1002
    */
1014
    */
1003
   static void _lcd_level_bed_continue() {
1015
   static void _lcd_level_bed_continue() {
1004
     defer_return_to_status = true;
1016
     defer_return_to_status = true;
1009
   }
1021
   }
1010
 
1022
 
1011
   /**
1023
   /**
1012
-   * MBL entry-point
1024
+   * 1. MBL entry-point: "Cancel" or "Level Bed"
1013
    */
1025
    */
1014
   static void lcd_level_bed() {
1026
   static void lcd_level_bed() {
1015
     START_MENU();
1027
     START_MENU();

Loading…
Cancel
Save