Help with custom macro

I don't have much experience with writing macros so my knowledge is quite limited. I currently have a servo driven nozzle wipe routine that I can call either manually (when homed and no print is running) or at the beginning of a print automatically (as part of the start print macro that I've customized to call it before the prime). I would also like to be able to call it from the console terminal at will during a print if desired. What statements are required to be added to it so the nozzle wipe macro can run without wrecking the print that's in process? How do I skip those same statements when they are not required (when no print is in process)? Thanks for the help.
3 Replies
blacksmithforlife
How are you calling it at the start of the print?
billyd
billyd14mo ago
Just copied the ratos macro (name escapes me at the moment) that calls for the prime line (or blob) into my printer.cfg and just prior to that I add a call to my nozzle_wipe macro. Problem is if I try to call it during a print, it seems to get confused, it doesn't finish the nozzle_wipe macro as expected. That only happens during a print. Otherwise it operates correctly. I think I have to save the state of the printer like what is done in ratos pause, then execute the macro, and then use ratos resume. I could add pause and resume into the nozzle_wipe macro, but I still want to be able to add conditional statements to skip pause and resume when it's not needed, such as when the printer is idle or when it is called prior to the primeline. That's where I need some help. How do I use the idle_timeout state in a conditional? I need an example so I know how to format it. {% if idle_timeout.state = "Printing" %} is that correct? Below is my guess.
gcode_macro NOZZLE_WIPE]
gcode:
{% set ispauseon = 0 %}
{% if idle_timeout.state = 'Printing' %}
PAUSE
{% set ispauseon = 1 %}
{% endif %}
{% set x_location = printer.toolhead.position.x %}
{% set y_location = printer.toolhead.position.y %}
{% set z_clearance = 0 %}
M118 Start Wiping macro
SET_SERVO SERVO=nozzle_wiper ANGLE=100
{% if printer.toolhead.position.z < 35 %}
{% set z_clearance = 35-printer.toolhead.position.z %}
G91
G1 Z{z_clearance}
{% endif %}
G90
G1 X490 Y250 F10000
M118 Deploy Servo
SET_SERVO SERVO=nozzle_wiper ANGLE=56
G1 X60 Y442 F10000
M118 Large Debris Removal
G1 X18 Y484 F10000
G4 P1000
SET_SERVO SERVO=nozzle_wiper ANGLE=100
M118 Begin Nozzle Scrub
G4 P500
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=66
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=68
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=70
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=72
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=70
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=68
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=66
G1 X0 Y500 F10000
G1 X35 Y484 F10000
M118 Wiping Done
G1 X{x_location} Y{y_location} F12000
M118 Nozzle Scrub Complete
M118 Retract Wiper
SET_SERVO SERVO=nozzle_wiper ANGLE=100
G4 P2000
{% if z_clearance > 0 %}
G91
G1 Z-{z_clearance}
G90
{% endif %}
M118 Wiping finished
{% if ispauseon > 0 %}
RESUME
{% endif %}
gcode_macro NOZZLE_WIPE]
gcode:
{% set ispauseon = 0 %}
{% if idle_timeout.state = 'Printing' %}
PAUSE
{% set ispauseon = 1 %}
{% endif %}
{% set x_location = printer.toolhead.position.x %}
{% set y_location = printer.toolhead.position.y %}
{% set z_clearance = 0 %}
M118 Start Wiping macro
SET_SERVO SERVO=nozzle_wiper ANGLE=100
{% if printer.toolhead.position.z < 35 %}
{% set z_clearance = 35-printer.toolhead.position.z %}
G91
G1 Z{z_clearance}
{% endif %}
G90
G1 X490 Y250 F10000
M118 Deploy Servo
SET_SERVO SERVO=nozzle_wiper ANGLE=56
G1 X60 Y442 F10000
M118 Large Debris Removal
G1 X18 Y484 F10000
G4 P1000
SET_SERVO SERVO=nozzle_wiper ANGLE=100
M118 Begin Nozzle Scrub
G4 P500
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=66
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=68
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=70
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=72
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=70
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=68
G1 X0 Y500 F10000
G1 X35 Y484 F10000
SET_SERVO SERVO=nozzle_wiper ANGLE=66
G1 X0 Y500 F10000
G1 X35 Y484 F10000
M118 Wiping Done
G1 X{x_location} Y{y_location} F12000
M118 Nozzle Scrub Complete
M118 Retract Wiper
SET_SERVO SERVO=nozzle_wiper ANGLE=100
G4 P2000
{% if z_clearance > 0 %}
G91
G1 Z-{z_clearance}
G90
{% endif %}
M118 Wiping finished
{% if ispauseon > 0 %}
RESUME
{% endif %}
What I posted has a syntax error, in the conditional statement near the very beginning involving the idle_timeout object. Can you tell me what it is? @miklschmidt Let me rephrase the question. How do I use the klipper object: idle_timeout in a conditional statement, in order to check the state of the printer (to determine whether or not it is actively printing).
miklschmidt
miklschmidt14mo ago
{% if printer.idle_timeout.state == "Printing" %}
{% if printer.idle_timeout.state == "Printing" %}
Want results from more Discord servers?
Add your server
More Posts