MECHANICAL_GANTRY_CALIBRATION implementation

Hi,
I have dual-Z on single driver and I’m looking for X-gantry align, similar to Marlin’s “MECHANICAL_GANTRY_CALIBRATION” which is basicaly automatized version of this configured into G34 command (it used to be M915 command in Marlin).

At this moment, the closest (working) solution I have is this:

[gcode_macro MECHANICAL_GANTRY_CALIBRATION]
gcode:
	{% set oldcurrent = printer.configfile.settings["tmc2209 stepper_z"].run_current %} ; TODO: Find runtime current settings
	G28
	G90
	G0 X110 Y110 F8000
	G0 Z215 F720 ; go to the Z-max at speed 12*60
	SET_TMC_CURRENT STEPPER=stepper_z CURRENT=0.3
	G4 P200 ; Probably not necessary, it is here just for sure
	FORCE_MOVE STEPPER=stepper_z DISTANCE=10 VELOCITY=6
	SET_TMC_CURRENT STEPPER=stepper_z CURRENT={oldcurrent}
	G4 P200 ; same as the first one
	FORCE_MOVE STEPPER=stepper_z DISTANCE=-10 VELOCITY=6
	G28

This works for me perfectly.
But in Klipper documentation it says FORCE_MOVE is “intended for low-level diagnostics and debugging” which is not my case.
So I’d like to ask, is there a solution which works exactly like this? I.e.:

  • Home
  • (optionaly) move carriage/hotend to the center
  • Move Z axis to the z_max
  • Lower the current to the stepper_z
  • Move further (beyond z_max) to bump into the mechanic endstops located slightly above z_max
  • Set stepper_z current back to its original value
  • (optionaly) move Z axis back to the “safe” area
  • Rehome (because at least Z axis definitely need it)

Thank you

There isn’t currently any builtin tool to perform the operation you have.

It does look like you’ve found a solution using force_move and a macro. If it was me, I’d continue to use that.

It is possible to use SET_KINEMATIC_POSITION instead of FORCE_MOVE for the same purpose - for example, something like SET_KINEMATIC_POSITION Z=0 followed by G1 Z10 and then G28. However, if you have it working with FORCE_MOVE, then I don’t see much gain in redoing it.

Cheers,
-Kevin

Thank you for response.
In the past I tried version with “SET_KINEMATIC_POSITION” but I had to do something wrong, because it didn’t work.
Today I tried it again (just to be sure about “it doesn’t work”) and… it works :slight_smile:
(Maybe I just don’t remember whether I tried “G92 Z0” or this)

So, you’re right, the “SET_KINEMATIC_POSITION” works too (with the same/similar notice “This is a diagnostic and debugging command”):

[gcode_macro MECHANICAL_GANTRY_CALIBRATION2]
gcode:
        {% set z_max = printer.configfile.settings.stepper_z.position_max %}
        {% set oldcurrent = printer.configfile.settings["tmc2209 stepper_z"].run_current %} ; TODO: Find runtime current settings
        G28
        G90
        G0 X110 Y110 F8000
        G0 Z{z_max} F720 ; 12*60
        SET_TMC_CURRENT STEPPER=stepper_z CURRENT=0.3
        G4 P200
        SET_KINEMATIC_POSITION Z=0 ; Fake Z position to allow move further
        G0 Z10 F360
        SET_TMC_CURRENT STEPPER=stepper_z CURRENT={oldcurrent}
        G4 P200
        G0 Z0 F360
        SET_KINEMATIC_POSITION Z={z_max} ; Set Z-pos back (otherwise it would try to do z-hop and it is too high for that)
        G28
1 Like

FWIW, if it was me, I’d backoff (G0 Z0) before raising the stepper motor current.

Cheers,
-Kevin

I was thinking as there’s better to avoid a missstep from motor (which can be caused by lower current).
That’s the reason why I raise the current back before “backoff”. Because whole way down (lower Z numbers) there shouldn’t be any obstruction until it reaches the bed (there’s no need to have lower current).

(This is just a description, or attempt to describe, why I decided how I decided, having lower current only the way towards the endstop. I can be wrong, of course)

Okay. FWIW, after the forced Z movement into the endstops, the carriage may be pressed against the endstop. Increasing the current at that point could increase the force on the frame and may cause the motors to “skip steps” at the point of current increase. There’s a slightly related blurb on this at: https://www.klipper3d.org/TMC_Drivers.html#using-macros-when-homing.

It is, of course, your choice.

Cheers,
-Kevin

1 Like

OK, seems my guess was wrong.

Hi did you manage to adjust the currents for the kinematic version compare to the version above? Any chance you cold share that thank you

Hi, I don’ have this printer anymore.
I believe the last version of this macro I’ve used is this:

[gcode_macro MECHANICAL_GANTRY_CALIBRATION]
gcode:
        {% set z_max = printer.configfile.settings.stepper_z.position_max %}
        {% set oldcurrent_z = printer.configfile.settings["tmc2209 stepper_z"].run_current %} 
        {% set oldcurrent_z1 = printer.configfile.settings["tmc2209 stepper_z1"].run_current %} 
        G28
        G90
        G0 X110 Y110 F8000
        G0 Z{z_max} F720 ; 12*60
        SET_TMC_CURRENT STEPPER=stepper_z CURRENT=0.150
        SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT=0.150
        G4 P100
        SET_KINEMATIC_POSITION Z=0 ; Fake Z position to allow move further
        G0 Z15 F360
        G4 P100
        G0 Z0 F360
        SET_TMC_CURRENT STEPPER=stepper_z CURRENT={oldcurrent_z}
        SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT={oldcurrent_z1}
        G4 P100
        SET_KINEMATIC_POSITION Z={z_max} ; Set Z-pos back
        G28

Thank you! This macro worked perfect on my SV06 (Second macro in the thread). The first one wasn’t hitting the top.