Skip to content

Commit

Permalink
WIP: toolchange helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Jan 21, 2024
1 parent 0a67687 commit c3edbdf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
66 changes: 66 additions & 0 deletions macros/toolhead.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
############################################################################################################
#
# Toolhead Selection
#
#############################################################################################################
[gcode_macro _SELECT_TOOL]
gcode:
CALCULATE_PRINTABLE_AREA # NOTE: this will not be updated in here.
{% if params.T is defined %}
{% set idex_mode = '' %}
{% if printer["dual_carriage"] is defined %}
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
{% if "xyz" not in printer.toolhead.homed_axes and (idex_mode == "copy" or idex_mode == "mirror") %}
IDEX_SINGLE
{% set idex_mode = 'reset' %}
{% endif %}
{% endif %}
{% if idex_mode != "copy" and idex_mode != "mirror" %}
{% set act_t = 1 if idex_mode == 'primary' else 0 %}
{% set new_t = params.T|int %}
{% set act_extruder = 'extruder%s' % ('' if new_t == 0 else new_t) %}
{% if new_t != act_t or printer.toolhead.extruder != act_extruder or idex_mode == 'reset' %}

M118 T{new_t} # echo
M220 S100 # reset any speed override from the purge tower

# parameters
{% set printing = params.PRINTING|default(0)|int %}
{% set z_hop = params.Z|default(0.0)|float %}
{% set new_x = params.X|default(-1)|float %}
{% set new_y = params.Y|default(-1)|float %}
{% set swipe = params.SWIPE|default(1)|int %}
{% if "xyz" not in printer.toolhead.homed_axes %}
{% set swipe = 0 %}
{% endif %}

# swap part cooling fans
{% set fan_speed = printer["fan_generic part_fan_t%s" % act_t].speed %}
{% set sync_fans = printer["gcode_macro RatOS"].toolchange_sync_fans|default(0)|int %}
{% if fan_speed > 0 %}
SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed if (new_t == 0 or sync_fans == 1) else 0}
SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed if (new_t == 1 or sync_fans == 1) else 0}
# Update core Klipper's fan speed to the fan speed of the active toolhead
# Only do this if you have a sacrificial [fan] section
M106.1 S{fan_speed}
{% endif %}

# change toolhead
_TOOLCHANGE T={new_t} X={new_x} Y={new_y} PRINTING={printing} SWIPE={swipe} Z_HOP={z_hop}

# set input shaper
{% set shaper_x_freq = printer["gcode_macro RatOS"].shaper_x_freq %}
{% set shaper_y_freq = printer["gcode_macro RatOS"].shaper_y_freq %}
{% set shaper_x_type = printer["gcode_macro RatOS"].shaper_x_type %}
{% set shaper_y_type = printer["gcode_macro RatOS"].shaper_y_type %}
SET_INPUT_SHAPER SHAPER_FREQ_X={(shaper_x_freq[new_t]|float)} SHAPER_FREQ_Y={(shaper_y_freq[new_t]|float)} SHAPER_TYPE_X={(shaper_x_type[new_t]|lower)} SHAPER_TYPE_Y={(shaper_y_type[new_t]|lower)}

# update global toolhead state
SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE={True if new_t==0 else False}
SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE={True if new_t==1 else False}

G90 # absolute positioning

{% endif %}
{% endif %}
{% endif %}
11 changes: 9 additions & 2 deletions macros/util.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ gcode:

[delayed_gcode RATOS_INIT]
initial_duration: 0.1
gcode:
CALCULATE_PRINTABLE_AREA

[gcode_macro CALCULATE_PRINTABLE_AREA]
gcode:
{% set bed_margin_x = printer["gcode_macro RatOS"].bed_margin_x %}
{% set bed_margin_y = printer["gcode_macro RatOS"].bed_margin_y %}
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=printable_x_max VALUE={printer.toolhead.axis_maximum.x - bed_margin_x[1]}
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=printable_y_max VALUE={printer.toolhead.axis_maximum.y - bed_margin_y[1]}
{% set tool = 0 if printer["gcode_macro T0"].active else 1 %}
{% set max_x = printer.toolhead.axis_maximum if tool == 0 else printer.toolhead.axis_maximum - bed_margin_x[1] %}
{% set max_y = printer.toolhead.axis_maximum.y - bed_margin_y[1]%}
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=printable_x_max VALUE={max_x}
SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=printable_y_max VALUE={max_y}

[gcode_macro CACHE_TOOLHEAD_SETTINGS]
variable_old_accel: 1000
Expand Down

0 comments on commit c3edbdf

Please sign in to comment.