Skip to content

Commit 1beee33

Browse files
thinkyheadAndy-Big
authored andcommitted
πŸ§‘β€πŸ’» Gather Z clearances (MarlinFirmware#25701)
1 parent e42b560 commit 1beee33

File tree

11 files changed

+101
-121
lines changed

11 files changed

+101
-121
lines changed

β€ŽMarlin/Configuration.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@
14601460
* on the right, enable and set TOUCH_MI_DEPLOY_XPOS to the deploy position.
14611461
*
14621462
* Also requires: BABYSTEPPING, BABYSTEP_ZPROBE_OFFSET, Z_SAFE_HOMING,
1463-
* and a minimum Z_HOMING_HEIGHT of 10.
1463+
* and a minimum Z_CLEARANCE_FOR_HOMING of 10.
14641464
*/
14651465
//#define TOUCH_MI_PROBE
14661466
#if ENABLED(TOUCH_MI_PROBE)
@@ -1796,10 +1796,10 @@
17961796
*/
17971797
//#define Z_IDLE_HEIGHT Z_HOME_POS
17981798

1799-
//#define Z_HOMING_HEIGHT 4 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ...
1800-
// Be sure to have this much clearance over your Z_MAX_POS to prevent grinding.
1799+
//#define Z_CLEARANCE_FOR_HOMING 4 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ...
1800+
// Be sure to have this much clearance over your Z_MAX_POS to prevent grinding.
18011801

1802-
//#define Z_AFTER_HOMING 10 // (mm) Height to move to after homing Z
1802+
//#define Z_AFTER_HOMING 10 // (mm) Height to move to after homing Z
18031803

18041804
// Direction of endstops when homing; 1=MAX, -1=MIN
18051805
// :[-1,1]

β€ŽMarlin/src/gcode/bedlevel/G35.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,7 @@ void GcodeSuite::G35() {
9898

9999
// Probe all positions
100100
LOOP_L_N(i, G35_PROBE_COUNT) {
101-
102-
// In BLTOUCH HS mode, the probe travels in a deployed state.
103-
// Users of G35 might have a badly misaligned bed, so raise Z by the
104-
// length of the deployed pin (BLTOUCH stroke < 7mm)
105-
106-
// Unsure if this is even required. The probe seems to lift correctly after probe done.
107101
const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true);
108-
109102
if (isnan(z_probed_height)) {
110103
SERIAL_ECHOPGM("G35 failed at point ", i + 1, " (");
111104
SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));

β€ŽMarlin/src/gcode/bedlevel/abl/G29.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -502,20 +502,13 @@ G29_TYPE GcodeSuite::G29() {
502502
#endif
503503

504504
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
505-
if (!abl.dryrun
506-
&& (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)
507-
) {
508-
// Reset grid to 0.0 or "not probed". (Also disables ABL)
509-
reset_bed_level();
510-
511-
// Can't re-enable (on error) until the new grid is written
512-
abl.reenable = false;
505+
if (!abl.dryrun && (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)) {
506+
reset_bed_level(); // Reset grid to 0.0 or "not probed". (Also disables ABL)
507+
abl.reenable = false; // Can't re-enable (on error) until the new grid is written
513508
}
514-
515509
// Pre-populate local Z values from the stored mesh
516510
TERN_(IS_KINEMATIC, COPY(abl.z_values, bedlevel.z_values));
517-
518-
#endif // AUTO_BED_LEVELING_BILINEAR
511+
#endif
519512

520513
} // !g29_in_progress
521514

β€ŽMarlin/src/gcode/calibrate/G28.cpp

+43-38
Original file line numberDiff line numberDiff line change
@@ -399,49 +399,50 @@ void GcodeSuite::G28() {
399399
doU = home_all || homeU, doV = home_all || homeV, doW = home_all || homeW
400400
);
401401

402+
#if !HAS_Y_AXIS
403+
constexpr bool doY = false;
404+
#endif
405+
402406
#if HAS_Z_AXIS
407+
403408
UNUSED(needZ); UNUSED(homeZZ);
404-
#else
405-
constexpr bool doZ = false;
406-
#if !HAS_Y_AXIS
407-
constexpr bool doY = false;
408-
#endif
409-
#endif
410409

411-
// Z may home first, e.g., when homing away from the bed
412-
TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS));
410+
// Z may home first, e.g., when homing away from the bed
411+
TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS));
413412

