From 19b9b3a8dfd66739523635fd97a3e42fe509e623 Mon Sep 17 00:00:00 2001 From: Alex Holden Date: Thu, 7 Sep 2023 10:55:05 +0100 Subject: [PATCH] Added an option HOMING_SET_ORIGIN_AFTER_PULLOFF This option sets the machine position to zero (or max_travel if homing direction is inverted) after instead of before performing the homing pulloff move. When soft limits are enabled, this provides a virtual buffer zone between the machine's 0 and the hardware limit switch that prevents the operator being able to jog right up to the switch and potentially accidentally trigger a hard limit alarm. --- grbl/config.h | 9 +++++++++ grbl/limits.c | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/grbl/config.h b/grbl/config.h index f48d9586..83d04766 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -128,6 +128,15 @@ // define to force Grbl to always set the machine origin at the homed location despite switch orientation. // #define HOMING_FORCE_SET_ORIGIN // Uncomment to enable. +// By default, Grbl sets the machine origin to zero at the exact point where the homing switches first +// make contact, then moves away from the switch by the homing pulloff distance given in setting 27. +// Even with soft limits enabled, this does not prevent the operator subsequently jogging right up to +// the machine origin and possibly triggering the limit switch. This option instead sets the machine +// origin to zero after it has performed the pulloff move, so that soft limits won't allow the machine +// to be jogged any closer to the limit switch than the pulloff distance. +// Note: this setting is ignored if HOMING_FORCE_SET_ORIGIN is enabled. +// #define HOMING_SET_ORIGIN_AFTER_PULLOFF + // Number of blocks Grbl executes upon startup. These blocks are stored in EEPROM, where the size // and addresses are defined in settings.h. With the current settings, up to 2 startup blocks may // be stored and executed in order. These startup blocks would typically be used to set the g-code diff --git a/grbl/limits.c b/grbl/limits.c index 1348c147..85b1362d 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -375,6 +375,16 @@ void limits_go_home(uint8_t cycle_mask) if (cycle_mask & bit(idx)) { #ifdef HOMING_FORCE_SET_ORIGIN set_axis_position = 0; + #else + #ifdef HOMING_SET_ORIGIN_AFTER_PULLOFF + if ( bit_istrue(settings.homing_dir_mask,bit(idx)) ) { + // Round up (i.e. away from the limit) to avoid a situation where a later + // rounding error sometimes causes the axis position after homing to be a tiny + // amount past max_travel, which immediately triggers its soft limit. + set_axis_position = lround(ceil(settings.max_travel[idx]*settings.steps_per_mm[idx])); + } else { + set_axis_position = 0; + } #else if ( bit_istrue(settings.homing_dir_mask,bit(idx)) ) { set_axis_position = lround((settings.max_travel[idx]+settings.homing_pulloff)*settings.steps_per_mm[idx]); @@ -382,6 +392,7 @@ void limits_go_home(uint8_t cycle_mask) set_axis_position = lround(-settings.homing_pulloff*settings.steps_per_mm[idx]); } #endif + #endif #ifdef COREXY if (idx==X_AXIS) {