Browse Source

Use apply_leveling, not MBL directly

Scott Lahteine 7 years ago
parent
commit
c06161b773
1 changed files with 25 additions and 14 deletions
  1. 25
    14
      Marlin/Marlin_main.cpp

+ 25
- 14
Marlin/Marlin_main.cpp View File

2224
   void set_bed_leveling_enabled(bool enable=true) {
2224
   void set_bed_leveling_enabled(bool enable=true) {
2225
     #if ENABLED(MESH_BED_LEVELING)
2225
     #if ENABLED(MESH_BED_LEVELING)
2226
 
2226
 
2227
-      if (!enable && mbl.active())
2228
-        current_position[Z_AXIS] +=
2229
-          mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)) - (MESH_HOME_SEARCH_Z);
2227
+      if (enable != mbl.active()) {
2230
 
2228
 
2231
-      mbl.set_active(enable && mbl.has_mesh()); // was set_has_mesh(). Is this not correct?
2229
+        if (!enable)
2230
+          planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2231
+
2232
+        mbl.set_active(enable && mbl.has_mesh());
2233
+
2234
+        if (enable) planner.unapply_leveling(current_position);
2235
+      }
2232
 
2236
 
2233
     #elif HAS_ABL
2237
     #elif HAS_ABL
2234
 
2238
 
3162
     #elif ENABLED(MESH_BED_LEVELING)
3166
     #elif ENABLED(MESH_BED_LEVELING)
3163
       SERIAL_ECHOPGM("Mesh Bed Leveling");
3167
       SERIAL_ECHOPGM("Mesh Bed Leveling");
3164
       if (mbl.active()) {
3168
       if (mbl.active()) {
3169
+        float lz = current_position[Z_AXIS];
3170
+        planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
3165
         SERIAL_ECHOLNPGM(" (enabled)");
3171
         SERIAL_ECHOLNPGM(" (enabled)");
3166
-        SERIAL_ECHOPAIR("MBL Adjustment Z", mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)));
3172
+        SERIAL_ECHOPAIR("MBL Adjustment Z", lz);
3167
       }
3173
       }
3168
       SERIAL_EOL;
3174
       SERIAL_EOL;
3169
     #endif
3175
     #endif
3321
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3327
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3322
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("MBL was active");
3328
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("MBL was active");
3323
       #endif
3329
       #endif
3324
-      // Save known Z position if already homed
3330
+      // Use known Z position if already homed
3325
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
3331
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
3332
+        set_bed_leveling_enabled(false);
3326
         pre_home_z = current_position[Z_AXIS];
3333
         pre_home_z = current_position[Z_AXIS];
3327
-        pre_home_z += mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS));
3328
       }
3334
       }
3329
-      mbl.set_active(false);
3330
-      current_position[Z_AXIS] = pre_home_z;
3335
+      else {
3336
+        mbl.set_active(false);
3337
+        current_position[Z_AXIS] = pre_home_z;
3338
+      }
3331
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3339
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3332
         if (DEBUGGING(LEVELING)) DEBUG_POS("Set Z to pre_home_z", current_position);
3340
         if (DEBUGGING(LEVELING)) DEBUG_POS("Set Z to pre_home_z", current_position);
3333
       #endif
3341
       #endif
3703
 
3711
 
3704
       case MeshReset:
3712
       case MeshReset:
3705
         if (mbl.active()) {
3713
         if (mbl.active()) {
3706
-          current_position[Z_AXIS] +=
3707
-            mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)) - MESH_HOME_SEARCH_Z;
3714
+          current_position[Z_AXIS] -= MESH_HOME_SEARCH_Z;
3715
+          planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
3708
           mbl.reset();
3716
           mbl.reset();
3709
           SYNC_PLAN_POSITION_KINEMATIC();
3717
           SYNC_PLAN_POSITION_KINEMATIC();
3710
         }
3718
         }
7640
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
7648
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
7641
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
7649
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
7642
                 #endif
7650
                 #endif
7643
-                float xpos = RAW_CURRENT_POSITION(X_AXIS),
7644
-                      ypos = RAW_CURRENT_POSITION(Y_AXIS);
7645
-                current_position[Z_AXIS] += mbl.get_z(xpos + xydiff[X_AXIS], ypos + xydiff[Y_AXIS]) - mbl.get_z(xpos, ypos);
7651
+                float x2 = current_position[X_AXIS] + xydiff[X_AXIS],
7652
+                      y2 = current_position[Y_AXIS] + xydiff[Y_AXIS],
7653
+                      z1 = current_position[Z_AXIS], z2 = z1;
7654
+                planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], z1);
7655
+                planner.apply_leveling(x2, y2, z2);
7656
+                current_position[Z_AXIS] += z2 - z1;
7646
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
7657
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
7647
                   if (DEBUGGING(LEVELING))
7658
                   if (DEBUGGING(LEVELING))
7648
                     SERIAL_ECHOLNPAIR(" after: ", current_position[Z_AXIS]);
7659
                     SERIAL_ECHOLNPAIR(" after: ", current_position[Z_AXIS]);

Loading…
Cancel
Save