Browse Source

Patches for leveling reactivation in G28 / M48

Scott Lahteine 7 years ago
parent
commit
e79b335367
3 changed files with 36 additions and 50 deletions
  1. 32
    44
      Marlin/Marlin_main.cpp
  2. 1
    4
      Marlin/mesh_bed_leveling.h
  3. 3
    2
      Marlin/ultralcd.cpp

+ 32
- 44
Marlin/Marlin_main.cpp View File

2429
       ubl.state.active = enable;
2429
       ubl.state.active = enable;
2430
       //set_current_from_steppers_for_axis(Z_AXIS);
2430
       //set_current_from_steppers_for_axis(Z_AXIS);
2431
 
2431
 
2432
-    #elif HAS_ABL
2432
+    #else
2433
 
2433
 
2434
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
2434
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
2435
         const bool can_change = (!enable || (bilinear_grid_spacing[0] && bilinear_grid_spacing[1]));
2435
         const bool can_change = (!enable || (bilinear_grid_spacing[0] && bilinear_grid_spacing[1]));
3750
 
3750
 
3751
   // Disable the leveling matrix before homing
3751
   // Disable the leveling matrix before homing
3752
   #if HAS_LEVELING
3752
   #if HAS_LEVELING
3753
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
3754
-      const bool bed_leveling_state_at_entry = ubl.state.active;
3755
-    #endif
3756
     set_bed_leveling_enabled(false);
3753
     set_bed_leveling_enabled(false);
3757
   #endif
3754
   #endif
3758
 
3755
 
3895
     do_blocking_move_to_z(delta_clip_start_height);
3892
     do_blocking_move_to_z(delta_clip_start_height);
3896
   #endif
3893
   #endif
3897
 
3894
 
3898
-  #if ENABLED(AUTO_BED_LEVELING_UBL)
3899
-    set_bed_leveling_enabled(bed_leveling_state_at_entry);
3900
-  #endif
3901
-
3902
-  // Enable mesh leveling again
3903
-  #if ENABLED(MESH_BED_LEVELING)
3904
-    if (mbl.reactivate()) {
3905
-      set_bed_leveling_enabled(true);
3906
-      if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
3907
-        #if ENABLED(MESH_G28_REST_ORIGIN)
3908
-          current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
3909
-          set_destination_to_current();
3910
-          line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
3911
-          stepper.synchronize();
3912
-        #endif
3913
-      }
3914
-    }
3915
-  #endif
3916
-
3917
   clean_up_after_endstop_or_probe_move();
3895
   clean_up_after_endstop_or_probe_move();
3918
 
3896
 
3919
   // Restore the active tool after homing
3897
   // Restore the active tool after homing
3982
     );
3960
     );
3983
   }
3961
   }
3984
 
3962
 
3963
+  void mesh_probing_done() {
3964
+    mbl.set_has_mesh(true);
3965
+    home_all_axes();
3966
+    set_bed_leveling_enabled(true);
3967
+    #if ENABLED(MESH_G28_REST_ORIGIN)
3968
+      current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
3969
+      set_destination_to_current();
3970
+      line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
3971
+      stepper.synchronize();
3972
+    #endif
3973
+  }
3974
+
3985
   /**
3975
   /**
3986
    * G29: Mesh-based Z probe, probes a grid and produces a
3976
    * G29: Mesh-based Z probe, probes a grid and produces a
3987
    *      mesh to compensate for variable bed height
3977
    *      mesh to compensate for variable bed height
4072
           line_to_current_position();
4062
           line_to_current_position();
4073
           stepper.synchronize();
4063
           stepper.synchronize();
4074
 
4064
 
4075
-          // After recording the last point, activate the mbl and home
4076
-          SERIAL_PROTOCOLLNPGM("Mesh probing done.");
4065
+          // After recording the last point, activate home and activate
4077
           mbl_probe_index = -1;
4066
           mbl_probe_index = -1;
4078
-          mbl.set_has_mesh(true);
4079
-          mbl.set_reactivate(true);
4080
-          enqueue_and_echo_commands_P(PSTR("G28"));
4067
+          SERIAL_PROTOCOLLNPGM("Mesh probing done.");
4081
           BUZZ(100, 659);
4068
           BUZZ(100, 659);
4082
           BUZZ(100, 698);
4069
           BUZZ(100, 698);
4070
+          mesh_probing_done();
4083
         }
4071
         }
4084
         break;
4072
         break;
4085
 
4073
 
5015
       SYNC_PLAN_POSITION_KINEMATIC();
5003
       SYNC_PLAN_POSITION_KINEMATIC();
5016
   }
5004
   }
5017
 
5005
 
5018
-#endif // HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
5006
+#endif // HAS_ABL && !AUTO_BED_LEVELING_UBL
5019
 
5007
 
5020
 #if HAS_BED_PROBE
5008
 #if HAS_BED_PROBE
5021
 
5009
 
6200
    * regenerated.
6188
    * regenerated.
6201
    */
6189
    */
