diff --git a/grbl/motion_control.c b/grbl/motion_control.c index 6e11e35c..9379b8be 100644 --- a/grbl/motion_control.c +++ b/grbl/motion_control.c @@ -277,6 +277,9 @@ uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_ return(GC_PROBE_FAIL_INIT); // Nothing else to do but bail. } + // Z Probing simplification : if Z travel exceeds soft limits, adjust Z to max. allowed value as probing stop is anyhow expected + system_do_limit_Z_travel(target); + // Setup and queue probing motion. Auto cycle-start should not start the cycle. mc_line(target, pl_data); diff --git a/grbl/system.c b/grbl/system.c index 55e6c406..a96b564a 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -351,6 +351,24 @@ uint8_t system_check_travel_limits(float *target) return(false); } +// Z Probing simplification : if Z travel exceeds soft limits, adjust Z to max. allowed value as probing stop is anyhow expected +// function code derived from above soft limit check +uint8_t system_do_limit_Z_travel(float *target) +{ + #ifdef HOMING_FORCE_SET_ORIGIN + // When homing forced set origin is enabled, soft limits checks need to account for directionality. + // NOTE: max_travel is stored as negative + if (bit_istrue(settings.homing_dir_mask,bit(Z_AXIS))) { + if (target[Z_AXIS] < 0 || target[Z_AXIS] > -settings.max_travel[Z_AXIS]) { target[Z_AXIS] = -settings.max_travel[Z_AXIS]; return(true); } + } else { + if (target[Z_AXIS] > 0 || target[Z_AXIS] < settings.max_travel[Z_AXIS]) { target[Z_AXIS] = settings.max_travel[Z_AXIS]; return(true); } + } + #else + // NOTE: max_travel is stored as negative + if (target[Z_AXIS] > 0 || target[Z_AXIS] < settings.max_travel[Z_AXIS]) { target[Z_AXIS] = settings.max_travel[Z_AXIS]; return(true); } + #endif + return(false); +} // Special handlers for setting and clearing Grbl's real-time execution flags. void system_set_exec_state_flag(uint8_t mask) { diff --git a/grbl/system.h b/grbl/system.h index cfc92738..0e317b1e 100644 --- a/grbl/system.h +++ b/grbl/system.h @@ -198,6 +198,9 @@ void system_convert_array_steps_to_mpos(float *position, int32_t *steps); // Checks and reports if target array exceeds machine travel limits. uint8_t system_check_travel_limits(float *target); +// Z Probing simplification : if Z travel exceeds soft limits, adjust Z to max. allowed value as probing stop is anyhow expected +uint8_t system_do_limit_Z_travel(float *target); + // Special handlers for setting and clearing Grbl's real-time execution flags. void system_set_exec_state_flag(uint8_t mask); void system_clear_exec_state_flag(uint8_t mask);