Browse Source

Merge pull request #5816 from thinkyhead/rc_abl_virt_reduce

Reduce memory use by ABL_BILINEAR_SUBDIVISION slightly
Scott Lahteine 8 years ago
parent
commit
467f01435f
1 changed files with 38 additions and 31 deletions
  1. 38
    31
      Marlin/Marlin_main.cpp

+ 38
- 31
Marlin/Marlin_main.cpp View File

2467
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2467
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2468
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2468
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2469
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2469
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2470
+    #define ABL_TEMP_POINTS_X (ABL_GRID_MAX_POINTS_X + 2)
2471
+    #define ABL_TEMP_POINTS_Y (ABL_GRID_MAX_POINTS_Y + 2)
2470
     float bed_level_grid_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
2472
     float bed_level_grid_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
2471
-    float bed_level_grid_virt_temp[ABL_GRID_MAX_POINTS_X + 2][ABL_GRID_MAX_POINTS_Y + 2]; //temporary for calculation (maybe dynamical?)
2472
     int bilinear_grid_spacing_virt[2] = { 0 };
2473
     int bilinear_grid_spacing_virt[2] = { 0 };
2473
 
2474
 
2474
     static void bed_level_virt_print() {
2475
     static void bed_level_virt_print() {
2486
           SERIAL_PROTOCOLCHAR(' ');
2487
           SERIAL_PROTOCOLCHAR(' ');
2487
           float offset = bed_level_grid_virt[x][y];
2488
           float offset = bed_level_grid_virt[x][y];
2488
           if (offset != UNPROBED) {
2489
           if (offset != UNPROBED) {
2489
-            if (offset > 0) SERIAL_CHAR('+');
2490
+            if (offset >= 0) SERIAL_CHAR('+');
2490
             SERIAL_PROTOCOL_F(offset, 5);
2491
             SERIAL_PROTOCOL_F(offset, 5);
2491
           }
2492
           }
2492
           else
2493
           else
2496
       }
2497
       }
2497
       SERIAL_EOL;
2498
       SERIAL_EOL;
2498
     }
2499
     }
2499
-    #define LINEAR_EXTRAPOLATION(E, I) (E * 2 - I)
2500
-    void bed_level_virt_prepare() {
2501
-      for (uint8_t y = 1; y <= ABL_GRID_MAX_POINTS_Y; y++) {
2502
-
2503
-        for (uint8_t x = 1; x <= ABL_GRID_MAX_POINTS_X; x++)
2504
-          bed_level_grid_virt_temp[x][y] = bed_level_grid[x - 1][y - 1];
2505
-
2506
-        bed_level_grid_virt_temp[0][y] = LINEAR_EXTRAPOLATION(
2507
-          bed_level_grid_virt_temp[1][y],
2508
-          bed_level_grid_virt_temp[2][y]
2509
-        );
2510
-
2511
-        bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 1][y] =
2512
-          LINEAR_EXTRAPOLATION(
2513
-            bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 2][y],
2514
-            bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 3][y]
2500
+    #define LINEAR_EXTRAPOLATION(E, I) ((E) * 2 - (I))
2501
+    float bed_level_virt_coord(const uint8_t x, const uint8_t y) {
2502
+      uint8_t ep = 0, ip = 1;
2503
+      if (!x || x == ABL_TEMP_POINTS_X - 1) {
2504
+        if (x) {
2505
+          ep = ABL_GRID_MAX_POINTS_X - 1;
2506
+          ip = ABL_GRID_MAX_POINTS_X - 2;
2507
+        }
2508
+        if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
2509
+          return LINEAR_EXTRAPOLATION(
2510
+            bed_level_grid[ep][y - 1],
2511
+            bed_level_grid[ip][y - 1]
2512
+          );
2513
+        else
2514
+          return LINEAR_EXTRAPOLATION(
2515
+            bed_level_virt_coord(ep + 1, y),
2516
+            bed_level_virt_coord(ip + 1, y)
2515
           );
2517
           );
2516
       }
2518
       }
2517
-      for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X + 2; x++) {
2518
-        bed_level_grid_virt_temp[x][0] = LINEAR_EXTRAPOLATION(
2519
-          bed_level_grid_virt_temp[x][1],
2520
-          bed_level_grid_virt_temp[x][2]
2521
-        );
2522
-        bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 1] =
2523
-          LINEAR_EXTRAPOLATION(
2524
-            bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 2],
2525
-            bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 3]
2519
+      if (!y || y == ABL_TEMP_POINTS_Y - 1) {
2520
+        if (y) {
2521
+          ep = ABL_GRID_MAX_POINTS_Y - 1;
2522
+          ip = ABL_GRID_MAX_POINTS_Y - 2;
2523
+        }
2524
+        if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
2525
+          return LINEAR_EXTRAPOLATION(
2526
+            bed_level_grid[x - 1][ep],
2527
+            bed_level_grid[x - 1][ip]
2528
+          );
2529
+        else
2530
+          return LINEAR_EXTRAPOLATION(
2531
+            bed_level_virt_coord(x, ep + 1),
2532
+            bed_level_virt_coord(x, ip + 1)
2526
           );
2533
           );
2527
       }
2534
       }
2535
+      return bed_level_grid[x - 1][y - 1];
2528
     }
2536
     }
2529
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2537
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2530
       return (
2538
       return (
2537
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2545
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2538
       float row[4], column[4];
2546
       float row[4], column[4];
2539
       for (uint8_t i = 0; i < 4; i++) {
2547
       for (uint8_t i = 0; i < 4; i++) {
2540
-        for (uint8_t j = 0; j < 4; j++) // can be memcopy or through memory access
2541
-          column[j] = bed_level_grid_virt_temp[i + x - 1][j + y - 1];
2548
+        for (uint8_t j = 0; j < 4; j++) {
2549
+          column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
2550
+        }
2542
         row[i] = bed_level_virt_cmr(column, 1, ty);
2551
         row[i] = bed_level_virt_cmr(column, 1, ty);
2543
       }
2552
       }
2544
       return bed_level_virt_cmr(row, 1, tx);
2553
       return bed_level_virt_cmr(row, 1, tx);
4242
       print_bilinear_leveling_grid();
4251
       print_bilinear_leveling_grid();
4243
 
4252
 
4244
       #if ENABLED(ABL_BILINEAR_SUBDIVISION)
4253
       #if ENABLED(ABL_BILINEAR_SUBDIVISION)
4245
-        bed_level_virt_prepare();
4246
         bed_level_virt_interpolate();
4254
         bed_level_virt_interpolate();
4247
         bed_level_virt_print();
4255
         bed_level_virt_print();
4248
       #endif
4256
       #endif
7141
       if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7149
       if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7142
         bed_level_grid[px][py] = z;
7150
         bed_level_grid[px][py] = z;
7143
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7151
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7144
-          bed_level_virt_prepare();
7145
           bed_level_virt_interpolate();
7152
           bed_level_virt_interpolate();
7146
         #endif
7153
         #endif
7147
       }
7154
       }

Loading…
Cancel
Save