Browse Source

Save ABL Bilinear Grid to EEPROM

Scott Lahteine 7 years ago
parent
commit
e42fd7813a
3 changed files with 144 additions and 61 deletions
  1. 7
    1
      Marlin/Marlin.h
  2. 2
    2
      Marlin/Marlin_main.cpp
  3. 135
    58
      Marlin/configuration_store.cpp

+ 7
- 1
Marlin/Marlin.h View File

330
 #endif
330
 #endif
331
 
331
 
332
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
332
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
333
-  extern int bilinear_grid_spacing[2];
333
+  extern int bilinear_grid_spacing[2], bilinear_start[2];
334
+  extern float bed_level_grid[ABL_GRID_MAX_POINTS_X][ABL_GRID_MAX_POINTS_Y];
334
   float bilinear_z_offset(float logical[XYZ]);
335
   float bilinear_z_offset(float logical[XYZ]);
336
+  void set_bed_leveling_enabled(bool enable=true);
337
+#endif
338
+
339
+#if PLANNER_LEVELING
340
+  void reset_bed_level();
335
 #endif
341
 #endif
336
 
342
 
337
 #if ENABLED(Z_DUAL_ENDSTOPS)
343
 #if ENABLED(Z_DUAL_ENDSTOPS)

+ 2
- 2
Marlin/Marlin_main.cpp View File

2482
       SERIAL_EOL;
2482
       SERIAL_EOL;
2483
     }
2483
     }
2484
     #define LINEAR_EXTRAPOLATION(E, I) (E * 2 - I)
2484
     #define LINEAR_EXTRAPOLATION(E, I) (E * 2 - I)
2485
-    static void bed_level_virt_prepare() {
2485
+    void bed_level_virt_prepare() {
2486
       for (uint8_t y = 1; y <= ABL_GRID_MAX_POINTS_Y; y++) {
2486
       for (uint8_t y = 1; y <= ABL_GRID_MAX_POINTS_Y; y++) {
2487
 
2487
 
2488
         for (uint8_t x = 1; x <= ABL_GRID_MAX_POINTS_X; x++)
2488
         for (uint8_t x = 1; x <= ABL_GRID_MAX_POINTS_X; x++)
2528
       }
2528
       }
2529
       return bed_level_virt_cmr(row, 1, tx);
2529
       return bed_level_virt_cmr(row, 1, tx);
2530
     }
2530
     }
