Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per material filament sensor switching #381

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions macros/base/start_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gcode:
{% set bed_mesh_enabled = printer["gcode_macro _USER_VARIABLES"].bed_mesh_enabled %}
{% set firmware_retraction_enabled = printer["gcode_macro _USER_VARIABLES"].firmware_retraction_enabled %}
{% set filter_enabled = printer["gcode_macro _USER_VARIABLES"].filter_enabled %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
tehniemer marked this conversation as resolved.
Show resolved Hide resolved

{% if MATERIAL not in printer["gcode_macro _USER_VARIABLES"].material_parameters %}
RESPOND MSG="Material '{MATERIAL}' is unknown!"
Expand Down Expand Up @@ -153,6 +154,10 @@ gcode:
START_FILTER SPEED={material.filter_speed / 100}
{% endif %}

{% if filament_sensor_enabled and not material.filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=0
{% endif %}

# And.... Goooo!
{% if status_leds_enabled %}
STATUS_LEDS COLOR="PRINTING"
Expand Down
9 changes: 6 additions & 3 deletions macros/helpers/filament_swap.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gcode:

{% set verbose = printer["gcode_macro _USER_VARIABLES"].verbose %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
{% set material_filament_sensor = printer["gcode_macro START_PRINT"].material.filament_sensor|default(1) %}
{% set klippain_ercf_enabled = printer["gcode_macro _USER_VARIABLES"].klippain_ercf_enabled %}

{% if filament_sensor_enabled %}
Expand Down Expand Up @@ -52,7 +53,7 @@ gcode:

RESTORE_GCODE_STATE NAME=UNLOAD_FILAMENT_state

{% if filament_sensor_enabled %}
{% if filament_sensor_enabled and material_filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% if verbose %}
RESPOND MSG="Filament unloaded, runout sensor reactivated"
Expand All @@ -79,6 +80,7 @@ gcode:

{% set verbose = printer["gcode_macro _USER_VARIABLES"].verbose %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
{% set material_filament_sensor = printer["gcode_macro START_PRINT"].material.filament_sensor|default(1) %}
{% set klippain_ercf_enabled = printer["gcode_macro _USER_VARIABLES"].klippain_ercf_enabled %}

{% if filament_sensor_enabled %}
Expand Down Expand Up @@ -112,7 +114,7 @@ gcode:
G92 E0
RESTORE_GCODE_STATE NAME=LOAD_FILAMENT_state

{% if filament_sensor_enabled %}
{% if filament_sensor_enabled and material_filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% if verbose %}
RESPOND MSG="Filament loaded, runout sensor reactivated"
Expand All @@ -138,6 +140,7 @@ gcode:

{% set verbose = printer["gcode_macro _USER_VARIABLES"].verbose %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
{% set material_filament_sensor = printer["gcode_macro START_PRINT"].material.filament_sensor|default(1) %}
{% set klippain_ercf_enabled = printer["gcode_macro _USER_VARIABLES"].klippain_ercf_enabled %}

{% if filament_sensor_enabled %}
Expand Down Expand Up @@ -182,7 +185,7 @@ gcode:

RESTORE_GCODE_STATE NAME=TIP_SHAPING_state

{% if filament_sensor_enabled %}
{% if filament_sensor_enabled and material_filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% if verbose %}
RESPOND MSG="Filament tip shaping done, runout sensor reactivated"
Expand Down
3 changes: 2 additions & 1 deletion macros/helpers/nozzle_cleaning.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ gcode:
{% set purgeclean_servo_enabled = printer["gcode_macro _USER_VARIABLES"].purgeclean_servo_enabled %}
{% set status_leds_enabled = printer["gcode_macro _USER_VARIABLES"].status_leds_enabled %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
{% set material_filament_sensor = printer["gcode_macro START_PRINT"].material.filament_sensor|default(1) %}
{% set verbose = printer["gcode_macro _USER_VARIABLES"].verbose %}

{% if purge_and_brush_enabled %}
Expand Down Expand Up @@ -114,7 +115,7 @@ gcode:
# No M400 needed here since G4 is also flushing Klipper's buffer
G4 P{OOZE_TIME * 1000}

{% if filament_sensor_enabled %}
{% if filament_sensor_enabled and material_filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% endif %}

Expand Down
3 changes: 2 additions & 1 deletion macros/helpers/prime_line.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gcode:

{% set klippain_ercf_enabled = printer["gcode_macro _USER_VARIABLES"].klippain_ercf_enabled %}
{% set filament_sensor_enabled = printer["gcode_macro _USER_VARIABLES"].filament_sensor_enabled %}
{% set material_filament_sensor = printer["gcode_macro START_PRINT"].material.filament_sensor|default(1) %}

{% set max_extrude_cross_section = printer["configfile"].config["extruder"]["max_extrude_cross_section"]|float %}
{% set filament_diameter = printer["configfile"].config["extruder"]["filament_diameter"]|float %}
Expand Down Expand Up @@ -114,6 +115,6 @@ gcode:
{% endif %}
{% endif %}

{% if filament_sensor_enabled %}
{% if filament_sensor_enabled and material_filament_sensor %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% endif %}
21 changes: 17 additions & 4 deletions user_templates/variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ variable_print_default_material: "XXX"

## Material configuration parameters applied during START_PRINT by using the slicer MATERIAL variable
## FYI, retract paramaters are used only if firmware retraction is enabled, filter speed (in %) is used if
## there is a filter installed on the machine, etc...
## there is a filter installed on the machine, filament sensor is on or off if installed, etc...
## If you are using another material, just extend the list bellow with a new material and everything should work :)
variable_material_parameters: {
'PLA': {
Expand All @@ -150,7 +150,8 @@ variable_material_parameters: {
'retract_speed': 40,
'unretract_speed': 30,
'filter_speed': 0,
'additional_z_offset': 0
'additional_z_offset': 0,
'filament_sensor': 1
},
'PET': {
'pressure_advance': 0.0650,
Expand All @@ -159,7 +160,8 @@ variable_material_parameters: {
'retract_speed': 30,
'unretract_speed': 20,
'filter_speed': 0,
'additional_z_offset': 0.020
'additional_z_offset': 0.020,
'filament_sensor': 1
},
'ABS': {
'pressure_advance': 0.0480,
Expand All @@ -168,7 +170,18 @@ variable_material_parameters: {
'retract_speed': 40,
'unretract_speed': 30,
'filter_speed': 80,
'additional_z_offset': 0
'additional_z_offset': 0,
'filament_sensor': 1
tehniemer marked this conversation as resolved.
Show resolved Hide resolved
},
'TPU': {
'pressure_advance': 0.0500,
'retract_length': 0.2,
'unretract_extra_length': 0,
'retract_speed': 5,
'unretract_speed': 5,
'filter_speed': 0,
'additional_z_offset': 0.040,
'filament_sensor': 0
}
}

Expand Down