Skip to content

Commit bb2f100

Browse files
committed
🚸 Use Z_STEPPER_ALIGN_STEPPER_XY to enable
1 parent 2e39bc3 commit bb2f100

File tree

8 files changed

+41
-36
lines changed

8 files changed

+41
-36
lines changed

Marlin/Configuration_adv.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -959,15 +959,17 @@
959959
//#define Z_STEPPERS_ORIENTATION 0
960960
#endif
961961

962-
// Provide Z stepper positions for more rapid convergence in bed alignment.
963-
// Requires triple stepper drivers (i.e., set NUM_Z_STEPPER_DRIVERS to 3)
964-
//#define Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
965-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
966-
// Define Stepper XY positions for Z1, Z2, Z3 corresponding to
967-
// the Z screw positions in the bed carriage.
968-
// Define one position per Z stepper in stepper driver order.
969-
#define Z_STEPPER_ALIGN_STEPPER_XY { { 210.7, 102.5 }, { 152.6, 220.0 }, { 94.5, 102.5 } }
970-
#else
962+
/**
963+
* Z Stepper positions for more rapid convergence in bed alignment.
964+
* Requires NUM_Z_STEPPER_DRIVERS to be 3 or 4.
965+
*
966+
* Define Stepper XY positions for Z1, Z2, Z3... corresponding to the screw
967+
* positions in the bed carriage, with one position per Z stepper in stepper
968+
* driver order.
969+
*/
970+
//#define Z_STEPPER_ALIGN_STEPPER_XY { { 210.7, 102.5 }, { 152.6, 220.0 }, { 94.5, 102.5 } }
971+
972+
#ifndef Z_STEPPER_ALIGN_STEPPER_XY
971973
// Amplification factor. Used to scale the correction step up or down in case
972974
// the stepper (spindle) position is farther out than the test point.
973975
#define Z_STEPPER_ALIGN_AMP 1.0 // Use a value > 1.0 NOTE: This may cause instability!

Marlin/src/feature/z_stepper_align.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ZStepperAlign z_stepper_align;
3535

3636
xy_pos_t ZStepperAlign::xy[NUM_Z_STEPPER_DRIVERS];
3737

38-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
38+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
3939
xy_pos_t ZStepperAlign::stepper_xy[NUM_Z_STEPPER_DRIVERS];
4040
#endif
4141

