Переглянути джерело

Fix UBL mesh inset Z position (#20538)

Chris Pepper 3 роки тому
джерело
коміт
c1b900aae9
Аккаунт користувача з таким Email не знайдено

+ 21
- 12
Marlin/src/feature/bedlevel/ubl/ubl.h Переглянути файл

@@ -122,20 +122,29 @@ class unified_bed_leveling {
122 122
 
123 123
     FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
124 124
 
125
+    static int8_t cell_index_x_raw(const float &x) {
126
+      return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST));
127
+    }
128
+
129
+    static int8_t cell_index_y_raw(const float &y) {
130
+      return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST));
131
+    }
132
+
133
+    static int8_t cell_index_x_valid(const float &x) {
134
+      return WITHIN(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X - 2));
135
+    }
136
+
137
+    static int8_t cell_index_y_valid(const float &y) {
138
+      return WITHIN(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y - 2));
139
+    }
140
+
125 141
     static int8_t cell_index_x(const float &x) {
126
-      const int8_t cx = (x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST);
127
-      return constrain(cx, 0, (GRID_MAX_POINTS_X) - 1);   // -1 is appropriate if we want all movement to the X_MAX
128
-    }                                                     // position. But with this defined this way, it is possible
129
-                                                          // to extrapolate off of this point even further out. Probably
130
-                                                          // that is OK because something else should be keeping that from
131
-                                                          // happening and should not be worried about at this level.
142
+      return constrain(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X) - 2);
143
+    }
144
+
132 145
     static int8_t cell_index_y(const float &y) {
133
-      const int8_t cy = (y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST);
134
-      return constrain(cy, 0, (GRID_MAX_POINTS_Y) - 1);   // -1 is appropriate if we want all movement to the Y_MAX
135
-    }                                                     // position. But with this defined this way, it is possible
136
-                                                          // to extrapolate off of this point even further out. Probably
137
-                                                          // that is OK because something else should be keeping that from
138
-                                                          // happening and should not be worried about at this level.
146
+      return constrain(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y) - 2);
147
+    }
139 148
 
140 149
     static inline xy_int8_t cell_indexes(const float &x, const float &y) {
141 150
       return { cell_index_x(x), cell_index_y(y) };

+ 19
- 26
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Переглянути файл

@@ -56,39 +56,32 @@
56 56
     // A move within the same cell needs no splitting
57 57
     if (istart == iend) {
58 58
 
59
-      // For a move off the bed, use a constant Z raise
60
-      if (!WITHIN(iend.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(iend.y, 0, GRID_MAX_POINTS_Y - 1)) {
59
+      FINAL_MOVE:
61 60
 
62
-        // Note: There is no Z Correction in this case. We are off the grid and don't know what
63
-        // a reasonable correction would be.  If the user has specified a UBL_Z_RAISE_WHEN_OFF_MESH
64
-        // value, that will be used instead of a calculated (Bi-Linear interpolation) correction.
61
+      // When UBL_Z_RAISE_WHEN_OFF_MESH is disabled Z correction is extrapolated from the edge of the mesh
62
+      #ifdef UBL_Z_RAISE_WHEN_OFF_MESH
63
+        // For a move off the UBL mesh, use a constant Z raise
64
+        if (!cell_index_x_valid(end.x) || !cell_index_y_valid(end.y)) {
65 65
 
66
-        #ifdef UBL_Z_RAISE_WHEN_OFF_MESH
67
-          end.z += UBL_Z_RAISE_WHEN_OFF_MESH;
68
-        #endif
69
-        planner.buffer_segment(end, scaled_fr_mm_s, extruder);
70
-        current_position = destination;
71
-        return;
72
-      }
66
+          // Note: There is no Z Correction in this case. We are off the mesh and don't know what
67
+          // a reasonable correction would be, UBL_Z_RAISE_WHEN_OFF_MESH will be used instead of
68
+          // a calculated (Bi-Linear interpolation) correction.
73 69
 
74
-      FINAL_MOVE:
70
+          end.z += UBL_Z_RAISE_WHEN_OFF_MESH;
71
+          planner.buffer_segment(end, scaled_fr_mm_s, extruder);
72
+          current_position = destination;
73
+          return;
74
+        }
75
+      #endif
75 76
 
76 77
       // The distance is always MESH_X_DIST so multiply by the constant reciprocal.
77
-      const float xratio = (end.x - mesh_index_to_xpos(iend.x)) * RECIPROCAL(MESH_X_DIST);
78
-
79
-      float z1, z2;
80
-      if (iend.x >= GRID_MAX_POINTS_X - 1)
81
-        z1 = z2 = 0.0;
82
-      else {
83
-        z1 = z_values[iend.x    ][iend.y    ] + xratio *
84
-            (z_values[iend.x + 1][iend.y    ] - z_values[iend.x][iend.y    ]),
85
-        z2 = z_values[iend.x    ][iend.y + 1] + xratio *
86
-            (z_values[iend.x + 1][iend.y + 1] - z_values[iend.x][iend.y + 1]);
87
-      }
78
+      const float xratio = (end.x - mesh_index_to_xpos(iend.x)) * RECIPROCAL(MESH_X_DIST),
79
+                  yratio = (end.y - mesh_index_to_ypos(iend.y)) * RECIPROCAL(MESH_Y_DIST),
80
+                  z1 = z_values[iend.x][iend.y    ] + xratio * (z_values[iend.x + 1][iend.y    ] - z_values[iend.x][iend.y    ]),
81
+                  z2 = z_values[iend.x][iend.y + 1] + xratio * (z_values[iend.x + 1][iend.y + 1] - z_values[iend.x][iend.y + 1]);
88 82
 
89 83
       // X cell-fraction done. Interpolate the two Z offsets with the Y fraction for the final Z offset.
90
-      const float yratio = (end.y - mesh_index_to_ypos(iend.y)) * RECIPROCAL(MESH_Y_DIST),
91
-                  z0 = iend.y < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end.z) : 0.0;
84
+      const float z0 = (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end.z);
92 85
 
93 86
       // Undefined parts of the Mesh in z_values[][] are NAN.
94 87
       // Replace NAN corrections with 0.0 to prevent NAN propagation.

Завантаження…
Відмінити
Зберегти