2531
-    static void bed_level_virt_interpolate() {
2531
+    void bed_level_virt_interpolate() {
2532
       for (uint8_t y = 0; y < ABL_GRID_MAX_POINTS_Y; y++)
2532
       for (uint8_t y = 0; y < ABL_GRID_MAX_POINTS_Y; y++)
2533
         for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++)
2533
         for (uint8_t x = 0; x < ABL_GRID_MAX_POINTS_X; x++)
2534
           for (uint8_t ty = 0; ty < BILINEAR_SUBDIVISIONS; ty++)
2534
           for (uint8_t ty = 0; ty < BILINEAR_SUBDIVISIONS; ty++)

+ 135
- 58
Marlin/configuration_store.cpp View File

36
  *
36
  *
37
  */
37
  */
38
 
38
 
39
-#define EEPROM_VERSION "V28"
39
+#define EEPROM_VERSION "V29"
40
 
40
 
41
 // Change EEPROM version if these are changed:
41
 // Change EEPROM version if these are changed:
42
 #define EEPROM_OFFSET 100
42
 #define EEPROM_OFFSET 100
43
 
43
 
44
 /**
44
 /**
45
- * V28 EEPROM Layout:
45
+ * V29 EEPROM Layout:
46
  *
46
  *
47
- *  100  Version (char x4)
48
- *  104  EEPROM Checksum (uint16_t)
47
+ *  100  Version                                   (char x4)
48
+ *  104  EEPROM Checksum                           (uint16_t)
49
  *
49
  *
50
- *  106  E_STEPPERS (uint8_t)
50
+ *  106            E_STEPPERS (uint8_t)
51
  *  107  M92 XYZE  planner.axis_steps_per_mm (float x4 ... x7)
51
  *  107  M92 XYZE  planner.axis_steps_per_mm (float x4 ... x7)
52
  *  123  M203 XYZE planner.max_feedrate_mm_s (float x4 ... x7)
52
  *  123  M203 XYZE planner.max_feedrate_mm_s (float x4 ... x7)
53
  *  139  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x7)
53
  *  139  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x7)
74
  * AUTO BED LEVELING
74
  * AUTO BED LEVELING
75
  *  262  M851      zprobe_zoffset (float)
75
  *  262  M851      zprobe_zoffset (float)
76
  *
76
  *
77
- * DELTA:
78
- *  266  M666 XYZ  endstop_adj (float x3)
79
- *  278  M665 R    delta_radius (float)
80
- *  282  M665 L    delta_diagonal_rod (float)
81
- *  286  M665 S    delta_segments_per_second (float)
82
- *  290  M665 A    delta_diagonal_rod_trim_tower_1 (float)
83
- *  294  M665 B    delta_diagonal_rod_trim_tower_2 (float)
84
- *  298  M665 C    delta_diagonal_rod_trim_tower_3 (float)
77
+ * AUTO_BED_LEVELING_BILINEAR (or placeholder):    47 bytes
78
+ *  266            ABL_GRID_MAX_POINTS_X           (uint8_t)
79
+ *  267            ABL_GRID_MAX_POINTS_Y           (uint8_t)
80
+ *  268            bilinear_grid_spacing           (int x2)   from G29: (B-F)/X, (R-L)/Y
81
+ *  272  G29 L F   bilinear_start                  (int x2)
82
+ *  276            bed_level_grid[][]              (float x9, up to float x256) +988
85
  *
83
  *
86
- * Z_DUAL_ENDSTOPS:
87
- *  302  M666 Z    z_endstop_adj (float)
84
+ * DELTA (if deltabot):                            36 bytes
85
+ *  312  M666 XYZ  endstop_adj                     (float x3)
86
+ *  324  M665 R    delta_radius                    (float)
87
+ *  328  M665 L    delta_diagonal_rod              (float)
88
+ *  332  M665 S    delta_segments_per_second       (float)
89
+ *  336  M665 A    delta_diagonal_rod_trim_tower_1 (float)
90
+ *  340  M665 B    delta_diagonal_rod_trim_tower_2 (float)
91
+ *  344  M665 C    delta_diagonal_rod_trim_tower_3 (float)
88
  *
92
  *
89
- * ULTIPANEL:
90
- *  306  M145 S0 H lcd_preheat_hotend_temp (int x2)
91
- *  310  M145 S0 B lcd_preheat_bed_temp (int x2)
92
- *  314  M145 S0 F lcd_preheat_fan_speed (int x2)
93
+ * Z_DUAL_ENDSTOPS:                                4 bytes
94
+ *  348  M666 Z    z_endstop_adj                   (float)
93
  *
95
  *
94
- * PIDTEMP:
95
- *  318  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
96
- *  334  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
97
- *  350  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
98
- *  366  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
99
- *  382  M301 L        lpq_len (int)
96
+ * ULTIPANEL:                                      6 bytes
97
+ *  352  M145 S0 H lcd_preheat_hotend_temp         (int x2)
98
+ *  356  M145 S0 B lcd_preheat_bed_temp            (int x2)
99
+ *  360  M145 S0 F lcd_preheat_fan_speed           (int x2)
100
+ *
101
+ * PIDTEMP:                                        66 bytes
102
+ *  364  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0]  (float x4)
103
+ *  380  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1]  (float x4)
104
+ *  396  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2]  (float x4)
105
+ *  412  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3]  (float x4)
106
+ *  428  M301 L        lpq_len                     (int)
100
  *
107
  *
101
  * PIDTEMPBED:
108
  * PIDTEMPBED:
102
- *  384  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
109
+ *  430  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
103
  *
110
  *
104
- * DOGLCD:
105
- *  396  M250 C    lcd_contrast (int)
111
+ * DOGLCD:                                          2 bytes
112
+ *  442  M250 C    lcd_contrast                     (int)
106
  *
113
  *
107
- * FWRETRACT:
108
- *  398  M209 S    autoretract_enabled (bool)
109
- *  399  M207 S    retract_length (float)
110
- *  403  M207 W    retract_length_swap (float)
111
- *  407  M207 F    retract_feedrate_mm_s (float)
112
- *  411  M207 Z    retract_zlift (float)
113
- *  415  M208 S    retract_recover_length (float)
114
- *  419  M208 W    retract_recover_length_swap (float)
115
- *  423  M208 F    retract_recover_feedrate_mm_s (float)
114
+ * FWRETRACT:                                       29 bytes
115
+ *  444  M209 S    autoretract_enabled              (bool)
116
+ *  445  M207 S    retract_length                   (float)
117
+ *  449  M207 W    retract_length_swap              (float)
118
+ *  453  M207 F    retract_feedrate_mm_s            (float)
119
+ *  457  M207 Z    retract_zlift                    (float)
120
+ *  461  M208 S    retract_recover_length           (float)
121
+ *  465  M208 W    retract_recover_length_swap      (float)
122
+ *  469  M208 F    retract_recover_feedrate_mm_s    (float)
116
  *
123
  *
117
- * Volumetric Extrusion:
118
- *  427  M200 D    volumetric_enabled (bool)
119
- *  428  M200 T D  filament_size (float x4) (T0..3)
124
+ * Volumetric Extrusion:                            17 bytes
125
+ *  473  M200 D    volumetric_enabled               (bool)
126
+ *  474  M200 T D  filament_size                    (float x4) (T0..3)
120
  *
127
  *
121
- *  444  This Slot is Available!
128
+ *  490                                Minimum end-point
129
+ * 1811 (490 + 36 + 9 + 288 + 988)     Maximum end-point
122
  *
130
  *
123
  */
131
  */
124
 #include "Marlin.h"
132
 #include "Marlin.h"
133
   #include "mesh_bed_leveling.h"
141
   #include "mesh_bed_leveling.h"
134
 #endif
142
 #endif
135
 
143
 
144
+#if ENABLED(ABL_BILINEAR_SUBDIVISION)
145
+  extern void bed_level_virt_prepare();
146
+  extern void bed_level_virt_interpolate();
147
+#endif
148
+
136
 /**
149
 /**
137
  * Post-process after Retrieve or Reset
150
  * Post-process after Retrieve or Reset
138
  */
151
  */
243
         LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]);
