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
   #define Z_STEPPER_ALIGN_ITERATIONS 5    // Number of iterations to apply during alignment
718
   #define Z_STEPPER_ALIGN_ITERATIONS 5    // Number of iterations to apply during alignment
719
   #define Z_STEPPER_ALIGN_ACC        0.02 // Stop iterating early if the accuracy is better than this
719
   #define Z_STEPPER_ALIGN_ACC        0.02 // Stop iterating early if the accuracy is better than this
720
   #define RESTORE_LEVELING_AFTER_G34      // Restore leveling after G34 is done?
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
 #endif
724
 #endif
722
 
725
 
723
 // @section motion
726
 // @section motion

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

141
     // iteration this will be re-calculated based on the actual bed position
141
     // iteration this will be re-calculated based on the actual bed position
142
     float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * (
142
     float z_probe = Z_BASIC_CLEARANCE + (G34_MAX_GRADE) * 0.01f * (
143
       #if NUM_Z_STEPPER_DRIVERS == 3
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
       #else
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
       #endif
149
       #endif
150
     );
150
     );
151
 
151
 
156
     current_position.z += z_probe * 0.5f;
156
     current_position.z += z_probe * 0.5f;
157
     sync_plan_position();
157
     sync_plan_position();
158
     // Now, the Z origin lies below the build plate. That allows to probe deeper, before run_z_probe throws an error.
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
     #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
161
     #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
161
       float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N(NUM_Z_STEPPER_DRIVERS, 10000.0f, 10000.0f, 10000.0f);
162
       float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N(NUM_Z_STEPPER_DRIVERS, 10000.0f, 10000.0f, 10000.0f);
166
           z_maxdiff = 0.0f,
167
           z_maxdiff = 0.0f,
167
           amplification = z_auto_align_amplification;
168
           amplification = z_auto_align_amplification;
168
 
169
 
170
+    // These are needed after the for-loop
169
     uint8_t iteration;
171
     uint8_t iteration;
170
     bool err_break = false;
172
     bool err_break = false;
173
+    float z_measured_min;
171
 
174
 
172
     #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
175
     #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
173
       bool adjustment_reverse = false;
176
       bool adjustment_reverse = false;
181
       SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1));
184
       SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1));
182
 
185
 
183
       // Initialize minimum value
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
       // Probe all positions (one per Z-Stepper)
190
       // Probe all positions (one per Z-Stepper)
188
       LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
191
       LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
238
         linear_fit_data lfd;
241
         linear_fit_data lfd;
239
         incremental_LSF_reset(&lfd);
242
         incremental_LSF_reset(&lfd);
240
         LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
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
           incremental_LSF(&lfd, z_stepper_align.xy[i], z_measured[i]);
245
           incremental_LSF(&lfd, z_stepper_align.xy[i], z_measured[i]);
243
         }
246
         }
244
         finish_incremental_LSF(&lfd);
247
         finish_incremental_LSF(&lfd);
245
 
248
 
246
         z_measured_min = 100000.0f;
249
         z_measured_min = 100000.0f;
247
         LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
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
           z_measured_min = _MIN(z_measured_min, z_measured[i]);
252
           z_measured_min = _MIN(z_measured_min, z_measured[i]);
250
         }
253
         }
251
 
254
 
345
 
348
 
346
     } // for (iteration)
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
     SERIAL_ECHOLNPAIR("Did ", int(iteration + (iteration != z_auto_align_iterations)), " iterations of ", int(z_auto_align_iterations));
357
     SERIAL_ECHOLNPAIR("Did ", int(iteration + (iteration != z_auto_align_iterations)), " iterations of ", int(z_auto_align_iterations));
351
     SERIAL_ECHOLNPAIR_F("Accuracy: ", z_maxdiff);
358
     SERIAL_ECHOLNPAIR_F("Accuracy: ", z_maxdiff);
363
       set_bed_leveling_enabled(leveling_was_active);
370
       set_bed_leveling_enabled(leveling_was_active);
364
     #endif
371
     #endif
365
 
372
 
366
-    // After this operation the z position needs correction
367
-    set_axis_is_not_at_home(Z_AXIS);
368
-
369
     // Stow the probe, as the last call to probe.probe_at_point(...) left
373
     // Stow the probe, as the last call to probe.probe_at_point(...) left
370
     // the probe deployed if it was successful.
374
     // the probe deployed if it was successful.
371
     probe.stow();
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
   }while(0);
391
   }while(0);
377
 
392
 

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

393
   //
393
   //
394
   GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
394
   GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
395
   #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
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
   #endif
399
   #endif
400
 
400
 
401
   //
401
   //

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

1460
 /**
1460
 /**
1461
  * Set an axis' to be unhomed.
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
   CBI(axis_known_position, axis);
1466
   CBI(axis_known_position, axis);
1467
   CBI(axis_homed, axis);
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
   #if ENABLED(I2C_POSITION_ENCODERS)
1471
   #if ENABLED(I2C_POSITION_ENCODERS)
1472
     I2CPEM.unhomed(axis);
1472
     I2CPEM.unhomed(axis);

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

244
 
244
 
245
 void set_axis_is_at_home(const AxisEnum axis);
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
 void homeaxis(const AxisEnum axis);
249
 void homeaxis(const AxisEnum axis);
250
 
250
 

Loading…
Cancel
Save