Hi everyone.
Some time ago I decided to convert my 3 axis dispensing robot to Klipper control. Previously I had to use a “teach pendant” to set up the program, which was time inefficient and inaccurate. Now I just need to create a program with G code from CAM and CAD.
However, I had a problem with the accuracy (axial symmetry) of the dispensing needle. I wanted to solve it this way:
Video
Thanks to user @gaolst I have a workable solution. Here is the original thread with the macro by @gaolst:
Original thread
Here is my version of the macro:
[gcode_button calibration_X_button]
pin: !PG12
press_gcode:
{% set position = printer.motion_report.live_position %}
SET_GCODE_VARIABLE MACRO=set_nozzle_offset VARIABLE=x0 VALUE={position.x}
{action_respond_info("X-press-trigger X: %.2f "% (position.x))}
release_gcode:
{% set position = printer.motion_report.live_position %}
SET_GCODE_VARIABLE MACRO=set_nozzle_offset VARIABLE=x1 VALUE={position.x}
{action_respond_info("X-release-trigger X: %.2f "% (position.x))}
[gcode_button calibration_Y_button]
pin: !PG13
press_gcode:
{% set position = printer.motion_report.live_position %}
SET_GCODE_VARIABLE MACRO=set_nozzle_offset VARIABLE=y0 VALUE={position.y}
{action_respond_info("Y-press-trigger Y: %.2f "% (position.y))}
release_gcode:
{% set position = printer.motion_report.live_position %}
SET_GCODE_VARIABLE MACRO=set_nozzle_offset VARIABLE=y1 VALUE={position.y}
{action_respond_info("Y-release-trigger Y: %.2f "% (position.y))}
[gcode_macro do_calibration_move]
description: Do calibration moves in X and In Y
gcode:
{% set microstep_count = 150%}
{% set microstep_size_x = 0.05 %}
{% set microstep_size_y = -0.05 %}
{% set microstep_speed = 100 %}
{% set move_speed = 3000 %}
{% set z_jump = 10 %}
SAVE_GCODE_STATE NAME=calibrate_1_state
G90
#Go to starting position for X calibration
G0 X90 Y250 F{move_speed}
G0 Z7 F{move_speed}
G91
#Do microsteps in X
{% for step in range(microstep_count) %}
G1 X{microstep_size_x} F{microstep_speed}
{% endfor %}
#Ok we finished X, now we need to return to start position
#but need to jump over trigger
G0 Z{z_jump} F{move_speed}
#Go in reverse to starting position for Y calibration
G0 X{microstep_size_x*microstep_count*(-1)} F{move_speed}
G90
G0 X68 Y224
G91
G0 Z-{z_jump} F{move_speed}
#Do microsteps in Y
{% for step in range(microstep_count) %}
G1 Y{microstep_size_y} F{microstep_speed}
{% endfor %}
G90
RESTORE_GCODE_STATE NAME=calibrate_1_state
[gcode_macro set_nozzle_offset]
description: Fetch stored X and Y and set offsets
variable_x0: 0.0
variable_x1: 0.0
variable_y0: 0.0
variable_y1: 0.0
gcode:
{% set me = printer["gcode_macro set_nozzle_offset"] %}
{% set dx = me.x0 - ((me.x0 - me.x1)/2) %}
{% set dy = me.y0 + ((me.y1 - me.y0)/2) %}
{action_respond_info("dX: %.2f, dY: %.2f" % (dx, dy)) }
G1 Y {dy} # Move needle to the centre of the optical gate "Y"
G92 Y218.85 # Setting the correct coordinate relative to the machine axis
G4 P500
G91
G0 Y7
G90
G0 X90 Y250
G1 X {dx} # Move needle to the centre of the optical gate "X"
G92 X94.15 # Setting the correct coordinate relative to the machine axis
G4 P500
G91
G0 X7
G90
G0 Z50
G0 X152.1 Y168.3
And here is a video of the calibration:
Needle calibration video
Z-axis calibration is not part of this macro. This is solved via PROBE.
I hope it helps to someone as much as it helped me
Tony