Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Gather Z clearances
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 17, 2023
1 parent b39b5bb commit 60c1e42
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 110 deletions.
8 changes: 4 additions & 4 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@
* on the right, enable and set TOUCH_MI_DEPLOY_XPOS to the deploy position.
*
* Also requires: BABYSTEPPING, BABYSTEP_ZPROBE_OFFSET, Z_SAFE_HOMING,
* and a minimum Z_HOMING_HEIGHT of 10.
* and a minimum Z_CLEARANCE_FOR_HOMING of 10.
*/
//#define TOUCH_MI_PROBE
#if ENABLED(TOUCH_MI_PROBE)
Expand Down Expand Up @@ -1730,10 +1730,10 @@
*/
//#define Z_IDLE_HEIGHT Z_HOME_POS

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

//#define Z_AFTER_HOMING 10 // (mm) Height to move to after homing Z
//#define Z_AFTER_HOMING 10 // (mm) Height to move to after homing Z

// Direction of endstops when homing; 1=MAX, -1=MIN
// :[-1,1]
Expand Down
15 changes: 4 additions & 11 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,13 @@ G29_TYPE GcodeSuite::G29() {
#endif

#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (!abl.dryrun
&& (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)
) {
// Reset grid to 0.0 or "not probed". (Also disables ABL)
reset_bed_level();

// Can't re-enable (on error) until the new grid is written
abl.reenable = false;
if (!abl.dryrun && (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)) {
reset_bed_level(); // Reset grid to 0.0 or "not probed". (Also disables ABL)
abl.reenable = false; // Can't re-enable (on error) until the new grid is written
}

// Pre-populate local Z values from the stored mesh
TERN_(IS_KINEMATIC, COPY(abl.z_values, bedlevel.z_values));

#endif // AUTO_BED_LEVELING_BILINEAR
#endif

} // !g29_in_progress

Expand Down
81 changes: 43 additions & 38 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,49 +399,50 @@ void GcodeSuite::G28() {
doU = home_all || homeU, doV = home_all || homeV, doW = home_all || homeW
);

#if !HAS_Y_AXIS
constexpr bool doY = false;
#endif

#if HAS_Z_AXIS

UNUSED(needZ); UNUSED(homeZZ);
#else
constexpr bool doZ = false;
#if !HAS_Y_AXIS
constexpr bool doY = false;
#endif
#endif

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

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

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

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

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

if (may_skate) {
// Apply Z clearance before doing any lateral motion
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:");
do_z_clearance(z_homing_height, with_probe);
if (may_skate) {
// Apply Z clearance before doing any lateral motion
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z before homing:");
do_z_clearance(z_homing_height, with_probe);
}
}
}

// Init BLTouch ahead of any lateral motion, even if not homing with the probe
TERN_(BLTOUCH, if (may_skate) bltouch.init());
// Init BLTouch ahead of any lateral motion, even if not homing with the probe
TERN_(BLTOUCH, if (may_skate) bltouch.init());

#endif // HAS_Z_AXIS

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

#if ENABLED(FOAMCUTTER_XYUV)
// skip homing of unused Z axis for foamcutters

// Skip homing of unused Z axis for foamcutters
if (doZ) set_axis_is_at_home(Z_AXIS);
#else

#elif HAS_Z_AXIS

// Home Z last if homing towards the bed
#if HAS_Z_AXIS && DISABLED(HOME_Z_FIRST)
#if DISABLED(HOME_Z_FIRST)
if (doZ) {
#if EITHER(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
stepper.set_all_z_lock(false);
Expand All @@ -513,7 +517,7 @@ void GcodeSuite::G28() {
#else
homeaxis(Z_AXIS);
#endif
probe.move_z_after_homing();
do_move_after_z_homing();
}
#endif

Expand All @@ -525,7 +529,8 @@ void GcodeSuite::G28() {
if (doV) homeaxis(V_AXIS),
if (doW) homeaxis(W_AXIS)
);
#endif

#endif // HAS_Z_AXIS

sync_plan_position();

Expand Down Expand Up @@ -629,7 +634,7 @@ void GcodeSuite::G28() {

report_current_position();

if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
if (BOTH(NANODLP_Z_SYNC, NANODLP_ALL_AXIS) || TERN0(HAS_Z_AXIS, doZ))
SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);

TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate));
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3180,24 +3180,24 @@
#endif

