Browse Source

Merge pull request #4202 from thinkyhead/rc_fix_gcode_t_position

Fix position adjustment with gcode_T and MBL
Scott Lahteine 9 years ago
parent
commit
60865fc45b
1 changed files with 21 additions and 20 deletions
  1. 21
    20
      Marlin/Marlin_main.cpp

+ 21
- 20
Marlin/Marlin_main.cpp View File

310
 // Set by M206, M428, or menu item. Saved to EEPROM.
310
 // Set by M206, M428, or menu item. Saved to EEPROM.
311
 float home_offset[3] = { 0 };
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
 // Software Endstops. Default to configured limits.
316
 // Software Endstops. Default to configured limits.
314
 float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
317
 float sw_endstop_min[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
315
 float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
318
 float sw_endstop_max[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
2766
       // Save known Z position if already homed
2769
       // Save known Z position if already homed
2767
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2770
       if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2768
         pre_home_z = current_position[Z_AXIS];
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
       mbl.set_active(false);
2774
       mbl.set_active(false);
2773
       current_position[Z_AXIS] = pre_home_z;
2775
       current_position[Z_AXIS] = pre_home_z;
3083
           stepper.synchronize();
3085
           stepper.synchronize();
3084
         #else
3086
         #else
3085
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z -
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
             #if Z_HOME_DIR > 0
3089
             #if Z_HOME_DIR > 0
3089
               + Z_MAX_POS
3090
               + Z_MAX_POS
3090
             #endif
3091
             #endif
3096
         SYNC_PLAN_POSITION_KINEMATIC();
3097
         SYNC_PLAN_POSITION_KINEMATIC();
3097
         mbl.set_active(true);
3098
         mbl.set_active(true);
3098
         current_position[Z_AXIS] = pre_home_z -
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
   #endif
3103
   #endif
3305
       case MeshReset:
3305
       case MeshReset:
3306
         if (mbl.active()) {
3306
         if (mbl.active()) {
3307
           current_position[Z_AXIS] +=
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
           mbl.reset();
3309
           mbl.reset();
3311
           SYNC_PLAN_POSITION_KINEMATIC();
3310
           SYNC_PLAN_POSITION_KINEMATIC();
3312
         }
3311
         }
6620
             }
6619
             }
6621
           #endif
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
           // The newly-selected extruder XY is actually at...
6634
           // The newly-selected extruder XY is actually at...
6634
           current_position[X_AXIS] += xydiff[X_AXIS];
6635
           current_position[X_AXIS] += xydiff[X_AXIS];
6635
           current_position[Y_AXIS] += xydiff[Y_AXIS];
6636
           current_position[Y_AXIS] += xydiff[Y_AXIS];
6636
 
6637
 
6637
-        #endif // no bed leveling
6638
+        #endif // !AUTO_BED_LEVELING_FEATURE
6638
 
6639
 
6639
         for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
6640
         for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
6640
           position_shift[i] += xydiff[i];
6641
           position_shift[i] += xydiff[i];
7476
     set_current_to_destination();
7477
     set_current_to_destination();
7477
     return;
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
   NOMORE(pcx, MESH_NUM_X_POINTS - 2);
7484
   NOMORE(pcx, MESH_NUM_X_POINTS - 2);
7484
   NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
7485
   NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
7485
   NOMORE(cx,  MESH_NUM_X_POINTS - 2);
7486
   NOMORE(cx,  MESH_NUM_X_POINTS - 2);

Loading…
Cancel
Save