klipper_switchwire/calibration_macros.cfg
2022-06-11 12:24:15 -07:00

195 lines
6.8 KiB
INI

[gcode_macro MEASURE_RESONNANCES_X]
gcode:
RESPOND PREFIX= MSG="Homing"
G28
Dock_probe
RESPOND PREFIX= MSG="Measuring resonnances on X Axis"
SHAPER_CALIBRATE AXIS=X
#Park_toolhead
[gcode_macro MEASURE_RESONNANCES_Y]
gcode:
RESPOND PREFIX= MSG="Homing"
G28
Dock_probe
RESPOND PREFIX= MSG="Measuring resonnances on Y Axis"
SHAPER_CALIBRATE AXIS=Y
#Park_toolhead
[gcode_macro Screws_tilt]
gcode:
{% set travel_speed = printer["gcode_macro GlobalVariables"].travel_speed %}
{% set home_x = printer["gcode_macro GlobalVariables"].home_x %}
{% set probe_x_offset = printer["gcode_macro GlobalVariables"].probe_x_offset %}
{% set BED_TEMP = params.BED_TEMP|default(100)|float %}
# Start bed heating and wait
RESPOND PREFIX= MSG="Waiting for bed temperature..."
M140 S{BED_TEMP}
{% if printer.toolhead.homed_axes != 'xyz' %}
G28 #Home All Axes
{% endif %}
G4 P15000
M190 S{BED_TEMP}
Attach_probe
SCREWS_TILT_CALCULATE samples=3
G1 X{ home_x - probe_x_offset } Y230 Z200 F{ travel_speed }
[gcode_macro M900]
gcode:
# Parameters
{% set pa = params.K|float %}
SET_PRESSURE_ADVANCE ADVANCE={pa}
[gcode_macro FLOW_CALIBRATION]
gcode:
M221 S{params.FLOW}
SET_PRESSURE_ADVANCE ADVANCE={params.PRESSURE_ADVANCE}
[gcode_macro SEARCH_VARS]
gcode:
{% set search = params.S|lower %}
{% set ns = namespace() %}
{% for item in printer %}
{% if ' ' in item %}
{% set ns.path = ['printer', "['%s']" % (item), ''] %}
{% else %}
{% set ns.path = ['printer.', item, ''] %}
{% endif %}
{% if search in ns.path|lower %}
{ action_respond_info(ns.path|join) }
{% endif %}
{% if printer[item].items() %}
{% for childkey, child in printer[item].items() recursive %}
{% set ns.path = ns.path[:loop.depth|int + 1] %}
{% if ' ' in childkey %}
{% set null = ns.path.append("['%s']" % (childkey)) %}
{% else %}
{% set null = ns.path.append(".%s" % (childkey)) %}
{% endif %}
{% if child is mapping %}
{ loop(child.items()) }
{% else %}
{% if search in ns.path|lower %}
{ action_respond_info("%s : %s" % (ns.path|join, child)) }
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
[gcode_macro TEST_Z_DOWN]
gcode:
{% set amount = params.amount|default(1)|int %}
TESTZ Z=-{amount}
[gcode_macro TEST_Z_UP]
gcode:
{% set amount = params.amount|default(1)|int %}
TESTZ Z=+{amount}
[gcode_macro TEST_Z_UP_MIDDLE]
gcode:
TESTZ Z=+
[gcode_macro TEST_Z_DOWN_MIDDLE]
gcode:
TESTZ Z=-
# Home, get position, throw around toolhead, home again.
# If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured.
# We only measure to a full step to accomodate for endstop variance.
# Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10
[gcode_macro TEST_SPEED]
gcode:
# Speed
{% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
# Iterations
{% set iterations = params.ITERATIONS|default(5)|int %}
# Acceleration
{% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
# Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
{% set bound = params.BOUND|default(20)|int %}
# Size for small pattern box
{% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %}
# Large pattern
# Max positions, inset by BOUND
{% set x_min = printer.toolhead.axis_minimum.x + bound %}
{% set x_max = printer.toolhead.axis_maximum.x - bound %}
{% set y_min = printer.toolhead.axis_minimum.y + bound %}
{% set y_max = printer.toolhead.axis_maximum.y - bound %}
# Small pattern at center
# Find X/Y center point
{% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %}
{% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %}
# Set small pattern box around center point
{% set x_center_min = x_center - (smallpatternsize/2) %}
{% set x_center_max = x_center + (smallpatternsize/2) %}
{% set y_center_min = y_center - (smallpatternsize/2) %}
{% set y_center_max = y_center + (smallpatternsize/2) %}
# Save current gcode state (absolute/relative, etc)
SAVE_GCODE_STATE NAME=TEST_SPEED
# Output parameters to g-code terminal
{ action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }
# Absolute positioning
G90
# Set new limits
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel}
# Home and get position for comparison later:
G28
# Go to starting position
G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}
{% for i in range(iterations) %}
# Large pattern
# Diagonals
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
# Box
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
# Small pattern
# Small diagonals
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
# Small box
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
{% endfor %}
# Restore max speed/accel/accel_to_decel to their configured values
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
# Restore previous gcode state (absolute/relative, etc)
RESTORE_GCODE_STATE NAME=TEST_SPEED