@@ -103,7 +103,7 @@ void ZStepperAlign::reset_to_default() {
103103

104104
COPY(xy, xy_init);
105105

106-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
106+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
107107
constexpr xy_pos_t stepper_xy_init[] = Z_STEPPER_ALIGN_STEPPER_XY;
108108
static_assert(
109109
COUNT(stepper_xy_init) == NUM_Z_STEPPER_DRIVERS,

Marlin/src/feature/z_stepper_align.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ZStepperAlign {
3131
public:
3232
static xy_pos_t xy[NUM_Z_STEPPER_DRIVERS];
3333

34-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
34+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
3535
static xy_pos_t stepper_xy[NUM_Z_STEPPER_DRIVERS];
3636
#endif
3737

Marlin/src/gcode/calibrate/G34_M422.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "../../module/tool_change.h"
4242
#endif
4343

44-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
44+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
4545
#include "../../libs/least_squares_fit.h"
4646
#endif
4747

@@ -122,7 +122,7 @@ void GcodeSuite::G34() {
122122
break;
123123
}
124124

125-
const float z_auto_align_amplification = TERN(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, Z_STEPPER_ALIGN_AMP, parser.floatval('A', Z_STEPPER_ALIGN_AMP));
125+
const float z_auto_align_amplification = TERN(HAS_Z_STEPPER_ALIGN_STEPPER_XY, Z_STEPPER_ALIGN_AMP, parser.floatval('A', Z_STEPPER_ALIGN_AMP));
126126
if (!WITHIN(ABS(z_auto_align_amplification), 0.5f, 2.0f)) {
127127
SERIAL_ECHOLNPGM("?(A)mplification out of bounds (0.5-2.0).");
128128
break;
@@ -179,7 +179,7 @@ void GcodeSuite::G34() {
179179
// Now, the Z origin lies below the build plate. That allows to probe deeper, before run_z_probe throws an error.
180180
// This hack is un-done at the end of G34 - either by re-homing, or by using the probed heights of the last iteration.
181181

182-
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
182+
#if !HAS_Z_STEPPER_ALIGN_STEPPER_XY
183183
float last_z_align_move[NUM_Z_STEPPER_DRIVERS] = ARRAY_N_1(NUM_Z_STEPPER_DRIVERS, 10000.0f);
184184
#else
185185
float last_z_align_level_indicator = 10000.0f;
@@ -188,7 +188,7 @@ void GcodeSuite::G34() {
188188
z_maxdiff = 0.0f,
189189
amplification = z_auto_align_amplification;
190190

191-
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
191+
#if !HAS_Z_STEPPER_ALIGN_STEPPER_XY
192192
bool adjustment_reverse = false;
193193
#endif
194194

@@ -256,7 +256,7 @@ void GcodeSuite::G34() {
256256
z_maxdiff = z_measured_max - z_measured_min;
257257
z_probe = Z_BASIC_CLEARANCE + z_measured_max + z_maxdiff;
258258

259-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
259+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
260260
// Replace the initial values in z_measured with calculated heights at
261261
// each stepper position. This allows the adjustment algorithm to be
262262
// shared between both possible probing mechanisms.
@@ -338,7 +338,7 @@ void GcodeSuite::G34() {
338338
return false;
339339
};
340340

341-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
341+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
342342
// Check if the applied corrections go in the correct direction.
343343
// Calculate the sum of the absolute deviations from the mean of the probe measurements.
344344
// Compare to the last iteration to ensure it's getting better.
@@ -370,7 +370,7 @@ void GcodeSuite::G34() {
370370
float z_align_move = z_measured[zstepper] - z_measured_min;
371371
const float z_align_abs = ABS(z_align_move);
372372

373-
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
373+
#if !HAS_Z_STEPPER_ALIGN_STEPPER_XY
374374
// Optimize one iteration's correction based on the first measurements
375375
if (z_align_abs) amplification = (iteration == 1) ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification;
376376

@@ -394,7 +394,7 @@ void GcodeSuite::G34() {
394394
// Lock all steppers except one
395395
stepper.set_all_z_lock(true, zstepper);
396396

397-
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
397+
#if !HAS_Z_STEPPER_ALIGN_STEPPER_XY
398398
// Decreasing accuracy was detected so move was inverted.
399399
// Will match reversed Z steppers on dual steppers. Triple will need more work to map.
400400
if (adjustment_reverse) {
@@ -467,7 +467,7 @@ void GcodeSuite::G34() {
467467
*
468468
* S<index> : Index of the probe point to set
469469
*
470-
* With Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS:
470+
* With Z_STEPPER_ALIGN_STEPPER_XY:
471471
* W<index> : Index of the Z stepper position to set
472472
* The W and S parameters may not be combined.
473473
*
@@ -488,18 +488,18 @@ void GcodeSuite::M422() {
488488

489489
const bool is_probe_point = parser.seen('S');
490490

491-
if (TERN0(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, is_probe_point && parser.seen('W'))) {
491+
if (TERN0(HAS_Z_STEPPER_ALIGN_STEPPER_XY, is_probe_point && parser.seen('W'))) {
492492
SERIAL_ECHOLNPGM("?(S) and (W) may not be combined.");
493493
return;
494494
}
495495

496496
xy_pos_t *pos_dest = (
497-
TERN_(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, !is_probe_point ? z_stepper_align.stepper_xy :)
497+
TERN_(HAS_Z_STEPPER_ALIGN_STEPPER_XY, !is_probe_point ? z_stepper_align.stepper_xy :)
498498
z_stepper_align.xy
499499
);
500500

501-
if (!is_probe_point && TERN1(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, !parser.seen('W'))) {
502-
SERIAL_ECHOLNPGM("?(S)" TERN_(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS, " or (W)") " is required.");
501+
if (!is_probe_point && TERN1(HAS_Z_STEPPER_ALIGN_STEPPER_XY, !parser.seen('W'))) {
502+
SERIAL_ECHOLNPGM("?(S)" TERN_(HAS_Z_STEPPER_ALIGN_STEPPER_XY, " or (W)") " is required.");
503503
return;
504504
}
505505

@@ -513,7 +513,7 @@ void GcodeSuite::M422() {
513513
}
514514
}
515515
else {
516-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
516+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
517517
position_index = parser.intval('W') - 1;
518518
if (!WITHIN(position_index, 0, NUM_Z_STEPPER_DRIVERS - 1)) {
519519
SERIAL_ECHOLNPGM("?(W) Z-stepper index invalid.");
@@ -551,7 +551,7 @@ void GcodeSuite::M422_report(const bool forReplay/*=true*/) {
551551
SP_Y_STR, z_stepper_align.xy[i].y
552552
);
553553
}
554-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
554+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
555555
LOOP_L_N(i, NUM_Z_STEPPER_DRIVERS) {
556556
report_echo_start(forReplay);
557557
SERIAL_ECHOLNPGM_P(

Marlin/src/inc/Conditionals_adv.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@
630630
#endif
631631

632632
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
633-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
633+
#ifdef Z_STEPPER_ALIGN_STEPPER_XY
634+
#define HAS_Z_STEPPER_ALIGN_STEPPER_XY 1
634635
#undef Z_STEPPER_ALIGN_AMP
635636
#endif
636637
#ifndef Z_STEPPER_ALIGN_AMP
@@ -986,7 +987,7 @@
986987
#endif
987988

988989
// Flag whether least_squares_fit.cpp is used
989-
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
990+
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, HAS_Z_STEPPER_ALIGN_STEPPER_XY)
990991
#define NEED_LSF 1
991992
#endif
992993

Marlin/src/inc/SanityCheck.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@
613613
#error "NOZZLE_PARK_X_ONLY is now NOZZLE_PARK_MOVE 1."
614614
#elif defined(NOZZLE_PARK_Y_ONLY)
615615
#error "NOZZLE_PARK_X_ONLY is now NOZZLE_PARK_MOVE 2."
616+
#elif defined(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
617+
#error "Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS is now just Z_STEPPER_ALIGN_STEPPER_XY."
616618
#endif
617619

618620
constexpr float arm[] = AXIS_RELATIVE_MODES;
@@ -3479,10 +3481,10 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
34793481
#error "Z_STEPPER_AUTO_ALIGN requires NUM_Z_STEPPER_DRIVERS greater than 1."
34803482
#elif !HAS_BED_PROBE
34813483
#error "Z_STEPPER_AUTO_ALIGN requires a Z-bed probe."
3482-
#elif ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
3484+
#elif HAS_Z_STEPPER_ALIGN_STEPPER_XY
34833485
static_assert(WITHIN(Z_STEPPER_ALIGN_AMP, 0.5, 2.0), "Z_STEPPER_ALIGN_AMP must be between 0.5 and 2.0.");
34843486
#if NUM_Z_STEPPER_DRIVERS < 3
3485-
#error "Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS requires NUM_Z_STEPPER_DRIVERS to be 3 or 4."
3487+
#error "Z_STEPPER_ALIGN_STEPPER_XY requires NUM_Z_STEPPER_DRIVERS to be 3 or 4."
34863488
#endif
34873489
#endif
34883490
#endif

Marlin/src/module/settings.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ typedef struct SettingsDataStruct {
341341
#endif
342342

343343
//
344-
// Z_STEPPER_AUTO_ALIGN, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
344+
// Z_STEPPER_AUTO_ALIGN, HAS_Z_STEPPER_ALIGN_STEPPER_XY
345345
//
346346
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
347347
xy_pos_t z_stepper_align_xy[NUM_Z_STEPPER_DRIVERS]; // M422 S X Y
348-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
348+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
349349
xy_pos_t z_stepper_align_stepper_xy[NUM_Z_STEPPER_DRIVERS]; // M422 W X Y
350350
#endif
351351
#endif
@@ -1005,7 +1005,7 @@ void MarlinSettings::postprocess() {
10051005

10061006
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
10071007
EEPROM_WRITE(z_stepper_align.xy);
1008-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
1008+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
10091009
EEPROM_WRITE(z_stepper_align.stepper_xy);
10101010
#endif
10111011
#endif
@@ -1924,7 +1924,7 @@ void MarlinSettings::postprocess() {
19241924

19251925
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
19261926
EEPROM_READ(z_stepper_align.xy);
1927-
#if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
1927+
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
19281928
EEPROM_READ(z_stepper_align.stepper_xy);
19291929
#endif
19301930
#endif

buildroot/tests/DUE

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options
3737
restore_configs
3838
opt_set MOTHERBOARD BOARD_RADDS NUM_Z_STEPPER_DRIVERS 3
3939
opt_enable USE_XMAX_PLUG USE_YMAX_PLUG ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR \
40-
Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS Z_SAFE_HOMING
40+
Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_STEPPER_XY Z_SAFE_HOMING
4141
pins_set ramps/RAMPS X_MAX_PIN -1
4242
pins_set ramps/RAMPS Y_MAX_PIN -1
4343
exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN, E_DUAL_STEPPER_DRIVERS" "$3"

0 commit comments

Comments
 (0)