414-
// 'R' to specify a specific raise. 'R0' indicates no raise, e.g., for recovery.resume
415-
// When 'R0' is used, there should already be adequate clearance, e.g., from homing Z to max.
416-
const bool seenR = parser.seenval('R');
413+
// 'R' to specify a specific raise. 'R0' indicates no raise, e.g., for recovery.resume
414+
// When 'R0' is used, there should already be adequate clearance, e.g., from homing Z to max.
415+
const bool seenR = parser.seenval('R');
417416

418-
// Use raise given by 'R' or Z_HOMING_HEIGHT (above the probe trigger point)
419-
float z_homing_height = seenR ? parser.value_linear_units() : Z_HOMING_HEIGHT;
417+
// Use raise given by 'R' or Z_CLEARANCE_FOR_HOMING (above the probe trigger point)
418+
float z_homing_height = seenR ? parser.value_linear_units() : Z_CLEARANCE_FOR_HOMING;
420419

421-
// Check for any lateral motion that might require clearance
422-
const bool may_skate = seenR || NUM_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW);
420+
// Check for any lateral motion that might require clearance
421+
const bool may_skate = seenR || NUM_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW);
423422

424-
if (seenR && z_homing_height == 0) {
425-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("R0 = No Z raise");
426-
}
427-
else {
428-
bool with_probe = ENABLED(HOMING_Z_WITH_PROBE);
429-
// Raise above the current Z (which should be synced in the planner)
430-
// The "height" for Z is a coordinate. But if Z is not trusted/homed make it relative.
431-
if (seenR || !TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(Z_AXIS)) {
432-
z_homing_height += current_position.z;
433-
with_probe = false;
423+
if (seenR && z_homing_height == 0) {
424+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("R0 = No Z raise");
434425
}
426+
else {
427+
bool with_probe = ENABLED(HOMING_Z_WITH_PROBE);
428+
// Raise above the current Z (which should be synced in the planner)
429+
// The "height" for Z is a coordinate. But if Z is not trusted/homed make it relative.
430+
if (seenR || !TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(Z_AXIS)) {
431+
z_homing_height += current_position.z;
432+
with_probe = false;
433+
}
435434

436-
if (may_skate) {
437-
// Apply Z clearance before doing any lateral motion
438-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:");
439-
do_z_clearance(z_homing_height, with_probe);
435+
if (may_skate) {
436+
// Apply Z clearance before doing any lateral motion
437+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:");
438+
do_z_clearance(z_homing_height, with_probe);
439+
}
440440
}
441-
}
442441

443-
// Init BLTouch ahead of any lateral motion, even if not homing with the probe
444-
TERN_(BLTOUCH, if (may_skate) bltouch.init());
442+
// Init BLTouch ahead of any lateral motion, even if not homing with the probe
443+
TERN_(BLTOUCH, if (may_skate) bltouch.init());
444+
445+
#endif // HAS_Z_AXIS
445446

446447
// Diagonal move first if both are homing
447448
TERN_(QUICK_HOME, if (doX && doY) quick_home_xy());
@@ -497,11 +498,14 @@ void GcodeSuite::G28() {
497498
TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state));
498499

499500
#if ENABLED(FOAMCUTTER_XYUV)
500-
// skip homing of unused Z axis for foamcutters
501+
502+
// Skip homing of unused Z axis for foamcutters
501503
if (doZ) set_axis_is_at_home(Z_AXIS);
502-
#else
504+
505+
#elif HAS_Z_AXIS
506+
503507
// Home Z last if homing towards the bed
504-
#if HAS_Z_AXIS && DISABLED(HOME_Z_FIRST)
508+
#if DISABLED(HOME_Z_FIRST)
505509
if (doZ) {
506510
#if EITHER(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
507511
stepper.set_all_z_lock(false);
@@ -513,7 +517,7 @@ void GcodeSuite::G28() {
513517
#else
514518
homeaxis(Z_AXIS);
515519
#endif
516-
probe.move_z_after_homing();
520+
do_move_after_z_homing();
517521
}
518522
#endif
519523

@@ -525,7 +529,8 @@ void GcodeSuite::G28() {
525529
if (doV) homeaxis(V_AXIS),
526530
if (doW) homeaxis(W_AXIS)
527531
);
528-
#endif
532+
533+
#endif // HAS_Z_AXIS
529534

530535
sync_plan_position();
531536

@@ -629,7 +634,7 @@ void GcodeSuite::G28() {
629634

630635
report_current_position();
631636

632-
if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
637+
if (BOTH(NANODLP_Z_SYNC, NANODLP_ALL_AXIS) || TERN0(HAS_Z_AXIS, doZ))
633638
SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
634639

635640
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate));

β€ŽMarlin/src/inc/Conditionals_post.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -3183,24 +3183,24 @@
31833183
#endif
31843184

31853185
/**
3186-
* Z_HOMING_HEIGHT / Z_CLEARANCE_BETWEEN_PROBES
3186+
* Z_CLEARANCE_FOR_HOMING / Z_CLEARANCE_BETWEEN_PROBES
31873187
*/
3188-
#ifndef Z_HOMING_HEIGHT
3188+
#ifndef Z_CLEARANCE_FOR_HOMING
31893189
#ifdef Z_CLEARANCE_BETWEEN_PROBES
3190-
#define Z_HOMING_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
3190+
#define Z_CLEARANCE_FOR_HOMING Z_CLEARANCE_BETWEEN_PROBES
31913191
#else
3192-
#define Z_HOMING_HEIGHT 0
3192+
#define Z_CLEARANCE_FOR_HOMING 0
31933193
#endif
31943194
#endif
31953195

31963196
#if PROBE_SELECTED
31973197
#ifndef Z_CLEARANCE_BETWEEN_PROBES
3198-
#define Z_CLEARANCE_BETWEEN_PROBES Z_HOMING_HEIGHT
3198+
#define Z_CLEARANCE_BETWEEN_PROBES Z_CLEARANCE_FOR_HOMING
31993199
#endif
3200-
#if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
3200+
#if Z_CLEARANCE_BETWEEN_PROBES > Z_CLEARANCE_FOR_HOMING
32013201
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_CLEARANCE_BETWEEN_PROBES
32023202
#else
3203-
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_HOMING_HEIGHT
3203+
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_CLEARANCE_FOR_HOMING
32043204
#endif
32053205
#ifndef Z_CLEARANCE_MULTI_PROBE
32063206
#define Z_CLEARANCE_MULTI_PROBE Z_CLEARANCE_BETWEEN_PROBES

β€ŽMarlin/src/inc/SanityCheck.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@
214214
#elif defined(PID_ADD_EXTRUSION_RATE)
215215
#error "PID_ADD_EXTRUSION_RATE is now PID_EXTRUSION_SCALING and is DISABLED by default."
216216
#elif defined(Z_RAISE_BEFORE_HOMING)
217-
#error "Z_RAISE_BEFORE_HOMING is now Z_HOMING_HEIGHT."
217+
#error "Z_RAISE_BEFORE_HOMING is now Z_CLEARANCE_FOR_HOMING."
218218
#elif defined(MIN_Z_HEIGHT_FOR_HOMING)
219-
#error "MIN_Z_HEIGHT_FOR_HOMING is now Z_HOMING_HEIGHT."
219+
#error "MIN_Z_HEIGHT_FOR_HOMING is now Z_CLEARANCE_FOR_HOMING."
220+
#elif defined(Z_HOMING_HEIGHT)
221+
#error "Z_HOMING_HEIGHT is now Z_CLEARANCE_FOR_HOMING."
220222
#elif defined(Z_RAISE_BEFORE_PROBING) || defined(Z_RAISE_AFTER_PROBING)
221223
#error "Z_RAISE_(BEFORE|AFTER)_PROBING are deprecated. Use Z_CLEARANCE_DEPLOY_PROBE and Z_AFTER_PROBING instead."
222224
#elif defined(Z_RAISE_PROBE_DEPLOY_STOW) || defined(Z_RAISE_BETWEEN_PROBINGS)
@@ -1943,8 +1945,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
19431945
#error "TOUCH_MI_PROBE requires TOUCH_MI_RETRACT_Z."
19441946
#elif defined(Z_AFTER_PROBING)
19451947
#error "TOUCH_MI_PROBE requires Z_AFTER_PROBING to be disabled."
1946-
#elif Z_HOMING_HEIGHT < 10
1947-
#error "TOUCH_MI_PROBE requires Z_HOMING_HEIGHT >= 10."
1948+
#elif Z_CLEARANCE_FOR_HOMING < 10
1949+
#error "TOUCH_MI_PROBE requires Z_CLEARANCE_FOR_HOMING >= 10."
19481950
#elif DISABLED(BABYSTEP_ZPROBE_OFFSET)
19491951
#error "TOUCH_MI_PROBE requires BABYSTEPPING with BABYSTEP_ZPROBE_OFFSET."
19501952
#elif !HAS_RESUME_CONTINUE

β€ŽMarlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
102102
current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
103103
probe.offset.z = calculated_z_offset;
104104
sync_plan_position();
105-
// Raise Z as if it was homed
106-
do_z_clearance(Z_POST_CLEARANCE);
105+
do_z_post_clearance();
107106
hal.watchdog_refresh();
108107
draw_return_ui();
109108
return;
110109
case ID_M_RETURN:
111110
probe.offset.z = z_offset_backup;
112111
SET_SOFT_ENDSTOP_LOOSE(false);
113112
TERN_(HAS_LEVELING, set_bed_leveling_enabled(mks_leveling_was_active));
113+
// On cancel the Z position needs correction
114114
#if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
115-
set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
115+
set_axis_never_homed(Z_AXIS);
116116
queue.inject_P(PSTR("G28Z"));
117-
#else // Otherwise do a Z clearance move like after Homing
118-
do_z_clearance(Z_POST_CLEARANCE);
117+
#else
118+
do_z_post_clearance();
119119
#endif
120120
hal.watchdog_refresh();
121121
draw_return_ui();

β€ŽMarlin/src/lcd/menu/menu_probe_offset.cpp

+5-17
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ void _goto_manual_move_z(const_float_t);
4545
// Global storage
4646
float z_offset_backup, calculated_z_offset, z_offset_ref;
4747

48-
inline void z_clearance_move() {
49-
do_z_clearance(Z_POST_CLEARANCE);
50-
}
51-
52-
void cancel_probe_offset_wizard_and_go_back()
53-
{
54-
probe.offset.z = z_offset_backup;
55-
SET_SOFT_ENDSTOP_LOOSE(false);
56-
TERN_(HAS_LEVELING, set_bed_leveling_enabled(menu_leveling_was_active));
57-
ui.goto_previous_screen_no_defer();
58-
}
59-
6048
void set_offset_and_go_back(const_float_t z) {
6149
probe.offset.z = z;
6250
SET_SOFT_ENDSTOP_LOOSE(false);
@@ -86,17 +74,17 @@ void probe_offset_wizard_menu() {
8674
set_offset_and_go_back(calculated_z_offset);
8775
current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
8876
sync_plan_position();
89-
z_clearance_move(); // Raise Z as if it was homed
77+
do_z_post_clearance();
9078
});
9179

9280
ACTION_ITEM(MSG_BUTTON_CANCEL, []{
9381
set_offset_and_go_back(z_offset_backup);
94-
// If wizard-homing was done by probe with PROBE_OFFSET_WIZARD_START_Z
82+
// On cancel the Z position needs correction
9583
#if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
96-
set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
84+
set_axis_never_homed(Z_AXIS);
9785
queue.inject(F("G28Z"));
98-
#else // Otherwise do a Z clearance move like after Homing
99-
z_clearance_move();
86+
#else
87+
do_z_post_clearance();
10088
#endif
10189
});
10290

β€ŽMarlin/src/module/motion.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "../lcd/marlinui.h"
3939
#endif
4040

41+
#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
42+
#include "../lcd/e3v2/proui/dwin.h"
43+
#endif
44+
4145
#if ENABLED(POLAR)
4246
#include "polar.h"
4347
#endif
@@ -795,6 +799,14 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
795799
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance_by(", zclear, ")");
796800
do_z_clearance(current_position.z + zclear, false);
797801
}
802+
void do_move_after_z_homing() {
803+
DEBUG_SECTION(mzah, "do_move_after_z_homing", DEBUGGING(LEVELING));
804+
#if defined(Z_AFTER_HOMING) || ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
805+
do_z_clearance(Z_POST_CLEARANCE, true, true);
806+
#elif ENABLED(USE_PROBE_FOR_Z_HOMING)
807+
probe.move_z_after_probing();
808+
#endif
809+
}
798810
#endif
799811

