소스 검색

Merge pull request #9087 from thinkyhead/bf2_mbl_localize

[2.0.x] MBL cleanup, has_mesh() method
Scott Lahteine 7 년 전
부모
커밋
e180b7a460
No account linked to committer's email address

+ 2
- 5
Marlin/src/feature/bedlevel/bedlevel.cpp 파일 보기

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

+ 14
- 17
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp 파일 보기

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

39
 
39
 
40
 class mesh_bed_leveling {
40
 class mesh_bed_leveling {
41
 public:
41
 public:
42
-  static bool has_mesh;
43
   static float z_offset,
42
   static float z_offset,
44
                z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
43
                z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
45
                index_to_xpos[GRID_MAX_POINTS_X],
44
                index_to_xpos[GRID_MAX_POINTS_X],
47
 
46
 
48
   mesh_bed_leveling();
47
   mesh_bed_leveling();
49
 
48
 
49
+  static void report_mesh();
50
+
50
   static void reset();
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
   static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
60
   static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
53
 
61
 
54
   static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
62
   static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
105
       #endif
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
 extern mesh_bed_leveling mbl;
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
 #endif // _MESH_BED_LEVELING_H_
125
 #endif // _MESH_BED_LEVELING_H_

+ 1
- 1
Marlin/src/gcode/bedlevel/M420.cpp 파일 보기

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

+ 1
- 5
Marlin/src/gcode/bedlevel/mbl/G29.cpp 파일 보기

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

+ 2
- 12
Marlin/src/module/configuration_store.cpp 파일 보기

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

Loading…
취소
저장