From 3b457c2dd3142b40213ab743793190ffb2959ac9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 14:31:01 -0700 Subject: [PATCH 1/8] Use deploy/stow with FIX_MOUNTED_PROBE too --- Marlin/Marlin_main.cpp | 381 +++++++++++++++++++++-------------------- 1 file changed, 192 insertions(+), 189 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 8c6ef5c3f..4c7c0aaae 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1684,6 +1684,197 @@ static void setup_for_endstop_move() { #endif +#if HAS_BED_PROBE + + static void deploy_z_probe() { + + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) DEBUG_POS("deploy_z_probe", current_position); + #endif + + if (endstops.z_probe_enabled) return; + + #if HAS_Z_SERVO_ENDSTOP + + // Make room for Z Servo + raise_z_for_servo(Z_RAISE_BEFORE_PROBING); + + // Engage Z Servo endstop if enabled + DEPLOY_Z_SERVO(); + + #elif ENABLED(Z_PROBE_ALLEN_KEY) + float old_feedrate = feedrate; + + feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE; + + // If endstop is already false, the Z probe is deployed + #if ENABLED(Z_MIN_PROBE_ENDSTOP) + bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); + if (z_probe_endstop) + #else + bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + if (z_min_endstop) + #endif + { + // Move to the start position to initiate deployment + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_X; + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_Y; + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_Z; + prepare_move_to_destination_raw(); // this will also set_current_to_destination + + // Move to engage deployment + if (Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE) + feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE; + if (Z_PROBE_ALLEN_KEY_DEPLOY_2_X != Z_PROBE_ALLEN_KEY_DEPLOY_1_X) + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_X; + if (Z_PROBE_ALLEN_KEY_DEPLOY_2_Y != Z_PROBE_ALLEN_KEY_DEPLOY_1_Y) + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_Y; + if (Z_PROBE_ALLEN_KEY_DEPLOY_2_Z != Z_PROBE_ALLEN_KEY_DEPLOY_1_Z) + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_Z; + prepare_move_to_destination_raw(); + + #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_3_X + if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE) + feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE; + + // Move to trigger deployment + if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE) + feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE; + if (Z_PROBE_ALLEN_KEY_DEPLOY_3_X != Z_PROBE_ALLEN_KEY_DEPLOY_2_X) + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_X; + if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Y != Z_PROBE_ALLEN_KEY_DEPLOY_2_Y) + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Y; + if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Z != Z_PROBE_ALLEN_KEY_DEPLOY_2_Z) + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Z; + + prepare_move_to_destination_raw(); + #endif + } + + // Partially Home X,Y for safety + destination[X_AXIS] *= 0.75; + destination[Y_AXIS] *= 0.75; + prepare_move_to_destination_raw(); // this will also set_current_to_destination + + feedrate = old_feedrate; + + stepper.synchronize(); + + #if ENABLED(Z_MIN_PROBE_ENDSTOP) + z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); + if (z_probe_endstop) + #else + z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + if (z_min_endstop) + #endif + { + if (IsRunning()) { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM("Z-Probe failed to engage!"); + LCD_ALERTMESSAGEPGM("Err: ZPROBE"); + } + stop(); + } + + #elif ENABLED(FIX_MOUNTED_PROBE) + + // Nothing to be done. Just enable_z_probe below... + + #endif + + endstops.enable_z_probe(); + } + + static void stow_z_probe() { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position); + #endif + + if (!endstops.z_probe_enabled) return; + + #if HAS_Z_SERVO_ENDSTOP + + // Make room for the servo + raise_z_for_servo(Z_RAISE_AFTER_PROBING); + + // Change the Z servo angle + STOW_Z_SERVO(); + + #elif ENABLED(Z_PROBE_ALLEN_KEY) + + float old_feedrate = feedrate; + + // Move up for safety + feedrate = Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE; + + #if Z_RAISE_AFTER_PROBING > 0 + destination[Z_AXIS] = current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING; + prepare_move_to_destination_raw(); // this will also set_current_to_destination + #endif + + // Move to the start position to initiate retraction + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_X; + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_Y; + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_Z; + prepare_move_to_destination_raw(); + + // Move the nozzle down to push the Z probe into retracted position + if (Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE != Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE) + feedrate = Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE; + if (Z_PROBE_ALLEN_KEY_STOW_2_X != Z_PROBE_ALLEN_KEY_STOW_1_X) + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_X; + if (Z_PROBE_ALLEN_KEY_STOW_2_Y != Z_PROBE_ALLEN_KEY_STOW_1_Y) + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_Y; + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_Z; + prepare_move_to_destination_raw(); + + // Move up for safety + if (Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE != Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE) + feedrate = Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE; + if (Z_PROBE_ALLEN_KEY_STOW_3_X != Z_PROBE_ALLEN_KEY_STOW_2_X) + destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_X; + if (Z_PROBE_ALLEN_KEY_STOW_3_Y != Z_PROBE_ALLEN_KEY_STOW_2_Y) + destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_Y; + destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_Z; + prepare_move_to_destination_raw(); + + // Home XY for safety + feedrate = homing_feedrate[X_AXIS] / 2; + destination[X_AXIS] = 0; + destination[Y_AXIS] = 0; + prepare_move_to_destination_raw(); // this will also set_current_to_destination + + feedrate = old_feedrate; + + stepper.synchronize(); + + #if ENABLED(Z_MIN_PROBE_ENDSTOP) + bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); + if (!z_probe_endstop) + #else + bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + if (!z_min_endstop) + #endif + { + if (IsRunning()) { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM("Z-Probe failed to retract!"); + LCD_ALERTMESSAGEPGM("Err: ZPROBE"); + } + stop(); + } + + #elif ENABLED(FIX_MOUNTED_PROBE) + + // Nothing to do here. Just clear endstops.z_probe_enabled + + #endif + + endstops.enable_z_probe(false); + } + +#endif // HAS_BED_PROBE + #if ENABLED(AUTO_BED_LEVELING_FEATURE) #if ENABLED(AUTO_BED_LEVELING_GRID) @@ -1872,194 +2063,6 @@ static void setup_for_endstop_move() { refresh_cmd_timeout(); } - #if HAS_BED_PROBE - - static void deploy_z_probe() { - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("deploy_z_probe", current_position); - #endif - - if (endstops.z_probe_enabled) return; - - #if HAS_Z_SERVO_ENDSTOP - - // Make room for Z Servo - raise_z_for_servo(Z_RAISE_BEFORE_PROBING); - - // Engage Z Servo endstop if enabled - DEPLOY_Z_SERVO(); - - #elif ENABLED(Z_PROBE_ALLEN_KEY) - float old_feedrate = feedrate; - - feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE; - - // If endstop is already false, the Z probe is deployed - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (z_probe_endstop) - #else - bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (z_min_endstop) - #endif - { - // Move to the start position to initiate deployment - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_X; - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_Y; - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_1_Z; - prepare_move_to_destination_raw(); // this will also set_current_to_destination - - // Move to engage deployment - if (Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE) - feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE; - if (Z_PROBE_ALLEN_KEY_DEPLOY_2_X != Z_PROBE_ALLEN_KEY_DEPLOY_1_X) - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_X; - if (Z_PROBE_ALLEN_KEY_DEPLOY_2_Y != Z_PROBE_ALLEN_KEY_DEPLOY_1_Y) - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_Y; - if (Z_PROBE_ALLEN_KEY_DEPLOY_2_Z != Z_PROBE_ALLEN_KEY_DEPLOY_1_Z) - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_2_Z; - prepare_move_to_destination_raw(); - - #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_3_X - if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE) - feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE; - - // Move to trigger deployment - if (Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE != Z_PROBE_ALLEN_KEY_DEPLOY_2_FEEDRATE) - feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_3_FEEDRATE; - if (Z_PROBE_ALLEN_KEY_DEPLOY_3_X != Z_PROBE_ALLEN_KEY_DEPLOY_2_X) - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_X; - if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Y != Z_PROBE_ALLEN_KEY_DEPLOY_2_Y) - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Y; - if (Z_PROBE_ALLEN_KEY_DEPLOY_3_Z != Z_PROBE_ALLEN_KEY_DEPLOY_2_Z) - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_3_Z; - - prepare_move_to_destination_raw(); - #endif - } - - // Partially Home X,Y for safety - destination[X_AXIS] *= 0.75; - destination[Y_AXIS] *= 0.75; - prepare_move_to_destination_raw(); // this will also set_current_to_destination - - feedrate = old_feedrate; - - stepper.synchronize(); - - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (z_probe_endstop) - #else - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (z_min_endstop) - #endif - { - if (IsRunning()) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Z-Probe failed to engage!"); - LCD_ALERTMESSAGEPGM("Err: ZPROBE"); - } - stop(); - } - - #endif // Z_PROBE_ALLEN_KEY - - #if ENABLED(FIX_MOUNTED_PROBE) - // Nothing to be done. Just enable_z_probe below... - #endif - - endstops.enable_z_probe(); - - } - - static void stow_z_probe() { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) DEBUG_POS("stow_z_probe", current_position); - #endif - - if (!endstops.z_probe_enabled) return; - - #if HAS_Z_SERVO_ENDSTOP - - // Make room for the servo - raise_z_for_servo(Z_RAISE_AFTER_PROBING); - - // Change the Z servo angle - STOW_Z_SERVO(); - - #elif ENABLED(Z_PROBE_ALLEN_KEY) - - float old_feedrate = feedrate; - - // Move up for safety - feedrate = Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE; - - #if Z_RAISE_AFTER_PROBING > 0 - destination[Z_AXIS] = current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING; - prepare_move_to_destination_raw(); // this will also set_current_to_destination - #endif - - // Move to the start position to initiate retraction - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_X; - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_Y; - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_1_Z; - prepare_move_to_destination_raw(); - - // Move the nozzle down to push the Z probe into retracted position - if (Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE != Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE) - feedrate = Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE; - if (Z_PROBE_ALLEN_KEY_STOW_2_X != Z_PROBE_ALLEN_KEY_STOW_1_X) - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_X; - if (Z_PROBE_ALLEN_KEY_STOW_2_Y != Z_PROBE_ALLEN_KEY_STOW_1_Y) - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_Y; - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_2_Z; - prepare_move_to_destination_raw(); - - // Move up for safety - if (Z_PROBE_ALLEN_KEY_STOW_3_FEEDRATE != Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE) - feedrate = Z_PROBE_ALLEN_KEY_STOW_2_FEEDRATE; - if (Z_PROBE_ALLEN_KEY_STOW_3_X != Z_PROBE_ALLEN_KEY_STOW_2_X) - destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_X; - if (Z_PROBE_ALLEN_KEY_STOW_3_Y != Z_PROBE_ALLEN_KEY_STOW_2_Y) - destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_Y; - destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_3_Z; - prepare_move_to_destination_raw(); - - // Home XY for safety - feedrate = homing_feedrate[X_AXIS] / 2; - destination[X_AXIS] = 0; - destination[Y_AXIS] = 0; - prepare_move_to_destination_raw(); // this will also set_current_to_destination - - feedrate = old_feedrate; - - stepper.synchronize(); - - #if ENABLED(Z_MIN_PROBE_ENDSTOP) - bool z_probe_endstop = (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING); - if (!z_probe_endstop) - #else - bool z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - if (!z_min_endstop) - #endif - { - if (IsRunning()) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Z-Probe failed to retract!"); - LCD_ALERTMESSAGEPGM("Err: ZPROBE"); - } - stop(); - } - #elif ENABLED(FIX_MOUNTED_PROBE) - // Nothing to do here. Just clear endstops.z_probe_enabled - #endif - - endstops.enable_z_probe(false); - } - #endif // HAS_BED_PROBE - enum ProbeAction { ProbeStay = 0, ProbeDeploy = _BV(0), @@ -2306,7 +2309,7 @@ static void homeaxis(AxisEnum axis) { #if ENABLED(Z_PROBE_SLED) #define _Z_DEPLOY (dock_sled(false)) #define _Z_STOW (dock_sled(true)) - #elif ENABLED(AUTO_BED_LEVELING_FEATURE) && (HAS_Z_SERVO_ENDSTOP || ENABLED(FIX_MOUNTED_PROBE)) + #elif (ENABLED(AUTO_BED_LEVELING_FEATURE) && HAS_Z_SERVO_ENDSTOP) || ENABLED(FIX_MOUNTED_PROBE) #define _Z_DEPLOY (deploy_z_probe()) #define _Z_STOW (stow_z_probe()) #elif HAS_Z_SERVO_ENDSTOP From f6b09cf465ed0d05685028cb32d35c2488557b97 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 15:50:51 -0700 Subject: [PATCH 2/8] Always use deploy/stow for dock_sled --- Marlin/Marlin_main.cpp | 252 +++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 135 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4c7c0aaae..0eba959b1 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1655,6 +1655,10 @@ static void setup_for_endstop_move() { feedrate = old_feedrate; } + inline void do_blocking_move_to_x(float x) { + do_blocking_move_to(x, current_position[Y_AXIS], current_position[Z_AXIS]); + } + inline void do_blocking_move_to_z(float z) { do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z); } @@ -1684,6 +1688,63 @@ static void setup_for_endstop_move() { #endif +#if HAS_BED_PROBE + + inline void raise_z_after_probing() { + #if Z_RAISE_AFTER_PROBING > 0 + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("raise_z_after_probing()"); + #endif + do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); + #endif + } +#endif + +#if ENABLED(Z_PROBE_SLED) + + #ifndef SLED_DOCKING_OFFSET + #define SLED_DOCKING_OFFSET 0 + #endif + + /** + * Method to dock/undock a sled designed by Charles Bell. + * + * dock[in] If true, move to MAX_X and engage the electromagnet + * offset[in] The additional distance to move to adjust docking location + */ + static void dock_sled(bool dock, int offset = 0) { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + SERIAL_ECHOPAIR("dock_sled(", dock); + SERIAL_ECHOLNPGM(")"); + } + #endif + + if (!axis_homed[X_AXIS] || !axis_homed[Y_AXIS] || !axis_homed[Z_AXIS]) { + axis_unhomed_error(true); + return; + } + + if (endstops.z_probe_enabled == !dock) return; // already docked/undocked? + + float oldXpos = current_position[X_AXIS]; // save x position + if (dock) { + raise_z_after_probing(); // raise Z + // Dock sled a bit closer to ensure proper capturing + do_blocking_move_to_x(X_MAX_POS + SLED_DOCKING_OFFSET + offset - 1); + digitalWrite(SLED_PIN, LOW); // turn off magnet + } + else { + float z_loc = current_position[Z_AXIS]; + if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING; + do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], z_loc); // this also updates current_position + digitalWrite(SLED_PIN, HIGH); // turn on magnet + } + do_blocking_move_to_x(oldXpos); // return to position before docking + } + +#endif // Z_PROBE_SLED + #if HAS_BED_PROBE static void deploy_z_probe() { @@ -1694,7 +1755,11 @@ static void setup_for_endstop_move() { if (endstops.z_probe_enabled) return; - #if HAS_Z_SERVO_ENDSTOP + #if ENABLED(Z_PROBE_SLED) + + dock_sled(false); + + #elif HAS_Z_SERVO_ENDSTOP // Make room for Z Servo raise_z_for_servo(Z_RAISE_BEFORE_PROBING); @@ -1792,7 +1857,11 @@ static void setup_for_endstop_move() { if (!endstops.z_probe_enabled) return; - #if HAS_Z_SERVO_ENDSTOP + #if ENABLED(Z_PROBE_SLED) + + dock_sled(true); + + #elif HAS_Z_SERVO_ENDSTOP // Make room for the servo raise_z_for_servo(Z_RAISE_AFTER_PROBING); @@ -2040,19 +2109,6 @@ static void setup_for_endstop_move() { do_blocking_move_to(x, y, current_position[Z_AXIS]); } - inline void do_blocking_move_to_x(float x) { - do_blocking_move_to(x, current_position[Y_AXIS], current_position[Z_AXIS]); - } - - inline void raise_z_after_probing() { - #if Z_RAISE_AFTER_PROBING > 0 - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("raise_z_after_probing()"); - #endif - do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); - #endif - } - static void clean_up_after_endstop_move() { #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("clean_up_after_endstop_move > ENDSTOPS_ONLY_FOR_HOMING > endstops.not_homing()"); @@ -2229,55 +2285,6 @@ static void setup_for_endstop_move() { } #endif -#if ENABLED(Z_PROBE_SLED) - - #ifndef SLED_DOCKING_OFFSET - #define SLED_DOCKING_OFFSET 0 - #endif - - /** - * Method to dock/undock a sled designed by Charles Bell. - * - * dock[in] If true, move to MAX_X and engage the electromagnet - * offset[in] The additional distance to move to adjust docking location - */ - static void dock_sled(bool dock, int offset = 0) { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - SERIAL_ECHOPAIR("dock_sled(", dock); - SERIAL_ECHOLNPGM(")"); - } - #endif - - if (!axis_homed[X_AXIS] || !axis_homed[Y_AXIS] || !axis_homed[Z_AXIS]) { - axis_unhomed_error(true); - return; - } - - if (endstops.z_probe_enabled == !dock) return; // already docked/undocked? - - float oldXpos = current_position[X_AXIS]; // save x position - if (dock) { - raise_z_after_probing(); // raise Z - // Dock sled a bit closer to ensure proper capturing - do_blocking_move_to_x(X_MAX_POS + SLED_DOCKING_OFFSET + offset - 1); - digitalWrite(SLED_PIN, LOW); // turn off magnet - } - else { - float z_loc = current_position[Z_AXIS]; - if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING; - do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], z_loc); // this also updates current_position - digitalWrite(SLED_PIN, HIGH); // turn on magnet - } - do_blocking_move_to_x(oldXpos); // return to position before docking - - endstops.enable_z_probe(!dock); // logically disable docked probe - } - -#endif // Z_PROBE_SLED - - - /** * Home an individual axis */ @@ -2306,24 +2313,13 @@ static void homeaxis(AxisEnum axis) { current_position[axis] = 0; sync_plan_position(); - #if ENABLED(Z_PROBE_SLED) - #define _Z_DEPLOY (dock_sled(false)) - #define _Z_STOW (dock_sled(true)) - #elif (ENABLED(AUTO_BED_LEVELING_FEATURE) && HAS_Z_SERVO_ENDSTOP) || ENABLED(FIX_MOUNTED_PROBE) - #define _Z_DEPLOY (deploy_z_probe()) - #define _Z_STOW (stow_z_probe()) - #elif HAS_Z_SERVO_ENDSTOP - #define _Z_DEPLOY do{ raise_z_for_servo(Z_RAISE_BEFORE_PROBING); DEPLOY_Z_SERVO(); endstops.z_probe_enabled = true; }while(0) - #define _Z_STOW do{ raise_z_for_servo(Z_RAISE_AFTER_PROBING); STOW_Z_SERVO(); endstops.z_probe_enabled = false; }while(0) - #endif - // Homing Z towards the bed? Deploy the Z probe or endstop. - #if HAS_Z_SERVO_ENDSTOP || ENABLED(Z_PROBE_SLED) || ENABLED(FIX_MOUNTED_PROBE) + #if HAS_BED_PROBE if (axis == Z_AXIS && axis_home_dir < 0) { #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > " STRINGIFY(_Z_DEPLOY)); + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > deploy_z_probe()"); #endif - _Z_DEPLOY; + deploy_z_probe(); } #endif @@ -2441,12 +2437,12 @@ static void homeaxis(AxisEnum axis) { axis_homed[axis] = true; // Put away the Z probe - #if HAS_Z_SERVO_ENDSTOP || ENABLED(Z_PROBE_SLED) || ENABLED(FIX_MOUNTED_PROBE) + #if HAS_BED_PROBE if (axis == Z_AXIS && axis_home_dir < 0) { #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > " STRINGIFY(_Z_STOW)); + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM(" > stow_z_probe()"); #endif - _Z_STOW; + stow_z_probe(); } #endif @@ -3468,9 +3464,7 @@ inline void gcode_G28() { #endif // !DELTA } - #if ENABLED(Z_PROBE_SLED) - dock_sled(false); // engage (un-dock) the Z probe - #elif ENABLED(FIX_MOUNTED_PROBE) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_ALLEN_KEY) || (ENABLED(DELTA) && HAS_Z_SERVO_ENDSTOP) + #if HAS_BED_PROBE deploy_z_probe(); #endif @@ -3721,14 +3715,7 @@ inline void gcode_G28() { #endif // !AUTO_BED_LEVELING_GRID - #if ENABLED(DELTA) - // Allen Key Probe for Delta - #if ENABLED(Z_PROBE_ALLEN_KEY) || HAS_Z_SERVO_ENDSTOP - stow_z_probe(); - #else - raise_z_after_probing(); // for non Allen Key probes, such as simple mechanical probe - #endif - #else // !DELTA + #if DISABLED(DELTA) if (verbose_level > 0) planner.bed_level_matrix.debug(" \n\nBed Level Correction Matrix:"); @@ -3788,7 +3775,7 @@ inline void gcode_G28() { #if HAS_Z_SERVO_ENDSTOP || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) + Z_RAISE_AFTER_PROBING #endif - ; + ; // current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home" sync_plan_position(); @@ -3796,18 +3783,13 @@ inline void gcode_G28() { if (DEBUGGING(LEVELING)) DEBUG_POS("> corrected Z in G29", current_position); #endif } - - // Sled assembly for Cartesian bots - #if ENABLED(Z_PROBE_SLED) - dock_sled(true); // dock the sled - #elif !HAS_Z_SERVO_ENDSTOP && DISABLED(Z_PROBE_ALLEN_KEY) && DISABLED(Z_PROBE_SLED) - // Raise Z axis for non-delta and non servo based probes - raise_z_after_probing(); - #endif - #endif // !DELTA - #if ENABLED(MECHANICAL_PROBE) + #if DISABLED(Z_PROBE_ALLEN_KEY) && DISABLED(Z_PROBE_SLED) && !HAS_Z_SERVO_ENDSTOP + raise_z_after_probing(); + #endif + + #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || ENABLED(MECHANICAL_PROBE) stow_z_probe(); #endif @@ -3838,38 +3820,38 @@ inline void gcode_G28() { KEEPALIVE_STATE(IN_HANDLER); } - #if DISABLED(Z_PROBE_SLED) // could be avoided +#endif //AUTO_BED_LEVELING_FEATURE - /** - * G30: Do a single Z probe at the current XY - */ - inline void gcode_G30() { - deploy_z_probe(); // Engage Z Servo endstop if available. Z_PROBE_SLED is missed here. +#if HAS_BED_PROBE - stepper.synchronize(); - // TODO: clear the leveling matrix or the planner will be set incorrectly - setup_for_endstop_move(); // Too late. Must be done before deploying. + /** + * G30: Do a single Z probe at the current XY + */ + inline void gcode_G30() { + deploy_z_probe(); - run_z_probe(); + stepper.synchronize(); + // TODO: clear the leveling matrix or the planner will be set incorrectly + setup_for_endstop_move(); // Too late. Must be done before deploying. - SERIAL_PROTOCOLPGM("Bed X: "); - SERIAL_PROTOCOL(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER + 0.0001); - SERIAL_PROTOCOLPGM(" Y: "); - SERIAL_PROTOCOL(current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER + 0.0001); - SERIAL_PROTOCOLPGM(" Z: "); - SERIAL_PROTOCOL(current_position[Z_AXIS] + 0.0001); - SERIAL_EOL; + run_z_probe(); - clean_up_after_endstop_move(); // Too early. must be done after the stowing. + SERIAL_PROTOCOLPGM("Bed X: "); + SERIAL_PROTOCOL(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER + 0.0001); + SERIAL_PROTOCOLPGM(" Y: "); + SERIAL_PROTOCOL(current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER + 0.0001); + SERIAL_PROTOCOLPGM(" Z: "); + SERIAL_PROTOCOL(current_position[Z_AXIS] + 0.0001); + SERIAL_EOL; - stow_z_probe(); // Retract Z Servo endstop if available. Z_PROBE_SLED is missed here. + clean_up_after_endstop_move(); // Too early. must be done after the stowing. - report_current_position(); - } + stow_z_probe(); - #endif //!Z_PROBE_SLED + report_current_position(); + } -#endif //AUTO_BED_LEVELING_FEATURE +#endif // HAS_BED_PROBE /** * G92: Set current position to given X Y Z E @@ -6875,24 +6857,24 @@ void process_next_command() { break; #endif - #if ENABLED(AUTO_BED_LEVELING_FEATURE) - - #if DISABLED(Z_PROBE_SLED) + #if HAS_BED_PROBE - case 30: // G30 Single Z probe - gcode_G30(); - break; + case 30: // G30 Single Z probe + gcode_G30(); + break; - #else // Z_PROBE_SLED + #if ENABLED(Z_PROBE_SLED) case 31: // G31: dock the sled + stow_z_probe(); + break; case 32: // G32: undock the sled - dock_sled(codenum == 31); + deploy_z_probe(); break; #endif // Z_PROBE_SLED - #endif // AUTO_BED_LEVELING_FEATURE + #endif // HAS_BED_PROBE case 90: // G90 relative_mode = false; From 51d52cb52a5e1b2604b8d5eeef4e59e6785b549e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 16:02:27 -0700 Subject: [PATCH 3/8] Make run_z_probe available for any bed probe --- Marlin/Marlin_main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0eba959b1..d6dbc9f38 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2021,6 +2021,10 @@ static void setup_for_endstop_move() { #endif // !AUTO_BED_LEVELING_GRID +#endif // AUTO_BED_LEVELING_FEATURE + +#if HAS_BED_PROBE + static void run_z_probe() { float old_feedrate = feedrate; @@ -2105,6 +2109,10 @@ static void setup_for_endstop_move() { feedrate = old_feedrate; } +#endif // HAS_BED_PROBE + +#if ENABLED(AUTO_BED_LEVELING_FEATURE) + inline void do_blocking_move_to_xy(float x, float y) { do_blocking_move_to(x, y, current_position[Z_AXIS]); } From ed75b0ea1171e2ec35d72ee7aa3303da7a3d4348 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 16:21:43 -0700 Subject: [PATCH 4/8] Make clean_up function available for probes --- Marlin/Marlin_main.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d6dbc9f38..e1206e488 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1583,6 +1583,16 @@ static void setup_for_endstop_move() { #if HAS_BED_PROBE + static void clean_up_after_endstop_move() { + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("clean_up_after_endstop_move > endstops.not_homing()"); + #endif + endstops.not_homing(); + feedrate = saved_feedrate; + feedrate_multiplier = saved_feedrate_multiplier; + refresh_cmd_timeout(); + } + #if ENABLED(DELTA) /** * Calculate delta, start a line, and set current_position to destination @@ -2067,7 +2077,10 @@ static void setup_for_endstop_move() { #else // !DELTA - planner.bed_level_matrix.set_to_identity(); + #if ENABLED(AUTO_BED_LEVELING_FEATURE) + planner.bed_level_matrix.set_to_identity(); + #endif + feedrate = homing_feedrate[Z_AXIS]; // Move down until the Z probe (or endstop?) is triggered @@ -2117,16 +2130,6 @@ static void setup_for_endstop_move() { do_blocking_move_to(x, y, current_position[Z_AXIS]); } - static void clean_up_after_endstop_move() { - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("clean_up_after_endstop_move > ENDSTOPS_ONLY_FOR_HOMING > endstops.not_homing()"); - #endif - endstops.not_homing(); - feedrate = saved_feedrate; - feedrate_multiplier = saved_feedrate_multiplier; - refresh_cmd_timeout(); - } - enum ProbeAction { ProbeStay = 0, ProbeDeploy = _BV(0), From 04e88d008e615564b2a695c066f287fda81f99c7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 16:18:30 -0700 Subject: [PATCH 5/8] Clear up ordering in G30 --- Marlin/Marlin_main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e1206e488..21b286730 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3839,11 +3839,13 @@ inline void gcode_G28() { * G30: Do a single Z probe at the current XY */ inline void gcode_G30() { + + setup_for_endstop_move(); + deploy_z_probe(); stepper.synchronize(); // TODO: clear the leveling matrix or the planner will be set incorrectly - setup_for_endstop_move(); // Too late. Must be done before deploying. run_z_probe(); @@ -3855,10 +3857,10 @@ inline void gcode_G28() { SERIAL_PROTOCOL(current_position[Z_AXIS] + 0.0001); SERIAL_EOL; - clean_up_after_endstop_move(); // Too early. must be done after the stowing. - stow_z_probe(); + clean_up_after_endstop_move(); + report_current_position(); } From 6aba98e4704b151e3b24753a884c73ae6e63102b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 16:18:41 -0700 Subject: [PATCH 6/8] Comment on setup_for_endstop_move --- Marlin/Marlin_main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 21b286730..52f97db7f 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1570,6 +1570,18 @@ inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[ inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); } inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); } +// +// Prepare to do endstop or probe moves +// with custom feedrates. +// +// - Save current feedrates +// - Reset the rate multiplier +// - Enable the endstops +// - Reset the command timeout +// +// clean_up_after_endstop_move() restores +// feedrates, sets endstops back to global state. +// static void setup_for_endstop_move() { saved_feedrate = feedrate; saved_feedrate_multiplier = feedrate_multiplier; From 2530371516f037760f1282d7b105f8f3e4ae10b3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 16:40:28 -0700 Subject: [PATCH 7/8] Always disable probe at the end of G29 --- Marlin/Marlin_main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 52f97db7f..119131b41 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3814,6 +3814,8 @@ inline void gcode_G28() { #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || ENABLED(MECHANICAL_PROBE) stow_z_probe(); + #else + endstops.enable_z_probe(false); #endif #ifdef Z_PROBE_END_SCRIPT @@ -3824,9 +3826,6 @@ inline void gcode_G28() { } #endif enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT)); - #if HAS_BED_PROBE - endstops.enable_z_probe(false); - #endif stepper.synchronize(); #endif @@ -3857,9 +3856,9 @@ inline void gcode_G28() { deploy_z_probe(); stepper.synchronize(); - // TODO: clear the leveling matrix or the planner will be set incorrectly - run_z_probe(); + // TODO: clear the leveling matrix or the planner will be set incorrectly + run_z_probe(); // clears the ABL non-delta matrix only SERIAL_PROTOCOLPGM("Bed X: "); SERIAL_PROTOCOL(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER + 0.0001); From 6563b07879a3537721d889bf958639b1755a7cc5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 Jun 2016 14:56:16 -0700 Subject: [PATCH 8/8] Test for mechanical and fix mounted probes --- .travis.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef027aa0b..1916669c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -90,13 +90,35 @@ script: - opt_enable PIDTEMPBED - build_marlin # - # Test a Servo Probe without leveling + # Test a "Fix Mounted" Probe + # + - restore_configs + - opt_enable FIX_MOUNTED_PROBE + - build_marlin + # + # ...with AUTO_BED_LEVELING_FEATURE & DEBUG_LEVELING_FEATURE + # + - opt_enable AUTO_BED_LEVELING_FEATURE DEBUG_LEVELING_FEATURE + - build_marlin + # + # Test a Mechanical Probe + # + - restore_configs + - opt_enable MECHANICAL_PROBE + - build_marlin + # + # ...with AUTO_BED_LEVELING_FEATURE & DEBUG_LEVELING_FEATURE + # + - opt_enable AUTO_BED_LEVELING_FEATURE DEBUG_LEVELING_FEATURE + - build_marlin + # + # Test a Servo Probe # - restore_configs - opt_enable NUM_SERVOS Z_ENDSTOP_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE - build_marlin # - # Test AUTO_BED_LEVELING_FEATURE & DEBUG_LEVELING_FEATURE with a Servo Probe + # ...with AUTO_BED_LEVELING_FEATURE & DEBUG_LEVELING_FEATURE # - opt_enable AUTO_BED_LEVELING_FEATURE DEBUG_LEVELING_FEATURE - build_marlin