|
@@ -141,11 +141,11 @@ void GcodeSuite::G34() {
|
141
|
141
|
// iteration this will be re-calculated based on the actual bed position
|
142
|
142
|
float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * (
|
143
|
143
|
#if NUM_Z_STEPPER_DRIVERS == 3
|
144
|
|
- SQRT(_MAX(HYPOT2(z_stepper_align.xy[0].x - z_stepper_align.xy[0].y, z_stepper_align.xy[1].x - z_stepper_align.xy[1].y),
|
145
|
|
- HYPOT2(z_stepper_align.xy[1].x - z_stepper_align.xy[1].y, z_stepper_align.xy[2].x - z_stepper_align.xy[2].y),
|
146
|
|
- HYPOT2(z_stepper_align.xy[2].x - z_stepper_align.xy[2].y, z_stepper_align.xy[0].x - z_stepper_align.xy[0].y)))
|
|
144
|
+ SQRT(_MAX(HYPOT2(z_stepper_align.xy[0].x - z_stepper_align.xy[1].x, z_stepper_align.xy[0].y - z_stepper_align.xy[1].y),
|
|
145
|
+ HYPOT2(z_stepper_align.xy[1].x - z_stepper_align.xy[2].x, z_stepper_align.xy[1].y - z_stepper_align.xy[2].y),
|
|
146
|
+ HYPOT2(z_stepper_align.xy[2].x - z_stepper_align.xy[0].x, z_stepper_align.xy[2].y - z_stepper_align.xy[0].y)))
|
147
|
147
|
#else
|
148
|
|
- HYPOT(z_stepper_align.xy[0].x - z_stepper_align.xy[0].y, z_stepper_align.xy[1].x - z_stepper_align.xy[1].y)
|
|
148
|
+ HYPOT(z_stepper_align.xy[0].x - z_stepper_align.xy[1].x, z_stepper_align.xy[0].y - z_stepper_align.xy[1].y)
|
149
|
149
|
#endif
|
150
|
150
|
);
|
151
|
151
|
|
|
@@ -156,6 +156,7 @@ void GcodeSuite::G34() {
|
156
|
156
|
current_position.z += z_probe * 0.5f;
|
157
|
157
|
sync_plan_position();
|
158
|
158
|
// Now, the Z origin lies below the build plate. That allows to probe deeper, before run_z_probe throws an error.
|
|
159
|
+ // This hack is un-done at the end of G34 - either by re-homing, or by using the probed heights of the last iteration.
|
159
|
160
|
|
160
|
161
|
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
|
161
|
162
|
float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N(NUM_Z_STEPPER_DRIVERS, 10000.0f, 10000.0f, 10000.0f);
|
|
@@ -166,8 +167,10 @@ void GcodeSuite::G34() {
|
166
|
167
|
z_maxdiff = 0.0f,
|
167
|
168
|
amplification = z_auto_align_amplification;
|
168
|
169
|
|
|
170
|
+ // These are needed after the for-loop
|
169
|
171
|
uint8_t iteration;
|
170
|
172
|
bool err_break = false;
|
|
173
|
+ float z_measured_min;
|
171
|
174
|
|
172
|
175
|
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
|
173
|
176
|
bool adjustment_reverse = false;
|
|
@@ -181,8 +184,8 @@ void GcodeSuite::G34() {
|
181
|
184
|
SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1));
|
182
|
185
|
|
183
|
186
|
// Initialize minimum value
|
184
|
|
- float z_measured_min = 100000.0f,
|
185
|
|
- z_measured_max = -100000.0f;
|
|
187
|
+ z_measured_min = 100000.0f;
|
|
188
|
+ float z_measured_max = -100000.0f;
|
186
|
189
|
|
187
|
190
|
// Probe all positions (one per Z-Stepper)
|
188
|
191
|
LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
|
|
@@ -238,14 +241,14 @@ void GcodeSuite::G34() {
|
238
|
241
|
linear_fit_data lfd;
|
239
|
242
|
incremental_LSF_reset(&lfd);
|
240
|
243
|
LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
|
241
|
|
- SERIAL_ECHOLNPAIR("PROBEPT_", i + '1', ": ", z_measured[i]);
|
|
244
|
+ SERIAL_ECHOLNPAIR("PROBEPT_", ('0' + i), ": ", z_measured[i]);
|
242
|
245
|
incremental_LSF(&lfd, z_stepper_align.xy[i], z_measured[i]);
|
243
|
246
|
}
|
244
|
247
|
finish_incremental_LSF(&lfd);
|
245
|
248
|
|
246
|
249
|
z_measured_min = 100000.0f;
|
247
|
250
|
LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
|
248
|
|
- z_measured[i] = -(lfd.A * z_stepper_align.stepper_xy[i].x + lfd.B * z_stepper_align.stepper_xy[i].y);
|
|
251
|
+ z_measured[i] = -(lfd.A * z_stepper_align.stepper_xy[i].x + lfd.B * z_stepper_align.stepper_xy[i].y + lfd.D);
|
249
|
252
|
z_measured_min = _MIN(z_measured_min, z_measured[i]);
|
250
|
253
|
}
|
251
|
254
|
|
|
@@ -345,7 +348,11 @@ void GcodeSuite::G34() {
|
345
|
348
|
|
346
|
349
|
} // for (iteration)
|
347
|
350
|
|
348
|
|
- if (err_break) { SERIAL_ECHOLNPGM("G34 aborted."); break; }
|
|
351
|
+ if (err_break) {
|
|
352
|
+ SERIAL_ECHOLNPGM("G34 aborted.");
|
|
353
|
+ set_axis_not_trusted(Z_AXIS); // The Z coordinate is messed up now
|
|
354
|
+ break;
|
|
355
|
+ }
|
349
|
356
|
|
350
|
357
|
SERIAL_ECHOLNPAIR("Did ", int(iteration + (iteration != z_auto_align_iterations)), " iterations of ", int(z_auto_align_iterations));
|
351
|
358
|
SERIAL_ECHOLNPAIR_F("Accuracy: ", z_maxdiff);
|
|
@@ -363,15 +370,23 @@ void GcodeSuite::G34() {
|
363
|
370
|
set_bed_leveling_enabled(leveling_was_active);
|
364
|
371
|
#endif
|
365
|
372
|
|
366
|
|
- // After this operation the z position needs correction
|
367
|
|
- set_axis_is_not_at_home(Z_AXIS);
|
368
|
|
-
|
369
|
373
|
// Stow the probe, as the last call to probe.probe_at_point(...) left
|
370
|
374
|
// the probe deployed if it was successful.
|
371
|
375
|
probe.stow();
|
372
|
376
|
|
373
|
|
- // Home Z after the alignment procedure
|
374
|
|
- process_subcommands_now_P(PSTR("G28 Z"));
|
|
377
|
+ #if ENABLED(HOME_AFTER_G34)
|
|
378
|
+ // After this operation the z position needs correction
|
|
379
|
+ set_axis_not_trusted(Z_AXIS);
|
|
380
|
+
|
|
381
|
+ // Home Z after the alignment procedure
|
|
382
|
+ process_subcommands_now_P(PSTR("G28Z"));
|
|
383
|
+ #else
|
|
384
|
+ // Use the probed height from the last iteration to determine the Z height.
|
|
385
|
+ // z_measured_min is used, because all steppers are aligned to z_measured_min.
|
|
386
|
+ // Ideally, this would be equal to the 'z_probe * 0.5f' which was added earlier.
|
|
387
|
+ current_position.z -= z_measured_min - (float)Z_CLEARANCE_BETWEEN_PROBES;
|
|
388
|
+ sync_plan_position();
|
|
389
|
+ #endif
|
375
|
390
|
|
376
|
391
|
}while(0);
|
377
|
392
|
|