Bläddra i källkod

Merge pull request #9087 from thinkyhead/bf2_mbl_localize

[2.0.x] MBL cleanup, has_mesh() method
Scott Lahteine 7 år sedan
förälder
incheckning
e180b7a460
Inget konto är kopplat till bidragsgivarens mejladress

+ 2
- 5
Marlin/src/feature/bedlevel/bedlevel.cpp Visa fil

@@ -49,7 +49,7 @@
49 49
 bool leveling_is_valid() {
50 50
   return
51 51
     #if ENABLED(MESH_BED_LEVELING)
52
-      mbl.has_mesh
52
+      mbl.has_mesh()
53 53
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
54 54
       !!bilinear_grid_spacing[X_AXIS]
55 55
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
@@ -178,10 +178,7 @@ void reset_bed_level() {
178 178
   #endif
179 179
   set_bed_leveling_enabled(false);
180 180
   #if ENABLED(MESH_BED_LEVELING)
181
-    if (leveling_is_valid()) {
182
-      mbl.reset();
183
-      mbl.has_mesh = false;
184
-    }
181
+    mbl.reset();
185 182
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
186 183
     ubl.reset();
187 184
   #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)

+ 14
- 17
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp Visa fil

@@ -31,8 +31,6 @@
31 31
 
32 32
   mesh_bed_leveling mbl;
33 33
 
34
-  bool mesh_bed_leveling::has_mesh;
35
-
36 34
   float mesh_bed_leveling::z_offset,
37 35
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
38 36
         mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X],
@@ -47,7 +45,6 @@
47 45
   }
48 46
 
49 47
   void mesh_bed_leveling::reset() {
50
-    has_mesh = false;
51 48
     z_offset = 0;
52 49
     ZERO(z_values);
53 50
   }
@@ -58,12 +55,12 @@
58 55
      * Prepare a mesh-leveled linear move in a Cartesian setup,
59 56
      * splitting the move where it crosses mesh borders.
60 57
      */
61
-    void mesh_line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) {
58
+    void mesh_bed_leveling::line_to_destination(const float fr_mm_s, uint8_t x_splits, uint8_t y_splits) {
62 59
       // Get current and destination cells for this line
63
-      int cx1 = mbl.cell_index_x(current_position[X_AXIS]),
64
-          cy1 = mbl.cell_index_y(current_position[Y_AXIS]),
65
-          cx2 = mbl.cell_index_x(destination[X_AXIS]),
66
-          cy2 = mbl.cell_index_y(destination[Y_AXIS]);
60
+      int cx1 = cell_index_x(current_position[X_AXIS]),
61
+          cy1 = cell_index_y(current_position[Y_AXIS]),
62
+          cx2 = cell_index_x(destination[X_AXIS]),
63
+          cy2 = cell_index_y(destination[Y_AXIS]);
67 64
       NOMORE(cx1, GRID_MAX_POINTS_X - 2);
68 65
       NOMORE(cy1, GRID_MAX_POINTS_Y - 2);
69 66
       NOMORE(cx2, GRID_MAX_POINTS_X - 2);
@@ -71,7 +68,7 @@
71 68
 
72 69
       // Start and end in the same cell? No split needed.
73 70
       if (cx1 == cx2 && cy1 == cy2) {
74
-        buffer_line_to_destination(fr_mm_s);
71
+        line_to_destination(fr_mm_s);
75 72
         set_current_from_destination();
76 73
         return;
77 74
       }
@@ -87,7 +84,7 @@
87 84
         // Split on the X grid line
88 85
         CBI(x_splits, gcx);
89 86
         COPY(end, destination);
90
-        destination[X_AXIS] = mbl.index_to_xpos[gcx];
87
+        destination[X_AXIS] = index_to_xpos[gcx];
91 88
         normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
92 89
         destination[Y_AXIS] = MBL_SEGMENT_END(Y);
93 90
       }
@@ -96,14 +93,14 @@
96 93
         // Split on the Y grid line
97 94
         CBI(y_splits, gcy);
98 95
         COPY(end, destination);
99
-        destination[Y_AXIS] = mbl.index_to_ypos[gcy];
96
+        destination[Y_AXIS] = index_to_ypos[gcy];
100 97
         normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
101 98
         destination[X_AXIS] = MBL_SEGMENT_END(X);
102 99
       }
