From a794538c5417a38288c1af912f305755aec46894 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 25 Mar 2020 16:18:48 +0800 Subject: [PATCH] Homing backoff enhancements - Define homing bump as an array - Add pre and post homing backoff options - Consolidate homing config options --- Marlin/Configuration_adv.h | 34 +++++++++++-------- Marlin/src/inc/SanityCheck.h | 4 +++ Marlin/src/module/delta.cpp | 4 +-- Marlin/src/module/motion.cpp | 32 ++++++----------- Marlin/src/module/motion.h | 17 ++++++---- .../share/tests/SAMD51_grandcentral_m4-tests | 4 +-- buildroot/share/tests/mega1280-tests | 1 + 7 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 1e29a355ff..5b28441882 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -592,8 +592,7 @@ // Default x offset in duplication mode (typically set to half print bed width) #define DEFAULT_DUPLICATION_X_OFFSET 100 - -#endif // DUAL_X_CARRIAGE +#endif // Activate a solenoid on the active extruder with M380. Disable all with M381. // Define SOL0_PIN, SOL1_PIN, etc., for each extruder that has a solenoid. @@ -601,19 +600,24 @@ // @section homing -// Homing hits each endstop, retracts by these distances, then does a slower bump. -#define X_HOME_BUMP_MM 5 -#define Y_HOME_BUMP_MM 5 -#define Z_HOME_BUMP_MM 2 -#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate) -//#define QUICK_HOME // If homing includes X and Y, do a diagonal move initially -//#define HOMING_BACKOFF_MM { 2, 2, 2 } // (mm) Move away from the endstops after homing +/** + * Homing Procedure + * Homing (G28) does an indefinite move towards the endstops to establish + * the position of the toolhead relative to the workspace. + */ + +//#define SENSORLESS_BACKOFF_MM { 2, 2 } // (mm) Backoff from endstops before sensorless homing -// When G28 is called, this option will make Y home before X -//#define HOME_Y_BEFORE_X +#define HOMING_BUMP_MM { 5, 5, 2 } // (mm) Backoff from endstops after first bump +#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate) -// Enable this if X or Y can't home without homing the other axis first. -//#define CODEPENDENT_XY_HOMING +//#define HOMING_BACKOFF_POST_MM { 2, 2, 2 } // (mm) Backoff from endstops after homing + +//#define QUICK_HOME // If G28 contains XY do a diagonal move first +//#define HOME_Y_BEFORE_X // If G28 contains XY home Y before X +//#define CODEPENDENT_XY_HOMING // If X/Y can't home without homing Y/X first + +// @section bltouch #if ENABLED(BLTOUCH) /** @@ -682,6 +686,8 @@ #endif // BLTOUCH +// @section extras + /** * Z Steppers Auto-Alignment * Add the G34 command to align multiple Z steppers using a bed probe. @@ -2319,7 +2325,7 @@ * HIGHEST 255 -64 (Too sensitive => False positive) * LOWEST 0 63 (Too insensitive => No trigger) * - * It is recommended to set [XYZ]_HOME_BUMP_MM to 0. + * It is recommended to set HOMING_BUMP_MM to { 0, 0, 0 }. * * SPI_ENDSTOPS *** Beta feature! *** TMC2130 Only *** * Poll the driver through SPI to determine load when homing. diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index bc41e4612f..ab64c9a4f8 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -493,6 +493,10 @@ #error "ORIG_Ex_AUTO_FAN_PIN is now just Ex_AUTO_FAN_PIN. Make sure your pins are up to date." #elif defined(ORIG_CHAMBER_AUTO_FAN_PIN) #error "ORIG_CHAMBER_AUTO_FAN_PIN is now just CHAMBER_AUTO_FAN_PIN. Make sure your pins are up to date." +#elif defined(HOMING_BACKOFF_MM) + #error "HOMING_BACKOFF_MM is now HOMING_BACKOFF_POST_MM. Please update Configuration_adv.h." +#elif defined(X_HOME_BUMP_MM) || defined(Y_HOME_BUMP_MM) || defined(Z_HOME_BUMP_MM) + #error "[XYZ]_HOME_BUMP_MM is now HOMING_BUMP_MM. Please update Configuration_adv.h." #endif /** diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index 8821236fd1..1f532767cc 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -280,8 +280,8 @@ void home_delta() { sync_plan_position(); - #if DISABLED(DELTA_HOME_TO_SAFE_ZONE) && defined(HOMING_BACKOFF_MM) - constexpr xyz_float_t endstop_backoff = HOMING_BACKOFF_MM; + #if DISABLED(DELTA_HOME_TO_SAFE_ZONE) && defined(HOMING_BACKOFF_POST_MM) + constexpr xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; if (endstop_backoff.z) { current_position.z -= ABS(endstop_backoff.z) * Z_HOME_DIR; line_to_current_position(homing_feedrate(Z_AXIS)); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 1cc0a04712..3c89b933d8 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -74,15 +74,6 @@ #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../core/debug_out.h" -#define XYZ_CONSTS(T, NAME, OPT) const PROGMEM XYZval NAME##_P = { X_##OPT, Y_##OPT, Z_##OPT } - -XYZ_CONSTS(float, base_min_pos, MIN_POS); -XYZ_CONSTS(float, base_max_pos, MAX_POS); -XYZ_CONSTS(float, base_home_pos, HOME_POS); -XYZ_CONSTS(float, max_length, MAX_LENGTH); -XYZ_CONSTS(float, home_bump_mm, HOME_BUMP_MM); -XYZ_CONSTS(signed char, home_dir, HOME_DIR); - /** * axis_homed * Flags that each linear axis was homed. @@ -1567,14 +1558,13 @@ void homeaxis(const AxisEnum axis) { if (axis == Z_AXIS && bltouch.deploy()) return; // The initial DEPLOY #endif - do_homing_move(axis, 1.5f * max_length( - #if ENABLED(DELTA) - Z_AXIS - #else - axis - #endif - ) * axis_home_dir - ); + #if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM) + const xy_float_t backoff = SENSORLESS_BACKOFF_MM; + if (((ENABLED(X_SENSORLESS) && axis == X_AXIS) || (ENABLED(Y_SENSORLESS) && axis == Y_AXIS)) && backoff[axis]) + do_homing_move(axis, -ABS(backoff[axis]) * axis_home_dir, homing_feedrate(axis)); + #endif + + do_homing_move(axis, 1.5f * max_length(TERN(DELTA, Z_AXIS, axis)) * axis_home_dir); #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE) if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) @@ -1583,14 +1573,14 @@ void homeaxis(const AxisEnum axis) { // When homing Z with probe respect probe clearance const float bump = axis_home_dir * ( #if HOMING_Z_WITH_PROBE - (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? _MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) : + (axis == Z_AXIS && home_bump_mm(Z_AXIS)) ? _MAX(Z_CLEARANCE_BETWEEN_PROBES, home_bump_mm(Z_AXIS)) : #endif home_bump_mm(axis) ); // If a second homing move is configured... if (bump) { - // Move away from the endstop by the axis HOME_BUMP_MM + // Move away from the endstop by the axis HOMING_BUMP_MM if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Move Away:"); do_homing_move(axis, -bump #if HOMING_Z_WITH_PROBE @@ -1785,8 +1775,8 @@ void homeaxis(const AxisEnum axis) { if (axis == Z_AXIS && probe.stow()) return; #endif - #if DISABLED(DELTA) && defined(HOMING_BACKOFF_MM) - const xyz_float_t endstop_backoff = HOMING_BACKOFF_MM; + #if DISABLED(DELTA) && defined(HOMING_BACKOFF_POST_MM) + const xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; if (endstop_backoff[axis]) { current_position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir; line_to_current_position( diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index e504f187f9..ee15205409 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -114,20 +114,25 @@ extern int16_t feedrate_percentage; extern float e_move_accumulator; #endif -FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float(p); } -FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte(p); } +inline float pgm_read_any(const float *p) { return pgm_read_float(p); } +inline signed char pgm_read_any(const signed char *p) { return pgm_read_byte(p); } #define XYZ_DEFS(T, NAME, OPT) \ - extern const XYZval NAME##_P; \ - FORCE_INLINE T NAME(AxisEnum axis) { return pgm_read_any(&NAME##_P[axis]); } - + inline T NAME(const AxisEnum axis) { \ + static const XYZval NAME##_P PROGMEM = { X_##OPT, Y_##OPT, Z_##OPT }; \ + return pgm_read_any(&NAME##_P[axis]); \ + } XYZ_DEFS(float, base_min_pos, MIN_POS); XYZ_DEFS(float, base_max_pos, MAX_POS); XYZ_DEFS(float, base_home_pos, HOME_POS); XYZ_DEFS(float, max_length, MAX_LENGTH); -XYZ_DEFS(float, home_bump_mm, HOME_BUMP_MM); XYZ_DEFS(signed char, home_dir, HOME_DIR); +inline float home_bump_mm(const AxisEnum axis) { + static const xyz_pos_t home_bump_mm_P PROGMEM = HOMING_BUMP_MM; + return pgm_read_any(&home_bump_mm_P[axis]); +} + #if HAS_WORKSPACE_OFFSET void update_workspace_offset(const AxisEnum axis); #else diff --git a/buildroot/share/tests/SAMD51_grandcentral_m4-tests b/buildroot/share/tests/SAMD51_grandcentral_m4-tests index f93ef3343f..3e47afe327 100644 --- a/buildroot/share/tests/SAMD51_grandcentral_m4-tests +++ b/buildroot/share/tests/SAMD51_grandcentral_m4-tests @@ -22,9 +22,7 @@ opt_set E0_DRIVER_TYPE TMC2209 opt_set RESTORE_LEVELING_AFTER_G28 false opt_set LCD_LANGUAGE it opt_set NUM_Z_STEPPER_DRIVERS 2 -opt_set X_HOME_BUMP_MM 0 -opt_set Y_HOME_BUMP_MM 0 -opt_set Z_HOME_BUMP_MM 0 +opt_set HOMING_BUMP_MM "{ 0, 0, 0 }" opt_set SDCARD_CONNECTION LCD opt_enable ENDSTOP_INTERRUPTS_FEATURE S_CURVE_ACCELERATION BLTOUCH Z_MIN_PROBE_REPEATABILITY_TEST \ FILAMENT_RUNOUT_SENSOR G26_MESH_VALIDATION MESH_EDIT_GFX_OVERLAY Z_SAFE_HOMING \ diff --git a/buildroot/share/tests/mega1280-tests b/buildroot/share/tests/mega1280-tests index c2d55a92e5..7f2872a0b4 100644 --- a/buildroot/share/tests/mega1280-tests +++ b/buildroot/share/tests/mega1280-tests @@ -18,6 +18,7 @@ set -e restore_configs opt_set LCD_LANGUAGE an opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \ + SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \ MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \ G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS exec_test $1 $2 "Spindle, MESH_BED_LEVELING, and LCD"