Hi! I implemented a backlash compensation module for Klipper and wanted to invite interested people for testing. The branch for testing is available here. Essentially, backlash compensation can be configured in printer.cfg via
[backlash_compensation]
smooth_time: 0.005
x_backlash: 0.02
y_backlash: 0.03
# z_backlash: ...
or at run-time via
SET_BACKLASH_COMPENSATION X_BACKLASH=0.02 Y_BACKLASH=0.03 SMOOTH_TIME=0.005
On printers with dual_carriage you need to configure it similarly to input shaper, e.g. via
[backlash_compensation]
smooth_time: 0.005
[delayed_gcode init_shapers]
initial_duration: 0.1
gcode:
SET_DUAL_CARRIAGE CARRIAGE=<dual_carriage_name>
SET_INPUT_SHAPER SHAPER_TYPE_X=<dual_carriage_shaper> SHAPER_FREQ_X=<dual_carriage_freq> SHAPER_TYPE_Y=<y_shaper> SHAPER_FREQ_Y=<y_freq>
SET_BACKLASH_COMPENSATION X_BACKLASH=<dual_carriage_backlash> Y_BACKLASH=<y_gantry_backlash>
SET_DUAL_CARRIAGE CARRIAGE=<primary_carriage_name>
SET_INPUT_SHAPER SHAPER_TYPE_X=<primary_carriage_shaper> SHAPER_FREQ_X=<primary_carriage_freq> SHAPER_TYPE_Y=<y_shaper> SHAPER_FREQ_Y=<y_freq>
SET_BACKLASH_COMPENSATION X_BACKLASH=<primary_carriage_backlash> Y_BACKLASH=<y_gantry_backlash>
The values that you put here are the full backlash of an axis when changing the motion in the opposite direction. Iād generally recommend to calibrate it using a camera (e.g. using this web tool or similar online or offline calibration tool) using approximately the following procedure:
- move a nozzle in the center of a camera
- move a nozzle 1mm in the negative direction in the X direction
- move a nozzle in the positive direction until it is back in the center, making sure to only move it in one direction
- record X coordinate X1
- move a nozzle 1mm further in the positive direction over X axis
- move a nozzle in the negative direction until it is back in the center, never moving it in the positive direction in the process
- record X coordinate X2
- compute x_backlash = abs(X2-X1)
- repeat steps 1-8 for Y axis
I would generally not recommend to use the dial gauge for this purpose (with the exception of Z axis, perhaps), because it will create some forces on the motion system that could skew the results.
FWIW, on my IDEX 3D printer which has pretty complicated kinematics and which requires high forces to move Y axis I measured X backlash of 0.01-0.02mm for the both tools and Y backlash of ~0.05-0.06mm for the gantry (which was the original reason to implement this). Iād generally think that backlash of 0.01-0.02mm does not require compensation, but around 0.05mm - certainly does, especially on the IDEX printers, since this backlash could create small gaps when printing two-filament object between the individual parts. To test that the code works, I printed Vector3D Califlower calibration test, and here is the screenshot of the results (left, no backlash compensation, right - SET_BACKLASH_COMPENSATION X_BACKLASH=0.02 Y_BACKLASH=0.05 SMOOTH_TIME=0.0025:
I think that the test does demonstrate that the compensation has an effect on the actual prints.
A note on the choice of smooth_time. This is in general the time over which Klipper will smooth out the backlash motion. Iād say the default smooth_time=0.005 is a good choice for backlash up to 0.1 mm. As a rule of thumb, you can estimate the additional acceleration from the backlash compensation to be 2 * backlash / smooth_time^2, and so for larger backlashes you could increase smooth_time to, say, 0.01 (sec) or larger.
In terms of details of implementation, this compensation is implemented at the level of stepper kinematics and works somewhat similarly to input shaping and pressure advance.
This is how some typical scenarios look with it:
Movement from one point to another
Without input shaper (but as if it was enabled, left) and with MZV input shaper (right):
Back and forth movements
Without input shaper (but as if it was enabled, left) and with MZV input shaper (right):
Motion along the square (one side)
Without input shaper (but as if it was enabled, left) and with MZV input shaper (right):
@koconnor FYI, and let me know what you think about it.














