# Axis twist calibration from Mainsail: run TWIST_CALIBRATE and follow the # windows. Starts scripts/twist_check.py (see there) in the background: inside # a macro it would deadlock, because the macro holds the G-code queue that the # script needs. # # TWIST_CALIBRATE the start: explains, checks, shows progress while running # TWIST_STOP stop a run: lifts the nozzle, nozzle heater off. It waits # for the command that is running (homing, QGL: up to a # minute); use the emergency stop in a real emergency. # # While running: progress on the status line (M117) and in TWIST_CALIBRATE, # logo as for Z calibration, the result opens a window. Reports and the # values to apply are in config/twist_data/. Nothing here changes printer.cfg. # # Started from Klipper, so restarting the Klipper service ends the run. [gcode_shell_command _twist_start] command: bash -c 'setsid nohup python3 "$HOME/printer_data/config/klipper-macros-scripts/twist_check.py" "$1" >/dev/null 2>&1 40 %} RESPOND TYPE=command MSG="action:prompt_text Note: the bed is at {bed|int} C. The reference runs were on a cold bed, so wait for it to cool unless you want this on purpose." {% endif %} RESPOND TYPE=command MSG="action:prompt_text It heats the nozzle to 150 C, homes, levels and takes {'25' if mode == 'measure' else '17'} minutes. The configuration is not changed." RESPOND TYPE=command MSG="action:prompt_footer_button Back|TWIST_CALIBRATE|secondary" RESPOND TYPE=command MSG="action:prompt_footer_button All checked, start|_TWIST_START MODE={mode}|primary" RESPOND TYPE=command MSG="action:prompt_show" [gcode_macro _TWIST_START] description: Start the twist script in the background (use TWIST_CALIBRATE) gcode: {% set mode = params.MODE|default('')|lower %} {% if mode not in ("measure", "verify") %} _ERROR MSG="_TWIST_START: MODE must be measure or verify" {% elif printer.print_stats.state in ("printing", "paused") %} _ERROR MSG="Twist calibration: a print is running" DISPLAY="Twist: not during a print" {% elif printer['gcode_macro _TWIST_STATE'].running %} _ERROR MSG="Twist calibration is already running. TWIST_CALIBRATE shows it, TWIST_STOP stops it." DISPLAY="Twist: already running" {% else %} M117 Twist {mode}: starting RESPOND TYPE=command MSG="action:prompt_begin Twist {mode} started" RESPOND TYPE=command MSG="action:prompt_text You can close this window: the run continues. The status line shows the progress, and a window opens with the result." RESPOND TYPE=command MSG="action:prompt_footer_button Stop the run|TWIST_STOP|error" RESPOND TYPE=command MSG="action:prompt_footer_button Close|_TWIST_CLOSE|secondary" RESPOND TYPE=command MSG="action:prompt_show" RUN_SHELL_COMMAND CMD=_twist_start PARAMS={mode} {% endif %} [gcode_macro TWIST_STOP] description: Stop a running twist calibration: lifts the nozzle, nozzle heater off gcode: RESPOND TYPE=command MSG="action:prompt_end" M117 Twist: stopping RUN_SHELL_COMMAND CMD=_twist_stop # Also clears the flag when a run has died without clearing it itself SET_GCODE_VARIABLE MACRO=_TWIST_STATE VARIABLE=running VALUE=0