jschuh / klipper-macros

A collection of useful macros for the Klipper 3D printer firmware
GNU General Public License v3.0
921 stars 167 forks source link

Add feature to only use filament sensor while printing #201

Closed sn4k3 closed 9 months ago

sn4k3 commented 9 months ago

When having a filament sensor, by default they are ON, causing unloading/loading events to trigger even if we don't want to (hand feed or preparation).

[filament_switch_sensor toolhead_runout]
pause_on_runout: true
runout_gcode:
    M117 Runout Detected
    UNLOAD_FILAMENT
insert_gcode:
    M117 Insert Detected
    LOAD_FILAMENT
switch_pin: ^P1.28

We can disable the sensor by default using:

[delayed_gcode DISABLE_FILAMENT_SENSOR]
initial_duration: 1
gcode:
    SET_FILAMENT_SENSOR SENSOR=toolhead_runout ENABLE=0

However, this introduces another problem, we want the sensor ON when printing, but OFF when not printing, as so, this PR allows the user to select a list of sensors to switch ON/OFF on those print events. This will allow user to do any handling of the extruder without the annoyance of removing the filament and it trigger an PAUSE which do HOME, PREHEAT, PARK and UNLOAD or insert the filament in cold just to prepare a future print and it trigger another unrequired sequence of events.

We could use slicer start and end gcode, but that is ugly, don't handle print cancel and make them less sharable. This integrated solution is cleaner and less prompt to error.

Usage:

variable_switch_filament_sensors: ['toolhead_runout'] # example: ('toolhead_runout')
jschuh commented 9 months ago

This can be done quite easily with print status events. You'd run the disable on the ready event and enable on the purge event.

sn4k3 commented 9 months ago

This can be done quite easily with print status events. You'd run the disable on the ready event and enable on the purge event.

Worked, tested with:

GCODE_ON_PRINT_STATUS STATUS=ready COMMAND="SET_FILAMENT_SENSOR SENSOR=toolhead_runout ENABLE=0" TYPE=ENTER WHEN=ALWAYS
GCODE_ON_PRINT_STATUS STATUS=purging COMMAND="SET_FILAMENT_SENSOR SENSOR=toolhead_runout ENABLE=1" TYPE=ENTER WHEN=ALWAYS

Thanks! You can close this PR if you wish.

jschuh commented 9 months ago

Yeah, I'm going to close. If I add something specific for runout sensors I'd want to address a broader range of scenarios (e.g. my own runout macro pauses immediately on the first layer, waits for a layer change everywhere else, and debounces the runout events).

sn4k3 commented 9 months ago

The filament sensors are poorly handled by klipper and lacking, it only supports them but then all functions must be handed by user macros. We need a more robust way to deal with them (configs and communication)...

Examples: