Browse Source

Reduce memory use by ABL_BILINEAR_SUBDIVISION slightly

jes 8 years ago
parent
commit
eaa829b58c
1 changed files with 38 additions and 31 deletions
  1. 38
    31
      Marlin/Marlin_main.cpp

+ 38
- 31
Marlin/Marlin_main.cpp View File

2454
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2454
   #if ENABLED(ABL_BILINEAR_SUBDIVISION)
2455
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2455
     #define ABL_GRID_POINTS_VIRT_X (ABL_GRID_MAX_POINTS_X - 1) * (BILINEAR_SUBDIVISIONS) + 1
2456
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2456
     #define ABL_GRID_POINTS_VIRT_Y (ABL_GRID_MAX_POINTS_Y - 1) * (BILINEAR_SUBDIVISIONS) + 1
2457
+    #define ABL_TEMP_POINTS_X (ABL_GRID_MAX_POINTS_X + 2)
2458
+    #define ABL_TEMP_POINTS_Y (ABL_GRID_MAX_POINTS_Y + 2)
2457
     float bed_level_grid_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
2459
     float bed_level_grid_virt[ABL_GRID_POINTS_VIRT_X][ABL_GRID_POINTS_VIRT_Y];
2458
-    float bed_level_grid_virt_temp[ABL_GRID_MAX_POINTS_X + 2][ABL_GRID_MAX_POINTS_Y + 2]; //temporary for calculation (maybe dynamical?)
2459
     int bilinear_grid_spacing_virt[2] = { 0 };
2460
     int bilinear_grid_spacing_virt[2] = { 0 };
2460
 
2461
 
2461
     static void bed_level_virt_print() {
2462
     static void bed_level_virt_print() {
2473
           SERIAL_PROTOCOLCHAR(' ');
2474
           SERIAL_PROTOCOLCHAR(' ');
2474
           float offset = bed_level_grid_virt[x][y];
2475
           float offset = bed_level_grid_virt[x][y];
2475
           if (offset != UNPROBED) {
2476
           if (offset != UNPROBED) {
2476
-            if (offset > 0) SERIAL_CHAR('+');
2477
+            if (offset >= 0) SERIAL_CHAR('+');
2477
             SERIAL_PROTOCOL_F(offset, 5);
2478
             SERIAL_PROTOCOL_F(offset, 5);
2478
           }
2479
           }
2479
           else
2480
           else
2483
       }
2484
       }
2484
       SERIAL_EOL;
2485
       SERIAL_EOL;
2485
     }
2486
     }
2486
-    #define LINEAR_EXTRAPOLATION(E, I) (E * 2 - I)
2487
-    void bed_level_virt_prepare() {
2488
-      for (uint8_t y = 1; y <= ABL_GRID_MAX_POINTS_Y; y++) {
2489
-
2490
-        for (uint8_t x = 1; x <= ABL_GRID_MAX_POINTS_X; x++)
2491
-          bed_level_grid_virt_temp[x][y] = bed_level_grid[x - 1][y - 1];
2492
-
2493
-        bed_level_grid_virt_temp[0][y] = LINEAR_EXTRAPOLATION(
2494
-          bed_level_grid_virt_temp[1][y],
2495
-          bed_level_grid_virt_temp[2][y]
2496
-        );
2497
-
2498
-        bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 1][y] =
2499
-          LINEAR_EXTRAPOLATION(
2500
-            bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 2][y],
2501
-            bed_level_grid_virt_temp[(ABL_GRID_MAX_POINTS_X + 2) - 3][y]
2487
+    #define LINEAR_EXTRAPOLATION(E, I) ((E) * 2 - (I))
2488
+    float bed_level_virt_coord(const uint8_t x, const uint8_t y) {
2489
+      uint8_t ep = 0, ip = 1;
2490
+      if (!x || x == ABL_TEMP_POINTS_X - 1) {
2491
+        if (x) {
2492
+          ep = ABL_GRID_MAX_POINTS_X - 1;
2493
+          ip = ABL_GRID_MAX_POINTS_X - 2;
2494
+        }
2495
+        if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
2496
+          return LINEAR_EXTRAPOLATION(
2497
+            bed_level_grid[ep][y - 1],
2498
+            bed_level_grid[ip][y - 1]
2499
+          );
2500
+        else
2501
+          return LINEAR_EXTRAPOLATION(
2502
+            bed_level_virt_coord(ep + 1, y),
2503
+            bed_level_virt_coord(ip + 1, y)
2502
           );
2504
           );
2503
       }
2505
       }
2504
-      for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X + 2; x++) {
2505
-        bed_level_grid_virt_temp[x][0] = LINEAR_EXTRAPOLATION(
2506
-          bed_level_grid_virt_temp[x][1],
2507
-          bed_level_grid_virt_temp[x][2]
2508
-        );
2509
-        bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 1] =
2510
-          LINEAR_EXTRAPOLATION(
2511
-            bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 2],
2512
-            bed_level_grid_virt_temp[x][(ABL_GRID_MAX_POINTS_Y + 2) - 3]
2506
+      if (!y || y == ABL_TEMP_POINTS_Y - 1) {
2507
+        if (y) {
2508
+          ep = ABL_GRID_MAX_POINTS_Y - 1;
2509
+          ip = ABL_GRID_MAX_POINTS_Y - 2;
2510
+        }
2511
+        if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
2512
+          return LINEAR_EXTRAPOLATION(
2513
+            bed_level_grid[x - 1][ep],
2514
+            bed_level_grid[x - 1][ip]
2515
+          );
2516
+        else
2517
+          return LINEAR_EXTRAPOLATION(
2518
+            bed_level_virt_coord(x, ep + 1),
2519
+            bed_level_virt_coord(x, ip + 1)
2513
           );
2520
           );
2514
       }
2521
       }
2522
+      return bed_level_grid[x - 1][y - 1];
2515
     }
2523
     }
2516
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2524
     static float bed_level_virt_cmr(const float p[4], const uint8_t i, const float t) {
2517
       return (
2525
       return (
2524
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2532
     static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
2525
       float row[4], column[4];
2533
       float row[4], column[4];
2526
       for (uint8_t i = 0; i < 4; i++) {
2534
       for (uint8_t i = 0; i < 4; i++) {
2527
-        for (uint8_t j = 0; j < 4; j++) // can be memcopy or through memory access
2528
-          column[j] = bed_level_grid_virt_temp[i + x - 1][j + y - 1];
2535
+        for (uint8_t j = 0; j < 4; j++) {
2536
+          column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
2537
+        }
2529
         row[i] = bed_level_virt_cmr(column, 1, ty);
2538
         row[i] = bed_level_virt_cmr(column, 1, ty);
2530
       }
2539
       }
2531
       return bed_level_virt_cmr(row, 1, tx);
2540
       return bed_level_virt_cmr(row, 1, tx);
4229
       print_bilinear_leveling_grid();
4238
       print_bilinear_leveling_grid();
4230
 
4239
 
4231
       #if ENABLED(ABL_BILINEAR_SUBDIVISION)
4240
       #if ENABLED(ABL_BILINEAR_SUBDIVISION)
4232
-        bed_level_virt_prepare();
4233
         bed_level_virt_interpolate();
4241
         bed_level_virt_interpolate();
4234
         bed_level_virt_print();
4242
         bed_level_virt_print();
4235
       #endif
4243
       #endif
7128
       if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7136
       if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7129
         bed_level_grid[px][py] = z;
7137
         bed_level_grid[px][py] = z;
7130
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7138
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7131
-          bed_level_virt_prepare();
7132
           bed_level_virt_interpolate();
7139
           bed_level_virt_interpolate();
7133
         #endif
7140
         #endif
7134
       }
7141
       }

Loading…
Cancel
Save