256
         LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]);
244
     #endif
257
     #endif
245
 
258
 
259
+    //
260
+    // Mesh Bed Leveling
261
+    //
262
+
246
     #if ENABLED(MESH_BED_LEVELING)
263
     #if ENABLED(MESH_BED_LEVELING)
247
       // Compile time test that sizeof(mbl.z_values) is as expected
264
       // Compile time test that sizeof(mbl.z_values) is as expected
248
       typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
265
       typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
258
       // For disabled MBL write a default mesh
275
       // For disabled MBL write a default mesh
259
       uint8_t mesh_num_x = 3,
276
       uint8_t mesh_num_x = 3,
260
               mesh_num_y = 3,
277
               mesh_num_y = 3,
261
-              dummy_uint8 = 0;
278
+              mbl_status = 0;
262
       dummy = 0.0f;
279
       dummy = 0.0f;
263
-      EEPROM_WRITE(dummy_uint8);
264
-      EEPROM_WRITE(dummy);
280
+      EEPROM_WRITE(mbl_status);
281
+      EEPROM_WRITE(dummy); // z_offset
265
       EEPROM_WRITE(mesh_num_x);
282
       EEPROM_WRITE(mesh_num_x);
266
       EEPROM_WRITE(mesh_num_y);
283
       EEPROM_WRITE(mesh_num_y);
267
-      for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_WRITE(dummy);
284
+      for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummy);
268
     #endif // MESH_BED_LEVELING
285
     #endif // MESH_BED_LEVELING
269
 
286
 
270
     #if !HAS_BED_PROBE
287
     #if !HAS_BED_PROBE
272
     #endif
289
     #endif
273
     EEPROM_WRITE(zprobe_zoffset);
290
     EEPROM_WRITE(zprobe_zoffset);
274
 
291
 