103 100
       else {
104 101
         // Must already have been split on these border(s)
105 102
         // This should be a rare case.
106
-        buffer_line_to_destination(fr_mm_s);
103
+        line_to_destination(fr_mm_s);
107 104
         set_current_from_destination();
108 105
         return;
109 106
       }
@@ -112,21 +109,21 @@
112 109
       destination[E_AXIS] = MBL_SEGMENT_END(E);
113 110
 
114 111
       // Do the split and look for more borders
115
-      mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
112
+      line_to_destination(fr_mm_s, x_splits, y_splits);
116 113
 
117 114
       // Restore destination from stack
118 115
       COPY(destination, end);
119
-      mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
116
+      line_to_destination(fr_mm_s, x_splits, y_splits);
120 117
     }
121 118
 
122 119
   #endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES
123 120
 
124
-  void mbl_mesh_report() {
121
+  void mesh_bed_leveling::report_mesh() {
125 122
     SERIAL_PROTOCOLLNPGM("Num X,Y: " STRINGIFY(GRID_MAX_POINTS_X) "," STRINGIFY(GRID_MAX_POINTS_Y));
126
-    SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(mbl.z_offset, 5);
123
+    SERIAL_PROTOCOLPGM("Z offset: "); SERIAL_PROTOCOL_F(z_offset, 5);
127 124
     SERIAL_PROTOCOLLNPGM("\nMeasured points:");
128 125
     print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5,
129
-      [](const uint8_t ix, const uint8_t iy) { return mbl.z_values[ix][iy]; }
126
+      [](const uint8_t ix, const uint8_t iy) { return z_values[ix][iy]; }
130 127
     );
131 128
   }
132 129
 

+ 14
- 8
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h Visa fil

@@ -39,7 +39,6 @@ enum MeshLevelingState {
39 39
 
40 40
 class mesh_bed_leveling {
41 41
 public:
42
-  static bool has_mesh;
43 42
   static float z_offset,
44 43
                z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
45 44
                index_to_xpos[GRID_MAX_POINTS_X],
@@ -47,8 +46,17 @@ public:
47 46
 
48 47
   mesh_bed_leveling();
49 48
 
49
+  static void report_mesh();
50
+
50 51
   static void reset();
51 52
 
53
+  FORCE_INLINE static bool has_mesh() {
54
+    for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
55
+      for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
56
+        if (z_values[x][y]) return true;
57
+    return false;
58
+  }
59
+
52 60
   static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
53 61
 
54 62
   static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
@@ -105,15 +113,13 @@ public:
105 113
       #endif
106 114
     ;
107 115
   }
116
+
117
+  // Support functions, which may be embedded in the class later
118
+  #if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
119
+    void line_to_destination(const float fr_mm_s, uint8_t x_splits=0xFF, uint8_t y_splits=0xFF);
120
+  #endif
108 121
 };
109 122
 
110 123
 extern mesh_bed_leveling mbl;
111 124
 
112
-// Support functions, which may be embedded in the class later
113
-#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
114
-  void mesh_line_to_destination(const float fr_mm_s, uint8_t x_splits=0xFF, uint8_t y_splits=0xFF);
115
-#endif
116
-
117
-void mbl_mesh_report();
118
-
119 125
 #endif // _MESH_BED_LEVELING_H_

+ 1
- 1
Marlin/src/gcode/bedlevel/M420.cpp Visa fil

@@ -100,7 +100,7 @@ void GcodeSuite::M420() {
100 100
           #endif
101 101
         #elif ENABLED(MESH_BED_LEVELING)
102 102
           SERIAL_ECHOLNPGM("Mesh Bed Level data:");
103
-          mbl_mesh_report();
103
+          mbl.report_mesh();
104 104
         #endif
105 105
       }
106 106
     #endif

+ 1
- 5
Marlin/src/gcode/bedlevel/mbl/G29.cpp Visa fil

