|
@@ -26,11 +26,10 @@
|
26
|
26
|
#include "MarlinConfig.h"
|
27
|
27
|
|
28
|
28
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
29
|
|
-
|
30
|
29
|
#include "Marlin.h"
|
|
30
|
+ #include "planner.h"
|
31
|
31
|
#include "math.h"
|
32
|
32
|
#include "vector_3.h"
|
33
|
|
- #include "planner.h"
|
34
|
33
|
|
35
|
34
|
#define UBL_VERSION "1.00"
|
36
|
35
|
#define UBL_OK false
|
|
@@ -49,10 +48,8 @@
|
49
|
48
|
void debug_current_and_destination(const char * const title);
|
50
|
49
|
void ubl_line_to_destination(const float&, uint8_t);
|
51
|
50
|
void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
|
52
|
|
- vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
|
53
|
51
|
float measure_business_card_thickness(const float&);
|
54
|
52
|
mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, unsigned int[16], bool);
|
55
|
|
- void find_mean_mesh_height();
|
56
|
53
|
void shift_mesh_height();
|
57
|
54
|
bool g29_parameter_parsing();
|
58
|
55
|
void g29_what_command();
|
|
@@ -67,10 +64,8 @@
|
67
|
64
|
void gcode_G26();
|
68
|
65
|
void gcode_G28();
|
69
|
66
|
void gcode_G29();
|
70
|
|
- extern char conv[9];
|
71
|
67
|
|
72
|
|
- void save_ubl_active_state_and_disable();
|
73
|
|
- void restore_ubl_active_state_and_leave();
|
|
68
|
+ extern int ubl_cnt;
|
74
|
69
|
|
75
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
71
|
|
|
@@ -79,7 +74,6 @@
|
79
|
74
|
void lcd_quick_feedback();
|
80
|
75
|
#endif
|
81
|
76
|
|
82
|
|
- enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
|
83
|
77
|
|
84
|
78
|
#define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
|
85
|
79
|
#define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
|
|
@@ -97,6 +91,43 @@
|
97
|
91
|
|
98
|
92
|
public:
|
99
|
93
|
|
|
94
|
+//
|
|
95
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
96
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
97
|
+// functions that call STATIC functions.
|
|
98
|
+//
|
|
99
|
+ void find_mean_mesh_height();
|
|
100
|
+ void shift_mesh_height();
|
|
101
|
+ void probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest);
|
|
102
|
+ void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
|
|
103
|
+ void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
|
|
104
|
+ void manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &card_thickness, const bool do_ubl_mesh_map);
|
|
105
|
+ void save_ubl_active_state_and_disable();
|
|
106
|
+ void restore_ubl_active_state_and_leave();
|
|
107
|
+ void g29_what_command();
|
|
108
|
+//
|
|
109
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
110
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
111
|
+// functions that call STATIC functions.
|
|
112
|
+//
|
|
113
|
+ void g29_eeprom_dump() ;
|
|
114
|
+ void g29_compare_current_mesh_to_stored_mesh();
|
|
115
|
+ void fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map);
|
|
116
|
+ void smart_fill_mesh();
|
|
117
|
+ void display_map(const int);
|
|
118
|
+ void reset();
|
|
119
|
+//
|
|
120
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
121
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
122
|
+// functions that call STATIC functions.
|
|
123
|
+//
|
|
124
|
+ void invalidate();
|
|
125
|
+ void store_state();
|
|
126
|
+ void load_state();
|
|
127
|
+ void store_mesh(const int16_t);
|
|
128
|
+ void load_mesh(const int16_t);
|
|
129
|
+ bool sanity_check();
|
|
130
|
+
|
100
|
131
|
static ubl_state state;
|
101
|
132
|
|
102
|
133
|
static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
@@ -125,32 +156,27 @@
|
125
|
156
|
|
126
|
157
|
static bool g26_debug_flag, has_control_of_lcd_panel;
|
127
|
158
|
|
128
|
|
- static int8_t eeprom_start;
|
|
159
|
+ static int16_t eeprom_start; // Please do no change this to 8 bits in size
|
|
160
|
+ // It needs to hold values bigger than this.
|
129
|
161
|
|
130
|
162
|
static volatile int encoder_diff; // Volatile because it's changed at interrupt time.
|
131
|
163
|
|
132
|
164
|
unified_bed_leveling();
|
133
|
165
|
|
134
|
|
- static void display_map(const int);
|
135
|
|
-
|
136
|
|
- static void reset();
|
137
|
|
- static void invalidate();
|
138
|
|
-
|
139
|
|
- static void store_mesh(const int16_t);
|
140
|
|
- static void load_mesh(const int16_t);
|
141
|
|
-
|
142
|
|
- static bool sanity_check();
|
143
|
|
-
|
144
|
|
- static FORCE_INLINE void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
|
145
|
|
-
|
146
|
|
- static int8_t get_cell_index_x(const float &x) {
|
|
166
|
+//
|
|
167
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
168
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
169
|
+// functions that call STATIC functions.
|
|
170
|
+//
|
|
171
|
+ FORCE_INLINE void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
|
|
172
|
+ int8_t get_cell_index_x(const float &x) {
|
147
|
173
|
const int8_t cx = (x - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
|
148
|
174
|
return constrain(cx, 0, (GRID_MAX_POINTS_X) - 1); // -1 is appropriate if we want all movement to the X_MAX
|
149
|
175
|
} // position. But with this defined this way, it is possible
|
150
|
176
|
// to extrapolate off of this point even further out. Probably
|
151
|
177
|
// that is OK because something else should be keeping that from
|
152
|
178
|
// happening and should not be worried about at this level.
|
153
|
|
- static int8_t get_cell_index_y(const float &y) {
|
|
179
|
+ int8_t get_cell_index_y(const float &y) {
|
154
|
180
|
const int8_t cy = (y - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_Y_DIST));
|
155
|
181
|
return constrain(cy, 0, (GRID_MAX_POINTS_Y) - 1); // -1 is appropriate if we want all movement to the Y_MAX
|
156
|
182
|
} // position. But with this defined this way, it is possible
|
|
@@ -158,12 +184,17 @@
|
158
|
184
|
// that is OK because something else should be keeping that from
|
159
|
185
|
// happening and should not be worried about at this level.
|
160
|
186
|
|
161
|
|
- static int8_t find_closest_x_index(const float &x) {
|
|
187
|
+//
|
|
188
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
189
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
190
|
+// functions that call STATIC functions.
|
|
191
|
+//
|
|
192
|
+ int8_t find_closest_x_index(const float &x) {
|
162
|
193
|
const int8_t px = (x - (UBL_MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
|
163
|
194
|
return WITHIN(px, 0, GRID_MAX_POINTS_X - 1) ? px : -1;
|
164
|
195
|
}
|
165
|
196
|
|
166
|
|
- static int8_t find_closest_y_index(const float &y) {
|
|
197
|
+ int8_t find_closest_y_index(const float &y) {
|
167
|
198
|
const int8_t py = (y - (UBL_MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
|
168
|
199
|
return WITHIN(py, 0, GRID_MAX_POINTS_Y - 1) ? py : -1;
|
169
|
200
|
}
|
|
@@ -183,15 +214,20 @@
|
183
|
214
|
* It is fairly expensive with its 4 floating point additions and 2 floating point
|
184
|
215
|
* multiplications.
|
185
|
216
|
*/
|
186
|
|
- static FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
|
|
217
|
+ FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
|
187
|
218
|
return z1 + (z2 - z1) * (a0 - a1) / (a2 - a1);
|
188
|
219
|
}
|
|
220
|
+//
|
|
221
|
+// Please do not put STATIC qualifiers in front of ANYTHING in this file. You WILL cause problems by doing that.
|
|
222
|
+// The GCC optimizer inlines static functions and this DRAMATICALLY increases the size of the stack frame of
|
|
223
|
+// functions that call STATIC functions.
|
|
224
|
+//
|
189
|
225
|
|
190
|
226
|
/**
|
191
|
227
|
* z_correction_for_x_on_horizontal_mesh_line is an optimization for
|
192
|
228
|
* the rare occasion when a point lies exactly on a Mesh line (denoted by index yi).
|
193
|
229
|
*/
|
194
|
|
- static inline float z_correction_for_x_on_horizontal_mesh_line(const float &lx0, const int x1_i, const int yi) {
|
|
230
|
+ inline float z_correction_for_x_on_horizontal_mesh_line(const float &lx0, const int x1_i, const int yi) {
|
195
|
231
|
if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
|
196
|
232
|
SERIAL_ECHOPAIR("? in z_correction_for_x_on_horizontal_mesh_line(lx0=", lx0);
|
197
|
233
|
SERIAL_ECHOPAIR(",x1_i=", x1_i);
|
|
@@ -210,7 +246,7 @@
|
210
|
246
|
//
|
211
|
247
|
// See comments above for z_correction_for_x_on_horizontal_mesh_line
|
212
|
248
|
//
|
213
|
|
- static inline float z_correction_for_y_on_vertical_mesh_line(const float &ly0, const int xi, const int y1_i) {
|
|
249
|
+ inline float z_correction_for_y_on_vertical_mesh_line(const float &ly0, const int xi, const int y1_i) {
|
214
|
250
|
if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) {
|
215
|
251
|
SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_x(ly0=", ly0);
|
216
|
252
|
SERIAL_ECHOPAIR(", x1_i=", xi);
|
|
@@ -232,7 +268,7 @@
|
232
|
268
|
* Z-Height at both ends. Then it does a linear interpolation of these heights based
|
233
|
269
|
* on the Y position within the cell.
|
234
|
270
|
*/
|
235
|
|
- static float get_z_correction(const float &lx0, const float &ly0) {
|
|
271
|
+ float get_z_correction(const float &lx0, const float &ly0) {
|
236
|
272
|
const int8_t cx = get_cell_index_x(RAW_X_POSITION(lx0)),
|
237
|
273
|
cy = get_cell_index_y(RAW_Y_POSITION(ly0));
|
238
|
274
|
|
|
@@ -308,7 +344,7 @@
|
308
|
344
|
*/
|
309
|
345
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
310
|
346
|
|
311
|
|
- static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
|
|
347
|
+ FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
|
312
|
348
|
if (planner.z_fade_height == 0.0) return 1.0;
|
313
|
349
|
|
314
|
350
|
static float fade_scaling_factor = 1.0;
|