/**
* Z_HOMING_HEIGHT / Z_CLEARANCE_BETWEEN_PROBES
* Z_CLEARANCE_FOR_HOMING / Z_CLEARANCE_BETWEEN_PROBES
*/
#ifndef Z_HOMING_HEIGHT
#ifndef Z_CLEARANCE_FOR_HOMING
#ifdef Z_CLEARANCE_BETWEEN_PROBES
#define Z_HOMING_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
#define Z_CLEARANCE_FOR_HOMING Z_CLEARANCE_BETWEEN_PROBES
#else
#define Z_HOMING_HEIGHT 0
#define Z_CLEARANCE_FOR_HOMING 0
#endif
#endif

#if PROBE_SELECTED
#ifndef Z_CLEARANCE_BETWEEN_PROBES
#define Z_CLEARANCE_BETWEEN_PROBES Z_HOMING_HEIGHT
#define Z_CLEARANCE_BETWEEN_PROBES Z_CLEARANCE_FOR_HOMING
#endif
#if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
#if Z_CLEARANCE_BETWEEN_PROBES > Z_CLEARANCE_FOR_HOMING
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_CLEARANCE_BETWEEN_PROBES
#else
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_HOMING_HEIGHT
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_CLEARANCE_FOR_HOMING
#endif
#ifndef Z_CLEARANCE_MULTI_PROBE
#define Z_CLEARANCE_MULTI_PROBE Z_CLEARANCE_BETWEEN_PROBES
Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@
#elif defined(PID_ADD_EXTRUSION_RATE)
#error "PID_ADD_EXTRUSION_RATE is now PID_EXTRUSION_SCALING and is DISABLED by default."
#elif defined(Z_RAISE_BEFORE_HOMING)
#error "Z_RAISE_BEFORE_HOMING is now Z_HOMING_HEIGHT."
#error "Z_RAISE_BEFORE_HOMING is now Z_CLEARANCE_FOR_HOMING."
#elif defined(MIN_Z_HEIGHT_FOR_HOMING)
#error "MIN_Z_HEIGHT_FOR_HOMING is now Z_HOMING_HEIGHT."
#error "MIN_Z_HEIGHT_FOR_HOMING is now Z_CLEARANCE_FOR_HOMING."
#elif defined(Z_HOMING_HEIGHT)
#error "Z_HOMING_HEIGHT is now Z_CLEARANCE_FOR_HOMING."
#elif defined(Z_RAISE_BEFORE_PROBING) || defined(Z_RAISE_AFTER_PROBING)
#error "Z_RAISE_(BEFORE|AFTER)_PROBING are deprecated. Use Z_CLEARANCE_DEPLOY_PROBE and Z_AFTER_PROBING instead."
#elif defined(Z_RAISE_PROBE_DEPLOY_STOW) || defined(Z_RAISE_BETWEEN_PROBINGS)
Expand Down Expand Up @@ -1945,8 +1947,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#error "TOUCH_MI_PROBE requires TOUCH_MI_RETRACT_Z."
#elif defined(Z_AFTER_PROBING)
#error "TOUCH_MI_PROBE requires Z_AFTER_PROBING to be disabled."
#elif Z_HOMING_HEIGHT < 10
#error "TOUCH_MI_PROBE requires Z_HOMING_HEIGHT >= 10."
#elif Z_CLEARANCE_FOR_HOMING < 10
#error "TOUCH_MI_PROBE requires Z_CLEARANCE_FOR_HOMING >= 10."
#elif DISABLED(BABYSTEP_ZPROBE_OFFSET)
#error "TOUCH_MI_PROBE requires BABYSTEPPING with BABYSTEP_ZPROBE_OFFSET."
#elif !HAS_RESUME_CONTINUE
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/mks_ui/draw_z_offset_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
probe.offset.z = calculated_z_offset;
sync_plan_position();
// Raise Z as if it was homed
do_z_clearance(Z_POST_CLEARANCE);
do_z_post_clearance();
hal.watchdog_refresh();
draw_return_ui();
return;
case ID_M_RETURN:
probe.offset.z = z_offset_backup;
SET_SOFT_ENDSTOP_LOOSE(false);
TERN_(HAS_LEVELING, set_bed_leveling_enabled(mks_leveling_was_active));
// On cancel the Z position needs correction
#if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
set_axis_never_homed(Z_AXIS);
queue.inject_P(PSTR("G28Z"));
#else // Otherwise do a Z clearance move like after Homing
do_z_clearance(Z_POST_CLEARANCE);
#else
do_z_post_clearance();
#endif
hal.watchdog_refresh();
draw_return_ui();
Expand Down
14 changes: 5 additions & 9 deletions Marlin/src/lcd/menu/menu_probe_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ void _goto_manual_move_z(const_float_t);
// Global storage
float z_offset_backup, calculated_z_offset, z_offset_ref;