@@ -81,7 +81,7 @@ void GcodeSuite::G29() {
81 81
     case MeshReport:
82 82
       if (leveling_is_valid()) {
83 83
         SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
84
-        mbl_mesh_report();
84
+        mbl.report_mesh();
85 85
       }
86 86
       else
87 87
         SERIAL_PROTOCOLLNPGM("Mesh bed leveling has no data.");
@@ -136,7 +136,6 @@ void GcodeSuite::G29() {
136 136
         SERIAL_PROTOCOLLNPGM("Mesh probing done.");
137 137
         BUZZ(100, 659);
138 138
         BUZZ(100, 698);
139
-        mbl.has_mesh = true;
140 139
 
141 140
         gcode.home_all_axes();
142 141
         set_bed_leveling_enabled(true);
@@ -185,9 +184,6 @@ void GcodeSuite::G29() {
185 184
         SERIAL_CHAR('Z'); echo_not_entered();
186 185
         return;
187 186
       }
188
-
189
-      mbl.has_mesh = true; // set since user manually entered a mesh point
190
-
191 187
       break;
192 188
 
193 189
     case MeshSetZOffset:

+ 2
- 12
Marlin/src/module/configuration_store.cpp Visa fil

@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V48"
40
+#define EEPROM_VERSION "V49"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -114,7 +114,6 @@ typedef struct SettingsDataStruct {
114 114
   //
115 115
   // MESH_BED_LEVELING
116 116
   //
117
-  bool mbl_has_mesh;                                    // mbl.has_mesh
118 117
   float mbl_z_offset;                                   // mbl.z_offset
119 118
   uint8_t mesh_num_x, mesh_num_y;                       // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
120 119
   #if ENABLED(MESH_BED_LEVELING)
@@ -297,7 +296,6 @@ void MarlinSettings::postprocess() {
297 296
 
298 297
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
299 298
     refresh_bed_level();
300
-    //set_bed_leveling_enabled(leveling_is_on);
301 299
   #endif
302 300
 
303 301
   #if HAS_MOTOR_CURRENT_PWM
@@ -425,16 +423,13 @@ void MarlinSettings::postprocess() {
425 423
         "MBL Z array is the wrong size."
426 424
       );
427 425
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
428
-      EEPROM_WRITE(mbl.has_mesh);
429 426
       EEPROM_WRITE(mbl.z_offset);
430 427
       EEPROM_WRITE(mesh_num_x);
431 428
       EEPROM_WRITE(mesh_num_y);
432 429
       EEPROM_WRITE(mbl.z_values);
433 430
     #else // For disabled MBL write a default mesh
434
-      const bool leveling_is_on = false;
435 431
       dummy = 0.0f;
436 432
       const uint8_t mesh_num_x = 3, mesh_num_y = 3;
437
-      EEPROM_WRITE(leveling_is_on);
438 433
       EEPROM_WRITE(dummy); // z_offset
439 434
       EEPROM_WRITE(mesh_num_x);
440 435
       EEPROM_WRITE(mesh_num_y);
@@ -925,18 +920,13 @@ void MarlinSettings::postprocess() {
925 920
       // Mesh (Manual) Bed Leveling
926 921
       //
927 922
 
928
-      bool leveling_is_on;
929 923
       uint8_t mesh_num_x, mesh_num_y;
930
-      EEPROM_READ_ALWAYS(leveling_is_on);
931 924
       EEPROM_READ(dummy);
932 925
       EEPROM_READ_ALWAYS(mesh_num_x);
933 926
       EEPROM_READ_ALWAYS(mesh_num_y);
934 927
 
935 928
       #if ENABLED(MESH_BED_LEVELING)
936
-        if (!validating) {
937
-          mbl.has_mesh = leveling_is_on;
938
-          mbl.z_offset = dummy;
939
-        }
929
+        if (!validating) mbl.z_offset = dummy;
940 930
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
941 931
           // EEPROM data fits the current mesh
942 932
           EEPROM_READ(mbl.z_values);

Laddar…
Avbryt
Spara