Skip to content

Commit 6f5800b

Browse files
Backlash Compensation for COREnn (#21612)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent d3a2c6a commit 6f5800b

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

Marlin/Configuration_adv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,9 @@
972972
#define BACKLASH_DISTANCE_MM { 0, 0, 0 } // (mm)
973973
#define BACKLASH_CORRECTION 0.0 // 0.0 = no correction; 1.0 = full correction
974974

975+
// Add steps for motor direction changes on CORE kinematics
976+
//#define CORE_BACKLASH
977+
975978
// Set BACKLASH_SMOOTHING_MM to spread backlash correction over multiple segments
976979
// to reduce print artifacts. (Enabling this is costly in memory and computation!)
977980
//#define BACKLASH_SMOOTHING_MM 3 // (mm)

Marlin/src/feature/backlash.cpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,24 @@ Backlash backlash;
6363
void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block) {
6464
static uint8_t last_direction_bits;
6565
uint8_t changed_dir = last_direction_bits ^ dm;
66-
// Ignore direction change if no steps are taken in that direction
67-
if (da == 0) CBI(changed_dir, X_AXIS);
68-
if (db == 0) CBI(changed_dir, Y_AXIS);
69-
if (dc == 0) CBI(changed_dir, Z_AXIS);
66+
// Ignore direction change unless steps are taken in that direction
67+
#if DISABLED(CORE_BACKLASH) || ENABLED(MARKFORGED_XY)
68+
if (!da) CBI(changed_dir, X_AXIS);
69+
if (!db) CBI(changed_dir, Y_AXIS);
70+
if (!dc) CBI(changed_dir, Z_AXIS);
71+
#elif CORE_IS_XY
72+
if (!(da + db)) CBI(changed_dir, X_AXIS);
73+
if (!(da - db)) CBI(changed_dir, Y_AXIS);
74+
if (!dc) CBI(changed_dir, Z_AXIS);
75+
#elif CORE_IS_XZ
76+
if (!(da + dc)) CBI(changed_dir, X_AXIS);
77+
if (!(da - dc)) CBI(changed_dir, Z_AXIS);
78+
if (!db) CBI(changed_dir, Y_AXIS);
79+
#elif CORE_IS_YZ
80+
if (!(db + dc)) CBI(changed_dir, Y_AXIS);
81+
if (!(db - dc)) CBI(changed_dir, Z_AXIS);
82+
if (!da) CBI(changed_dir, X_AXIS);
83+
#endif
7084
last_direction_bits ^= changed_dir;
7185

7286
if (correction == 0) return;
@@ -105,18 +119,35 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
105119
// Take up a portion of the residual_error in this segment, but only when
106120
// the current segment travels in the same direction as the correction
107121
if (reversing == (error_correction < 0)) {
108-
if (segment_proportion == 0)
109-
segment_proportion = _MIN(1.0f, block->millimeters / smoothing_mm);
122+
if (segment_proportion == 0) segment_proportion = _MIN(1.0f, block->millimeters / smoothing_mm);
110123
error_correction = CEIL(segment_proportion * error_correction);
111124
}
112125
else
113126
error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps
114127
}
115128
#endif
116-
// Making a correction reduces the residual error and adds block steps
129+
130+
// This correction reduces the residual error and adds block steps
117131
if (error_correction) {
118132
block->steps[axis] += ABS(error_correction);
119-
residual_error[axis] -= error_correction;
133+
#if ENABLED(CORE_BACKLASH)
134+
switch (axis) {
135+
case CORE_AXIS_1:
136+
//block->steps[CORE_AXIS_2] += influence_distance_mm[axis] * planner.settings.axis_steps_per_mm[CORE_AXIS_2];
137+
//SERIAL_ECHOLNPAIR("CORE_AXIS_1 dir change. distance=", distance_mm[axis], " r.err=", residual_error[axis],
138+
// " da=", da, " db=", db, " block->steps[axis]=", block->steps[axis], " err_corr=", error_correction);
139+
break;
140+
case CORE_AXIS_2:
141+
//block->steps[CORE_AXIS_1] += influence_distance_mm[axis] * planner.settings.axis_steps_per_mm[CORE_AXIS_1];;
142+
//SERIAL_ECHOLNPAIR("CORE_AXIS_2 dir change. distance=", distance_mm[axis], " r.err=", residual_error[axis],
143+
// " da=", da, " db=", db, " block->steps[axis]=", block->steps[axis], " err_corr=", error_correction);
144+
break;
145+
case NORMAL_AXIS: break;
146+
}
147+
residual_error[axis] = 0; // No residual_error needed for next CORE block, I think...
148+
#else
149+
residual_error[axis] -= error_correction;
150+
#endif
120151
}
121152
}
122153
}

Marlin/src/lcd/menu/menu_backlash.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ void menu_backlash() {
3838

3939
EDIT_ITEM_FAST(percent, MSG_BACKLASH_CORRECTION, &backlash.correction, all_off, all_on);
4040

41+
#if DISABLED(CORE_BACKLASH) || ENABLED(MARKFORGED_XY)
42+
#define _CAN_CALI AXIS_CAN_CALIBRATE
43+
#else
44+
#define _CAN_CALI(A) true
45+
#endif
4146
#define EDIT_BACKLASH_DISTANCE(N) EDIT_ITEM_FAST(float43, MSG_BACKLASH_##N, &backlash.distance_mm[_AXIS(N)], 0.0f, 9.9f);
42-
if (AXIS_CAN_CALIBRATE(A)) EDIT_BACKLASH_DISTANCE(A);
43-
if (AXIS_CAN_CALIBRATE(B)) EDIT_BACKLASH_DISTANCE(B);
44-
if (AXIS_CAN_CALIBRATE(C)) EDIT_BACKLASH_DISTANCE(C);
47+
if (_CAN_CALI(A)) EDIT_BACKLASH_DISTANCE(A);
48+
if (_CAN_CALI(B)) EDIT_BACKLASH_DISTANCE(B);
49+
if (_CAN_CALI(C)) EDIT_BACKLASH_DISTANCE(C);
4550

4651
#ifdef BACKLASH_SMOOTHING_MM
4752
EDIT_ITEM_FAST(float43, MSG_BACKLASH_SMOOTHING, &backlash.smoothing_mm, 0.0f, 9.9f);

buildroot/tests/teensy35

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ exec_test $1 $2 "Teensy 3.5/3.6 COREXY" "$3"
9393
#
9494
restore_configs
9595
opt_set MOTHERBOARD BOARD_TEENSY35_36
96-
opt_enable COREXZ
97-
exec_test $1 $2 "Teensy 3.5/3.6 COREXZ" "$3"
96+
opt_enable COREXZ BACKLASH_COMPENSATION BACKLASH_GCODE CORE_BACKLASH
97+
exec_test $1 $2 "Teensy 3.5/3.6 COREXZ | BACKLASH" "$3"
9898

9999
#
100100
# Enable Dual Z with Dual Z endstops

0 commit comments

Comments
 (0)