inline void z_clearance_move() {
do_z_clearance(Z_POST_CLEARANCE);
}

void set_offset_and_go_back(const_float_t z) {
probe.offset.z = z;
SET_SOFT_ENDSTOP_LOOSE(false);
Expand Down Expand Up @@ -75,17 +71,17 @@ void probe_offset_wizard_menu() {
set_offset_and_go_back(calculated_z_offset);
current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
sync_plan_position();
z_clearance_move(); // Raise Z as if it was homed
do_z_post_clearance();
});

ACTION_ITEM(MSG_BUTTON_CANCEL, []{
set_offset_and_go_back(z_offset_backup);
// If wizard-homing was done by probe with PROBE_OFFSET_WIZARD_START_Z
// On cancel the Z position needs correction
#if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
set_axis_never_homed(Z_AXIS);
queue.inject(F("G28Z"));
#else // Otherwise do a Z clearance move like after Homing
z_clearance_move();
#else
do_z_post_clearance();
#endif
});

Expand Down
19 changes: 14 additions & 5 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include "../lcd/marlinui.h"
#endif

#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
#include "../lcd/e3v2/proui/dwin.h"
#endif

#if ENABLED(POLAR)
#include "polar.h"
#endif
Expand Down Expand Up @@ -795,6 +799,14 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("do_z_clearance_by(", zclear, ")");
do_z_clearance(current_position.z + zclear, false);
}
void do_move_after_z_homing() {
DEBUG_SECTION(mzah, "do_move_after_z_homing", DEBUGGING(LEVELING));
#if defined(Z_AFTER_HOMING) || ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
do_z_clearance(Z_POST_CLEARANCE, true, true);
#elif ENABLED(USE_PROBE_FOR_Z_HOMING)
probe.move_z_after_probing();
#endif
}
#endif

//
Expand All @@ -803,13 +815,10 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s/*=0.0*/) {
//
static float saved_feedrate_mm_s;
static int16_t saved_feedrate_percentage;
void remember_feedrate_and_scaling() {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("remember_feedrate_and_scaling: fr=", feedrate_mm_s, " ", feedrate_percentage, "%");
void remember_feedrate_scaling_off() {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("remember_feedrate_scaling_off: fr=", feedrate_mm_s, " ", feedrate_percentage, "%");
saved_feedrate_mm_s = feedrate_mm_s;
saved_feedrate_percentage = feedrate_percentage;
}
void remember_feedrate_scaling_off() {
remember_feedrate_and_scaling();
feedrate_percentage = 100;
}
void restore_feedrate_and_scaling() {
Expand Down
10 changes: 9 additions & 1 deletion Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,21 @@ void do_blocking_move_to_x(const_float_t rx, const_feedRate_t fr_mm_s=0.0f);
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); }
#endif

void remember_feedrate_and_scaling();
void remember_feedrate_scaling_off();
void restore_feedrate_and_scaling();

#if HAS_Z_AXIS
#if ALL(DWIN_LCD_PROUI, INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
#define Z_POST_CLEARANCE HMI_data.z_after_homing
#elif defined(Z_AFTER_HOMING)
#define Z_POST_CLEARANCE Z_AFTER_HOMING
#else
#define Z_POST_CLEARANCE Z_CLEARANCE_FOR_HOMING
#endif
void do_z_clearance(const_float_t zclear, const bool with_probe=true, const bool lower_allowed=false);
void do_z_clearance_by(const_float_t zclear);
void do_move_after_z_homing();
inline void do_z_post_clearance() { do_z_clearance(Z_POST_CLEARANCE); }
#else
inline void do_z_clearance(float, bool=true, bool=false) {}
inline void do_z_clearance_by(float) {}
Expand Down
Loading

0 comments on commit 60c1e42

Please sign in to comment.