浏览代码

Fix large Z corrections when nozzle moves off of UBL mesh (#7415)

Roxy-3D 6 年前
父节点
当前提交
2cbdc0ebb6
共有 2 个文件被更改,包括 30 次插入10 次删除
  1. 19
    8
      Marlin/ubl.h
  2. 11
    2
      Marlin/ubl_motion.cpp

+ 19
- 8
Marlin/ubl.h 查看文件

@@ -152,7 +152,7 @@
152 152
       static void save_ubl_active_state_and_disable();
153 153
       static void restore_ubl_active_state_and_leave();
154 154
       static void display_map(const int);
155
-      static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, unsigned int[16], bool);
155
+      static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16], bool);
156 156
       static void reset();
157 157
       static void invalidate();
158 158
       static void set_all_mesh_points_to_value(float);
@@ -247,10 +247,10 @@
247 247
 
248 248
       /**
249 249
        * z_correction_for_x_on_horizontal_mesh_line is an optimization for
250
-       * the rare occasion when a point lies exactly on a Mesh line (denoted by index yi).
250
+       * the case where the printer is making a vertical line that only crosses horizontal mesh lines.
251 251
        */
252 252
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &lx0, const int x1_i, const int yi) {
253
-        if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
253
+        if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
254 254
           serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
255 255
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(lx0=", lx0);
256 256
           SERIAL_ECHOPAIR(",x1_i=", x1_i);
@@ -270,7 +270,7 @@
270 270
       // See comments above for z_correction_for_x_on_horizontal_mesh_line
271 271
       //
272 272
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ly0, const int xi, const int y1_i) {
273
-        if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
273
+        if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 2)) {
274 274
           serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
275 275
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ly0=", ly0);
276 276
           SERIAL_ECHOPAIR(", xi=", xi);
@@ -296,7 +296,7 @@
296 296
         const int8_t cx = get_cell_index_x(RAW_X_POSITION(lx0)),
297 297
                      cy = get_cell_index_y(RAW_Y_POSITION(ly0));
298 298
 
299
-        if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 1)) {
299
+        if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 2)) {
300 300
 
301 301
           SERIAL_ECHOPAIR("? in get_z_correction(lx0=", lx0);
302 302
           SERIAL_ECHOPAIR(", ly0=", ly0);
@@ -307,7 +307,7 @@
307 307
             strcpy(lcd_status_message, "get_z_correction() indexes out of range.");
308 308
             lcd_quick_feedback();
309 309
           #endif
310
-          return 0.0; // this used to return state.z_offset
310
+          return NAN; // this used to return state.z_offset
311 311
         }
312 312
 
313 313
         const float z1 = calc_z0(RAW_X_POSITION(lx0),
@@ -384,8 +384,19 @@
384 384
         FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) { return 1.0; }
385 385
       #endif
386 386
 
387
-      FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) { return pgm_read_float(&_mesh_index_to_xpos[i]); }
388
-      FORCE_INLINE static float mesh_index_to_ypos(const uint8_t i) { return pgm_read_float(&_mesh_index_to_ypos[i]); }
387
+      FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) { 
388
+        if (i<GRID_MAX_POINTS_X) 
389
+          return pgm_read_float(&_mesh_index_to_xpos[i]); 
390
+        else  
391
+          return UBL_MESH_MIN_X + i * (MESH_X_DIST);
392
+      }
393
+
394
+      FORCE_INLINE static float mesh_index_to_ypos(const uint8_t i) { 
395
+        if (i<GRID_MAX_POINTS_Y) 
396
+          return pgm_read_float(&_mesh_index_to_ypos[i]); 
397
+        else  
398
+          return UBL_MESH_MIN_Y + i * (MESH_Y_DIST);
399
+      }
389 400
 
390 401
       static bool prepare_segmented_line_to(const float ltarget[XYZE], const float &feedrate);
391 402
       static void line_to_destination_cartesian(const float &fr, uint8_t e);

+ 11
- 2
Marlin/ubl_motion.cpp 查看文件

@@ -173,12 +173,18 @@
173 173
        * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
174 174
        */
175 175
 
176
-      const float xratio = (RAW_X_POSITION(end[X_AXIS]) - mesh_index_to_xpos(cell_dest_xi)) * (1.0 / (MESH_X_DIST)),
177
-                  z1 = z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
176
+      const float xratio = (RAW_X_POSITION(end[X_AXIS]) - mesh_index_to_xpos(cell_dest_xi)) * (1.0 / (MESH_X_DIST));
177
+
178
+      float z1 = z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
178 179
                       (z_values[cell_dest_xi + 1][cell_dest_yi    ] - z_values[cell_dest_xi][cell_dest_yi    ]),
179 180
                   z2 = z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
180 181
                       (z_values[cell_dest_xi + 1][cell_dest_yi + 1] - z_values[cell_dest_xi][cell_dest_yi + 1]);
181 182
 
183
+      if ( cell_dest_xi >= GRID_MAX_POINTS_X-1) {
184
+        z1 = 0.0;
185
+        z2 = 0.0;
186
+      }
187
+
182 188
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
183 189
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
184 190
 
@@ -186,6 +192,9 @@
186 192
 
187 193
       float z0 = z1 + (z2 - z1) * yratio;
188 194
 
195
+      if ( cell_dest_yi >= GRID_MAX_POINTS_Y-1) 
196
+        z0 = 0.0;
197
+
189 198
       z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
190 199
 
191 200
       /**

正在加载...
取消
保存