121 lines
5 KiB
INI
121 lines
5 KiB
INI
#####################################################################
|
|
# Macros for z-calibration
|
|
# - CALIBRATE_Z
|
|
# - _CG28
|
|
# - _SET_CURRENT
|
|
# - _SET_ACC
|
|
#####################################################################
|
|
|
|
|
|
## CALIBRATE_Z
|
|
[gcode_macro CALIBRATE_Z]
|
|
description: Automatically calibrates the nozzles offset to the print surface and dock/undock MagProbe
|
|
rename_existing: _CALIBRATE_Z_BASE
|
|
gcode:
|
|
##### get user defines #####
|
|
{% set z_hop = printer['gcode_macro _USER_VARIABLE'].probe_z_min|float %}
|
|
##### get toolhead parameters #####
|
|
{% set act_z = printer.gcode_move.gcode_position.z|float %}
|
|
#### end of definitions #####
|
|
## reduce current of motors
|
|
_SET_ACC VAL=HOME
|
|
_SET_CURRENT VAL=HOME
|
|
_CG28 RESET_SETTINGS=false
|
|
{% if act_z < z_hop %}
|
|
G90 ; absolute positioning
|
|
{action_respond_info("CALIBRATE_Z: High must be above %.2f" % z_hop)}
|
|
G1 Z{z_hop} F900 ; move head up
|
|
{% endif %}
|
|
{% if printer.quad_gantry_level.applied|lower == 'false' %}
|
|
QUAD_GANTRY_LEVEL PARK=false
|
|
{% endif %}
|
|
#ATTACH_PROBE ; if not using start_gcode
|
|
_CALIBRATE_Z_BASE
|
|
#DETACH_PROBE ; if not using end_gcode
|
|
{% if params.RESET_SETTINGS|default('true') == 'true' %}
|
|
## return to org current settings
|
|
_SET_CURRENT
|
|
_SET_ACC
|
|
{% endif %}
|
|
|
|
|
|
## _CG28
|
|
[gcode_macro _CG28]
|
|
description: conditional home
|
|
gcode:
|
|
{% if "xyz" not in printer.toolhead.homed_axes %}
|
|
G28 RESET_SETTINGS={ params.RESET_SETTINGS|default('true') }
|
|
{% endif %}
|
|
|
|
## _SET_ACC
|
|
[gcode_macro _SET_ACC]
|
|
description: Helper: Set accel and accel_to_decel value
|
|
variable_last_val: 'CONFIG'
|
|
gcode:
|
|
##### set default value #####
|
|
{% set default_respond = printer['gcode_macro _USER_VARIABLE'].respond_set_acc|int %}
|
|
{% set val = params.VAL|default('CONFIG') %}
|
|
{% set respond = params.RESPOND|default(default_respond)|int %}
|
|
{% if val == 'HOME' %}
|
|
{% set accel = printer['gcode_macro _USER_VARIABLE'].home_accel %}
|
|
{% set accel_to_decel = printer['gcode_macro _USER_VARIABLE'].home_accel|int / 2 %}
|
|
{% else %}
|
|
{% set accel = printer.configfile.settings.printer.max_accel %}
|
|
{% set accel_to_decel = printer.configfile.settings.printer.max_accel_to_decel %}
|
|
{% endif %}
|
|
##### end of definition #####
|
|
{% if val != last_val %}
|
|
SET_GCODE_VARIABLE MACRO=_SET_ACC VARIABLE=last_val VALUE='"{val}"'
|
|
{% if respond == 1 %}
|
|
{action_respond_info("VELOCITY_LIMIT set ACCEL: %d ACCEL_TO_DECEL: %d" % (accel|int, accel_to_decel|int))}
|
|
{% endif %}
|
|
SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel_to_decel} RESPOND=0
|
|
{% endif %}
|
|
|
|
|
|
## _SET_CURRENT
|
|
[gcode_macro _SET_CURRENT]
|
|
description: Helper: Set Z-drive motor current
|
|
variable_last_val: 'CONFIG'
|
|
gcode:
|
|
###### set default values #####
|
|
{% set default_respond = printer['gcode_macro _USER_VARIABLE'].respond_set_current|int %}
|
|
{% set val = params.VAL|default('CONFIG') %}
|
|
{% set respond = params.Z_RESPOND|default(default_respond)|int %}
|
|
{% if val == 'HOME' %}
|
|
{% set xy_run = printer['gcode_macro _USER_VARIABLE'].xy_home_current %}
|
|
{% set xy_hold = printer['gcode_macro _USER_VARIABLE'].xy_home_current %}
|
|
{% set z_run = printer['gcode_macro _USER_VARIABLE'].z_home_current %}
|
|
{% set z_hold = printer['gcode_macro _USER_VARIABLE'].z_home_current %}
|
|
{% else %}
|
|
## XY
|
|
{% if 'tmc2209 stepper_x' in printer.configfile.settings %}
|
|
{% set xy_run = printer.configfile.settings['tmc2209 stepper_x'].run_current %}
|
|
{% set xy_hold = printer.configfile.settings['tmc2209 stepper_x'].hold_current %}
|
|
{% elif 'tmc5160 stepper_x' in printer.configfile.settings %}
|
|
{% set xy_run = printer.configfile.settings['tmc5160 stepper_x'].run_current %}
|
|
{% set xy_hold = printer.configfile.settings['tmc5160 stepper_x'].hold_current %}
|
|
{% endif %}
|
|
## Z
|
|
{% if 'tmc2209 stepper_z' in printer.configfile.settings %}
|
|
{% set z_run = printer.configfile.settings['tmc2209 stepper_z'].run_current %}
|
|
{% set z_hold = printer.configfile.settings['tmc2209 stepper_z'].hold_current %}
|
|
{% elif 'tmc5160 stepper_z' in printer.configfile.settings %}
|
|
{% set z_run = printer.configfile.settings['tmc5160 stepper_z'].run_current %}
|
|
{% set z_hold = printer.configfile.settings['tmc5160 stepper_z'].hold_current %}
|
|
{% endif %}
|
|
{% endif %}
|
|
##### end of definition #####
|
|
{% if val != last_val %}
|
|
SET_GCODE_VARIABLE MACRO=_SET_CURRENT VARIABLE=last_val VALUE='"{val}"'
|
|
{% if respond == 1 %}
|
|
{action_respond_info("Home&Probe: RunCur %.2fA rms HoldCur %.2fA rms" % (z_run|float, z_hold|float))}
|
|
{% endif %}
|
|
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={xy_run} HOLDCURRENT={xy_hold}
|
|
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={xy_run} HOLDCURRENT={xy_hold}
|
|
SET_TMC_CURRENT STEPPER=stepper_z CURRENT={z_run} HOLDCURRENT={z_hold}
|
|
SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT={z_run} HOLDCURRENT={z_hold}
|
|
SET_TMC_CURRENT STEPPER=stepper_z2 CURRENT={z_run} HOLDCURRENT={z_hold}
|
|
SET_TMC_CURRENT STEPPER=stepper_z3 CURRENT={z_run} HOLDCURRENT={z_hold}
|
|
M400
|
|
{% endif %}
|