Browse Source

Fix G34, add HOME_AFTER_G34 option (#17108)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
jufimu12 4 years ago
parent
commit
627aa8db2d
No account linked to committer's email address

+ 3
- 0
Marlin/Configuration_adv.h View File

@@ -718,6 +718,9 @@
718 718
   #define Z_STEPPER_ALIGN_ITERATIONS 5    // Number of iterations to apply during alignment
719 719
   #define Z_STEPPER_ALIGN_ACC        0.02 // Stop iterating early if the accuracy is better than this
720 720
   #define RESTORE_LEVELING_AFTER_G34      // Restore leveling after G34 is done?
721
+  // After G34, re-home Z (G28 Z) or just calculate it from the last probe heights?
722
+  // Re-homing might be more precise in reproducing the actual 'G28 Z' homing height, especially on an uneven bed.
723
+  #define HOME_AFTER_G34
721 724
 #endif
722 725
 
723 726
 // @section motion

+ 29
- 14
Marlin/src/gcode/calibrate/G34_M422.cpp View File

@@ -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
 

+ 3
- 3
Marlin/src/lcd/menu/menu_motion.cpp View File

@@ -393,9 +393,9 @@ void menu_motion() {
393 393
   //
394 394
   GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
395 395
   #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
396
-    GCODES_ITEM(MSG_AUTO_HOME_X, PSTR("G28 X"));
397
-    GCODES_ITEM(MSG_AUTO_HOME_Y, PSTR("G28 Y"));
398
-    GCODES_ITEM(MSG_AUTO_HOME_Z, PSTR("G28 Z"));
396
+    GCODES_ITEM(MSG_AUTO_HOME_X, PSTR("G28X"));
397
+    GCODES_ITEM(MSG_AUTO_HOME_Y, PSTR("G28Y"));
398
+    GCODES_ITEM(MSG_AUTO_HOME_Z, PSTR("G28Z"));
399 399
   #endif
400 400
 
401 401
   //

+ 3
- 3
Marlin/src/module/motion.cpp View File

@@ -1460,13 +1460,13 @@ void set_axis_is_at_home(const AxisEnum axis) {
1460 1460
 /**
1461 1461
  * Set an axis' to be unhomed.
1462 1462
  */
1463
-void set_axis_is_not_at_home(const AxisEnum axis) {
1464
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_not_at_home(", axis_codes[axis], ")");
1463
+void set_axis_not_trusted(const AxisEnum axis) {
1464
+  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_not_trusted(", axis_codes[axis], ")");
1465 1465
 
1466 1466
   CBI(axis_known_position, axis);
1467 1467
   CBI(axis_homed, axis);
1468 1468
 
1469
-  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_is_not_at_home(", axis_codes[axis], ")");
1469
+  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_not_trusted(", axis_codes[axis], ")");
1470 1470
 
1471 1471
   #if ENABLED(I2C_POSITION_ENCODERS)
1472 1472
     I2CPEM.unhomed(axis);

+ 1
- 1
Marlin/src/module/motion.h View File

@@ -244,7 +244,7 @@ bool axis_unhomed_error(uint8_t axis_bits=0x07);
244 244
 
245 245
 void set_axis_is_at_home(const AxisEnum axis);
246 246
 
247
-void set_axis_is_not_at_home(const AxisEnum axis);
247
+void set_axis_not_trusted(const AxisEnum axis);
248 248
 
249 249
 void homeaxis(const AxisEnum axis);
250 250
 

Loading…
Cancel
Save