From 653eff3b31d38f2819ec55134831fdd5daf3e980 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 13:40:38 +0200 Subject: [PATCH 1/7] Clean up `quick_home_xy()` Since we do the actual homing now in the 'normal' routines `quick_home_xy()` can be simplified to a relative simple diagonal move. --- Marlin/Marlin_main.cpp | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 8b419b9e7e..0c35885768 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2779,8 +2779,6 @@ inline void gcode_G4() { int x_axis_home_dir = home_dir(X_AXIS); #endif - SYNC_PLAN_POSITION_KINEMATIC(); - float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS), mlratio = mlx > mly ? mly / mlx : mlx / mly; @@ -2789,30 +2787,9 @@ inline void gcode_G4() { feedrate = min(homing_feedrate[X_AXIS], homing_feedrate[Y_AXIS]) * sqrt(mlratio * mlratio + 1); line_to_destination(); stepper.synchronize(); - - set_axis_is_at_home(X_AXIS); - set_axis_is_at_home(Y_AXIS); - SYNC_PLAN_POSITION_KINEMATIC(); - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 1", current_position); - #endif - - destination[X_AXIS] = current_position[X_AXIS]; - destination[Y_AXIS] = current_position[Y_AXIS]; - line_to_destination(); - stepper.synchronize(); endstops.hit_on_purpose(); // clear endstop hit flags - current_position[X_AXIS] = destination[X_AXIS]; - current_position[Y_AXIS] = destination[Y_AXIS]; - #if DISABLED(SCARA) - current_position[Z_AXIS] = destination[Z_AXIS]; - #endif - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("> QUICK_HOME 2", current_position); - #endif + destination[X_AXIS] = destination[Y_AXIS] = 0; } #endif // QUICK_HOME @@ -2917,8 +2894,8 @@ inline void gcode_G28() { #elif defined(MIN_Z_HEIGHT_FOR_HOMING) && MIN_Z_HEIGHT_FOR_HOMING > 0 - // Raise Z before homing X or Y, if specified if (home_all_axis || homeX || homeY) { + // Raise Z before homing any other axes and z is not already high enough (never lower z) float z_dest = home_offset[Z_AXIS] + MIN_Z_HEIGHT_FOR_HOMING; if (z_dest > current_position[Z_AXIS]) { From 88ed232f53a4b2053dfd5303c6103b81788e1ef8 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 13:47:40 +0200 Subject: [PATCH 2/7] Remove HAS_BED_PROBE case in first raise in G28 Differentiating made sense here when we could save a dozen lines of code, but not for one line. --- Marlin/Marlin_main.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0c35885768..160274c112 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2907,14 +2907,8 @@ inline void gcode_G28() { #endif feedrate = homing_feedrate[Z_AXIS]; - - #if HAS_BED_PROBE - do_blocking_move_to_z(z_dest); - #else - line_to_z(z_dest); - stepper.synchronize(); - #endif - + line_to_z(z_dest); + stepper.synchronize(); destination[Z_AXIS] = current_position[Z_AXIS] = z_dest; } } From de3a16933603ff892ffde48ec077488519ec5153 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 15:08:32 +0200 Subject: [PATCH 3/7] Always define MIN_Z_HEIGHT_FOR_HOMING even if 0 Always define MIN_Z_HEIGHT_FOR_HOMING even if 0 Always make a potential rise to `home_offset[Z_AXIS]` possible in G28. Get rid of some very ugly constructs in MBL (ultralcd.cpp). --- Marlin/Conditionals.h | 15 +++++++++++++++ Marlin/Marlin_main.cpp | 4 ++-- Marlin/ultralcd.cpp | 14 +++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h index 6b8a682ac6..844d2a4e54 100644 --- a/Marlin/Conditionals.h +++ b/Marlin/Conditionals.h @@ -842,5 +842,20 @@ #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2 #endif #endif + + /** + * MIN_Z_HEIGHT_FOR_HOMING / Z_RAISE_BETWEEN_PROBINGS + */ + #ifndef MIN_Z_HEIGHT_FOR_HOMING + #ifndef Z_RAISE_BETWEEN_PROBINGS + #define MIN_Z_HEIGHT_FOR_HOMING 0 + #else + #define MIN_Z_HEIGHT_FOR_HOMING Z_RAISE_BETWEEN_PROBINGS + #endif + #endif + #ifndef Z_RAISE_BETWEEN_PROBINGS + #define Z_RAISE_BETWEEN_PROBING MIN_Z_HEIGHT_FOR_HOMING + #endif + #endif //CONFIGURATION_LCD #endif //CONDITIONALS_H diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 160274c112..ef01f1226b 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2892,7 +2892,7 @@ inline void gcode_G28() { #endif } - #elif defined(MIN_Z_HEIGHT_FOR_HOMING) && MIN_Z_HEIGHT_FOR_HOMING > 0 + #else if (home_all_axis || homeX || homeY) { // Raise Z before homing any other axes and z is not already high enough (never lower z) @@ -2913,7 +2913,7 @@ inline void gcode_G28() { } } - #endif // MIN_Z_HEIGHT_FOR_HOMING + #endif #if ENABLED(QUICK_HOME) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 87104d87ec..e7a59d4cc5 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -978,17 +978,13 @@ static void lcd_status_screen() { // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z // Z position will be restored with the final action, a G28 inline void _mbl_goto_xy(float x, float y) { - current_position[Z_AXIS] = MESH_HOME_SEARCH_Z - #if MIN_Z_HEIGHT_FOR_HOMING > 0 - + MIN_Z_HEIGHT_FOR_HOMING - #endif - ; + current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + MIN_Z_HEIGHT_FOR_HOMING; line_to_current(Z_AXIS); current_position[X_AXIS] = x + home_offset[X_AXIS]; current_position[Y_AXIS] = y + home_offset[Y_AXIS]; line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS); #if MIN_Z_HEIGHT_FOR_HOMING > 0 - current_position[Z_AXIS] = MESH_HOME_SEARCH_Z; + current_position[Z_AXIS] = MESH_HOME_SEARCH_Z; // How do condition and action match? line_to_current(Z_AXIS); #endif stepper.synchronize(); @@ -1038,11 +1034,7 @@ static void lcd_status_screen() { if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) { lcd_goto_screen(_lcd_level_bed_done, true); - current_position[Z_AXIS] = MESH_HOME_SEARCH_Z - #if MIN_Z_HEIGHT_FOR_HOMING > 0 - + MIN_Z_HEIGHT_FOR_HOMING - #endif - ; + current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + MIN_Z_HEIGHT_FOR_HOMING; line_to_current(Z_AXIS); stepper.synchronize(); From 0ea6247fc2dd921be941c14236eb44dbeae7dc8f Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 14:43:01 +0200 Subject: [PATCH 4/7] Use logic in Z_SAFE_HOMING Use logic in Z_SAFE_HOMING From ``` if (home_all_axis || homeZ) { if (home_all_axis) { ... home z } else if (homeZ) { // Don't need to Home Z twice home z } } ``` to ``` if (home_all_axis || homeZ) { if (home_all_axis) { ... } home z } ``` --- Marlin/Marlin_main.cpp | 46 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index ef01f1226b..e89d702d86 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3015,36 +3015,30 @@ inline void gcode_G28() { */ current_position[X_AXIS] = destination[X_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS]; + } + + // Let's see if X and Y are homed + if (axis_unhomed_error(true, true, false)) return; + + /** + * Make sure the Z probe is within the physical limits + * NOTE: This doesn't necessarily ensure the Z probe is also + * within the bed! + */ + float cpx = current_position[X_AXIS], cpy = current_position[Y_AXIS]; + if ( cpx >= X_MIN_POS - (X_PROBE_OFFSET_FROM_EXTRUDER) + && cpx <= X_MAX_POS - (X_PROBE_OFFSET_FROM_EXTRUDER) + && cpy >= Y_MIN_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER) + && cpy <= Y_MAX_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER)) { // Home the Z axis HOMEAXIS(Z); } - - else if (homeZ) { // Don't need to Home Z twice - - // Let's see if X and Y are homed - if (axis_unhomed_error(true, true, false)) return; - - /** - * Make sure the Z probe is within the physical limits - * NOTE: This doesn't necessarily ensure the Z probe is also - * within the bed! - */ - float cpx = current_position[X_AXIS], cpy = current_position[Y_AXIS]; - if ( cpx >= X_MIN_POS - (X_PROBE_OFFSET_FROM_EXTRUDER) - && cpx <= X_MAX_POS - (X_PROBE_OFFSET_FROM_EXTRUDER) - && cpy >= Y_MIN_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER) - && cpy <= Y_MAX_POS - (Y_PROBE_OFFSET_FROM_EXTRUDER)) { - - // Home the Z axis - HOMEAXIS(Z); - } - else { - LCD_MESSAGEPGM(MSG_ZPROBE_OUT); - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT); - } - } // !home_all_axes && homeZ + else { + LCD_MESSAGEPGM(MSG_ZPROBE_OUT); + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT); + } #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { From f69434d81c730c7366f4201d65713872698e3456 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 15:23:20 +0200 Subject: [PATCH 5/7] Eliminate `void setup_for_endstop_move()` --- Marlin/Marlin_main.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e89d702d86..82dbf01cbc 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1620,10 +1620,6 @@ static void setup_for_endstop_or_probe_move() { feedrate_multiplier = 100; refresh_cmd_timeout(); } -static void setup_for_endstop_move() { - setup_for_endstop_or_probe_move(); - endstops.enable(); -} static void clean_up_after_endstop_or_probe_move() { #if ENABLED(DEBUG_LEVELING_FEATURE) @@ -2843,7 +2839,8 @@ inline void gcode_G28() { } #endif - setup_for_endstop_move(); + setup_for_endstop_or_probe_move(); + endstops.enable(); #if ENABLED(DELTA) /** From eff791224342adac0a68b92417938f873e642d1f Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 15:49:10 +0200 Subject: [PATCH 6/7] Ensble/disable hardware endstops in G28 globally. For moving away from the endstops we do not have to disable them. They are not tested anyway. --- Marlin/Marlin_main.cpp | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 82dbf01cbc..e57c1f2e98 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2390,21 +2390,11 @@ static void homeaxis(AxisEnum axis) { current_position[axis] = 0; sync_plan_position(); - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(false)"); - #endif - endstops.enable(false); // Disable endstops while moving away - // Move away from the endstop by the axis HOME_BUMP_MM destination[axis] = -home_bump_mm(axis) * axis_home_dir; line_to_destination(); stepper.synchronize(); - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(true)"); - #endif - endstops.enable(true); // Enable endstops for next homing move - // Slow down the feedrate for the next move set_homing_bump_feedrate(axis); @@ -2445,10 +2435,6 @@ static void homeaxis(AxisEnum axis) { #if ENABLED(DELTA) // retrace by the amount specified in endstop_adj if (endstop_adj[axis] * axis_home_dir < 0) { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(false)"); - #endif - endstops.enable(false); // Disable endstops while moving away sync_plan_position(); destination[axis] = endstop_adj[axis]; #if ENABLED(DEBUG_LEVELING_FEATURE) @@ -2459,19 +2445,7 @@ static void homeaxis(AxisEnum axis) { #endif line_to_destination(); stepper.synchronize(); - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(true)"); - #endif - endstops.enable(true); // Enable endstops for next homing move } - #if ENABLED(DEBUG_LEVELING_FEATURE) - else { - if (DEBUGGING(LEVELING)) { - SERIAL_ECHOPAIR("> endstop_adj * axis_home_dir = ", endstop_adj[axis] * axis_home_dir); - SERIAL_EOL; - } - } - #endif #endif // Set the axis position to its home position (plus home offsets) @@ -2840,7 +2814,11 @@ inline void gcode_G28() { #endif setup_for_endstop_or_probe_move(); - endstops.enable(); + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(true)"); + #endif + endstops.enable(true); // Enable endstops for next homing move + #if ENABLED(DELTA) /** @@ -3061,7 +3039,11 @@ inline void gcode_G28() { #endif // !DELTA (gcode_G28) + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.not_homing()"); + #endif endstops.not_homing(); + endstops.hit_on_purpose(); // clear endstop hit flags // Enable mesh leveling again #if ENABLED(MESH_BED_LEVELING) @@ -3101,8 +3083,6 @@ inline void gcode_G28() { clean_up_after_endstop_or_probe_move(); - endstops.hit_on_purpose(); // clear endstop hit flags - #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28"); #endif From 468f7f03a21fdfe3e83f880f3b1301d358efbb99 Mon Sep 17 00:00:00 2001 From: AnHardt Date: Fri, 8 Jul 2016 15:59:33 +0200 Subject: [PATCH 7/7] homeaxis() can leave early when no known axis needs to be homed. Most changes are only caused from altering the indentation. ``` if (axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) { ... } to if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0)) return; ... ``` --- Marlin/Marlin_main.cpp | 215 ++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 108 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e57c1f2e98..fec3b9382d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2344,135 +2344,134 @@ static void clean_up_after_endstop_or_probe_move() { #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS) static void homeaxis(AxisEnum axis) { + #define HOMEAXIS_DO(LETTER) \ + ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) + + if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0)) return; + #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR(">>> homeaxis(", axis); SERIAL_ECHOLNPGM(")"); } #endif - #define HOMEAXIS_DO(LETTER) \ - ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) - if (axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) { + int axis_home_dir = + #if ENABLED(DUAL_X_CARRIAGE) + (axis == X_AXIS) ? x_home_dir(active_extruder) : + #endif + home_dir(axis); - int axis_home_dir = - #if ENABLED(DUAL_X_CARRIAGE) - (axis == X_AXIS) ? x_home_dir(active_extruder) : + // Homing Z towards the bed? Deploy the Z probe or endstop. + #if HAS_BED_PROBE + if (axis == Z_AXIS && axis_home_dir < 0) { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); #endif - home_dir(axis); + if (DEPLOY_PROBE()) return; + } + #endif - // Homing Z towards the bed? Deploy the Z probe or endstop. - #if HAS_BED_PROBE - if (axis == Z_AXIS && axis_home_dir < 0) { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); - #endif - if (DEPLOY_PROBE()) return; + // Set the axis position as setup for the move + current_position[axis] = 0; + sync_plan_position(); + + // Set a flag for Z motor locking + #if ENABLED(Z_DUAL_ENDSTOPS) + if (axis == Z_AXIS) stepper.set_homing_flag(true); + #endif + + // Move towards the endstop until an endstop is triggered + destination[axis] = 1.5 * max_length(axis) * axis_home_dir; + feedrate = homing_feedrate[axis]; + line_to_destination(); + stepper.synchronize(); + + // Set the axis position as setup for the move + current_position[axis] = 0; + sync_plan_position(); + + // Move away from the endstop by the axis HOME_BUMP_MM + destination[axis] = -home_bump_mm(axis) * axis_home_dir; + line_to_destination(); + stepper.synchronize(); + + // Slow down the feedrate for the next move + set_homing_bump_feedrate(axis); + + // Move slowly towards the endstop until triggered + destination[axis] = 2 * home_bump_mm(axis) * axis_home_dir; + line_to_destination(); + stepper.synchronize(); + + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) DEBUG_POS("> TRIGGER ENDSTOP", current_position); + #endif + + #if ENABLED(Z_DUAL_ENDSTOPS) + if (axis == Z_AXIS) { + float adj = fabs(z_endstop_adj); + bool lockZ1; + if (axis_home_dir > 0) { + adj = -adj; + lockZ1 = (z_endstop_adj > 0); } - #endif + else + lockZ1 = (z_endstop_adj < 0); - // Set the axis position as setup for the move - current_position[axis] = 0; - sync_plan_position(); + if (lockZ1) stepper.set_z_lock(true); else stepper.set_z2_lock(true); + sync_plan_position(); - // Set a flag for Z motor locking - #if ENABLED(Z_DUAL_ENDSTOPS) - if (axis == Z_AXIS) stepper.set_homing_flag(true); - #endif + // Move to the adjusted endstop height + feedrate = homing_feedrate[axis]; + destination[Z_AXIS] = adj; + line_to_destination(); + stepper.synchronize(); - // Move towards the endstop until an endstop is triggered - destination[axis] = 1.5 * max_length(axis) * axis_home_dir; - feedrate = homing_feedrate[axis]; - line_to_destination(); - stepper.synchronize(); + if (lockZ1) stepper.set_z_lock(false); else stepper.set_z2_lock(false); + stepper.set_homing_flag(false); + } // Z_AXIS + #endif - // Set the axis position as setup for the move - current_position[axis] = 0; - sync_plan_position(); - - // Move away from the endstop by the axis HOME_BUMP_MM - destination[axis] = -home_bump_mm(axis) * axis_home_dir; - line_to_destination(); - stepper.synchronize(); - - // Slow down the feedrate for the next move - set_homing_bump_feedrate(axis); - - // Move slowly towards the endstop until triggered - destination[axis] = 2 * home_bump_mm(axis) * axis_home_dir; - line_to_destination(); - stepper.synchronize(); - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("> TRIGGER ENDSTOP", current_position); - #endif - - #if ENABLED(Z_DUAL_ENDSTOPS) - if (axis == Z_AXIS) { - float adj = fabs(z_endstop_adj); - bool lockZ1; - if (axis_home_dir > 0) { - adj = -adj; - lockZ1 = (z_endstop_adj > 0); + #if ENABLED(DELTA) + // retrace by the amount specified in endstop_adj + if (endstop_adj[axis] * axis_home_dir < 0) { + sync_plan_position(); + destination[axis] = endstop_adj[axis]; + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]); + DEBUG_POS("", destination); } - else - lockZ1 = (z_endstop_adj < 0); + #endif + line_to_destination(); + stepper.synchronize(); + } + #endif - if (lockZ1) stepper.set_z_lock(true); else stepper.set_z2_lock(true); - sync_plan_position(); + // Set the axis position to its home position (plus home offsets) + set_axis_is_at_home(axis); - // Move to the adjusted endstop height - feedrate = homing_feedrate[axis]; - destination[Z_AXIS] = adj; - line_to_destination(); - stepper.synchronize(); + SYNC_PLAN_POSITION_KINEMATIC(); - if (lockZ1) stepper.set_z_lock(false); else stepper.set_z2_lock(false); - stepper.set_homing_flag(false); - } // Z_AXIS - #endif + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position); + #endif - #if ENABLED(DELTA) - // retrace by the amount specified in endstop_adj - if (endstop_adj[axis] * axis_home_dir < 0) { - sync_plan_position(); - destination[axis] = endstop_adj[axis]; - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]); - DEBUG_POS("", destination); - } - #endif - line_to_destination(); - stepper.synchronize(); - } - #endif + destination[axis] = current_position[axis]; + endstops.hit_on_purpose(); // clear endstop hit flags + axis_known_position[axis] = true; + axis_homed[axis] = true; - // Set the axis position to its home position (plus home offsets) - set_axis_is_at_home(axis); - - SYNC_PLAN_POSITION_KINEMATIC(); - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position); - #endif - - destination[axis] = current_position[axis]; - endstops.hit_on_purpose(); // clear endstop hit flags - axis_known_position[axis] = true; - axis_homed[axis] = true; - - // Put away the Z probe - #if HAS_BED_PROBE - if (axis == Z_AXIS && axis_home_dir < 0) { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); - #endif - if (STOW_PROBE()) return; - } - #endif - - } + // Put away the Z probe + #if HAS_BED_PROBE + if (axis == Z_AXIS && axis_home_dir < 0) { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> "); + #endif + if (STOW_PROBE()) return; + } + #endif #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) {