Browse Source

Better off mesh behavior for UBL (#8713)

* Better off mesh behaviour for UBL

* Spacing changes...
Roxy-3D 7 years ago
parent
commit
23dd2cb6e7
No account linked to committer's email address
2 changed files with 13 additions and 9 deletions
  1. 1
    1
      Marlin/example_configurations/gCreate/gMax1.5+/Configuration.h
  2. 12
    8
      Marlin/ubl.h

+ 1
- 1
Marlin/example_configurations/gCreate/gMax1.5+/Configuration.h View File

978
   //========================= Unified Bed Leveling ============================
978
   //========================= Unified Bed Leveling ============================
979
   //===========================================================================
979
   //===========================================================================
980
 
980
 
981
-  //#define MESH_EDIT_GFX_OVERLAY   // Display a graphics overlay while editing the mesh
981
+  #define MESH_EDIT_GFX_OVERLAY     // Display a graphics overlay while editing the mesh
982
 
982
 
983
   #define MESH_INSET 45             // Mesh inset margin on print area
983
   #define MESH_INSET 45             // Mesh inset margin on print area
984
   #define GRID_MAX_POINTS_X 10      // Don't use more than 15 points per axis, implementation limited.
984
   #define GRID_MAX_POINTS_X 10      // Don't use more than 15 points per axis, implementation limited.

+ 12
- 8
Marlin/ubl.h View File

204
        * the case where the printer is making a vertical line that only crosses horizontal mesh lines.
204
        * the case where the printer is making a vertical line that only crosses horizontal mesh lines.
205
        */
205
        */
206
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
206
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
207
-        if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
207
+        if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
208
         #if ENABLED(DEBUG_LEVELING_FEATURE)
208
         #if ENABLED(DEBUG_LEVELING_FEATURE)
209
           if (DEBUGGING(LEVELING)) {
209
           if (DEBUGGING(LEVELING)) {
210
           serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
210
           serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
221
         const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)),
221
         const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)),
222
                     z1 = z_values[x1_i][yi];
222
                     z1 = z_values[x1_i][yi];
223
 
223
 
224
-        return z1 + xratio * (z_values[x1_i + 1][yi] - z1);
224
+        return z1 + xratio * (z_values[x1_i < GRID_MAX_POINTS_X - 1 ? x1_i + 1 : x1_i][yi] - z1);  // Don't allow x1_i+1 to be past the end of the array
225
+                                                                                                   // If it is, it is clamped to the last element of the 
226
+                                                                                                   // z_values[][] array and no correction is applied.
225
       }
227
       }
226
 
228
 
227
       //
229
       //
228
       // See comments above for z_correction_for_x_on_horizontal_mesh_line
230
       // See comments above for z_correction_for_x_on_horizontal_mesh_line
229
       //
231
       //
230
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
232
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
231
-        if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 2)) {
233
+        if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
232
         #if ENABLED(DEBUG_LEVELING_FEATURE)
234
         #if ENABLED(DEBUG_LEVELING_FEATURE)
233
           if (DEBUGGING(LEVELING)) {
235
           if (DEBUGGING(LEVELING)) {
234
           serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
236
           serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
245
         const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (MESH_Y_DIST)),
247
         const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (MESH_Y_DIST)),
246
                     z1 = z_values[xi][y1_i];
248
                     z1 = z_values[xi][y1_i];
247
 
249
 
248
-        return z1 + yratio * (z_values[xi][y1_i + 1] - z1);
250
+        return z1 + yratio * (z_values[xi][y1_i < GRID_MAX_POINTS_Y - 1 ? y1_i + 1 : y1_i] - z1);  // Don't allow y1_i+1 to be past the end of the array
251
+                                                                                                   // If it is, it is clamped to the last element of the 
252
+                                                                                                   // z_values[][] array and no correction is applied.
249
       }
253
       }
250
 
254
 
251
       /**
255
       /**
258
         const int8_t cx = get_cell_index_x(rx0),
262
         const int8_t cx = get_cell_index_x(rx0),
259
                      cy = get_cell_index_y(ry0);
263
                      cy = get_cell_index_y(ry0);
260
 
264
 
261
-        if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 2)) {
265
+        if (!WITHIN(cx, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(cy, 0, GRID_MAX_POINTS_Y - 1)) {
262
 
266
 
263
           SERIAL_ECHOPAIR("? in get_z_correction(rx0=", rx0);
267
           SERIAL_ECHOPAIR("? in get_z_correction(rx0=", rx0);
264
           SERIAL_ECHOPAIR(", ry0=", ry0);
268
           SERIAL_ECHOPAIR(", ry0=", ry0);
274
 
278
 
275
         const float z1 = calc_z0(rx0,
279
         const float z1 = calc_z0(rx0,
276
                                  mesh_index_to_xpos(cx), z_values[cx][cy],
280
                                  mesh_index_to_xpos(cx), z_values[cx][cy],
277
-                                 mesh_index_to_xpos(cx + 1), z_values[cx + 1][cy]);
281
+                                 mesh_index_to_xpos(cx + 1), z_values[cx < GRID_MAX_POINTS_X - 1 ? cx + 1 : cx][cy]);
278
 
282
 
279
         const float z2 = calc_z0(rx0,
283
         const float z2 = calc_z0(rx0,
280
-                                 mesh_index_to_xpos(cx), z_values[cx][cy + 1],
281
-                                 mesh_index_to_xpos(cx + 1), z_values[cx + 1][cy + 1]);
284
+                                 mesh_index_to_xpos(cx), z_values[cx][cy < GRID_MAX_POINTS_Y - 1 ? cy + 1 : cy],
285
+                                 mesh_index_to_xpos(cx + 1), z_values[cx < GRID_MAX_POINTS_X - 1 ? cx + 1 : cx][cy<GRID_MAX_POINTS_Y - 1 ? cy + 1 : cy]);
282
 
286
 
283
         float z0 = calc_z0(ry0,
287
         float z0 = calc_z0(ry0,
284
                            mesh_index_to_ypos(cy), z1,
288
                            mesh_index_to_ypos(cy), z1,

Loading…
Cancel
Save