diff --git a/Configuration/Blob_Purge.cfg b/Configuration/Blob_Purge.cfg new file mode 100644 index 0000000..e78d0f5 --- /dev/null +++ b/Configuration/Blob_Purge.cfg @@ -0,0 +1,228 @@ +# Author: Jamin Collins +# based on RatOS: https://github.com/Rat-OS/RatOS-configuration/blob/v2.x/macros.cfg#L180 + +# WARNING: DO NOT EDIT THIS FILE +# To override settings from this file, you can copy and paste the relevant +# sections into your printer.cfg and change it there. + +[gcode_macro BLOB_PURGE] +variable_probe_for_priming_result: None +gcode: + _PROBE_FOR_PRIMING + _ADD_PRIME_PROBE_TO_OFFSET + _BLOB_PURGE + _SUBTRACT_PRIME_PROBE_FROM_OFFSET + +[gcode_macro _BLOB_PURGE_SETTINGS] +variable_debug: False +variable_adaptive_prime_offset_threshold: -1.0 +variable_prime_x: 5 +variable_prime_y: 5 +# default to moving forward (increasing y, aka toward back of most printers) +variable_y_direction: 1 +variable_fan_speed: 50 +variable_travel_speed: 0 +gcode: + +[delayed_gcode _SET_TRAVEL_SPEED] +initial_duration: 1 +gcode: + {% set travel_speed = printer["gcode_macro _BLOB_PURGE_SETTINGS"].travel_speed %} + {% if travel_speed == 0 %} + {% set travel_speed = printer.toolhead.max_velocity * 60 * 0.5 | float %} + SET_GCODE_VARIABLE MACRO=_BLOB_PURGE_SETTINGS VARIABLE=travel_speed VALUE={travel_speed} + {% endif %} + +[gcode_macro _BLOB_PURGE] +description: Prints a blog purge, used internally, if configured, as part of the START_PRINT macro. Slower than LINE_PURGE but much more effective. +gcode: + SAVE_GCODE_STATE NAME=blob_purge_state + {% set debug = printer["gcode_macro _BLOB_PURGE_SETTINGS"].debug %} + + M117 Priming nozzle with blob purge.. + RESPOND MSG="Priming nozzle with blob purge.." + + # don't want to travel at the absolute maximum configured, let's go 50% + {% set travel_speed = printer["gcode_macro _BLOB_PURGE_SETTINGS"].travel_speed %} + {% set cross_section = printer.configfile.settings.extruder.max_extrude_cross_section | float %} + + {% set z = printer.configfile.settings.bed_mesh.horizontal_move_z|float %} + {% set z_speed = printer.configfile.settings.stepper_z.homing_speed * 60 | float %} + {% set fan_speed = printer["gcode_macro _BLOB_PURGE_SETTINGS"].fan_speed%} + + {% set x_start = printer["gcode_macro _BLOB_PURGE_SETTINGS"].prime_x %} + {% set y_start = printer["gcode_macro _BLOB_PURGE_SETTINGS"].prime_y %} + + {action_respond_info("Blob purge starting at {}, {}".format( + (x_start), + (y_start) + )) } + + {% set y_factor = printer["gcode_macro _BLOB_PURGE_SETTINGS"].y_direction %} + + {% if cross_section < 5 %} + {action_respond_info("[Extruder] max_extrude_cross_section is insufficient for purge, please set it to 5 or greater. Purge skipped.")} + {% else %} + # Absolute positioning + G90 + # Relative extrusion + M83 + # Lift to start print Z height + G0 Z{z} F{z_speed} + # move close to blob position along the edge of the print + G1 X{x_start} F{travel_speed} + G1 Y{y_start + (15 * y_factor)} F{travel_speed} + # Lower to blob extrusion height + G1 Z0.5 F{z_speed} + # Move to final position horizontally + G1 Y{y_start} F{travel_speed} + # Extrude a blob + G1 F60 E20 + # 40% fan + M106 S{fan_speed} + # Move the extruder up by 5mm while extruding, breaks away from blob + G1 Z5 F100 E5 + # Move to wipe position, but keep extruding so the wipe is attached to blob + G1 F200 Y{y_start + (25 * y_factor)} E1 + # Go down diagonally while extruding + # Broken down in z moves under 2mm as a workaround for a tuning tower test. + # The tuning tower command thinks a new print has been started when z moves over 2mm and aborts. + G1 F200 Y{y_start + (30 * y_factor)} Z3.8 E0.5 + G1 F200 Y{y_start + (35 * y_factor)} Z2.6 E0.5 + G1 F200 Y{y_start + (40 * y_factor)} Z1.4 E0.5 + G1 F200 Y{y_start + (45 * y_factor)} Z0.2 E0.5 + # 0% fan + M106 S0 + # small wipe line + G1 F200 Y{y_start + (50 * y_factor)} Z0.2 E0.6 + # Break away wipe + G1 F{travel_speed} Y{y_start + (100 * y_factor)} + {% endif %} + RESTORE_GCODE_STATE NAME=blob_purge_state + +[gcode_macro _PROBE_FOR_PRIMING] +gcode: + SAVE_GCODE_STATE NAME=probe_for_priming_state + RESPOND MSG="Probing the prime location.." + {% set debug = printer["gcode_macro _BLOB_PURGE_SETTINGS"].debug %} + {% set speed = printer["gcode_macro _BLOB_PURGE_SETTINGS"].travel_speed %} + {% set x_start = printer["gcode_macro _BLOB_PURGE_SETTINGS"].prime_x %} + {% set y_start = printer["gcode_macro _BLOB_PURGE_SETTINGS"].prime_y %} + {% set z = printer.configfile.settings.bed_mesh.horizontal_move_z|float %} + {% set z_speed = printer.configfile.settings.stepper_z.homing_speed * 60 | float %} + # get bed mesh config object + {% set mesh_config = printer.configfile.config.bed_mesh %} + + # Get probe offsets + {% if printer.configfile.settings.bltouch is defined %} + {% set x_offset = printer.configfile.settings.bltouch.x_offset|float %} + {% set y_offset = printer.configfile.settings.bltouch.y_offset|float %} + {% elif printer.configfile.settings.probe is defined %} + {% set x_offset = printer.configfile.settings.probe.x_offset|float %} + {% set y_offset = printer.configfile.settings.probe.y_offset|float %} + {% elif printer.configfile.settings.beacon is defined %} + {% set x_offset = printer.configfile.settings.beacon.x_offset|float %} + {% set y_offset = printer.configfile.settings.beacon.y_offset|float %} + {% else %} + { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } + {% endif %} + + # get configured bed mesh area + {% set min_x = mesh_config.mesh_min.split(",")[0]|float - x_offset %} + {% set min_y = mesh_config.mesh_min.split(",")[1]|float - y_offset %} + {% set max_x = mesh_config.mesh_max.split(",")[0]|float - x_offset %} + {% set max_y = mesh_config.mesh_max.split(",")[1]|float - y_offset %} + + # make sure probe coordinates lie within the configured mesh area + {% set x_start = [[x_start, max_x]|min, min_x]|max %} + {% set y_start = [[y_start, max_y]|min, min_y]|max %} + + RESPOND MSG="_PROBE_FOR_PRIMING: Probing the prime location at X: {x_start} Y: {y_start}" + + # Absolute positioning + G90 + # Relative extrusion + M83 + # Lift to horizontal_move_z + G0 Z{z} F{z_speed} + # move close to blob position + G1 X{x_start} Y{y_start} F{speed} + _PROBE_CURRENT_POSITION + _SAVE_PROBE_RESULT VARIABLE=probe_for_priming_result + RESTORE_GCODE_STATE NAME=probe_for_priming_state + +[gcode_macro _SAVE_PROBE_RESULT] +gcode: + {% set debug = printer["gcode_macro _BLOB_PURGE_SETTINGS"].debug %} + {% set last_z = printer.probe.last_z_result %} + {% if debug == True %} + {action_respond_info("_SAVE_PROBE_RESULT: last_z: {}".format( + (last_z) + )) } + {% endif %} + SET_GCODE_VARIABLE MACRO=BLOB_PURGE VARIABLE={params.VARIABLE|default('last_z')} VALUE={last_z} + +[gcode_macro _PROBE_CURRENT_POSITION] +gcode: + SAVE_GCODE_STATE NAME=probe_current_position_state + {% set kamp_settings = printer["gcode_macro _KAMP_Settings"] %} # Pull variables from _KAMP_Settings + {% set probe_dock_enable = kamp_settings.probe_dock_enable | abs %} # Pull probe dockable probe settings from _KAMP_Settings + {% set attach_macro = kamp_settings.attach_macro | string %} # Pull attach probe command from _KAMP_Settings + {% set detach_macro = kamp_settings.detach_macro | string %} # Pull detach probe command from _KAMP_Settings + ; perhaps this can be asserted? + {% if probe_dock_enable %} + ; query the probe state, if triggered, fetch? + {attach_macro} + {% endif %} + PROBE + {% if probe_dock_enable %} + {detach_macro} + {% endif %} + RESTORE_GCODE_STATE NAME=probe_current_position_state MOVE=1 MOVE_SPEED={printer.configfile.settings.stepper_z.homing_speed * 60 | float} + +[gcode_macro _ADD_PRIME_PROBE_TO_OFFSET] +gcode: + {% set debug = printer["gcode_macro _BLOB_PURGE_SETTINGS"].debug %} + {% set last_z = printer["gcode_macro BLOB_PURGE"].probe_for_priming_result|float(9999.9) %} + {% if printer.configfile.settings.bltouch is defined %} + {% set z_offset = printer.configfile.settings.bltouch.z_offset|float %} + {% elif printer.configfile.settings.probe is defined %} + {% set z_offset = printer.configfile.settings.probe.z_offset|float %} + {% else %} + { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } + {% endif %} + {% if last_z == 9999.9 %} + { action_raise_error("No probe result found for prime area. This is likely a bug.") } + {% endif %} + {% if debug == True %} + { action_respond_info("last_z: {}, z_offset: {}".format( + (last_z), + (z_offset), + )) } + {% endif %} + {% set adjustment = last_z - z_offset %} + {% set adjustment_threshold = printer["gcode_macro _BLOB_PURGE_SETTINGS"].adaptive_prime_offset_threshold|float %} + {% if adjustment < adjustment_threshold %} + { action_raise_error("Abnormal probe offset detected. Needed offset of {} is below the offset threshold of -1mm. Please verify the probe is over the bed when probing for priming. If it isn't, you should adjust you min/max bed_mesh settings so the probe is always over the print area.".format( + (adjustment) + )) } + {% endif %} + RESPOND MSG="_ADD_PRIME_PROBE_TO_OFFSET: adjusting z offset by {adjustment}." + SET_GCODE_OFFSET Z_ADJUST={adjustment} MOVE=1 + +[gcode_macro _SUBTRACT_PRIME_PROBE_FROM_OFFSET] +gcode: + {% set last_z = printer["gcode_macro BLOB_PURGE"].probe_for_priming_result|float(9999.9) %} + {% if printer.configfile.settings.bltouch is defined %} + {% set z_offset = printer.configfile.settings.bltouch.z_offset|float %} + {% elif printer.configfile.settings.probe is defined %} + {% set z_offset = printer.configfile.settings.probe.z_offset|float %} + {% else %} + { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } + {% endif %} + {% if last_z == 9999.9 %} + { action_raise_error("No probe result found for prime area. This is likely a bug.") } + {% endif %} + {% set adjustment = z_offset - last_z %} + RESPOND MSG="_SUBTRACT_PRIME_PROBE_FROM_OFFSET: adjusting z offset by {adjustment}" + SET_GCODE_OFFSET Z_ADJUST={adjustment} MOVE=1 diff --git a/Configuration/KAMP_Settings.cfg b/Configuration/KAMP_Settings.cfg index 7b3b0be..cc5456d 100644 --- a/Configuration/KAMP_Settings.cfg +++ b/Configuration/KAMP_Settings.cfg @@ -3,6 +3,7 @@ #[include ./KAMP/Adaptive_Meshing.cfg] # Include to enable adaptive meshing configuration. #[include ./KAMP/Line_Purge.cfg] # Include to enable adaptive line purging configuration. #[include ./KAMP/Voron_Purge.cfg] # Include to enable adaptive Voron logo purging configuration. +#[include ./KAMP/Blob_Purge.cfg] # Include to enable adaptive blog purging configuration. #[include ./KAMP/Smart_Park.cfg] # Include to enable the Smart Park function, which parks the printhead near the print area for final heating. [gcode_macro _KAMP_Settings]