292
+    //
293
+    // Bilinear Auto Bed Leveling
294
+    //
295
+
296
+    #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
297
+      // Compile time test that sizeof(bed_level_grid) is as expected
298
+      typedef char c_assert[(sizeof(bed_level_grid) == (ABL_GRID_MAX_POINTS_X) * (ABL_GRID_MAX_POINTS_Y) * sizeof(dummy)) ? 1 : -1];
299
+      const uint8_t grid_max_x = ABL_GRID_MAX_POINTS_X, grid_max_y = ABL_GRID_MAX_POINTS_Y;
300
+      EEPROM_WRITE(grid_max_x);            // 1 byte
301
+      EEPROM_WRITE(grid_max_y);            // 1 byte
302
+      EEPROM_WRITE(bilinear_grid_spacing); // 2 ints
303
+      EEPROM_WRITE(bilinear_start);        // 2 ints
304
+      EEPROM_WRITE(bed_level_grid);        // 9-256 floats
305
+    #else
306
+      // For disabled Bilinear Grid write an empty 3x3 grid
307
+      const uint8_t grid_max_x = 3, grid_max_y = 3;
308
+      const int bilinear_start[2] = { 0 }, bilinear_grid_spacing[2] = { 0 };
309
+      dummy = 0.0f;
310
+      EEPROM_WRITE(grid_max_x);
311
+      EEPROM_WRITE(grid_max_y);
312
+      EEPROM_WRITE(bilinear_grid_spacing);
313
+      EEPROM_WRITE(bilinear_start);
314
+      for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummy);
315
+    #endif // AUTO_BED_LEVELING_BILINEAR
316
+
275
     // 9 floats for DELTA / Z_DUAL_ENDSTOPS
317
     // 9 floats for DELTA / Z_DUAL_ENDSTOPS
276
     #if ENABLED(DELTA)
318
     #if ENABLED(DELTA)
277
       EEPROM_WRITE(endstop_adj);               // 3 floats
319
       EEPROM_WRITE(endstop_adj);               // 3 floats
452
           LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]);
494
           LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]);
453
       #endif
495
       #endif
454
 
496
 
455
-      uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
497
+      //
498
+      // Mesh (Manual) Bed Leveling
499
+      //
500
+
501
+      uint8_t dummy_uint8, mesh_num_x, mesh_num_y;
456
       EEPROM_READ(dummy_uint8);
502
       EEPROM_READ(dummy_uint8);
457
       EEPROM_READ(dummy);
503
       EEPROM_READ(dummy);
458
       EEPROM_READ(mesh_num_x);
504
       EEPROM_READ(mesh_num_x);
467
         else {
513
         else {
468
           // EEPROM data is stale
514
           // EEPROM data is stale
469
           mbl.reset();
515
           mbl.reset();
470
-          for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ(dummy);
516
+          for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
471
         }
517
         }
472
       #else
518
       #else
473
         // MBL is disabled - skip the stored data
519
         // MBL is disabled - skip the stored data
474
-        for (uint8_t q = 0; q < mesh_num_x * mesh_num_y; q++) EEPROM_READ(dummy);
520
+        for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
475
       #endif // MESH_BED_LEVELING
521
       #endif // MESH_BED_LEVELING
476
 
522
 
477
       #if !HAS_BED_PROBE
523
       #if !HAS_BED_PROBE
479
       #endif
525
       #endif
480
       EEPROM_READ(zprobe_zoffset);
526
       EEPROM_READ(zprobe_zoffset);
481
 
527
 
528
+      //
529
+      // Bilinear Auto Bed Leveling
530
+      //
531
+
532
+      uint8_t grid_max_x, grid_max_y;
533
+      EEPROM_READ(grid_max_x);                       // 1 byte
534
+      EEPROM_READ(grid_max_y);                       // 1 byte
535
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
536
+        if (grid_max_x == ABL_GRID_MAX_POINTS_X && grid_max_y == ABL_GRID_MAX_POINTS_Y) {
537
+          set_bed_leveling_enabled(false);
538
+          EEPROM_READ(bilinear_grid_spacing);        // 2 ints
539
+          EEPROM_READ(bilinear_start);               // 2 ints
540
+          EEPROM_READ(bed_level_grid);               // 9 to 256 floats
541
+          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
542
+            bed_level_virt_prepare();
543
+            bed_level_virt_interpolate();
544
+          #endif
545
+        }
546
+        else // EEPROM data is stale
547
+      #endif // AUTO_BED_LEVELING_BILINEAR
548
+        {
549
+          // Skip past disabled (or stale) Bilinear Grid data
550
+          int bgs[2], bs[2];
551
+          EEPROM_READ(bgs);
552
+          EEPROM_READ(bs);
553
+          for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
554
+        }
555
+
482
       #if ENABLED(DELTA)
