Procházet zdrojové kódy

Fix position adjustment with gcode_T and MBL

Scott Lahteine před 9 roky
rodič
revize
f31af61ee2
1 změnil soubory, kde provedl 21 přidání a 20 odebrání
  1. 21
    20
      Marlin/Marlin_main.cpp

+ 21
- 20
Marlin/Marlin_main.cpp Zobrazit soubor

@@ -310,6 +310,9 @@ float position_shift[3] = { 0 };
310 310
 // Set by M206, M428, or menu item. Saved to EEPROM.
311 311
 float home_offset[3] = { 0 };
312 312
 
313
+#define RAW_POSITION(POS, AXIS) (POS - home_offset[AXIS] - position_shift[AXIS])
314
+#define RAW_CURRENT_POSITION(AXIS) (RAW_POSITION(current_position[AXIS], AXIS))
315
+
313 316
 // Software Endstops. Default to configured limits.
314 317
 float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
315 318
 float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
@@ -2766,8 +2769,7 @@ inline void gcode_G28() {
2766 2769
       // Save known Z position if already homed
2767 2770
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2768 2771
         pre_home_z = current_position[Z_AXIS];
2769
-        pre_home_z += mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
2770
-                                current_position[Y_AXIS] - home_offset[Y_AXIS]);
2772
+        pre_home_z += mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS));
2771 2773
       }
2772 2774
       mbl.set_active(false);
2773 2775
       current_position[Z_AXIS] = pre_home_z;
@@ -3083,8 +3085,7 @@ inline void gcode_G28() {
3083 3085
           stepper.synchronize();
3084 3086
         #else
3085 3087
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z -
3086
-            mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
3087
-                      current_position[Y_AXIS] - home_offset[Y_AXIS])
3088
+            mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS))
3088 3089
             #if Z_HOME_DIR > 0
3089 3090
               + Z_MAX_POS
3090 3091
             #endif
@@ -3096,8 +3097,7 @@ inline void gcode_G28() {
3096 3097
         SYNC_PLAN_POSITION_KINEMATIC();
3097 3098
         mbl.set_active(true);
3098 3099
         current_position[Z_AXIS] = pre_home_z -
3099
-          mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
3100
-                    current_position[Y_AXIS] - home_offset[Y_AXIS]);
3100
+          mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS));
3101 3101
       }
3102 3102
     }
3103 3103
   #endif
@@ -3305,8 +3305,7 @@ inline void gcode_G28() {
3305 3305
       case MeshReset:
3306 3306
         if (mbl.active()) {
3307 3307
           current_position[Z_AXIS] +=
3308
-            mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
3309
-                      current_position[Y_AXIS] - home_offset[Y_AXIS]) - MESH_HOME_SEARCH_Z;
3308
+            mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)) - MESH_HOME_SEARCH_Z;
3310 3309
           mbl.reset();
3311 3310
           SYNC_PLAN_POSITION_KINEMATIC();
3312 3311
         }
@@ -6620,21 +6619,23 @@ inline void gcode_T(uint8_t tmp_extruder) {
6620 6619
             }
6621 6620
           #endif
6622 6621
 
6623
-        #elif ENABLED(MESH_BED_LEVELING)
6622
+        #else // !AUTO_BED_LEVELING_FEATURE
6624 6623
 
6625
-          if (mbl.active()) {
6626
-            float xpos = current_position[X_AXIS] - home_offset[X_AXIS],
6627
-                  ypos = current_position[Y_AXIS] - home_offset[Y_AXIS];
6628
-            current_position[Z_AXIS] += mbl.get_z(xpos + xydiff[X_AXIS], ypos + xydiff[Y_AXIS]) - mbl.get_z(xpos, ypos);
6629
-          }
6624
+          #if ENABLED(MESH_BED_LEVELING)
6625
+
6626
+            if (mbl.active()) {
6627
+              float xpos = RAW_CURRENT_POSITION(X_AXIS),
6628
+                    ypos = RAW_CURRENT_POSITION(Y_AXIS);
6629
+              current_position[Z_AXIS] += mbl.get_z(xpos + xydiff[X_AXIS], ypos + xydiff[Y_AXIS]) - mbl.get_z(xpos, ypos);
6630
+            }
6630 6631
 
6631
-        #else // no bed leveling
6632
+          #endif // MESH_BED_LEVELING
6632 6633
 
6633 6634
           // The newly-selected extruder XY is actually at...
6634 6635
           current_position[X_AXIS] += xydiff[X_AXIS];
6635 6636
           current_position[Y_AXIS] += xydiff[Y_AXIS];
6636 6637
 
6637
-        #endif // no bed leveling
6638
+        #endif // !AUTO_BED_LEVELING_FEATURE
6638 6639
 
6639 6640
         for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
6640 6641
           position_shift[i] += xydiff[i];
@@ -7476,10 +7477,10 @@ void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate,
7476 7477
     set_current_to_destination();
7477 7478
     return;
7478 7479
   }
7479
-  int pcx = mbl.cell_index_x(current_position[X_AXIS] - home_offset[X_AXIS]);
7480
-  int pcy = mbl.cell_index_y(current_position[Y_AXIS] - home_offset[Y_AXIS]);
7481
-  int cx = mbl.cell_index_x(x - home_offset[X_AXIS]);
7482
-  int cy = mbl.cell_index_y(y - home_offset[Y_AXIS]);
7480
+  int pcx = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7481
+      pcy = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7482
+      cx = mbl.cell_index_x(RAW_POSITION(x, X_AXIS)),
7483
+      cy = mbl.cell_index_y(RAW_POSITION(x, Y_AXIS));
7483 7484
   NOMORE(pcx, MESH_NUM_X_POINTS - 2);
7484 7485
   NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
7485 7486
   NOMORE(cx,  MESH_NUM_X_POINTS - 2);

Loading…
Zrušit
Uložit