6202
   inline void gcode_M48() {
6190
   inline void gcode_M48() {
6203
-  #if ENABLED(AUTO_BED_LEVELING_UBL)
6204
-  bool bed_leveling_state_at_entry=0;
6205
-    bed_leveling_state_at_entry = ubl.state.active;
6206
-  #endif
6207
 
6191
 
6208
     if (axis_unhomed_error(true, true, true)) return;
6192
     if (axis_unhomed_error(true, true, true)) return;
6209
 
6193
 
6222
       return;
6206
       return;
6223
     }
6207
     }
6224
 
6208
 
6225
-    float  X_current = current_position[X_AXIS],
6226
-           Y_current = current_position[Y_AXIS];
6209
+    float X_current = current_position[X_AXIS],
6210
+          Y_current = current_position[Y_AXIS];
6227
 
6211
 
6228
     bool stow_probe_after_each = code_seen('E');
6212
     bool stow_probe_after_each = code_seen('E');
6229
 
6213
 
6269
       SERIAL_PROTOCOLLNPGM("Positioning the probe...");
6253
       SERIAL_PROTOCOLLNPGM("Positioning the probe...");
6270
 
6254
 
6271
     // Disable bed level correction in M48 because we want the raw data when we probe
6255
     // Disable bed level correction in M48 because we want the raw data when we probe
6272
-    #if HAS_ABL
6273
-      const bool abl_was_enabled = planner.abl_enabled;
6256
+
6257
+    #if HAS_LEVELING
6258
+      const bool was_enabled =
6259
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
6260
+          ubl.state.active
6261
+        #elif ENABLED(MESH_BED_LEVELING)
6262
+          mbl.active()
6263
+        #else
6264
+          planner.abl_enabled
6265
+        #endif
6266
+      ;
6274
       set_bed_leveling_enabled(false);
6267
       set_bed_leveling_enabled(false);
6275
     #endif
6268
     #endif
6276
 
6269
 
6422
 
6415
 
6423
     clean_up_after_endstop_or_probe_move();
6416
     clean_up_after_endstop_or_probe_move();
6424
 
6417
 
6425
-    // Re-enable bed level correction if it has been on
6418
+    // Re-enable bed level correction if it had been on
6426
     #if HAS_ABL
6419
     #if HAS_ABL
6427
-      set_bed_leveling_enabled(abl_was_enabled);
6428
-    #endif
6429
-
6430
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
6431
-      set_bed_leveling_enabled(bed_leveling_state_at_entry);
6432
-      ubl.state.active = bed_leveling_state_at_entry;
6420
+      set_bed_leveling_enabled(was_enabled);
6433
     #endif
6421
     #endif
6434
 
6422
 
6435
     report_current_position();
6423
     report_current_position();

+ 1
- 4
Marlin/mesh_bed_leveling.h View File

36
   enum MBLStatus {
36
   enum MBLStatus {
37
     MBL_STATUS_NONE = 0,
37
     MBL_STATUS_NONE = 0,
38
     MBL_STATUS_HAS_MESH_BIT = 0,
38
     MBL_STATUS_HAS_MESH_BIT = 0,
39
-    MBL_STATUS_ACTIVE_BIT = 1,
40
-    MBL_STATUS_REACTIVATE_BIT = 2
39
+    MBL_STATUS_ACTIVE_BIT = 1
41
   };
40
   };
42
 
41
 
43
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
42
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
61
     static void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
60
     static void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
62
     static bool has_mesh()                     { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
61
     static bool has_mesh()                     { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
63
     static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
62
     static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
64
-    static bool reactivate()                   { bool b = TEST(status, MBL_STATUS_REACTIVATE_BIT); CBI(status, MBL_STATUS_REACTIVATE_BIT); return b; }
65
-    static void set_reactivate(const bool onOff) { onOff ? SBI(status, MBL_STATUS_REACTIVATE_BIT) : CBI(status, MBL_STATUS_REACTIVATE_BIT); }
66
 
63
 
67
     static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
64
     static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
68
       px = index % (GRID_MAX_POINTS_X);
65
       px = index % (GRID_MAX_POINTS_X);

+ 3
- 2
Marlin/ultralcd.cpp View File

162
 
162
 
163
   #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
163
   #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
164
     #include "mesh_bed_leveling.h"
164
     #include "mesh_bed_leveling.h"
165
+    extern void mesh_probing_done();
165
   #endif
166
   #endif
166
 
167
 
167
   ////////////////////////////////////////////
168
   ////////////////////////////////////////////
1539
           // Enable leveling, if needed
1540
           // Enable leveling, if needed
1540
           #if ENABLED(MESH_BED_LEVELING)
1541
           #if ENABLED(MESH_BED_LEVELING)
1541
 
1542
 
1543
+            lcd_synchronize();
1542
             mbl.set_has_mesh(true);
1544
             mbl.set_has_mesh(true);
1543
-            mbl.set_reactivate(true);
1544
-            enqueue_and_echo_commands_P(PSTR("G28"));
1545
+            mesh_probing_done();
1545
 
1546
 
1546
           #elif ENABLED(AUTO_BED_LEVELING_UBL)
1547
           #elif ENABLED(AUTO_BED_LEVELING_UBL)
1547
 
1548
 

Loading…
Cancel
Save