Parcourir la source

Merge pull request #4310 from thinkyhead/rc_mbl_position_shift

Fix position shift with MBL
Scott Lahteine il y a 9 ans
Parent
révision
3422103863
3 fichiers modifiés avec 51 ajouts et 66 suppressions
  1. 48
    63
      Marlin/Marlin_main.cpp
  2. 2
    2
      Marlin/SanityCheck.h
  3. 1
    1
      Marlin/configuration_store.cpp

+ 48
- 63
Marlin/Marlin_main.cpp Voir le fichier

@@ -7831,76 +7831,59 @@ void clamp_to_software_endstops(float target[3]) {
7831 7831
 #if ENABLED(MESH_BED_LEVELING)
7832 7832
 
7833 7833
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7834
-void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7835
-  if (!mbl.active()) {
7836
-    planner.buffer_line(x, y, z, e, fr_mm_s, extruder);
7837
-    set_current_to_destination();
7838
-    return;
7839
-  }
7840
-  int pcx = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7841
-      pcy = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7842
-      cx = mbl.cell_index_x(RAW_POSITION(x, X_AXIS)),
7843
-      cy = mbl.cell_index_y(RAW_POSITION(y, Y_AXIS));
7844
-  NOMORE(pcx, MESH_NUM_X_POINTS - 2);
7845
-  NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
7846
-  NOMORE(cx,  MESH_NUM_X_POINTS - 2);
7847
-  NOMORE(cy,  MESH_NUM_Y_POINTS - 2);
7848
-  if (pcx == cx && pcy == cy) {
7834
+void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7835
+  int cx1 = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
7836
+      cy1 = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
7837
+      cx2 = mbl.cell_index_x(RAW_POSITION(destination[X_AXIS], X_AXIS)),
7838
+      cy2 = mbl.cell_index_y(RAW_POSITION(destination[Y_AXIS], Y_AXIS));
7839
+  NOMORE(cx1, MESH_NUM_X_POINTS - 2);
7840
+  NOMORE(cy1, MESH_NUM_Y_POINTS - 2);
7841
+  NOMORE(cx2, MESH_NUM_X_POINTS - 2);
7842
+  NOMORE(cy2, MESH_NUM_Y_POINTS - 2);
7843
+
7844
+  if (cx1 == cx2 && cy1 == cy2) {
7849 7845
     // Start and end on same mesh square
7850
-    planner.buffer_line(x, y, z, e, fr_mm_s, extruder);
7846
+    line_to_destination(fr_mm_m);
7851 7847
     set_current_to_destination();
7852 7848
     return;
7853 7849
   }
7854
-  float nx, ny, nz, ne, normalized_dist;
7855
-  if (cx > pcx && TEST(x_splits, cx)) {
7856
-    nx = mbl.get_probe_x(cx) + home_offset[X_AXIS];
7857
-    normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]);
7858
-    ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
7859
-    nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
7860
-    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
7861
-    CBI(x_splits, cx);
7862
-  }
7863
-  else if (cx < pcx && TEST(x_splits, pcx)) {
7864
-    nx = mbl.get_probe_x(pcx) + home_offset[X_AXIS];
7865
-    normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]);
7866
-    ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
7867
-    nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
7868
-    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
7869
-    CBI(x_splits, pcx);
7870
-  }
7871
-  else if (cy > pcy && TEST(y_splits, cy)) {
7872
-    ny = mbl.get_probe_y(cy) + home_offset[Y_AXIS];
7873
-    normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
7874
-    nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
7875
-    nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
7876
-    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
7877
-    CBI(y_splits, cy);
7878
-  }
7879
-  else if (cy < pcy && TEST(y_splits, pcy)) {
7880
-    ny = mbl.get_probe_y(pcy) + home_offset[Y_AXIS];
7881
-    normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
7882
-    nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
7883
-    nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
7884
-    ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
7885
-    CBI(y_splits, pcy);
7850
+
7851
+  #define MBL_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist)
7852
+
7853
+  float normalized_dist, end[NUM_AXIS];
7854
+
7855
+  // Split at the left/front border of the right/top square
7856
+  int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
7857
+  if (cx2 != cx1 && TEST(x_splits, gcx)) {
7858
+    memcpy(end, destination, sizeof(end));
7859
+    destination[X_AXIS] = mbl.get_probe_x(gcx) + home_offset[X_AXIS] + position_shift[X_AXIS];
7860
+    normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
7861
+    destination[Y_AXIS] = MBL_SEGMENT_END(Y);
7862
+    CBI(x_splits, gcx);
7863
+  }
7864
+  else if (cy2 != cy1 && TEST(y_splits, gcy)) {
7865
+    memcpy(end, destination, sizeof(end));
7866
+    destination[Y_AXIS] = mbl.get_probe_y(gcy) + home_offset[Y_AXIS] + position_shift[Y_AXIS];
7867
+    normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
7868
+    destination[X_AXIS] = MBL_SEGMENT_END(X);
7869
+    CBI(y_splits, gcy);
7886 7870
   }
7887 7871
   else {
7888 7872
     // Already split on a border
7889
-    planner.buffer_line(x, y, z, e, fr_mm_s, extruder);
7873
+    line_to_destination(fr_mm_m);
7890 7874
     set_current_to_destination();
7891 7875
     return;
7892 7876
   }
7877
+
7878
+  destination[Z_AXIS] = MBL_SEGMENT_END(Z);
7879
+  destination[E_AXIS] = MBL_SEGMENT_END(E);
7880
+
7893 7881
   // Do the split and look for more borders
7894
-  destination[X_AXIS] = nx;
7895
-  destination[Y_AXIS] = ny;
7896
-  destination[Z_AXIS] = nz;
7897
-  destination[E_AXIS] = ne;
7898
-  mesh_buffer_line(nx, ny, nz, ne, fr_mm_s, extruder, x_splits, y_splits);
7899
-  destination[X_AXIS] = x;
7900
-  destination[Y_AXIS] = y;
7901
-  destination[Z_AXIS] = z;
7902
-  destination[E_AXIS] = e;
7903
-  mesh_buffer_line(x, y, z, e, fr_mm_s, extruder, x_splits, y_splits);
7882
+  mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
7883
+
7884
+  // Restore destination from stack
7885
+  memcpy(destination, end, sizeof(end));
7886
+  mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
7904 7887
 }