556
       #if ENABLED(DELTA)
483
         EEPROM_READ(endstop_adj);                // 3 floats
557
         EEPROM_READ(endstop_adj);                // 3 floats
484
         EEPROM_READ(delta_radius);               // 1 float
558
         EEPROM_READ(delta_radius);               // 1 float
647
     LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp4[i][e];
721
     LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp4[i][e];
648
   #endif
722
   #endif
649
 
723
 
650
-  #if ENABLED(MESH_BED_LEVELING)
651
-    mbl.reset();
724
+  #if PLANNER_LEVELING
725
+    reset_bed_level();
652
   #endif
726
   #endif
653
 
727
 
654
   #if HAS_BED_PROBE
728
   #if HAS_BED_PROBE
660
     endstop_adj[A_AXIS] = adj[A_AXIS];
734
     endstop_adj[A_AXIS] = adj[A_AXIS];
661
     endstop_adj[B_AXIS] = adj[B_AXIS];
735
     endstop_adj[B_AXIS] = adj[B_AXIS];
662
     endstop_adj[C_AXIS] = adj[C_AXIS];
736
     endstop_adj[C_AXIS] = adj[C_AXIS];
663
-    delta_radius =  DELTA_RADIUS;
664
-    delta_diagonal_rod =  DELTA_DIAGONAL_ROD;
665
-    delta_segments_per_second =  DELTA_SEGMENTS_PER_SECOND;
737
+    delta_radius = DELTA_RADIUS;
738
+    delta_diagonal_rod = DELTA_DIAGONAL_ROD;
739
+    delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
666
     delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1;
740
     delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1;
667
     delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2;
741
     delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2;
668
     delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
742
     delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
863
 
937
 
864
     #if ENABLED(MESH_BED_LEVELING)
938
     #if ENABLED(MESH_BED_LEVELING)
865
       if (!forReplay) {
939
       if (!forReplay) {
866
-        SERIAL_ECHOLNPGM("Mesh bed leveling:");
940
+        SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
867
         CONFIG_ECHO_START;
941
         CONFIG_ECHO_START;
868
       }
942
       }
869
-      SERIAL_ECHOPAIR("  M420 S", mbl.has_mesh() ? 1 : 0);
870
-      SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
871
-      SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
872
-      SERIAL_EOL;
943
+      SERIAL_ECHOLNPAIR("  M420 S", mbl.has_mesh() ? 1 : 0);
873
       for (uint8_t py = 1; py <= MESH_NUM_Y_POINTS; py++) {
944
       for (uint8_t py = 1; py <= MESH_NUM_Y_POINTS; py++) {
874
         for (uint8_t px = 1; px <= MESH_NUM_X_POINTS; px++) {
945
         for (uint8_t px = 1; px <= MESH_NUM_X_POINTS; px++) {
875
           CONFIG_ECHO_START;
946
           CONFIG_ECHO_START;
880
           SERIAL_EOL;
951
           SERIAL_EOL;
881
         }
952
         }
882
       }
953
       }
954
+    #elif HAS_ABL
955
+      if (!forReplay) {
956
+        SERIAL_ECHOLNPGM("Auto Bed Leveling:");
957
+        CONFIG_ECHO_START;
958
+      }
959
+      SERIAL_ECHOLNPAIR("  M420 S", planner.abl_enabled ? 1 : 0);
883
     #endif
960
     #endif
884
 
961
 
885
     #if ENABLED(DELTA)
962
     #if ENABLED(DELTA)

Loading…
Cancel
Save