20
20
*
21
21
*/
22
22
23
- #include " ../../inc/MarlinConfig .h"
23
+ #include " ../../inc/MarlinConfigPre .h"
24
24
25
25
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
26
26
27
27
#include " ../../feature/z_stepper_align.h"
28
28
29
29
#include " ../gcode.h"
30
- #include " ../../module/planner.h"
31
- #include " ../../module/stepper.h"
32
30
#include " ../../module/motion.h"
31
+ #include " ../../module/stepper.h"
32
+ #include " ../../module/planner.h"
33
33
#include " ../../module/probe.h"
34
-
35
- #if HAS_MULTI_HOTEND
36
- #include " ../../module/tool_change.h"
37
- #endif
34
+ #include " ../../lcd/ultralcd.h" // for LCD_MESSAGEPGM
38
35
39
36
#if HAS_LEVELING
40
37
#include " ../../feature/bedlevel/bedlevel.h"
41
38
#endif
42
39
40
+ #if HAS_MULTI_HOTEND
41
+ #include " ../../module/tool_change.h"
42
+ #endif
43
+
43
44
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
44
- #include " ../../libs/least_squares_fit.h"
45
+ #include " ../../libs/least_squares_fit.h"
45
46
#endif
46
47
47
48
#define DEBUG_OUT ENABLED (DEBUG_LEVELING_FEATURE)
@@ -117,7 +118,7 @@ void GcodeSuite::G34() {
117
118
// In BLTOUCH HS mode, the probe travels in a deployed state.
118
119
// Users of G34 might have a badly misaligned bed, so raise Z by the
119
120
// length of the deployed pin (BLTOUCH stroke < 7mm)
120
- #define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES + 7 .0f * BOTH (BLTOUCH, BLTOUCH_HS_MODE)
121
+ #define Z_BASIC_CLEARANCE ( Z_CLEARANCE_BETWEEN_PROBES + 7 .0f * BOTH (BLTOUCH, BLTOUCH_HS_MODE) )
121
122
122
123
// Compute a worst-case clearance height to probe from. After the first
123
124
// iteration this will be re-calculated based on the actual bed position
@@ -154,21 +155,29 @@ void GcodeSuite::G34() {
154
155
z_maxdiff = 0 .0f ,
155
156
amplification = z_auto_align_amplification;
156
157
157
- // These are needed after the for-loop
158
- uint8_t iteration;
159
- bool err_break = false ;
160
- float z_measured_min;
161
-
162
158
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
163
159
bool adjustment_reverse = false ;
164
160
#endif
165
161
166
- // 'iteration' is declared above and is also used after the for-loop.
167
- // *not* the same as LOOP_L_N(iteration, z_auto_align_iterations)
168
- for (iteration = 0 ; iteration < z_auto_align_iterations; ++iteration) {
162
+ #if HAS_DISPLAY
163
+ PGM_P const msg_iteration = GET_TEXT (MSG_ITERATION);
164
+ const uint8_t iter_str_len = strlen_P (msg_iteration);
165
+ #endif
166
+
167
+ // Final z and iteration values will be used after breaking the loop
168
+ float z_measured_min;
169
+ uint8_t iteration = 0 ;
170
+ bool err_break = false ; // To break out of nested loops
171
+ while (iteration < z_auto_align_iterations) {
169
172
if (DEBUGGING (LEVELING)) DEBUG_ECHOLNPGM (" > probing all positions." );
170
173
171
- SERIAL_ECHOLNPAIR (" \n ITERATION: " , int (iteration + 1 ));
174
+ const int iter = iteration + 1 ;
175
+ SERIAL_ECHOLNPAIR (" \n G34 Iteration: " , iter);
176
+ #if HAS_DISPLAY
177
+ char str[iter_str_len + 2 + 1 ];
178
+ sprintf_P (str, msg_iteration, iter);
179
+ ui.set_status (str);
180
+ #endif
172
181
173
182
// Initialize minimum value
174
183
z_measured_min = 100000 .0f ;
@@ -190,7 +199,8 @@ void GcodeSuite::G34() {
190
199
// current_position.z has been manually altered in the "dirty trick" above.
191
200
const float z_probed_height = probe.probe_at_point (z_stepper_align.xy [iprobe], raise_after, 0 , true , false );
192
201
if (isnan (z_probed_height)) {
193
- SERIAL_ECHOLNPGM (" Probing failed." );
202
+ SERIAL_ECHOLNPGM (" Probing failed" );
203
+ LCD_MESSAGEPGM (MSG_LCD_PROBING_FAILED);
194
204
err_break = true ;
195
205
break ;
196
206
}
@@ -249,8 +259,39 @@ void GcodeSuite::G34() {
249
259
, " Z3-Z1=" , ABS (z_measured[2 ] - z_measured[0 ])
250
260
#endif
251
261
);
262
+ #if HAS_DISPLAY
263
+ char fstr1[10 ];
264
+ #if NUM_Z_STEPPER_DRIVERS == 2
265
+ char msg[6 + (6 + 5 ) * 1 + 1 ];
266
+ #else
267
+ char msg[6 + (6 + 5 ) * 3 + 1 ], fstr2[10 ], fstr3[10 ];
268
+ #endif
269
+ sprintf_P (msg,
270
+ PSTR (" Diffs Z1-Z2=%s"
271
+ #if NUM_Z_STEPPER_DRIVERS == 3
272
+ " Z2-Z3=%s"
273
+ " Z3-Z1=%s"
274
+ #endif
275
+ ), dtostrf (ABS (z_measured[0 ] - z_measured[1 ]), 1 , 3 , fstr1)
276
+ #if NUM_Z_STEPPER_DRIVERS == 3
277
+ , dtostrf (ABS (z_measured[1 ] - z_measured[2 ]), 1 , 3 , fstr2)
278
+ , dtostrf (ABS (z_measured[2 ] - z_measured[0 ]), 1 , 3 , fstr3)
279
+ #endif
280
+ );
281
+ ui.set_status (msg);
282
+ #endif
283
+
284
+ auto decreasing_accuracy = [](const float &v1, const float &v2){
285
+ if (v1 < v2 * 0 .7f ) {
286
+ SERIAL_ECHOLNPGM (" Decreasing Accuracy Detected." );
287
+ LCD_MESSAGEPGM (MSG_DECREASING_ACCURACY);
288
+ return true ;
289
+ }
290
+ return false ;
291
+ };
252
292
253
293
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
294
+
254
295
// Check if the applied corrections go in the correct direction.
255
296
// Calculate the sum of the absolute deviations from the mean of the probe measurements.
256
297
// Compare to the last iteration to ensure it's getting better.
@@ -266,11 +307,8 @@ void GcodeSuite::G34() {
266
307
z_align_level_indicator += ABS (z_measured[zstepper] - z_measured_mean);
267
308
268
309
// If it's getting worse, stop and throw an error
269
- if (last_z_align_level_indicator < z_align_level_indicator * 0 .7f ) {
270
- SERIAL_ECHOLNPGM (" Decreasing accuracy detected." );
271
- err_break = true ;
272
- break ;
273
- }
310
+ err_break = decreasing_accuracy (last_z_align_level_indicator, z_align_level_indicator);
311
+ if (err_break) break ;
274
312
275
313
last_z_align_level_indicator = z_align_level_indicator;
276
314
#endif
@@ -290,8 +328,7 @@ void GcodeSuite::G34() {
290
328
if (z_align_abs) amplification = (iteration == 1 ) ? _MIN (last_z_align_move[zstepper] / z_align_abs, 2 .0f ) : z_auto_align_amplification;
291
329
292
330
// Check for less accuracy compared to last move
293
- if (last_z_align_move[zstepper] < z_align_abs * 0 .7f ) {
294
- SERIAL_ECHOLNPGM (" Decreasing accuracy detected." );
331
+ if (decreasing_accuracy (last_z_align_move[zstepper], z_align_abs)) {
295
332
if (DEBUGGING (LEVELING)) DEBUG_ECHOLNPAIR (" > Z" , int (zstepper + 1 ), " last_z_align_move = " , last_z_align_move[zstepper]);
296
333
if (DEBUGGING (LEVELING)) DEBUG_ECHOLNPAIR (" > Z" , int (zstepper + 1 ), " z_align_abs = " , z_align_abs);
297
334
adjustment_reverse = !adjustment_reverse;
@@ -329,9 +366,14 @@ void GcodeSuite::G34() {
329
366
330
367
if (err_break) break ;
331
368
332
- if (success_break) { SERIAL_ECHOLNPGM (" Target accuracy achieved." ); break ; }
369
+ if (success_break) {
370
+ SERIAL_ECHOLNPGM (" Target accuracy achieved." );
371
+ LCD_MESSAGEPGM (MSG_ACCURACY_ACHIEVED);
372
+ break ;
373
+ }
333
374
334
- } // for (iteration)
375
+ iteration++;
376
+ } // while (iteration < z_auto_align_iterations)
335
377
336
378
if (err_break)
337
379
SERIAL_ECHOLNPGM (" G34 aborted." );
0 commit comments