G34 Z stepper locking (#20091)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
InsanityAutomation 2020-11-12 23:54:18 -05:00 committed by Scott Lahteine
parent 7b745345f7
commit dc949f5488
6 changed files with 382 additions and 339 deletions

View File

@ -375,6 +375,11 @@ void GcodeSuite::G28() {
// Home Z last if homing towards the bed // Home Z last if homing towards the bed
#if DISABLED(HOME_Z_FIRST) #if DISABLED(HOME_Z_FIRST)
if (doZ) { if (doZ) {
#if EITHER(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
stepper.set_all_z_lock(false);
stepper.set_separate_multi_axis(false);
#endif
TERN_(BLTOUCH, bltouch.init()); TERN_(BLTOUCH, bltouch.init());
TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS)); TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS));
probe.move_z_after_homing(); probe.move_z_after_homing();

View File

@ -22,7 +22,7 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#if ENABLED(Z_STEPPER_AUTO_ALIGN) #if EITHER(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
#include "../../feature/z_stepper_align.h" #include "../../feature/z_stepper_align.h"
@ -51,15 +51,52 @@
/** /**
* G34: Z-Stepper automatic alignment * G34: Z-Stepper automatic alignment
* *
* I<iterations> * Manual stepper lock controls (reset by G28):
* T<accuracy> * L Unlock all steppers
* A<amplification> * Z<1-4> Z stepper to lock / unlock
* R<recalculate> points based on current probe offsets * S<state> 0=UNLOCKED 1=LOCKED. If omitted, assume LOCKED.
*
* Examples:
* G34 Z1 ; Lock Z1
* G34 L Z2 ; Unlock all, then lock Z2
* G34 Z2 S0 ; Unlock Z2
*
* With Z_STEPPER_AUTO_ALIGN:
* I<iterations> Number of tests. If omitted, Z_STEPPER_ALIGN_ITERATIONS.
* T<accuracy> Target Accuracy factor. If omitted, Z_STEPPER_ALIGN_ACC.
* A<amplification> Provide an Amplification value. If omitted, Z_STEPPER_ALIGN_AMP.
* R Flag to recalculate points based on current probe offsets
*/ */
void GcodeSuite::G34() { void GcodeSuite::G34() {
DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING)); DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING));
if (DEBUGGING(LEVELING)) log_machine_info(); if (DEBUGGING(LEVELING)) log_machine_info();
planner.synchronize(); // Prevent damage
const bool seenL = parser.seen('L');
if (seenL) stepper.set_all_z_lock(false);
const bool seenZ = parser.seenval('Z');
if (seenZ) {
const bool state = parser.boolval('S', true);
switch (parser.intval('Z')) {
case 1: stepper.set_z1_lock(state); break;
case 2: stepper.set_z2_lock(state); break;
#if NUM_Z_STEPPER_DRIVERS >= 3
case 3: stepper.set_z3_lock(state); break;
#if NUM_Z_STEPPER_DRIVERS >= 4
case 4: stepper.set_z4_lock(state); break;
#endif
#endif
}
}
if (seenL || seenZ) {
stepper.set_separate_multi_axis(seenZ);
return;
}
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
do { // break out on error do { // break out on error
#if NUM_Z_STEPPER_DRIVERS == 4 #if NUM_Z_STEPPER_DRIVERS == 4
@ -81,24 +118,16 @@ void GcodeSuite::G34() {
break; break;
} }
const float z_auto_align_amplification = const float z_auto_align_amplification = TERN(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, Z_STEPPER_ALIGN_AMP, parser.floatval('A', Z_STEPPER_ALIGN_AMP));
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
Z_STEPPER_ALIGN_AMP;
#else
parser.floatval('A', Z_STEPPER_ALIGN_AMP);
if (!WITHIN(ABS(z_auto_align_amplification), 0.5f, 2.0f)) { if (!WITHIN(ABS(z_auto_align_amplification), 0.5f, 2.0f)) {
SERIAL_ECHOLNPGM("?(A)mplification out of bounds (0.5-2.0)."); SERIAL_ECHOLNPGM("?(A)mplification out of bounds (0.5-2.0).");
break; break;
} }
#endif
if (parser.seen('R')) z_stepper_align.reset_to_default(); if (parser.seen('R')) z_stepper_align.reset_to_default();
const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE; const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE;
// Wait for planner moves to finish!
planner.synchronize();
// Disable the leveling matrix before auto-aligning // Disable the leveling matrix before auto-aligning
#if HAS_LEVELING #if HAS_LEVELING
TERN_(RESTORE_LEVELING_AFTER_G34, const bool leveling_was_active = planner.leveling_active); TERN_(RESTORE_LEVELING_AFTER_G34, const bool leveling_was_active = planner.leveling_active);
@ -407,8 +436,13 @@ void GcodeSuite::G34() {
#endif #endif
}while(0); }while(0);
#endif
} }
#endif // Z_MULTI_ENDSTOPS || Z_STEPPER_AUTO_ALIGN
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
/** /**
* M422: Set a Z-Stepper automatic alignment XY point. * M422: Set a Z-Stepper automatic alignment XY point.
* Use repeatedly to set multiple points. * Use repeatedly to set multiple points.

View File

@ -327,7 +327,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 33: G33(); break; // G33: Delta Auto-Calibration case 33: G33(); break; // G33: Delta Auto-Calibration
#endif #endif
#if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
case 34: G34(); break; // G34: Z Stepper automatic alignment using probe case 34: G34(); break; // G34: Z Stepper automatic alignment using probe
#endif #endif

View File

@ -468,7 +468,7 @@ private:
TERN_(DELTA_AUTO_CALIBRATION, static void G33()); TERN_(DELTA_AUTO_CALIBRATION, static void G33());
#if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) #if ANY(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
static void G34(); static void G34();
#endif #endif

View File

@ -2792,9 +2792,12 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#error "Z_STEPPER_AUTO_ALIGN requires NUM_Z_STEPPER_DRIVERS greater than 1." #error "Z_STEPPER_AUTO_ALIGN requires NUM_Z_STEPPER_DRIVERS greater than 1."
#elif !HAS_BED_PROBE #elif !HAS_BED_PROBE
#error "Z_STEPPER_AUTO_ALIGN requires a Z-bed probe." #error "Z_STEPPER_AUTO_ALIGN requires a Z-bed probe."
#elif ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) && NUM_Z_STEPPER_DRIVERS < 3 #elif ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
static_assert(WITHIN(Z_STEPPER_ALIGN_AMP, 0.5, 2.0), "Z_STEPPER_ALIGN_AMP must be between 0.5 and 2.0.");
#if NUM_Z_STEPPER_DRIVERS < 3
#error "Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS requires NUM_Z_STEPPER_DRIVERS to be 3 or 4." #error "Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS requires NUM_Z_STEPPER_DRIVERS to be 3 or 4."
#endif #endif
#endif
#endif #endif
#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) #if ENABLED(MECHANICAL_GANTRY_CALIBRATION)

View File

@ -316,6 +316,7 @@ EXT_SOLENOID|MANUAL_SOLENOID_CONTROL = src_filter=+<src/feature/solenoid.cpp> +<
HAS_CUTTER = src_filter=+<src/feature/spindle_laser.cpp> +<src/gcode/control/M3-M5.cpp> HAS_CUTTER = src_filter=+<src/feature/spindle_laser.cpp> +<src/gcode/control/M3-M5.cpp>
EXPERIMENTAL_I2CBUS = src_filter=+<src/feature/twibus.cpp> +<src/gcode/feature/i2c> EXPERIMENTAL_I2CBUS = src_filter=+<src/feature/twibus.cpp> +<src/gcode/feature/i2c>
MECHANICAL_GANTRY_CAL.+ = src_filter=+<src/gcode/calibrate/G34.cpp> MECHANICAL_GANTRY_CAL.+ = src_filter=+<src/gcode/calibrate/G34.cpp>
Z_MULTI_ENDSTOPS = src_filter=+<src/gcode/calibrate/G34_M422.cpp>
Z_STEPPER_AUTO_ALIGN = src_filter=+<src/feature/z_stepper_align.cpp> +<src/gcode/calibrate/G34_M422.cpp> Z_STEPPER_AUTO_ALIGN = src_filter=+<src/feature/z_stepper_align.cpp> +<src/gcode/calibrate/G34_M422.cpp>
G26_MESH_VALIDATION = src_filter=+<src/gcode/bedlevel/G26.cpp> G26_MESH_VALIDATION = src_filter=+<src/gcode/bedlevel/G26.cpp>
ASSISTED_TRAMMING = src_filter=+<src/gcode/bedlevel/G35.cpp> ASSISTED_TRAMMING = src_filter=+<src/gcode/bedlevel/G35.cpp>