800812
//
@@ -803,13 +815,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
803815
//
804816
static float saved_feedrate_mm_s;
805817
static int16_t saved_feedrate_percentage;
806-
void remember_feedrate_and_scaling() {
807-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("remember_feedrate_and_scaling: fr=", feedrate_mm_s, " ", feedrate_percentage, "%");
818+
void remember_feedrate_scaling_off() {
819+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("remember_feedrate_scaling_off: fr=", feedrate_mm_s, " ", feedrate_percentage, "%");
808820
saved_feedrate_mm_s = feedrate_mm_s;
809821
saved_feedrate_percentage = feedrate_percentage;
810-
}
811-
void remember_feedrate_scaling_off() {
812-
remember_feedrate_and_scaling();
813822
feedrate_percentage = 100;
814823
}
815824
void restore_feedrate_and_scaling() {

β€ŽMarlin/src/module/motion.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,21 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s=0.0f);
398398
FORCE_INLINE void do_blocking_move_to_xy_z(const xyze_pos_t &raw, const_float_t z, const_feedRate_t fr_mm_s=0.0f) { do_blocking_move_to_xy_z(xy_pos_t(raw), z, fr_mm_s); }
399399
#endif
400400

401-
void remember_feedrate_and_scaling();
402401
void remember_feedrate_scaling_off();
403402
void restore_feedrate_and_scaling();
404403

405404
#if HAS_Z_AXIS
405+
#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
406+
#define Z_POST_CLEARANCE HMI_data.z_after_homing
407+
#elif defined(Z_AFTER_HOMING)
408+
#define Z_POST_CLEARANCE Z_AFTER_HOMING
409+
#else
410+
#define Z_POST_CLEARANCE Z_CLEARANCE_FOR_HOMING
411+
#endif
406412
void do_z_clearance(const_float_t zclear, const bool with_probe=true, const bool lower_allowed=false);
407413
void do_z_clearance_by(const_float_t zclear);
414+
void do_move_after_z_homing();
415+
inline void do_z_post_clearance() { do_z_clearance(Z_POST_CLEARANCE); }
408416
#else
409417
inline void do_z_clearance(float, bool=true, bool=false) {}
410418
inline void do_z_clearance_by(float) {}

0 commit comments

Comments
Β (0)