7905 7888
 #endif  // MESH_BED_LEVELING
7906 7889
 
@@ -7997,11 +7980,13 @@ void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, c
7997 7980
     }
7998 7981
     else {
7999 7982
       #if ENABLED(MESH_BED_LEVELING)
8000
-        mesh_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], MMM_TO_MMS_SCALED(feedrate_mm_m), active_extruder);
8001
-        return false;
8002
-      #else
8003
-        line_to_destination(MMM_SCALED(feedrate_mm_m));
7983
+        if (mbl.active()) {
7984
+          mesh_line_to_destination(MMM_SCALED(feedrate_mm_m));
7985
+          return false;
7986
+        }
7987
+        else
8004 7988
       #endif
7989
+          line_to_destination(MMM_SCALED(feedrate_mm_m));
8005 7990
     }
8006 7991
     return true;
8007 7992
   }

+ 2
- 2
Marlin/SanityCheck.h Voir le fichier

@@ -238,8 +238,8 @@
238 238
     #error "MESH_BED_LEVELING does not yet support DELTA printers."
239 239
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
240 240
     #error "Select AUTO_BED_LEVELING_FEATURE or MESH_BED_LEVELING, not both."
241
-  #elif MESH_NUM_X_POINTS > 7 || MESH_NUM_Y_POINTS > 7
242
-    #error "MESH_NUM_X_POINTS and MESH_NUM_Y_POINTS need to be less than 8."
241
+  #elif MESH_NUM_X_POINTS > 9 || MESH_NUM_Y_POINTS > 9
242
+    #error "MESH_NUM_X_POINTS and MESH_NUM_Y_POINTS must be less than 10."
243 243
   #endif
244 244
 #elif ENABLED(MANUAL_BED_LEVELING)
245 245
   #error "MESH_BED_LEVELING is required for MANUAL_BED_LEVELING."

+ 1
- 1
Marlin/configuration_store.cpp Voir le fichier

@@ -67,7 +67,7 @@
67 67
  *  203            z_offset (float)
68 68
  *  207            mesh_num_x (uint8 as set in firmware)
69 69
  *  208            mesh_num_y (uint8 as set in firmware)
70
- *  209 G29 S3 XYZ z_values[][] (float x9, by default)
70
+ *  209 G29 S3 XYZ z_values[][] (float x9, by default, up to float x 81)
71 71
  *
72 72
  * AUTO BED LEVELING
73 73
  *  245  M851      zprobe_zoffset (float)

Chargement…
Annuler
Enregistrer