From 8ffee456c7ce4ea0830ea9fec21ec8e35504093d Mon Sep 17 00:00:00 2001 From: Mikkel Schmidt Date: Thu, 25 Jan 2024 02:15:57 +0100 Subject: [PATCH] Macros: implement IDEX support (#162) Adds support for IDEX along with a couple of new features such as homing Y before X, `RATOS_ECHO`, `DEBUG_ENABLE/DISABLE/ECHO` and priming along X instead of Y. --------- Co-authored-by: HelgeKeck --- .github/workflows/ConfiguratorTests.yml | 2 +- homing.cfg | 246 ++++-- macros.cfg | 923 ++++++-------------- macros/filament.cfg | 101 +++ macros/idex/idex.cfg | 354 ++++++++ macros/idex/idex_is.cfg | 342 ++++++++ macros/idex/overrides.cfg | 88 ++ macros/idex/vaoc.cfg | 133 +++ macros/mesh.cfg | 175 ++++ macros/parking.cfg | 64 ++ macros/priming.cfg | 420 +++++++++ macros/toolheads.cfg | 658 ++++++++++++++ macros/user-hooks.cfg | 27 + macros/util.cfg | 196 +++++ printers/base.cfg | 2 +- printers/caramba-hybrid/macros.cfg | 14 +- printers/caramba-idex/macros.cfg | 88 +- printers/caramba/macros.cfg | 9 +- printers/initial-setup.cfg | 10 +- printers/v-core-3/macros.cfg | 9 +- printers/v-core-pro/macros.cfg | 9 +- printers/voron-v24/macros.cfg | 9 +- scripts/idex-generate-belt-tension-graph.sh | 111 +++ scripts/idex-generate-shaper-graph.sh | 231 +++++ sensors/prusa-mini-filament-switch.cfg | 4 +- sensors/prusa-mk3s-filament-switch.cfg | 4 +- shell-macros.cfg | 64 +- 27 files changed, 3467 insertions(+), 826 deletions(-) create mode 100644 macros/filament.cfg create mode 100644 macros/idex/idex.cfg create mode 100644 macros/idex/idex_is.cfg create mode 100644 macros/idex/overrides.cfg create mode 100644 macros/idex/vaoc.cfg create mode 100644 macros/mesh.cfg create mode 100644 macros/parking.cfg create mode 100644 macros/priming.cfg create mode 100644 macros/toolheads.cfg create mode 100644 macros/user-hooks.cfg create mode 100644 macros/util.cfg create mode 100755 scripts/idex-generate-belt-tension-graph.sh create mode 100755 scripts/idex-generate-shaper-graph.sh diff --git a/.github/workflows/ConfiguratorTests.yml b/.github/workflows/ConfiguratorTests.yml index 389ee0f3..4d3faae7 100644 --- a/.github/workflows/ConfiguratorTests.yml +++ b/.github/workflows/ConfiguratorTests.yml @@ -33,7 +33,7 @@ jobs: with: path: "ratos-configurator" repository: Rat-OS/RatOS-configurator - ref: ${{ github.base_ref || github.ref_name }} + ref: "development" - name: Setup Node.js environment uses: actions/setup-node@v4.0.1 diff --git a/homing.cfg b/homing.cfg index 513a51a4..8366ca55 100644 --- a/homing.cfg +++ b/homing.cfg @@ -7,50 +7,111 @@ axes: xyz z_hop: 15 z_hop_speed: 15 gcode: - {% set x_homed = 'x' in printer.toolhead.homed_axes %} - {% set y_homed = 'y' in printer.toolhead.homed_axes %} - {% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %} - {% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %} - {% if safe_home_x is not defined or safe_home_x|lower == 'middle' %} - {% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %} + {% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %} + + {% if printer["dual_carriage"] is defined %} + # reset IDEX mode + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set target_idex_mode = printer["dual_carriage"].carriage_1|lower %} + _IDEX_SINGLE + _SELECT_TOOL T={default_toolhead} TOOLSHIFT=false {% endif %} - {% if safe_home_y is not defined or safe_home_y|lower == 'middle' %} - {% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %} + + # Make stowable probe assertion failures cause an emergency stop + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True + + # Wait for moves to finish + M400 + # Absolute positioning + G90 + + # home printer + {% set X = true if params.X is defined else false %} + {% set Y = true if params.Y is defined else false %} + {% set Z = true if params.Z is defined else false %} + {% if printer["gcode_macro RatOS"].home_y_first|default(false)|lower == 'true' %} + HOME_Y X={X} Y={Y} Z={Z} + HOME_X X={X} Y={Y} Z={Z} + {% else %} + HOME_X X={X} Y={Y} Z={Z} + HOME_Y X={X} Y={Y} Z={Z} {% endif %} - {% set z_probe = printer["gcode_macro RatOS"].z_probe|lower %} - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} - {% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %} - {% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %} + HOME_Z X={X} Y={Y} Z={Z} + + # Reset stowable probe stop on error state + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error} + + {% if printer["dual_carriage"] is defined %} + # restore IDEX mode + {% if target_idex_mode == "copy" %} + _IDEX_COPY + {% elif target_idex_mode == "mirror" %} + _IDEX_MIRROR + {% endif %} + {% endif %} + +[gcode_macro HOME_X] +gcode: + {% set x_homed = 'x' in printer.toolhead.homed_axes %} {% set homing = printer["gcode_macro RatOS"].homing|lower %} {% set homing_x = printer["gcode_macro RatOS"].homing_x|lower %} - {% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %} {% set homing_x = homing_x if homing_x else homing %} - {% set homing_y = homing_y if homing_y else homing %} - {% set prev_stop_on_error = printer["gcode_macro RatOS"].stowable_probe_stop_on_error %} - - # Make stowable probe assertion failures cause an emergency stop - SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE=True + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %} + {% if safe_home_x is not defined or safe_home_x|lower == 'middle' %} + {% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %} + {% endif %} - M400 # Wait for moves to finish - G90 # Absolute positioning + {% set X = true if params.X|lower == 'true' else false %} + {% set Y = true if params.Y|lower == 'true' else false %} + {% set Z = true if params.Z|lower == 'true' else false %} - {% if params.X is defined or params.Y is not defined and params.Z is not defined %} + {% if X or not Y and not Z %} {% if homing_x == 'endstop' %} G28 X {% elif homing_x == 'sensorless' %} + {% if printer["dual_carriage"] is defined %} + { action_emergency_stop("sensorless homing not supported on IDEX!") } + {% endif %} HOME_X_SENSORLESS {% else %} { action_emergency_stop("expected RatOS variable_homing_x to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_x, homing)) } {% endif %} + {% if printer["dual_carriage"] is defined %} + # park secondary toolhead in its parking position instead of the endstop position + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set parking_position = printer["gcode_macro RatOS"].parking_position %} + SET_DUAL_CARRIAGE CARRIAGE={0 if default_toolhead==1 else 1} MODE=PRIMARY + G1 X{parking_position[0 if default_toolhead==1 else 1]} F{speed} + SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} MODE=PRIMARY + {% endif %} {% set x_homed = True %} G0 X{safe_home_x} F{speed} {% endif %} - {% if params.Y is defined or params.X is not defined and params.Z is not defined %} +[gcode_macro HOME_Y] +gcode: + {% set y_homed = 'y' in printer.toolhead.homed_axes %} + {% set homing = printer["gcode_macro RatOS"].homing|lower %} + {% set homing_y = printer["gcode_macro RatOS"].homing_y|lower %} + {% set homing_y = homing_y if homing_y else homing %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %} + {% if safe_home_y is not defined or safe_home_y|lower == 'middle' %} + {% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %} + {% endif %} + + {% set X = true if params.X|lower == 'true' else false %} + {% set Y = true if params.Y|lower == 'true' else false %} + {% set Z = true if params.Z|lower == 'true' else false %} + + {% if Y or not X and not Z %} {% if homing_y == 'endstop' %} G28 Y {% elif homing_y == 'sensorless' %} + {% if printer["dual_carriage"] is defined %} + { action_emergency_stop("sensorless homing not supported on IDEX!") } + {% endif %} HOME_Y_SENSORLESS {% else %} { action_emergency_stop("expected RatOS variable_homing_y to be 'sensorless' 'endstop' or variable_homing to be 'sensorless' or 'endstops' but found {} and {}".format(homing_y, homing)) } @@ -59,10 +120,29 @@ gcode: G0 Y{safe_home_y} F{speed} {% endif %} - {% if params.Z is defined or params.Y is not defined and params.X is not defined %} - RESPOND MSG="Homing Z" +[gcode_macro HOME_Z] +gcode: + {% set x_homed = 'x' in printer.toolhead.homed_axes %} + {% set y_homed = 'y' in printer.toolhead.homed_axes %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set z_hop = printer.configfile.config.ratos_homing.z_hop|float %} + {% set z_hop_speed = printer.configfile.config.ratos_homing.z_hop_speed|float * 60 %} + {% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %} + {% if safe_home_x is not defined or safe_home_x|lower == 'middle' %} + {% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %} + {% endif %} + {% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %} + {% if safe_home_y is not defined or safe_home_y|lower == 'middle' %} + {% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %} + {% endif %} + + {% set X = true if params.X|lower == 'true' else false %} + {% set Y = true if params.Y|lower == 'true' else false %} + {% set Z = true if params.Z|lower == 'true' else false %} + + {% if Z or not Y and not X %} + RATOS_ECHO MSG="Homing Z" {% if x_homed == False or y_homed == False %} - M118 X and Y must be homed before homing Z { action_emergency_stop("X and Y must be homed before homing Z") } {% else %} {% if z_probe == "stowable" %} @@ -78,12 +158,10 @@ gcode: {% endif %} {% endif %} {% endif %} - - # Reset stowable probe stop on error state - SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=stowable_probe_stop_on_error VALUE={prev_stop_on_error} [gcode_macro HOME_X_SENSORLESS] gcode: + CACHE_TOOLHEAD_SETTINGS {% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %} {% if safe_home_x is not defined or safe_home_x|lower == 'middle' %} {% set safe_home_x = printer.toolhead.axis_maximum.x / 2 %} @@ -137,11 +215,11 @@ gcode: {% endif %} # Wait for currents to settle G4 P300 - # Restore acceleration - M204 S{printer.configfile.config.printer.max_accel} + RESTORE_TOOLHEAD_SETTINGS [gcode_macro HOME_Y_SENSORLESS] gcode: + CACHE_TOOLHEAD_SETTINGS {% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %} {% if safe_home_y is not defined or safe_home_y|lower == 'middle' %} {% set safe_home_y = printer.toolhead.axis_maximum.y / 2 %} @@ -195,62 +273,60 @@ gcode: {% endif %} # Wait for currents to settle G4 P300 - # Restore acceleration - M204 S{printer.configfile.config.printer.max_accel} + RESTORE_TOOLHEAD_SETTINGS [gcode_macro MAYBE_HOME] description: Only home unhomed axis variable_is_kinematic_position_overriden: False gcode: - {% if printer["gcode_macro MAYBE_HOME"].is_kinematic_position_overriden|lower == 'true' %} - RESPOND MSG="SET_CENTER_KINEMATIC_POSITION has been abused. Homing all axes. Please refrain from using SET_CENTER_KINEMATIC_POSITION outside of debugging purposes." - G28 - SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=False - {% else %} - {% set axes = '' %} - {% set isHomed = true %} - {% set axesToHome = '' %} - {% if params.X is defined %} - {% set axes = axes ~ 'X ' %} - {% if 'x' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'X ' %} - {% endif %} - {% endif %} - {% if params.Y is defined %} - {% set axes = axes ~ 'Y ' %} - {% if 'y' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'Y ' %} - {% endif %} - {% endif %} - {% if params.Z is defined %} - {% set axes = axes ~ 'Z ' %} - {% if 'z' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'Z ' %} - {% endif %} - {% endif %} - {% if params.X is not defined and params.Y is not defined and params.Z is not defined %} - {% set axes = '' %} - {% if 'x' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'X ' %} - {% endif %} - {% if 'y' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'Y ' %} - {% endif %} - {% if 'z' not in printer.toolhead.homed_axes %} - {% set isHomed = false %} - {% set axesToHome = axesToHome ~ 'Z ' %} - {% endif %} - {% endif %} - {% if isHomed is false %} - M117 Homing {axesToHome} - RESPOND MSG="Homing {axesToHome}" - G28 {axesToHome} - {% else %} - RESPOND MSG="All requested axes already homed, skipping.." - {% endif %} - {% endif %} + {% if printer["gcode_macro MAYBE_HOME"].is_kinematic_position_overriden|lower == 'true' %} + RATOS_ECHO MSG="SET_CENTER_KINEMATIC_POSITION has been abused. Homing all axes. Please refrain from using SET_CENTER_KINEMATIC_POSITION outside of debugging purposes." + G28 + SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=False + {% else %} + {% set axes = '' %} + {% set isHomed = true %} + {% set axesToHome = '' %} + {% if params.X is defined %} + {% set axes = axes ~ 'X ' %} + {% if 'x' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'X ' %} + {% endif %} + {% endif %} + {% if params.Y is defined %} + {% set axes = axes ~ 'Y ' %} + {% if 'y' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'Y ' %} + {% endif %} + {% endif %} + {% if params.Z is defined %} + {% set axes = axes ~ 'Z ' %} + {% if 'z' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'Z ' %} + {% endif %} + {% endif %} + {% if params.X is not defined and params.Y is not defined and params.Z is not defined %} + {% set axes = '' %} + {% if 'x' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'X ' %} + {% endif %} + {% if 'y' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'Y ' %} + {% endif %} + {% if 'z' not in printer.toolhead.homed_axes %} + {% set isHomed = false %} + {% set axesToHome = axesToHome ~ 'Z ' %} + {% endif %} + {% endif %} + {% if isHomed is false %} + RATOS_ECHO MSG="Homing {axesToHome}" + G28 {axesToHome} + {% else %} + RATOS_ECHO MSG="All requested axes already homed, skipping.." + {% endif %} + {% endif %} diff --git a/macros.cfg b/macros.cfg index 7adeff4c..89198307 100644 --- a/macros.cfg +++ b/macros.cfg @@ -3,77 +3,9 @@ # sections into your printer.cfg and change it there. ##### -# CONFIGURATION VARIABLES +# INCLUDE MACRO FILES ##### - -[gcode_macro ECHO_RATOS_VARS] -description: Echo RatOS variables to the console. -gcode: - {% for var, value in printer["gcode_macro RatOS"].items() %} - {action_respond_info(var ~ ": " ~ value)} - {% endfor %} - -[gcode_macro RatOS] -description: RatOS variable storage macro, will echo variables to the console when run. -# Configuration Defaults -# This is only here to make the config backwards compatible. -# Configuration should exclusively happen in printer.cfg. -variable_relative_extrusion: False -variable_force_absolute_position: False -variable_preheat_extruder: True -variable_preheat_extruder_temp: 150 -variable_calibrate_bed_mesh: True -variable_nozzle_priming: "primeblob" -variable_nozzle_prime_start_x: "max" # min, max or number -variable_nozzle_prime_start_y: "min" # min, max or number -variable_nozzle_prime_direction: "auto" # auto, forwards, backwards -variable_nozzle_prime_bridge_fan: 102 -variable_filament_unload_length: 130 -variable_filament_unload_speed: 5 -variable_filament_load_length: 100 -variable_filament_load_speed: 10 -variable_start_print_park_in: "back" -variable_start_print_park_z_height: 50 -variable_start_print_heat_chamber_bed_temp: 115 -variable_end_print_park_in: "back" -variable_pause_print_park_in: "back" -variable_macro_travel_speed: 150 -variable_macro_travel_accel: 2000 -variable_macro_z_speed: 15 -variable_end_print_park_z_hop: 20 -# Possible values: 'sensorless' or 'endstops'. -variable_homing: "endstops" -variable_sensorless_x_current: 0.6 -variable_sensorless_y_current: 0.9 -# Possible values: 'static' or 'stowable' -variable_z_probe: "static" -# Possible Values: 'middle' or an absolute x coordinate -variable_safe_home_x: "middle" -# Possible Values: 'middle' or an absolute y coordinate -variable_safe_home_y: "middle" -variable_stowable_probe_stop_on_error: False -variable_driver_type_x: "tmc2209" -variable_driver_type_y: "tmc2209" -variable_adaptive_mesh: False -variable_probe_for_priming_result: None -variable_probe_for_priming_end_result: None -variable_adaptive_prime_offset_threshold: -1.0 -variable_bed_margin_x: [0, 0] -variable_bed_margin_y: [0, 0] -variable_printable_x_min: 0 -variable_printable_x_max: 0 -variable_printable_y_min: 0 -variable_printable_y_max: 0 -gcode: - ECHO_RATOS_VARS - -[delayed_gcode RATOS_INIT] -initial_duration: 0.1 -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]} +[include macros/*.cfg] ##### # GENERAL MACROS @@ -87,10 +19,8 @@ gcode: SAVE_GCODE_STATE NAME=PAUSE_state # Define park positions {% set E = printer["gcode_macro PAUSE"].extrude|float %} - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set accel = printer["gcode_macro RatOS"].macro_travel_accel %} - {% set old_accel = printer.toolhead.max_accel %} - {% set old_decel = printer.toolhead.max_accel_to_decel %} + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} # Calculate safe Z position {% set max_z = printer.toolhead.axis_maximum.z|float %} @@ -100,7 +30,6 @@ gcode: {% else %} {% set z_safe = max_z - current_z %} {% endif %} - M204 S{accel} PAUSE_BASE G91 # Retract @@ -116,15 +45,22 @@ gcode: {% else %} {action_respond_info("Printer not homed")} {% endif %} - M204 S{old_accel} + RESTORE_TOOLHEAD_SETTINGS [gcode_macro RESUME] description: Resumes the print if the printer is paused. rename_existing: RESUME_BASE gcode: + {% set can_extrude = printer['extruder'].can_extrude|lower %} + {% if printer["dual_carriage"] is defined %} + # IDEX + {% if printer.toolhead.extruder == 'extruder1' %} + {% set can_extrude = printer['extruder1'].can_extrude|lower %} + {% endif %} + {% endif %} {% set E = printer["gcode_macro PAUSE"].extrude|float %} # Prime - {% if printer.extruder.can_extrude|lower == 'true' %} + {% if can_extrude == 'true' %} G91 G1 E{E} F2100 G90 @@ -143,246 +79,115 @@ gcode: CLEAR_PAUSE #SDCARD_RESET_FILE CANCEL_PRINT_BASE + +##### +# START PRINT MACROS +# Call this from your slicer (custom g-code). +# Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers +##### -[gcode_macro PRIME_LINE] -description: Prints a primeline, used internally, if configured, as part of the START_PRINT macro. -gcode: - RESPOND MSG="Prime line has been discontinued, switching to prime blob.." - PRIME_BLOB - -[gcode_macro PRIME_BLOB] -description: Prints a primeblob, used internally, if configured, as part of the START_PRINT macro. Slower than PRIME_LINE but much more effective. -gcode: - SAVE_GCODE_STATE NAME=prime_blob_state - M117 Priming nozzle with prime blob.. - RESPOND MSG="Priming nozzle with prime blob.." - {% set bed_margin_x = printer["gcode_macro RatOS"].bed_margin_x %} - {% set bed_margin_y = printer["gcode_macro RatOS"].bed_margin_y %} - {% set has_start_offset = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) != 9999.9 %} - {% set has_end_offset = printer["gcode_macro RatOS"].probe_for_priming_end_result|float(9999.9) != 9999.9 %} - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set accel = printer["gcode_macro RatOS"].macro_travel_accel %} - {% set old_accel = printer.toolhead.max_accel %} - {% set old_decel = printer.toolhead.max_accel_to_decel %} - {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} - {% set fan_speed = printer["gcode_macro RatOS"].nozzle_prime_bridge_fan|float %} - {% set nozzle_diameter = printer.configfile.settings.extruder.nozzle_diameter|float %} - {% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %} - {% set x_start = 5 %} - {% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %} - {% set x_start = printer["gcode_macro RatOS"].printable_x_max - 5 %} - {% else %} - {% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %} - {% endif %} - {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} - {% set y_start = 5 %} - {% set y_factor = 1 %} - {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} - {% set y_start = printer["gcode_macro RatOS"].printable_y_max - 5 %} - {% set y_factor = -1 %} - {% else %} - {% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %} - {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|float < printer["gcode_macro RatOS"].printable_y_max / 2 %} - {% set y_factor = 1 %} - {% else %} - {% set y_factor = -1 %} +[gcode_macro START_PRINT] +description: Start print procedure, use this in your Slicer. +variable_is_printing_gcode: False # used for toolchange macros to know if we are printing gcode and not just in the priming phase +variable_both_toolheads: True # used for toolchange macros +gcode: + # get ratos settings + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set z_probe_stowable = printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} + {% set start_print_heat_chamber_bed_temp = printer["gcode_macro RatOS"].start_print_heat_chamber_bed_temp|default(0.0)|float %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + + # get macro parameters + {% set X0 = params.X0|default(-1)|float %} + {% set X1 = params.X1|default(-1)|float %} + {% set Y0 = params.Y0|default(-1)|float %} + {% set Y1 = params.Y1|default(-1)|float %} + {% set initial_tool = params.INITIAL_TOOL|default(default_toolhead)|int %} + {% set chamber_temp = params.CHAMBER_TEMP|default(0.0)|float %} + {% set bed_temp = params.BED_TEMP|default(printer.heater_bed.target, true)|float %} + {% set extruder_temp = params.EXTRUDER_TEMP|default(printer.extruder.target, true) %} + {% set extruder_temp_1 = params.EXTRUDER_TEMP_1|default(0, true)|float %} + {% set extruder_other_layer_temp = params.EXTRUDER_OTHER_LAYER_TEMP|default(0, true)|float %} + {% set extruder_other_layer_temp_1 = params.EXTRUDER_OTHER_LAYER_TEMP_1|default(0, true)|float %} + + # reset 0 state + SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=False + + # update mainsail UI + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE=True + {% if printer["dual_carriage"] is defined %} + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE=True + {% endif %} + {% if params.COLOR is defined and params.COLOR_1 is defined %} + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=color VALUE='"{params.COLOR|string}"' + {% if printer["dual_carriage"] is defined %} + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=color VALUE='"{params.COLOR_1|string}"' {% endif %} {% endif %} - {% if printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'forwards' %} - {% set y_factor = 1 %} - {% elif printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'backwards' %} - {% set y_factor = -1 %} + + # this parameter is created by the post processing script, if the script isnt used we assume both heads will be needed + {% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %} + SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=both_toolheads VALUE={both_toolheads} + + # cache some values for the layer change macro + {% if printer["dual_carriage"] is defined %} + SET_GCODE_VARIABLE MACRO=_LAYER_CHANGE VARIABLE=layer_number VALUE=1 + SET_GCODE_VARIABLE MACRO=_LAYER_CHANGE VARIABLE=t VALUE={initial_tool} + SET_GCODE_VARIABLE MACRO=_LAYER_CHANGE VARIABLE=extruder_other_layer_temp VALUE={extruder_other_layer_temp} + SET_GCODE_VARIABLE MACRO=_LAYER_CHANGE VARIABLE=extruder_other_layer_temp_1 VALUE={extruder_other_layer_temp_1} + {% endif %} + + # IDEX mode + {% set idex_mode = '' %} + {% if printer["dual_carriage"] is defined %} + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + _IDEX_SINGLE X={printer["gcode_macro RatOS"].parking_position[default_toolhead]} {% endif %} - {% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %} - - {% set start_z_offset = 0 %} - {% set end_z_offset = 0 %} - {% if has_start_offset %} - {% set start_z_probe_result = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) %} - {% set end_z_probe_result = printer["gcode_macro RatOS"].probe_for_priming_end_result|float(9999.9) %} - {% if printer.configfile.settings.bltouch is not defined and printer.configfile.settings.probe is not defined and printer.configfile.settings.beacon is not defined %} - { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } - {% endif %} - {% if start_z_probe_result == 9999.9 %} - { action_raise_error("No start probe result found for prime area. This is likely a bug.") } - {% endif %} - {% if end_z_probe_result == 9999.9 %} - { action_raise_error("No end probe result found for prime area. This is likely a bug.") } - {% endif %} - {% set adjustment_threshold = printer["gcode_macro RatOS"].adaptive_prime_offset_threshold|float %} - {% if start_z_probe_result < adjustment_threshold %} - { action_raise_error("Abnormal probe offset detected. Needed offset of {start_adjustment} 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.") } - {% endif %} - {% if end_z_probe_result < adjustment_threshold %} - { action_raise_error("Abnormal probe offset detected. Needed offset of {end_adjustment} 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.") } - {% endif %} - {% set start_z_offset = start_z_probe_result %} - {% set end_z_offset = end_z_probe_result %} + {% if both_toolheads and (idex_mode == "copy" or idex_mode == "mirror") %} + { action_raise_error("Gcode tool changes found. Copy and mirror mode do not support toolchanges.")} + {% endif %} + {% if idex_mode == "copy" or idex_mode == "mirror" %} + {% set both_toolheads = true %} {% endif %} - # Absolute positioning - G90 - M204 S{accel} - # 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 bed - G1 X{x_start} F{speed} - G1 Y{y_start + (15 * y_factor)} F{speed} - # Lower to blob extrusion height - G1 Z{0.5 + start_z_offset} F{z_speed} - # Move to final position horizontally - G1 Y{y_start} F{speed} - # Extrude a blob (split in two moves to avoid thresholds) - G1 F300 E{10 / ((0.4 / nozzle_diameter) ** 2)} - G1 F300 E{10 / ((0.4 / nozzle_diameter) ** 2)} - # 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 F3000 Y{y_start + (15 * y_factor)} E{1 / ((0.4 / nozzle_diameter) ** 2)} - # 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 F3000 Y{y_start + (20 * y_factor)} Z{3.8 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} - G1 F3000 Y{y_start + (34 * y_factor)} Z{2.6 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} - G1 F3000 Y{y_start + (38 * y_factor)} Z{1.4 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} - G1 F3000 Y{y_start + (42 * y_factor)} Z{0.2 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} - # 0% fan - M106 S0 - # small wipe line - G1 F3000 Y{y_start + (46 * y_factor)} Z{0.2 + end_z_offset} E0.6 - # Break away wipe - G1 F{speed} Y{y_start + (50 * y_factor)} - M204 S{old_accel} - RESTORE_GCODE_STATE NAME=prime_blob_state - -[gcode_macro _PARK] -gcode: - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set accel = printer["gcode_macro RatOS"].macro_travel_accel %} - {% set old_accel = printer.toolhead.max_accel %} - {% set old_decel = printer.toolhead.max_accel_to_decel %} - # Get X position - {% if params.X != '' %} - {% if params.X|float >= printer.toolhead.axis_minimum.x + 5 and params.X|float <= printer.toolhead.axis_maximum.x - 5 %} - {% set safe_x = params.X|float %} + # IDEX copy and mirror mode sanity check + {% if idex_mode == "copy" or idex_mode == "mirror" %} + {% set min_x = X0 %} + {% set max_x = X1 %} + {% if params.MIN_X is defined and params.MAX_X is defined %} + {% set min_x = params.MIN_X|default(-1)|float %} # params.MIN_X | bounding box value | post processor + {% set max_x = params.MAX_X|default(-1)|float %} # params.MAX_X | bounding box value | post processor + {% endif %} + {% set safe_distance = printer.configfile.settings.dual_carriage.safe_distance|float %} + {% if min_x >= 0 and max_x >= 0 %} + {% if idex_mode == "copy" %} + {% if max_x - min_x > center_x %} + { action_raise_error("Object is too big for copy mode! Max supported width is %s mm" % (center_x)) } + {% endif %} + {% elif idex_mode == "mirror" %} + {% if max_x - min_x > center_x - safe_distance / 2 %} + { action_raise_error("Object is too big for mirror mode! Max supported width is %s mm" % (center_x - safe_distance / 2)) } + {% endif %} + {% endif %} {% else %} - {action_respond_info('The requested X co-ordinate is outside the defined axis bounds - using defaults')} - {% set safe_x = printer["gcode_macro RatOS"].printable_x_max / 2 %} + { action_raise_error("No print area coordinates found! Please add the X0, X1, Y0 and Y1 parameter to your start print gcode.") } {% endif %} - {% else %} - {% set safe_x = printer["gcode_macro RatOS"].printable_x_max / 2 %} - {% endif %} - # Get Y position - {% if params.LOCATION|default('back')|lower == 'back' %} - {% set y = printer.toolhead.axis_maximum.y - 5 %} - {% elif params.LOCATION|lower == 'front' %} - {% set y = printer.toolhead.axis_minimum.y + 5 %} - {% elif params.LOCATION|lower == 'center' %} - {% set y = printer["gcode_macro RatOS"].printable_y_max / 2 %} {% endif %} - # Absolute positioning - G90 - # Park - M204 S{accel} - G0 X{safe_x} Y{y} F{speed} - M204 S{old_accel} - -##### -# COLOR CHANGE -##### -[gcode_macro M600] -description: Executes a color change by pausing the printer an unloading the filament. -gcode: - PAUSE - UNLOAD_FILAMENT - M117 Please load new filament and resume - RESPOND MSG="Please load new filament and resume" -##### -# FILAMENT MANAGEMENT -##### - -[gcode_macro UNLOAD_FILAMENT] -description: Unloads the filament. Note: be careful with PETG, make sure you inspect the tip of your filament before reloading to avoid jams. -gcode: - SAVE_GCODE_STATE NAME=unload_state - G91 - {% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %} - M117 Heating... - # Heat up hotend to provided temp or 220 as default as that should work OK with most filaments. - M104 S{params.TEMP|default(220, true)} - TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)} - {% endif %} - {% set unload_speed = printer["gcode_macro RatOS"].filament_unload_speed|float * 60 %} - {% set unload_length = printer["gcode_macro RatOS"].filament_unload_length|float %} - M117 Unloading filament... - # Extrude a bit - G0 E10 F300 - # Extract filament to cold end area - G0 E-5 F3600 - # Wait for three seconds - G4 P3000 - # Push back the filament to smash any stringing - G0 E5 F3600 - # Extract back fast in to the cold zone - G0 E-15 F3600 - # Continue extraction slowly, allow the filament time to cool solid before it reaches the gears - G0 E-{unload_length} F{unload_speed} - M117 Filament unloaded! - RESPOND MSG="Filament unloaded! Please inspect the tip of the filament before reloading." - RESTORE_GCODE_STATE NAME=unload_state - -[gcode_macro LOAD_FILAMENT] -description: Loads new filament. Note: be careful with PETG, make sure you inspect the tip of your filament before loading to avoid jams. -gcode: - SAVE_GCODE_STATE NAME=load_state - G91 - # Heat up hotend to provided temp or 220 as default as that should work OK with most filaments. - {% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %} - M117 Heating... - M104 S{params.TEMP|default(220, true)} - TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.TEMP|default(220, true)} - {% endif %} - {% set load_speed = printer["gcode_macro RatOS"].filament_load_speed|float * 60 %} - {% set load_length = printer["gcode_macro RatOS"].filament_load_length|float %} - M117 Loading filament... - # Load the filament into the hotend area. - G0 E{load_length} F{load_speed} - # Wait a secod - G4 P1000 - # Purge - G0 E40 F100 - # Wait for purge to complete - M400 - M117 Filament loaded! - RESPOND MSG="Filament loaded!" - RESTORE_GCODE_STATE NAME=load_state - -[gcode_macro SET_CENTER_KINEMATIC_POSITION] -description: FOR DEBUGGING PURPOSES ONLY. Sets the internal printer kinematic state to the center of all axes regardless of actual physical position. -gcode: - RESPOND MSG="WARNING: ONLY USE SET_CENTER_KINEMATIC_POSITION FOR DEBUGGING PURPOSES. YOU'RE OVERRIDING THE INTERNAL POSITIONING STATE OF THE PRINTER. PROCEED WITH CAUTION AND DO A PROPER G28 WHEN DONE." - SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=True - SET_KINEMATIC_POSITION X={printer["gcode_macro RatOS"].printable_x_max / 2} Y={printer["gcode_macro RatOS"].printable_y_max / 2} Z={printer.toolhead.axis_maximum.z / 2} - -##### -# START PRINT MACROS -# Call this from your slicer (custom g-code). -# Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers -##### + # reset toolhead offset + {% if printer["dual_carriage"] is defined %} + {% if idex_mode == '' %} + _SET_TOOLHEAD_OFFSET T={default_toolhead} MOVE={1 if "xyz" in printer.toolhead.homed_axes else 0} + {% endif %} + {% endif %} -[gcode_macro START_PRINT] -description: Start print procedure, use this in your Slicer. -gcode: - CLEAR_PAUSE + # start + CLEAR_PAUSE # clear pause state {% if printer["gcode_macro RatOS"].force_absolute_position|lower == 'true' %} - G90 + G90 {% endif %} - SAVE_GCODE_STATE NAME=start_print_state + SAVE_GCODE_STATE NAME=start_print_state # save gcode state # Metric values G21 # Absolute positioning @@ -390,129 +195,210 @@ gcode: # Set extruder to absolute mode M82 _USER_START_PRINT_BEFORE_HOMING - {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} - STOWABLE_PROBE_BEGIN_BATCH + # handle stowable probe + {% if z_probe_stowable == true %} + STOWABLE_PROBE_BEGIN_BATCH {% endif %} # Home if needed MAYBE_HOME - {% if params.CHAMBER_TEMP is defined %} - _START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={params.CHAMBER_TEMP} BED_TEMP={printer["gcode_macro RatOS"].start_print_heat_chamber_bed_temp} - _USER_START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={params.CHAMBER_TEMP} BED_TEMP={printer["gcode_macro RatOS"].start_print_heat_chamber_bed_temp} + # move toolhead to the oozeguard + {% if idex_mode != '' %} + PARK_TOOLHEAD + {% endif %} + {% if chamber_temp > 0 %} + _START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={chamber_temp} BED_TEMP={start_print_heat_chamber_bed_temp} + _USER_START_PRINT_HEAT_CHAMBER CHAMBER_TEMP={chamber_temp} BED_TEMP={start_print_heat_chamber_bed_temp} {% endif %} M117 Heating bed... RESPOND MSG="Heating bed..." # Wait for bed to heat up - M190 S{params.BED_TEMP|default(printer.heater_bed.target, true) } + M190 S{bed_temp} # Run the user created "AFTER_HEATING_BED" macro _USER_START_PRINT_AFTER_HEATING_BED # Run the customizable "AFTER_HEATING_BED" macro. - _START_PRINT_AFTER_HEATING_BED + _START_PRINT_AFTER_HEATING_BED T={initial_tool} BOTH_TOOLHEADS={both_toolheads} # Run the user created "START_PRINT_BED_MESH" macro - _USER_START_PRINT_BED_MESH + _USER_START_PRINT_BED_MESH X0={X0} X1={X1} Y0={Y0} Y1={Y1} # Run the customizable "BED_MESH" macro - _START_PRINT_BED_MESH X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1} - {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} - STOWABLE_PROBE_END_BATCH + _START_PRINT_BED_MESH X0={X0} X1={X1} Y0={Y0} Y1={Y1} T={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} + # handle stowable probe + {% if z_probe_stowable == true %} + STOWABLE_PROBE_END_BATCH + {% endif %} + # cool down the preheated probing toolhead if not needed for printing + {% if idex_mode != '' %} + {% if not both_toolheads %} + {% if initial_tool != default_toolhead %} + M104 S{0} T{default_toolhead} + {% endif %} + {% endif %} {% endif %} # Start heating extruder - M104 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) } + {% if idex_mode == '' %} + M104 S{extruder_temp} + {% else %} + {% if t == 0 or both_toolheads %} + M104 S{extruder_temp} T0 + {% endif %} + {% if t == 1 or both_toolheads %} + M104 S{extruder_temp_1|default(printer.extruder1.target, true)} T1 + {% endif %} + {% endif %} # Run the users "PARK" macro _USER_START_PRINT_PARK # Run the customizable "PARK" macro _START_PRINT_PARK # Wait for extruder to heat up - M117 Heating Extruder... - RESPOND MSG="Heating Extruder..." - M109 S{params.EXTRUDER_TEMP|default(printer.extruder.target, true) } + RATOS_ECHO MSG="Heating Extruder..." + {% if idex_mode == '' %} + M109 S{extruder_temp} + {% else %} + {% if initial_tool == 0 or both_toolheads %} + M109 S{extruder_temp} T0 + {% endif %} + {% if initial_tool == 1 or both_toolheads %} + M109 S{extruder_temp_1|default(printer.extruder1.target, true) } T1 + {% endif %} + {% endif %} # Run the user created "AFTER_HEATING_EXTRUDER" macro. - _USER_START_PRINT_AFTER_HEATING_EXTRUDER X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1} + _USER_START_PRINT_AFTER_HEATING_EXTRUDER X0={X0} X1={X1} Y0={Y0} Y1={Y1} # Run the customizable "AFTER_HEATING_EXTRUDER" macro. - _START_PRINT_AFTER_HEATING_EXTRUDER X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1} + _START_PRINT_AFTER_HEATING_EXTRUDER X0={X0} X1={X1} Y0={Y0} Y1={Y1} INITIAL_TOOLHEAD={initial_tool} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} M117 Printing... RESPOND MSG="Printing..." - RESTORE_GCODE_STATE NAME=start_print_state + {% if idex_mode != '' %} + # cache x offset + {% set x_offset = printer.toolhead.position.x|float - printer.gcode_move.gcode_position.x|float %} + {% endif %} + # restore gcode state + RESTORE_GCODE_STATE NAME=start_print_state + {% if idex_mode != '' %} + # restore x offset + {% set act_idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %} + {% if act_idex_mode == "copy" or act_idex_mode == "mirror" %} + SET_GCODE_OFFSET X={x_offset} MOVE=0 + {% endif %} + {% endif %} + # restore IDEX mode + {% if idex_mode != '' %} + {% if idex_mode == "copy" or idex_mode == "mirror" %} + {% if idex_mode == "copy" and idex_mode != act_idex_mode %} + _IDEX_COPY DANCE=0 + {% elif idex_mode == "mirror" and idex_mode != act_idex_mode %} + _IDEX_MIRROR DANCE=0 + {% endif %} + {% else %} + _SELECT_TOOL T={initial_tool} TOOLSHIFT=false + {% if initial_tool != default_toolhead %} + _SET_TOOLHEAD_OFFSET T={initial_tool} MOVE=1 + {% endif %} + {% endif %} + {% endif %} # Set extrusion mode based on user configuration {% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %} - M83 + M83 {% else %} - M82 + M82 {% endif %} - G92 E0 + # set is_printing_gcode state + SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=True + # reset extrusion distance + G92 E0 ##### # START PRINT MACRO HOOKS # You can copy these to printer.cfg and modify them to your liking, or just use them as is. #### -[gcode_macro _USER_START_PRINT_BEFORE_HOMING] -gcode: - [gcode_macro _START_PRINT_AFTER_HEATING_BED] gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} - -[gcode_macro _USER_START_PRINT_AFTER_HEATING_BED] -gcode: -[gcode_macro _START_PRINT_BED_MESH] +[gcode_macro _START_PRINT_AFTER_HEATING_EXTRUDER] gcode: - {% set default_profile = printer["gcode_macro RatOS"].bed_mesh_profile|default('ratos') %} - {% if printer["gcode_macro RatOS"].calibrate_bed_mesh|lower == 'true' %} - BED_MESH_CLEAR - {% if printer["gcode_macro RatOS"].adaptive_mesh|lower == 'true' %} - CALIBRATE_ADAPTIVE_MESH PROFILE={default_profile} X0={params.X0} X1={params.X1} Y0={params.Y0} Y1={params.Y1} + # config + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + + # parameter + {% set X0 = params.X0|default(-1)|int %} + {% set Y1 = params.Y1|default(-1)|int %} + {% set idex_mode = params.IDEX_MODE|default('')|lower %} + {% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %} + {% set initial_toolhead = params.INITIAL_TOOLHEAD|default(default_toolhead)|int %} + + {% if idex_mode == '' %} + # COREXY - HYBRID + _PRIME + {% else %} + # IDEX + {% if idex_mode == "copy" or idex_mode == "mirror" %} + RATOS_ECHO PREFIX="IDEX" MSG="using combined prime offset for IDEX {idex_mode} mode" + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} {% else %} - BED_MESH_CALIBRATE PROFILE={default_profile} + {% if both_toolheads %} + {% if initial_toolhead == 0 %} + RATOS_ECHO PREFIX="IDEX" MSG="using prime offset for T1" + _SELECT_TOOL T=1 TOOLSHIFT=false + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} + RATOS_ECHO PREFIX="IDEX" MSG="using prime offset for T0" + _SELECT_TOOL T=0 TOOLSHIFT=false + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} + {% else %} + RATOS_ECHO PREFIX="IDEX" MSG="using prime offset for T0" + _SELECT_TOOL T=0 TOOLSHIFT=false + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} + RATOS_ECHO PREFIX="IDEX" MSG="using prime offset for T1" + _SELECT_TOOL T=1 TOOLSHIFT=false + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} + {% endif %} + {% else %} + RATOS_ECHO PREFIX="IDEX" MSG="using prime offset for T{initial_toolhead}" + _SELECT_TOOL T={initial_toolhead} TOOLSHIFT=false + _PRIME INITIAL_TOOLHEAD={initial_toolhead} BOTH_TOOLHEADS={both_toolheads} IDEX_MODE={idex_mode} Y1={Y1} + {% endif %} {% endif %} - BED_MESH_PROFILE LOAD={default_profile} - {% elif printer["gcode_macro RatOS"].bed_mesh_profile is defined %} - BED_MESH_CLEAR - BED_MESH_PROFILE LOAD={printer["gcode_macro RatOS"].bed_mesh_profile} {% endif %} - -[gcode_macro _USER_START_PRINT_BED_MESH] -gcode: -[gcode_macro _START_PRINT_PARK] -gcode: - {% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %} - {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} - _PARK LOCATION={printer["gcode_macro RatOS"].start_print_park_in} X={printer["gcode_macro RatOS"].start_print_park_x} - G0 Z{z} F{z_speed} - -[gcode_macro _USER_START_PRINT_PARK] -gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS -[gcode_macro _START_PRINT_AFTER_HEATING_EXTRUDER] -gcode: - {% set has_start_offset = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) != 9999.9 %} - {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeline' %} - PRIME_LINE + # z-hop after priming + {% if idex_mode != "copy" and idex_mode != "mirror" %} + G0 Z3 F{z_speed} {% endif %} - {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeblob' %} - PRIME_BLOB + + # move to print area + {% if idex_mode == "mirror" %} + G0 Y{Y1} F{speed} {% endif %} - {% if has_start_offset %} - G0 Z3 F{z_speed} - G0 X{params.X0} Y{params.Y1} F{speed} + {% if idex_mode != "copy" and idex_mode != "mirror" %} + G0 X{X0} Y{Y1} F{speed} {% endif %} + + RESTORE_TOOLHEAD_SETTINGS + {% if printer["gcode_macro RatOS"].skew_profile is defined %} SKEW_PROFILE LOAD={printer["gcode_macro RatOS"].skew_profile} {% endif %} - -[gcode_macro _USER_START_PRINT_AFTER_HEATING_EXTRUDER] + +[gcode_macro _PRIME] gcode: + {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeline' %} + PRIME_LINE INITIAL_TOOLHEAD={params.INITIAL_TOOLHEAD} BOTH_TOOLHEADS={params.BOTH_TOOLHEADS} IDEX_MODE={params.IDEX_MODE} Y1={params.Y1} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_priming|lower == 'primeblob' %} + PRIME_BLOB INITIAL_TOOLHEAD={params.INITIAL_TOOLHEAD} BOTH_TOOLHEADS={params.BOTH_TOOLHEADS} IDEX_MODE={params.IDEX_MODE} Y1={params.Y1} + {% endif %} [gcode_macro _START_PRINT_HEAT_CHAMBER] description: Uses the extruder sensor to wait for chamber temp. Override the _START_PRINT_HEAT_CHAMBER macro to implement heated chamber handling. @@ -522,17 +408,12 @@ gcode: {% set zSpeed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} G0 Z{z} F{zSpeed} M84 - M117 Heating chamber... - RESPOND MSG="Heating chamber..." + RATOS_ECHO MSG="Heating chamber..." M140 S{params.BED_TEMP} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={params.CHAMBER_TEMP} MAYBE_HOME {% endif %} -[gcode_macro _USER_START_PRINT_HEAT_CHAMBER] -description: Uses the extruder sensor to wait for chamber temp. Override the _START_PRINT_HEAT_CHAMBER macro to implement heated chamber handling. -gcode: - ##### # END PRINT MACROS # Call this from your slicer (custom g-code). @@ -544,6 +425,10 @@ gcode: description: End print procedure, use this in your Slicer. gcode: SAVE_GCODE_STATE NAME=end_print_state + {% if printer["dual_carriage"] is defined %} + # IDEX - reset is_printing_gcode state + SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=False + {% endif %} _USER_END_PRINT_BEFORE_HEATERS_OFF _END_PRINT_BEFORE_HEATERS_OFF TURN_OFF_HEATERS @@ -555,15 +440,22 @@ gcode: {% if printer["gcode_macro RatOS"].skew_profile is defined %} SET_SKEW CLEAR=1 {% endif %} - # Steppers off - M84 + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + M84 + {% endif %} # Part cooling fan off M107 # Clear bed mesh so that G28 doesn't fail. BED_MESH_CLEAR M117 Done :) - RESPOND MSG="Done :)" + RATOS_ECHO MSG="Done :)" RESTORE_GCODE_STATE NAME=end_print_state + {% if printer["dual_carriage"] is defined %} + # IDEX + # for the IDEX we must do this after RESTORE_GCODE_STATE + M84 + {% endif %} ##### # END PRINT MACRO HOOKS @@ -572,11 +464,7 @@ gcode: [gcode_macro _END_PRINT_BEFORE_HEATERS_OFF] gcode: - RESPOND MSG="Cleaning up..." - - -[gcode_macro _USER_END_PRINT_BEFORE_HEATERS_OFF] -gcode: + RATOS_ECHO MSG="Cleaning up..." [gcode_macro _END_PRINT_AFTER_HEATERS_OFF] gcode: @@ -585,9 +473,9 @@ gcode: {% set current_z = printer.toolhead.position.z|float %} {% set z_hop = printer["gcode_macro RatOS"].end_print_park_z_hop|float %} {% if current_z < (max_z - z_hop) %} - {% set z_safe = z_hop %} + {% set z_safe = z_hop %} {% else %} - {% set z_safe = max_z - current_z %} + {% set z_safe = max_z - current_z %} {% endif %} # Relative positioning G91 @@ -599,266 +487,3 @@ gcode: G1 E-2 F3600 # Back to absolute positioning G90 - -[gcode_macro _USER_END_PRINT_AFTER_HEATERS_OFF] -gcode: - -[gcode_macro _END_PRINT_PARK] -gcode: - _PARK LOCATION={printer["gcode_macro RatOS"].end_print_park_in} X={printer["gcode_macro RatOS"].end_print_park_x} - -[gcode_macro _USER_END_PRINT_PARK] -gcode: - -##### -# MESH MACROS -#### - -[gcode_macro SAVE_PROBE_RESULT] -gcode: - {% set last_z_offset = 9999.9 %} - {% if printer.configfile.settings.beacon is defined %} - {% set current_z = printer.toolhead.position.z|float %} - {% set last_z_offset = printer.beacon.last_sample.dist - current_z %} - {% elif printer.configfile.settings.bltouch is defined %} - {% set config_offset = printer.configfile.settings.bltouch.z_offset|float %} - {% set last_z_offset = printer.probe.last_z_result - config_offset %} - {% elif printer.configfile.settings.probe is defined %} - {% set config_offset = printer.configfile.settings.probe.z_offset|float %} - {% set last_z_offset = printer.probe.last_z_result - config_offset %} - {% endif %} - SET_GCODE_VARIABLE MACRO=RatOS VARIABLE={params.VARIABLE|default('last_z_offset')} VALUE={last_z_offset} - -[gcode_macro PROBE_FOR_PRIMING] -gcode: - {% if printer["gcode_macro RatOS"].nozzle_priming|lower != 'false' %} - SAVE_GCODE_STATE NAME=probe_for_priming_state - RESPOND MSG="Probing the prime location.." - {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} - {% set accel = printer["gcode_macro RatOS"].macro_travel_accel %} - {% set old_accel = printer.toolhead.max_accel %} - {% set old_decel = printer.toolhead.max_accel_to_decel %} - {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} - {% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %} - {% set x_start = 5 %} - {% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %} - {% set x_start = printer["gcode_macro RatOS"].printable_x_max - 5 %} - {% else %} - {% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %} - {% endif %} - {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} - {% set y_start = 5 %} - {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} - {% set y_start = printer["gcode_macro RatOS"].printable_y_max - 5 %} - {% else %} - {% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %} - {% endif %} - {% set z = printer.configfile.settings.bed_mesh.horizontal_move_z|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, bltouch or beacon section found. Adaptive priming only works with [probe], [beacon] and [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 - M204 S{accel} - 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 - M204 S{old_accel} - {% set x_end = x_start %} - {% set y_end = y_start + 45 %} - G1 X{x_end} Y{y_end} F{speed} - PROBE_CURRENT_POSITION - SAVE_PROBE_RESULT VARIABLE=probe_for_priming_end_result - - RESTORE_GCODE_STATE NAME=probe_for_priming_state - {% endif %} - -[gcode_macro RESET_PRIME_PROBE_STATE] -gcode: - SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_result VALUE=None - SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_end_result VALUE=None - -[gcode_macro PROBE_CURRENT_POSITION] -gcode: - SAVE_GCODE_STATE NAME=probe_current_position_state - {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} - ASSERT_PROBE_DEPLOYED - {% endif %} - PROBE - {% if printer.configfile.settings.beacon is defined %} - BEACON_QUERY - {% else %} - # Only restore state if we're not using a beacon, so we state at scanning height - RESTORE_GCODE_STATE NAME=probe_current_position_state MOVE=1 MOVE_SPEED={printer["gcode_macro RatOS"].macro_z_speed|float} - {% endif %} - -[gcode_macro ADD_PRIME_PROBE_TO_OFFSET] -gcode: - {% set last_z_offset = printer["gcode_macro RatOS"].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_offset == 9999.9 %} - { action_raise_error("No probe result found for prime area. This is likely a bug.") } - {% endif %} - {% set adjustment = last_z_offset - z_offset %} - {% set adjustment_threshold = printer["gcode_macro RatOS"].adaptive_prime_offset_threshold|float %} - {% if adjustment < adjustment_threshold %} - { action_raise_error("Abnormal probe offset detected. Needed offset of {adjustment} 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.") } - {% 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_offset = printer["gcode_macro RatOS"].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_offset == 9999.9 %} - { action_raise_error("No probe result found for prime area. This is likely a bug.") } - {% endif %} - RESPOND MSG="SUBTRACT_PRIME_PROBE_FROM_OFFSET: adjusting z offset by {z_offset - last_z_offset}" - SET_GCODE_OFFSET Z_ADJUST={z_offset - last_z_offset} MOVE=1 - -[gcode_macro CALIBRATE_ADAPTIVE_MESH] -gcode: - # get default mesh profile - {% set default_profile = params.PROFILE %} - - # coordinates from the slicer start gcode - {% set x0 = params.X0|default(-1)|float %} - {% set y0 = params.Y0|default(-1)|float %} - {% set x1 = params.X1|default(-1)|float %} - {% set y1 = params.Y1|default(-1)|float %} - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Recieved coordinates X0={x0} Y0={y0} X1={x1} Y1={y1}" - - {% if x0 >= x1 or y0 >= y1 %} - # coordinates are invalid, fall back to full bed mesh - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Invalid coordinates received. Please check your slicer settings. Falling back to full bed mesh." - BED_MESH_CALIBRATE PROFILE={default_profile} - {% else %} - # get bed mesh config object - {% set mesh_config = printer.configfile.config.bed_mesh %} - - # get configured bed mesh area - {% set min_x = mesh_config.mesh_min.split(",")[0]|float %} - {% set min_y = mesh_config.mesh_min.split(",")[1]|float %} - {% set max_x = mesh_config.mesh_max.split(",")[0]|float %} - {% set max_y = mesh_config.mesh_max.split(",")[1]|float %} - - # make sure mesh coordinates lie within the configured mesh area - {% set mesh_x0 = [[x0, max_x]|min, min_x]|max %} - {% set mesh_y0 = [[y0, max_y]|min, min_y]|max %} - {% set mesh_x1 = [[x1, max_x]|min, min_x]|max %} - {% set mesh_y1 = [[y1, max_y]|min, min_y]|max %} - - {% if mesh_x0 == min_x and mesh_y0 == min_y and mesh_x1 == max_x and mesh_y1 == max_y %} - # coordinates are invalid, fall back to full bed mesh - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: Print is using the full bed, falling back to full bed mesh." - BED_MESH_CALIBRATE PROFILE={default_profile} - {% else %} - {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} - DEPLOY_PROBE - {% endif %} - # get configured probe count - {% set probe_count_x = mesh_config.probe_count.split(",")[0]|int %} - {% if mesh_config.probe_count.split(",")|length == 2 %} - {% set probe_count_y = mesh_config.probe_count.split(",")[1]|int %} - {% else %} - {% set probe_count_y = mesh_config.probe_count.split(",")[0]|int %} - {% endif %} - - # calculate mesh point resolution - {% set probe_x_step = (max_x - min_x) / probe_count_x %} - {% set probe_y_step = (max_y - min_y) / probe_count_y %} - - # calculate xy probe count - {% set mesh_count_x = ([(mesh_x1 - mesh_x0) / probe_x_step, 3]|max)|int %} - {% set mesh_count_y = ([(mesh_y1 - mesh_y0) / probe_y_step, 3]|max)|int %} - {% set min_mesh_count = [mesh_count_x, mesh_count_y]|min %} - {% set max_mesh_count = [mesh_count_x, mesh_count_y]|max %} - - # check algorithms - {% set algorithm = mesh_config.algorithm %} - {% if algorithm|lower == 'lagrange' and max_mesh_count > 6 %} - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: cannot exceed a probe_count of 6 when using lagrange interpolation. Falling back to bicubic interpolation." - {% set algorithm = 'bicubic' %} - {% endif %} - {% if algorithm|lower == 'bicubic' and min_mesh_count < 4 %} - {% if max_mesh_count > 6 %} - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: invalid probe_count option when using bicubic interpolation. Combination of 3 points on one axis with more than 6 on another is not permitted. Forcing minimum mesh count to be 4." - {% set min_mesh_count = 4 %} - {% else %} - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: bicubic interpolation with a probe_count of less than 4 points detected. Forcing lagrange interpolation." - {% set algorithm = 'lagrange' %} - {% endif %} - {% endif %} - - {% set mesh_count_x = ([min_mesh_count, mesh_count_x]|max)|int %} - {% set mesh_count_x = ([max_mesh_count, mesh_count_x]|min)|int %} - {% set mesh_count_y = ([min_mesh_count, mesh_count_y]|max)|int %} - {% set mesh_count_y = ([max_mesh_count, mesh_count_y]|min)|int %} - - {% set should_prime = printer["gcode_macro RatOS"].nozzle_priming == 'primeline' or printer["gcode_macro RatOS"].nozzle_priming == 'primeblob' %} - {% set probe_first = printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == "min" or printer["gcode_macro RatOS"].nozzle_prime_start_y|float(printer["gcode_macro RatOS"].printable_y_max) < printer["gcode_macro RatOS"].printable_y_max / 2 %} - - {% if printer.configfile.settings.beacon is defined and printer.configfile.settings.beacon.mesh_runs % 2 != 0 and probe_first %} - {% set probe_first = false %} - {% elif printer.configfile.settings.beacon is defined and printer.configfile.settings.beacon.mesh_runs % 2 == 0 and not probe_first %} - {% set probe_first = true %} - {% endif %} - {% if should_prime and probe_first %} - PROBE_FOR_PRIMING - {% endif %} - # mesh - RESPOND MSG="CALIBRATE_ADAPTIVE_MESH: mesh coordinates X0={mesh_x0} Y0={mesh_y0} X1={mesh_x1} Y1={mesh_y1}" - BED_MESH_CALIBRATE PROFILE={default_profile} algorithm={algorithm} mesh_min={mesh_x0},{mesh_y0} mesh_max={mesh_x1},{mesh_y1} probe_count={mesh_count_x},{mesh_count_y} relative_reference_index=-1 - - {% if should_prime and not probe_first %} - PROBE_FOR_PRIMING - {% endif %} - {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} - STOW_PROBE - {% endif %} - - {% endif %} - {% endif %} diff --git a/macros/filament.cfg b/macros/filament.cfg new file mode 100644 index 00000000..b021f5b8 --- /dev/null +++ b/macros/filament.cfg @@ -0,0 +1,101 @@ +[gcode_macro LOAD_FILAMENT] +description: Loads new filament. Note: be careful with PETG, make sure you inspect the tip of your filament before loading to avoid jams. +gcode: + SAVE_GCODE_STATE NAME=load_state + G91 + {% set temp = params.TEMP|default(220)|int %} + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + RATOS_ECHO MSG="Heating..." + M104 S{temp} + TEMPERATURE_WAIT SENSOR=extruder MINIMUM={temp} + _LOAD_FILAMENT + {% else %} + # IDEX + {% set t = params.TOOLHEAD|default(-1)|int %} + {% if t==0 or t==1 %} + {% set old_extruder = printer.toolhead.extruder %} + RATOS_ECHO MSG="Heating Extruder T{t}..." # response + M104 S{temp} T{t} + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if t==0 else t} + TEMPERATURE_WAIT SENSOR=extruder{'' if t==0 else t} MINIMUM={temp} + _LOAD_FILAMENT + ACTIVATE_EXTRUDER EXTRUDER={old_extruder} + {% else %} + RATOS_ECHO MSG="Please select toolhead! 0 = left, 1 = right toolhead" + {% endif %} + {% endif %} + RESTORE_GCODE_STATE NAME=load_state + +[gcode_macro _LOAD_FILAMENT] +gcode: + {% set load_speed = printer["gcode_macro RatOS"].filament_load_speed|float * 60 %} + {% set load_length = printer["gcode_macro RatOS"].filament_load_length|float %} + RATOS_ECHO MSG="Loading filament..." + # Load the filament into the hotend area. + G0 E{load_length} F{load_speed} + # Wait a second + G4 P1000 + # Purge + G0 E40 F100 + # Wait for purge to complete + M400 + RATOS_ECHO MSG="Filament loaded!" + +[gcode_macro UNLOAD_FILAMENT] +description: Unloads the filament. Note: be careful with PETG, make sure you inspect the tip of your filament before reloading to avoid jams. +gcode: + SAVE_GCODE_STATE NAME=unload_state + G91 + {% set temp = params.TEMP|default(220)|int %} + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + RATOS_ECHO MSG="Heating..." + M104 S{temp} + TEMPERATURE_WAIT SENSOR=extruder MINIMUM={temp} + _UNLOAD_FILAMENT + {% else %} + # IDEX + {% set t = params.TOOLHEAD|default(-1)|int %} + {% if t==0 or t==1 %} + {% set old_extruder = printer.toolhead.extruder %} + RATOS_ECHO MSG="Heating Extruder T{t}..." # response + M104 S{temp} T{t} + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if t==0 else t} + TEMPERATURE_WAIT SENSOR=extruder{'' if t==0 else t} MINIMUM={temp} + _UNLOAD_FILAMENT + ACTIVATE_EXTRUDER EXTRUDER={old_extruder} + {% else %} + RATOS_ECHO MSG="Please select toolhead! 0 = left, 1 = right toolhead" + {% endif %} + {% endif %} + RESTORE_GCODE_STATE NAME=unload_state + +[gcode_macro _UNLOAD_FILAMENT] +gcode: + {% set unload_speed = printer["gcode_macro RatOS"].filament_unload_speed|float * 60 %} + {% set unload_length = printer["gcode_macro RatOS"].filament_unload_length|float %} + RATOS_ECHO MSG="Unloading filament..." + # Extrude a bit + G0 E10 F300 + # Extract filament to cold end area + G0 E-5 F3600 + # Wait for three seconds + G4 P3000 + # Push back the filament to smash any stringing + G0 E5 F3600 + # Extract back fast in to the cold zone + G0 E-15 F3600 + # Continue extraction slowly, allow the filament time to cool solid before it reaches the gears + G0 E-{unload_length} F{unload_speed} + RATOS_ECHO MSG="Filament unloaded! Please inspect the tip of the filament before reloading." + +##### +# COLOR CHANGE +##### +[gcode_macro M600] +description: Executes a color change by pausing the printer an unloading the filament. +gcode: + PAUSE + UNLOAD_FILAMENT + RATOS_ECHO MSG="Please load new filament and resume" diff --git a/macros/idex/idex.cfg b/macros/idex/idex.cfg new file mode 100644 index 00000000..036d77f3 --- /dev/null +++ b/macros/idex/idex.cfg @@ -0,0 +1,354 @@ +[gcode_macro IDEX_SINGLE] +gcode: + _IDEX_SINGLE + +[gcode_macro _IDEX_SINGLE] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set init = params.INIT|default(0)|int %} + {% set new_x = params.X|default(-1)|int %} + + # config + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed * 60 %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set parking_position = printer["gcode_macro RatOS"].parking_position %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + {% set act_t = 1 if idex_mode == 'primary' else 0 %} + + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="init: {init}, new_x: {new_x}, idex_mode: {idex_mode}, max_x: {max_x}, center_x: {center_x}, act_t: {act_t}" + + {% if idex_mode == "copy" or idex_mode == "mirror" or init == 1 %} + + # reset gcode offset + {% if 'x' in printer.toolhead.homed_axes %} + {% if idex_mode == "copy" or idex_mode == "mirror" %} + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="reset gcode offset" + G1 X{center_x} F{(speed)} + SET_GCODE_OFFSET X_ADJUST={center_x / 2} MOVE=0 + {% endif %} + {% endif %} + + # activate default carriage + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="activate default carriage" + SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} MODE=PRIMARY + + # set toolheads + {% if 'x' in printer.toolhead.homed_axes %} + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="set toolheads" + G90 # absolute positioning + + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="move secondary toolhead to parking position." + SET_DUAL_CARRIAGE CARRIAGE={0 if default_toolhead==1 else 1} + G1 X{parking_position[0 if default_toolhead==1 else 1]} F{(speed)} + + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="move default toolhead to its new position." + SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} + {% if new_x == -1 %} + {% set new_x = center_x %} + {% endif %} + G1 X{new_x} F{(speed)} + + M400 # wait for movements + {% else %} + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="X Axis not homed." + # select primary toolhead + SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} + {% endif %} + + # set extruder motion queue + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="set extruder motion queue." + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if default_toolhead==0 else default_toolhead} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder1 + + # set toolhead offset + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="set toolhead offset." + _SET_TOOLHEAD_OFFSET T={default_toolhead} + + # set input shaper + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="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[default_toolhead]|float)} SHAPER_FREQ_Y={(shaper_y_freq[default_toolhead]|float)} SHAPER_TYPE_X={(shaper_x_type[default_toolhead]|lower)} SHAPER_TYPE_Y={(shaper_y_type[default_toolhead]|lower)} + + # update mainsail UI + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="update mainsail UI." + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE={True if default_toolhead==0 else False} + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE={True if default_toolhead==1 else False} + {% else %} + {% if "xyz" in printer.toolhead.homed_axes %} + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="move secondary toolhead to parking position" + SET_DUAL_CARRIAGE CARRIAGE={0 if act_t==1 else 1} + G1 X{parking_position[0 if act_t==1 else 1]} F{(speed)} + SET_DUAL_CARRIAGE CARRIAGE={act_t} + {% else %} + DEBUG_ECHO PREFIX="IDEX_SINGLE" MSG="Axis not homed." + # select primary toolhead + SET_DUAL_CARRIAGE CARRIAGE={default_toolhead} + {% endif %} + {% endif %} + RESTORE_TOOLHEAD_SETTINGS + +[gcode_macro IDEX_COPY] +gcode: + _IDEX_COPY + +[gcode_macro _IDEX_COPY] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set y = params.Y|default(-1)|int %} + {% set dance = params.DANCE|default(1)|int %} + + # config + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed * 60 %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + + DEBUG_ECHO PREFIX="IDEX_COPY" MSG="idex_mode: {idex_mode}, max_x: {max_x}, center_x: {center_x}, dance: {dance}, y: {y}" + + # set idex mode + {% if "xyz" in printer.toolhead.homed_axes %} + {% if idex_mode != "copy" %} + {% if idex_mode == "mirror" %} + {% if y>=0 %} + G1 X{center_x} Y{y} F{(speed)} + {% else %} + G1 X{center_x} F{(speed)} + {% endif %} + {% endif %} + + {% if idex_mode == "primary" or idex_mode == "inactive" %} + _IDEX_SET_TOOLHEADS + {% endif %} + + # set extruder motion queue + ACTIVATE_EXTRUDER EXTRUDER='extruder' + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder + + # activate copy mode + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY + + # sync pressure advance + {% if idex_mode != "mirror" %} + SET_PRESSURE_ADVANCE + {% endif %} + + # set toolhead offset + {% if idex_mode != "mirror" %} + SET_GCODE_OFFSET X_ADJUST=-{center_x / 2} MOVE=0 + {% else %} + _SET_TOOLHEAD_OFFSET T={default_toolhead} + {% endif %} + + # dance + {% if dance == 1 %} + G1 X{center_x} F{(speed)} + G1 X{center_x - 30} F{(speed)} + G1 X{center_x + 30} F{(speed)} + G1 X{center_x} F{(speed)} + {% endif %} + + # 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[2]|float)} SHAPER_FREQ_Y={(shaper_y_freq[2]|float)} SHAPER_TYPE_X={(shaper_x_type[2]|lower)} SHAPER_TYPE_Y={(shaper_y_type[2]|lower)} + + # update mainsail UI + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE=True + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE=True + + {% endif %} + {% else %} + {action_respond_info("Printer not homed")} + {% endif %} + RESTORE_TOOLHEAD_SETTINGS + +[gcode_macro IDEX_MIRROR] +gcode: + _IDEX_MIRROR + +[gcode_macro _IDEX_MIRROR] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set dance = params.DANCE|default(1)|int %} + {% set priming = params.PRIMING|default(0)|int %} + + # config + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed * 60 %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + + DEBUG_ECHO PREFIX="IDEX_MIRROR" MSG="idex_mode: {idex_mode}, max_x: {max_x}, center_x: {center_x}, dance: {dance}" + + # set idex mode + {% if "xyz" in printer.toolhead.homed_axes %} + {% if idex_mode != "mirror" %} + + {% if idex_mode == "copy" %} + G1 X{center_x} F{(speed)} + {% endif %} + + {% if idex_mode == "primary" or idex_mode == "inactive" %} + _IDEX_SET_TOOLHEADS MIRROR_PRIMING={params.PRIMING} + {% endif %} + + # set extruder motion queue + ACTIVATE_EXTRUDER EXTRUDER='extruder' + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder + + # activate mirror mode + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=MIRROR + + # sync pressure advance + {% if idex_mode != "copy" %} + SET_PRESSURE_ADVANCE + {% endif %} + + # set toolhead offset + {% if idex_mode != "copy" %} + SET_GCODE_OFFSET X_ADJUST=-{center_x / 2} MOVE=0 + {% else %} + _SET_TOOLHEAD_OFFSET T={default_toolhead} + {% endif %} + + # dance + {% if dance and not priming %} + G1 X{center_x} F{(speed)} + G1 X{center_x - 30} F{(speed)} + G1 X{center_x + 30} F{(speed)} + G1 X{center_x} F{(speed)} + {% endif %} + + # 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[3]|float)} SHAPER_FREQ_Y={(shaper_y_freq[3]|float)} SHAPER_TYPE_X={(shaper_x_type[3]|lower)} SHAPER_TYPE_Y={(shaper_y_type[3]|lower)} + + # update mainsail UI + SET_GCODE_VARIABLE MACRO=T0 VARIABLE=active VALUE=True + SET_GCODE_VARIABLE MACRO=T1 VARIABLE=active VALUE=True + + {% endif %} + {% else %} + {action_respond_info("Printer not homed")} + {% endif %} + RESTORE_TOOLHEAD_SETTINGS + +[gcode_macro _IDEX_SET_TOOLHEADS] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set mirror_priming = params.MIRROR_PRIMING|default(0)|int %} + + # idex mode + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set act_t = 1 if idex_mode == 'primary' else 0 %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + + # config + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed * 60 %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set parking_position = printer["gcode_macro RatOS"].parking_position %} + + DEBUG_ECHO PREFIX="_IDEX_SET_TOOLHEADS" MSG="idex_mode: {idex_mode}, act_t: {act_t}, center_x: {center_x}, mirror_priming: {mirror_priming}" + + # reset toolhead offset + {% if act_t != default_toolhead %} + _SET_TOOLHEAD_OFFSET T={default_toolhead} MOVE=1 + {% endif %} + + # make sure inactive toolhead is in its parking position + {% if not mirror_priming %} + SET_DUAL_CARRIAGE CARRIAGE={0 if act_t==1 else 1} MODE=PRIMARY + G1 X{parking_position[0 if act_t==1 else 1]} F{(speed)} + {% endif %} + + # move dc toolhead to its new position in case its already active + {% if act_t==1 and not mirror_priming %} + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{center_x / 2 + center_x} F{(speed)} + {% endif %} + + # move x toolhead to its new position + {% if not mirror_priming %} + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + G1 X{center_x / 2} F{(speed)} + {% endif %} + + # move dc toolhead to its new position + {% if not mirror_priming %} + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{center_x / 2 + center_x} F{(speed)} + {% endif %} + + # fix parking position offset + {% if mirror_priming %} + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{max_x + parking_position[0]|abs} F{(speed)} + {% endif %} + + RESTORE_TOOLHEAD_SETTINGS + +[gcode_macro IDEX_PARK] +gcode: + # ensures compatibility with users of helges mainsail fork + PARK_TOOLHEAD + +[gcode_macro PARK_TOOLHEAD] +gcode: + # get IDEX mode + {% set idex_mode = 'none' %} + {% if printer["dual_carriage"] is defined %} + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% endif %} + {% set act_t = 1 if idex_mode=='primary' else 0 %} + + DEBUG_ECHO PREFIX="PARK_TOOLHEAD" MSG="Parking T{act_t}.." + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set acceleration = printer["gcode_macro RatOS"].toolchange_travel_accel %} + {% set home = printer["gcode_macro RatOS"].parking_position %} + + # park toolhead + {% if idex_mode != "copy" and idex_mode != "mirror" and 'x' in printer.toolhead.homed_axes %} + SAVE_GCODE_STATE NAME=_PARK_TOOLHEAD + G90 # absolute positioning + SET_VELOCITY_LIMIT ACCEL={acceleration} ACCEL_TO_DECEL={(acceleration/2)} + + # move both toolheads to parking position + G1 X{home[act_t]} F{(speed)} + SET_DUAL_CARRIAGE CARRIAGE={0 if act_t==1 else 1} + G1 X{home[0 if act_t==1 else 1]} F{(speed)} + SET_DUAL_CARRIAGE CARRIAGE={act_t} + + SET_VELOCITY_LIMIT ACCEL={printer.toolhead.max_accel} ACCEL_TO_DECEL={(printer.toolhead.max_accel/2)} + M400 # wait for movements + RESTORE_GCODE_STATE NAME=_PARK_TOOLHEAD + {% endif %} diff --git a/macros/idex/idex_is.cfg b/macros/idex/idex_is.cfg new file mode 100644 index 00000000..c7dd5a30 --- /dev/null +++ b/macros/idex/idex_is.cfg @@ -0,0 +1,342 @@ +##### +# IS MACROS +#### +[gcode_macro GENERATE_SHAPER_GRAPHS] +description: Genarates input shaper resonances graphs for analysis. Uses the AXIS, TOOLHEAD, FREQUNECY_START and FREQUENCY_END parameter if you want to do specific measurements, (eg. GENERATE_SHAPER_GRAPHS AXIS=X TOOLHEAD=0 FREQUENCY_START=10 FREQUENCY_END=20) +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set measure_t0 = true %} + {% set measure_t1 = true %} + {% if params.TOOLHEAD is defined %} + {% if params.TOOLHEAD|lower == '0' %} + {% set measure_t1 = false %} + {% elif params.TOOLHEAD|lower == '1' %} + {% set measure_t0 = false %} + {% else %} + {action_raise_error("Unknown toolhead specified. Expected 0 or 1 (left or right)")} + {% endif %} + {% endif %} + {% set axis = params.AXIS|default('')|lower %} + {% set freq_start = params.FREQUENCY_START|default(10)|int %} + {% set freq_end = params.FREQUENCY_END|default(133)|int %} + {% set hz_per_sec = params.HZ_PER_SEC|default(1)|float %} + + # config + {% set idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %} + {% set act_t = 1 if idex_mode == 'primary' else 0 %} + {% set svv = printer.save_variables.variables %} + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set home = printer["gcode_macro RatOS"].parking_position %} + {% set adxl_chip = printer["gcode_macro RatOS"].adxl_chip %} + {% set probe_points = printer.configfile.settings.resonance_tester.probe_points[0] %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + + # home toolheads + MAYBE_HOME + {% if idex_mode == 'copy' %} + _IDEX_COPY DANCE=0 + {% elif idex_mode == 'mirror' %} + _IDEX_MIRROR DANCE=0 + {% else %} + _IDEX_SINGLE + {% endif %} + G90 + + # input shaping + {% if axis != '' %} + {% if axis == 'x' %} + {% if idex_mode == 'copy' or idex_mode == 'mirror' %} + {% if idex_mode == 'copy' %} + _IDEX_COPY DANCE=0 + {% elif idex_mode == 'mirror' %} + _IDEX_MIRROR DANCE=0 + {% endif %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if idex_mode == 'copy' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% elif idex_mode == 'mirror' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + {% else %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if measure_t0 == true %} + _SELECT_TOOL T=0 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[1]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[0]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + G4 P5000 + {% if measure_t0 == true and measure_t1 == false %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == false and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == true and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 2 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + RATOS_ECHO MSG="Input shaper graph generated for the X axis. You'll find it in the input_shaper folder in the machine tab!" + {% elif axis == 'y' %} + {% if idex_mode == 'copy' or idex_mode == 'mirror' %} + {% if idex_mode == 'copy' %} + _IDEX_COPY DANCE=0 + {% elif idex_mode == 'mirror' %} + _IDEX_MIRROR DANCE=0 + {% endif %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if idex_mode == 'copy' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% elif idex_mode == 'mirror' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + {% else %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if measure_t0 == true %} + _SELECT_TOOL T=0 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[1]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[0]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + G4 P5000 + {% if measure_t0 == true and measure_t1 == false %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == false and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == true and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 2 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + RATOS_ECHO MSG="Input shaper graph generated for the Y axis. You'll find it in the input_shaper folder in the machine tab!" + {% else %} + {action_raise_error("Unknown axis specified. Expected X or Y.")} + {% endif %} + {% else %} + {% if idex_mode == 'copy' or idex_mode == 'mirror' %} + {% if idex_mode == 'copy' %} + _IDEX_COPY DANCE=0 + {% elif idex_mode == 'mirror' %} + _IDEX_MIRROR DANCE=0 + {% endif %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if idex_mode == 'copy' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1_copy FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 1 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% elif idex_mode == 'mirror' %} + {% if measure_t0 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1_mirror FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0] - center_x / 2},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% if measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 2 %s %s %s" % ('%0.3f'|format(probe_points[0] - center_x / 2), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + {% else %} + G1 X{probe_points[0]} Y{probe_points[1]} F{speed} + {% if measure_t0 == true %} + _SELECT_TOOL T=0 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[1]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[0]} NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + {% if measure_t1 == true %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[0]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]} NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} HZ_PER_SEC={hz_per_sec} POINT={probe_points[0]},{probe_points[1]},{probe_points[2]} + {% endif %} + G4 P5000 + {% if measure_t0 == true and measure_t1 == false %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 0 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 0 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == false and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 1 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 1 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% elif measure_t0 == true and measure_t1 == true %} + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"x 2 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + RUN_SHELL_COMMAND CMD=generate_shaper_graphs PARAMS="{"y 2 0 %s %s %s" % ('%0.3f'|format(probe_points[0]), '%0.3f'|format(probe_points[1]), '%0.3f'|format(probe_points[2]))}" + {% endif %} + {% endif %} + RATOS_ECHO MSG="Input shaper graphs generated for X and Y. You'll find them in the input_shaper folder in the machine tab!" + {% endif %} + + RESTORE_TOOLHEAD_SETTINGS + +[gcode_shell_command generate_shaper_graphs] +command: /home/pi/printer_data/config/RatOS/scripts/idex-generate-shaper-graph.sh +timeout: 120. +verbose: True + +[gcode_macro MEASURE_COREXY_BELT_TENSION] +description: Generates resonance graph used to ensure belts are equally tensioned. Uses the AXIS, TOOLHEAD, FREQUNECY_START and FREQUENCY_END parameter if you want to do specific measurements, (eg. GENERATE_SHAPER_GRAPHS AXIS=X TOOLHEAD=0 FREQUENCY_START=10 FREQUENCY_END=20) +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameters + {% set measure_t0 = true %} + {% set measure_t1 = true %} + {% if params.TOOLHEAD is defined %} + {% if params.TOOLHEAD|lower == '0' %} + {% set measure_t1 = false %} + {% elif params.TOOLHEAD|lower == '1' %} + {% set measure_t0 = false %} + {% else %} + {action_raise_error("Unknown toolhead specified. Expected 0 or 1 (left or right)")} + {% endif %} + {% endif %} + {% set freq_start = params.FREQUENCY_START|default(10)|int %} + {% set freq_end = params.FREQUENCY_END|default(133)|int %} + + # config + {% set idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %} + {% set svv = printer.save_variables.variables %} + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set home = printer["gcode_macro RatOS"].parking_position %} + {% set adxl_chip = printer["gcode_macro RatOS"].adxl_chip %} + {% set probe_points = printer.configfile.settings.resonance_tester.probe_points[0] %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + + # home toolheads + MAYBE_HOME + _IDEX_SINGLE + G90 + + {% if params.AXIS is defined %} + {% if params.AXIS|lower == 'x' %} + {% if measure_t1 == true %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[0]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} OUTPUT=raw_data NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} + {% endif %} + {% if measure_t0 == true %} + _SELECT_TOOL T=0 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[1]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} OUTPUT=raw_data NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} + {% endif %} + G4 P5000 + {% if measure_t1 == true and measure_t0 == false %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="x 1" + {% elif measure_t1 == false and measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="x 0" + {% elif measure_t1 == true and measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS=x + {% endif %} + RATOS_ECHO MSG="Belt tension graph generated for X and/or Y. You'll find them in the input_shaper folder in the machine tab!" + {% elif params.AXIS|lower == 'y' %} + {% if measure_t1 == false or measure_t0 == false %} + {action_raise_error("Axis specified. Not supported for belt tension on Y.")} + {% else %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={home[1]} Y={probe_points[0]} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]},{adxl_chip[0]} OUTPUT=raw_data NAME=t2 POINT={home[1]},{probe_points[1]},{probe_points[2]} FREQ_START={freq_start} FREQ_END={freq_end} + G4 P5000 + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="y 2" + RATOS_ECHO MSG="Belt tension graph generated for X and/or Y. You'll find them in the input_shaper folder in the machine tab!" + {% endif %} + {% else %} + {action_raise_error("Unknown axis specified. Expected X or Y.")} + {% endif %} + {% else %} + {% if measure_t1 == true %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[0]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[1]} OUTPUT=raw_data NAME=t1 FREQ_START={freq_start} FREQ_END={freq_end} + {% endif %} + {% if measure_t0 == true %} + _SELECT_TOOL T=0 TOOLSHIFT=false X={probe_points[0]} Y={probe_points[1]} + TEST_RESONANCES AXIS=X CHIPS={adxl_chip[0]} OUTPUT=raw_data NAME=t0 FREQ_START={freq_start} FREQ_END={freq_end} + {% endif %} + {% if params.TOOLHEAD is not defined %} + _SELECT_TOOL T=1 TOOLSHIFT=false X={home[1]} Y={probe_points[0]} + G1 X{home[1]} F{speed} + TEST_RESONANCES AXIS=Y CHIPS={adxl_chip[1]},{adxl_chip[0]} OUTPUT=raw_data NAME=t2 POINT={home[1]},{probe_points[1]},{probe_points[2]} FREQ_START={freq_start} FREQ_END={freq_end} + {% endif %} + G4 P5000 + {% if measure_t1 == true and measure_t0 == false %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="x 1" + {% elif measure_t1 == false and measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="x 0" + {% elif measure_t1 == true and measure_t0 == true %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS=x + {% endif %} + {% if params.TOOLHEAD is not defined %} + RUN_SHELL_COMMAND CMD=generate_tension_graphs PARAMS="y 2" + {% endif %} + RATOS_ECHO MSG="Belt tension graph generated for X and/or Y. You'll find them in the input_shaper folder in the machine tab!" + {% endif %} + + RESTORE_TOOLHEAD_SETTINGS + +[gcode_shell_command generate_tension_graphs] +command: /home/pi/printer_data/config/RatOS/scripts/idex-generate-belt-tension-graph.sh +timeout: 120. +verbose: True diff --git a/macros/idex/overrides.cfg b/macros/idex/overrides.cfg new file mode 100644 index 00000000..79c7edd4 --- /dev/null +++ b/macros/idex/overrides.cfg @@ -0,0 +1,88 @@ +[gcode_macro M84] +rename_existing: M84.1 +gcode: + # IDEX + # reset is_printing_gcode state + SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=is_printing_gcode VALUE=False + # reset applied toolhead offset index + _SET_TOOLHEAD_OFFSET T={printer["gcode_macro RatOS"].default_toolhead|int} MOVE=0 + # reset offsets + # this is a temporarily safety measurement and very anoying + # to ensure we start the next print with known offsets + # the anoying part is that when you do live first layer z-offset baby steps, + # the value is gone after a M84 and you cant save it + # and probably some other side effects as well + SET_GCODE_OFFSET X=0 Y=0 Z=0 MOVE=0 + M84.1 + +[gcode_macro SET_PRESSURE_ADVANCE] +rename_existing: SET_PRESSURE_ADVANCE_BASE +gcode: + {% set extruder = params.EXTRUDER|default('extruder')|lower %} + {% set advance = params.ADVANCE|default(printer[extruder].pressure_advance|float)|float %} + {% set smooth_time = params.SMOOTH_TIME|default(printer[extruder].smooth_time|float)|float %} + {% if printer[extruder] is defined %} + {% set idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %} + {% if idex_mode == 'copy' or idex_mode == 'mirror' %} + RATOS_ECHO MSG="SET_PRESSURE_ADVANCE T0" + SET_PRESSURE_ADVANCE_BASE EXTRUDER='extruder' ADVANCE={advance} SMOOTH_TIME={smooth_time} + RATOS_ECHO MSG="SET_PRESSURE_ADVANCE T1" + SET_PRESSURE_ADVANCE_BASE EXTRUDER='extruder1' ADVANCE={advance} SMOOTH_TIME={smooth_time} + {% else %} + SET_PRESSURE_ADVANCE_BASE EXTRUDER={extruder} ADVANCE={advance} SMOOTH_TIME={smooth_time} + {% endif %} + {% else %} + RATOS_ECHO MSG="SET_PRESSURE_ADVANCE: Extruder {extruder} not found!" + {% endif %} + +[gcode_macro M106] +# Only rename_existing if you have a sacrificial [fan] section +rename_existing: M106.1 +# The variable that controls fan speed swopping if not specifying P parameter +# -1 means the control is disabled, a value of 0-1 is the requested fan speed. +# Access via {printer["gcode_macro M106"].swap_speed} +variable_swap_speed: -1 +gcode: + # parameters + {% set s = [[params.S|default(255)|int, 255]|min, 0]|max %} + {% set p = params.P|default(-1)|int %} + {% set speed = s / 255 %} + + # get IDEX mode + {% set idex_mode = printer["dual_carriage"].carriage_1|default('')|lower %} + {% set t = 1 if idex_mode=='primary' else 0 %} + {% set sync_fans = true if printer["gcode_macro RatOS"].toolchange_sync_fans|default(0)|int == 1 else false %} + {% if idex_mode == "copy" or idex_mode == "mirror" %} + {% set sync_fans = true %} + {% endif %} + + # Set speed to -1 by default + SET_GCODE_VARIABLE MACRO=M106 VARIABLE=swap_speed VALUE=-1 + + # Set speed + {% if p == -1 %} + # Set current active extruder fan + {% if speed == 0 %} + # Always turn off all fans if S0 is specified without a specific fan + SET_FAN_SPEED FAN=part_fan_t0 SPEED={speed} + SET_FAN_SPEED FAN=part_fan_t1 SPEED={speed} + {% else %} + # Opt into fan speed swop control + SET_GCODE_VARIABLE MACRO=M106 VARIABLE=swap_speed VALUE={speed} + SET_FAN_SPEED FAN=part_fan_t0 SPEED={(speed if (t == 0 or sync_fans) else 0)} + SET_FAN_SPEED FAN=part_fan_t1 SPEED={(speed if (t == 1 or sync_fans) else 0)} + {% endif %} + {% else %} + # Set specified active extruder fan + SET_FAN_SPEED FAN=part_fan_t0 SPEED={speed if t == p else 0} + SET_FAN_SPEED FAN=part_fan_t1 SPEED={speed if t == p else 0} + {% endif %} + + # Update core Klipper's fan speed + M106.1 S{s} + +[gcode_macro M107] +rename_existing: M107.1 +gcode: + {% set p = params.P|default(-1)|int %} + M106 S0 P{p} diff --git a/macros/idex/vaoc.cfg b/macros/idex/vaoc.cfg new file mode 100644 index 00000000..73b90c4e --- /dev/null +++ b/macros/idex/vaoc.cfg @@ -0,0 +1,133 @@ +############################################################################################################# +# +# visual assisted offset calibration macros, called from the mainsail nozzle calibration UI +# +############################################################################################################# +[gcode_macro _NOZZLE_CALIBRATION_LOAD_TOOL] +gcode: + # parameters + {% set t = params.T|default(0)|int %} + + # echo + DEBUG_ECHO PREFIX="_NOZZLE_CALIBRATION_LOAD_TOOL" MSG="T={t}" + + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + + # load toolhead + {% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(150)|float %} + {% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(30)|float %} + {% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %} + RATOS_ECHO PREFIX="VAOC" MSG="Move T{t} to control point: X{idex_xcontrolpoint} Y{idex_ycontrolpoint} Z{idex_zcontrolpoint}" + T{t} X{idex_xcontrolpoint} Y{idex_ycontrolpoint} + G1 Z{idex_zcontrolpoint} F{z_speed} + G1 X{idex_xcontrolpoint} F{speed} + G1 Y{idex_ycontrolpoint} F{speed} + +[gcode_macro _NOZZLE_CALIBRATION_SET_TOOL] +gcode: + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # get IDEX mode + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set toolhead = 1 if idex_mode=='primary' else 0 %} + + {% if toolhead == printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + # set control point + {% set x = printer.toolhead.position.x|float %} + {% set y = printer.toolhead.position.y|float %} + {% set z = printer.toolhead.position.z|float %} + SAVE_VARIABLE VARIABLE=idex_xcontrolpoint VALUE={x} + SAVE_VARIABLE VARIABLE=idex_ycontrolpoint VALUE={y} + SAVE_VARIABLE VARIABLE=idex_zcontrolpoint VALUE={z} + RATOS_ECHO PREFIX="VAOC" MSG="Control point was set: X{x} Y{y} Z{z}" + {% else %} + # set toolhead offset + {% set x = printer.toolhead.position.x|float - svv.idex_xcontrolpoint|float %} + {% set y = printer.toolhead.position.y|float - svv.idex_ycontrolpoint|float %} + {% set z = printer.toolhead.position.z|float - svv.idex_zcontrolpoint|float %} + SAVE_VARIABLE VARIABLE=idex_xoffset VALUE={x} + SAVE_VARIABLE VARIABLE=idex_yoffset VALUE={y} + SAVE_VARIABLE VARIABLE=idex_zoffset VALUE={z} + SET_GCODE_OFFSET X_ADJUST={0-svv.idex_xoffset} Y_ADJUST={0-svv.idex_yoffset} Z_ADJUST={0-svv.idex_zoffset} MOVE=0 + SET_GCODE_OFFSET X_ADJUST={x} Y_ADJUST={y} Z_ADJUST={z} MOVE=0 + RATOS_ECHO PREFIX="VAOC" MSG="T{t} offset was set: X{x} Y{y} Z{z}" + {% endif %} + +[gcode_macro _NOZZLE_CALIBRATION_PROBE_Z_OFFSET] +gcode: + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # config + {% set x_offset = printer["zoffsetprobe"].x_offset|default(0)|float %} + {% set y_offset = printer["zoffsetprobe"].y_offset|default(0)|float %} + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + + # probe z-offset + {% if printer["zoffsetprobe"] is defined %} + {% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(150)|float %} + {% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(30)|float %} + {% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %} + G1 Z{idex_zcontrolpoint} F{z_speed} + G1 X{idex_xcontrolpoint + x_offset} Y{idex_ycontrolpoint + y_offset} F{speed} + Z_OFFSET_PROBE + G0 Z{idex_zcontrolpoint} F{z_speed} + G1 X{idex_xcontrolpoint} Y{idex_ycontrolpoint} F{speed} + UPDATE_DELAYED_GCODE ID=_NOZZLE_CALIBRATION_SET_Z_OFFSET DURATION=0.1 + {% endif %} + +[delayed_gcode _NOZZLE_CALIBRATION_SET_Z_OFFSET] +gcode: + # get IDEX mode + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set toolhead = 1 if idex_mode=='primary' else 0 %} + + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # config + {% set last_z = printer["zoffsetprobe"].last_z_result|default(0)|float %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + + {% if printer["zoffsetprobe"] is defined %} + {% if toolhead == printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + # set control point + RATOS_ECHO PREFIX="VAOC" MSG="Z-offset control point set: {last_z}" + SAVE_VARIABLE VARIABLE=idex_zoffsetcontrolpoint VALUE={last_z} + {% else %} + # set toolhead offset + {% set z = last_z - svv.idex_zoffsetcontrolpoint|float %} + RATOS_ECHO PREFIX="VAOC" MSG="T{t} offset set: Z{z}" + SAVE_VARIABLE VARIABLE=idex_zoffset VALUE={z} + SET_GCODE_OFFSET Z_ADJUST={0-svv.idex_zoffset} MOVE=0 + SET_GCODE_OFFSET Z_ADJUST={z} MOVE=0 + G0 Z{svv.idex_zcontrolpoint|float} F{z_speed} + {% endif %} + {% endif %} + +[gcode_macro _NOZZLE_CALIBRATION_SWITCH_LED] +gcode: + {% if params.STATE|default(0)|int == 1 %} + NOZZLE_CALIBRATION_LIGHT_ON + {% else %} + NOZZLE_CALIBRATION_LIGHT_OFF + {% endif %} + +[gcode_macro NOZZLE_CALIBRATION_LIGHT_ON] +gcode: + {% if printer['neopixel nozzle_calibration_led'] is defined %} + SET_LED LED=nozzle_calibration_led RED=1.0 GREEN=1.0 BLUE=1.0 + {% endif %} + +[gcode_macro NOZZLE_CALIBRATION_LIGHT_OFF] +gcode: + {% if printer['neopixel nozzle_calibration_led'] is defined %} + SET_LED LED=nozzle_calibration_led RED=0.0 GREEN=0.0 BLUE=0.0 + {% endif %} diff --git a/macros/mesh.cfg b/macros/mesh.cfg new file mode 100644 index 00000000..50c4aafe --- /dev/null +++ b/macros/mesh.cfg @@ -0,0 +1,175 @@ +[gcode_macro _START_PRINT_BED_MESH] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + # parameter + {% set idex_mode = params.IDEX_MODE|default('')|lower %} + {% set X=[params.X0|default(-1)|float, params.X1|default(-1)|float] %} + {% set Y=[params.Y0|default(-1)|float, params.Y1|default(-1)|float] %} + + # config + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% if idex_mode == "copy" or idex_mode == "mirror" %} + # in copy and mirror mode we mesh the whole x bed length of the print area + # this is later needed for the live toohlead z-offset compensation + # it should also be used for a sanity check + # we should check if the secondary toolheads z-offset doesnt scratch the bed while shifting the toolheads and eventually raising the z-hop to prevent it + {% set X=[0, max_x] %} + {% endif %} + + # calibrate bed mesh + {% set default_profile = printer["gcode_macro RatOS"].bed_mesh_profile|default('ratos') %} + {% if printer["gcode_macro RatOS"].calibrate_bed_mesh|lower == 'true' %} + BED_MESH_CLEAR + {% if printer["gcode_macro RatOS"].adaptive_mesh|lower == 'true' %} + CALIBRATE_ADAPTIVE_MESH PROFILE={default_profile} X0={X[0]} X1={X[1]} Y0={Y[0]} Y1={Y[1]} T={params.T|int} BOTH_TOOLHEADS={params.BOTH_TOOLHEADS} IDEX_MODE={idex_mode} + {% else %} + BED_MESH_CALIBRATE PROFILE={default_profile} + {% endif %} + BED_MESH_PROFILE LOAD={default_profile} + {% elif printer["gcode_macro RatOS"].bed_mesh_profile is defined %} + BED_MESH_CLEAR + BED_MESH_PROFILE LOAD={printer["gcode_macro RatOS"].bed_mesh_profile} + {% endif %} + RESTORE_TOOLHEAD_SETTINGS + +[gcode_macro CALIBRATE_ADAPTIVE_MESH] +gcode: + # idex mode + {% set idex_mode = params.IDEX_MODE|default('')|lower %} + {% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %} + + # get default mesh profile + {% set default_profile = params.PROFILE %} + + # coordinates from the slicer start gcode + {% set x0 = params.X0|default(-1)|float %} + {% set y0 = params.Y0|default(-1)|float %} + {% set x1 = params.X1|default(-1)|float %} + {% set y1 = params.Y1|default(-1)|float %} + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Recieved coordinates X0={x0} Y0={y0} X1={x1} Y1={y1}" + + {% if x0 >= x1 or y0 >= y1 %} + # coordinates are invalid, fall back to full bed mesh + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Invalid coordinates received. Please check your slicer settings. Falling back to full bed mesh." + BED_MESH_CALIBRATE PROFILE={default_profile} + {% else %} + # get bed mesh config object + {% set mesh_config = printer.configfile.config.bed_mesh %} + + # get configured bed mesh area + {% set min_x = mesh_config.mesh_min.split(",")[0]|float %} + {% set min_y = mesh_config.mesh_min.split(",")[1]|float %} + {% set max_x = mesh_config.mesh_max.split(",")[0]|float %} + {% set max_y = mesh_config.mesh_max.split(",")[1]|float %} + + # make sure mesh coordinates lie within the configured mesh area + {% set mesh_x0 = [[x0, max_x]|min, min_x]|max %} + {% set mesh_y0 = [[y0, max_y]|min, min_y]|max %} + {% set mesh_x1 = [[x1, max_x]|min, min_x]|max %} + {% set mesh_y1 = [[y1, max_y]|min, min_y]|max %} + + {% if mesh_x0 == min_x and mesh_y0 == min_y and mesh_x1 == max_x and mesh_y1 == max_y %} + # coordinates are invalid, fall back to full bed mesh + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Print is using the full bed, falling back to full bed mesh." + BED_MESH_CALIBRATE PROFILE={default_profile} + {% else %} + {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} + DEPLOY_PROBE + {% endif %} + # get configured probe count + {% set probe_count_x = mesh_config.probe_count.split(",")[0]|int %} + {% if mesh_config.probe_count.split(",")|length == 2 %} + {% set probe_count_y = mesh_config.probe_count.split(",")[1]|int %} + {% else %} + {% set probe_count_y = mesh_config.probe_count.split(",")[0]|int %} + {% endif %} + + # calculate mesh point resolution + {% set probe_x_step = (max_x - min_x) / probe_count_x %} + {% set probe_y_step = (max_y - min_y) / probe_count_y %} + + # calculate xy probe count + {% set mesh_count_x = ([(mesh_x1 - mesh_x0) / probe_x_step, 3]|max)|int %} + {% set mesh_count_y = ([(mesh_y1 - mesh_y0) / probe_y_step, 3]|max)|int %} + {% set min_mesh_count = [mesh_count_x, mesh_count_y]|min %} + {% set max_mesh_count = [mesh_count_x, mesh_count_y]|max %} + + # check algorithms + {% set algorithm = mesh_config.algorithm %} + {% if algorithm|lower == 'lagrange' and max_mesh_count > 6 %} + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="cannot exceed a probe_count of 6 when using lagrange interpolation. Falling back to bicubic interpolation." + {% set algorithm = 'bicubic' %} + {% endif %} + {% if algorithm|lower == 'bicubic' and min_mesh_count < 4 %} + {% if max_mesh_count > 6 %} + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="invalid probe_count option when using bicubic interpolation. Combination of 3 points on one axis with more than 6 on another is not permitted. Forcing minimum mesh count to be 4." + {% set min_mesh_count = 4 %} + {% else %} + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="bicubic interpolation with a probe_count of less than 4 points detected. Forcing lagrange interpolation." + {% set algorithm = 'lagrange' %} + {% endif %} + {% endif %} + + {% set mesh_count_x = ([min_mesh_count, mesh_count_x]|max)|int %} + {% set mesh_count_x = ([max_mesh_count, mesh_count_x]|min)|int %} + {% set mesh_count_y = ([min_mesh_count, mesh_count_y]|max)|int %} + {% set mesh_count_y = ([max_mesh_count, mesh_count_y]|min)|int %} + + {% set should_prime = printer["gcode_macro RatOS"].nozzle_priming == 'primeline' or printer["gcode_macro RatOS"].nozzle_priming == 'primeblob' %} + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + {% set probe_first = printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == "min" or printer["gcode_macro RatOS"].nozzle_prime_start_y|float(printer["gcode_macro RatOS"].printable_y_max) < printer["gcode_macro RatOS"].printable_y_max / 2 %} + {% else %} + # IDEX + {% set probe_first = printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == "min" or printer["gcode_macro RatOS"].nozzle_prime_start_y|float(printer.toolhead.axis_maximum.y) < printer.toolhead.axis_maximum.y / 2 %} + {% endif %} + {% if printer.configfile.settings.beacon is defined and printer.configfile.settings.beacon.mesh_runs % 2 != 0 and probe_first %} + {% set probe_first = false %} + {% elif printer.configfile.settings.beacon is defined and printer.configfile.settings.beacon.mesh_runs % 2 == 0 and not probe_first %} + {% set probe_first = true %} + {% endif %} + + # probe for priming + {% if should_prime and probe_first %} + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + PROBE_FOR_PRIMING + {% else %} + # IDEX + {% if both_toolheads %} + PROBE_FOR_PRIMING TOOLHEAD=0 IDEX_MODE={idex_mode} + PROBE_FOR_PRIMING TOOLHEAD=1 IDEX_MODE={idex_mode} + {% else %} + PROBE_FOR_PRIMING TOOLHEAD={params.T|int} IDEX_MODE={idex_mode} + {% endif %} + {% endif %} + {% endif %} + + # mesh + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="mesh coordinates X0={mesh_x0} Y0={mesh_y0} X1={mesh_x1} Y1={mesh_y1}" + BED_MESH_CALIBRATE PROFILE={default_profile} algorithm={algorithm} mesh_min={mesh_x0},{mesh_y0} mesh_max={mesh_x1},{mesh_y1} probe_count={mesh_count_x},{mesh_count_y} relative_reference_index=-1 + + # probe for priming + {% if should_prime and not probe_first %} + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + PROBE_FOR_PRIMING + {% else %} + # IDEX + {% if both_toolheads %} + PROBE_FOR_PRIMING TOOLHEAD=0 IDEX_MODE={idex_mode} + PROBE_FOR_PRIMING TOOLHEAD=1 IDEX_MODE={idex_mode} + {% else %} + PROBE_FOR_PRIMING TOOLHEAD={params.T|int} IDEX_MODE={idex_mode} + {% endif %} + {% endif %} + {% endif %} + + # stow probe + {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} + STOW_PROBE + {% endif %} + + {% endif %} + {% endif %} diff --git a/macros/parking.cfg b/macros/parking.cfg new file mode 100644 index 00000000..fc67492d --- /dev/null +++ b/macros/parking.cfg @@ -0,0 +1,64 @@ +[gcode_macro _START_PRINT_PARK] +gcode: + {% if printer["dual_carriage"] is defined %} + # IDEX + {% if printer["gcode_macro RatOS"].start_print_park_x is defined and printer["gcode_macro RatOS"].start_print_park_x != '' %} + RATOS_ECHO PREFIX="WARNING" MSG="start_print_park_x is ignored for IDEX printers" + {% endif %} + PARK_TOOLHEAD + G90 + {% endif %} + {% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + _PARK LOCATION={printer["gcode_macro RatOS"].start_print_park_in} X={printer["gcode_macro RatOS"].start_print_park_x} + G0 Z{z} F{z_speed} + +[gcode_macro _END_PRINT_PARK] +gcode: + {% if printer["dual_carriage"] is defined %} + # IDEX + {% if printer["gcode_macro RatOS"].end_print_park_x is defined and printer["gcode_macro RatOS"].end_print_park_x != '' %} + RATOS_ECHO PREFIX="WARNING" MSG="end_print_park_x is ignored for IDEX printers" + {% endif %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + _IDEX_SINGLE X={printer["gcode_macro RatOS"].parking_position[default_toolhead]} + PARK_TOOLHEAD + G90 + {% endif %} + _PARK LOCATION={printer["gcode_macro RatOS"].end_print_park_in} X={printer["gcode_macro RatOS"].end_print_park_x} + +[gcode_macro _PARK] +gcode: + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + # Get X position + {% if params.X != '' %} + {% if params.X|float >= printer.toolhead.axis_minimum.x + 5 and params.X|float <= printer.toolhead.axis_maximum.x - 5 %} + {% set safe_x = params.X|float %} + {% else %} + {action_respond_info('The requested X co-ordinate is outside the defined axis bounds - using defaults')} + {% set safe_x = printer["gcode_macro RatOS"].printable_x_max / 2 %} + {% endif %} + {% else %} + {% set safe_x = printer["gcode_macro RatOS"].printable_x_max / 2 %} + {% endif %} + # Get Y position + {% if params.LOCATION|default('back')|lower == 'back' %} + {% set y = printer.toolhead.axis_maximum.y - 5 %} + {% elif params.LOCATION|lower == 'front' %} + {% set y = printer.toolhead.axis_minimum.y + 5 %} + {% elif params.LOCATION|lower == 'center' %} + {% set y = printer["gcode_macro RatOS"].printable_y_max / 2 %} + {% endif %} + # Absolute positioning + G90 + # Park + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + G0 X{safe_x} Y{y} F{speed} + {% else %} + # IDEX + G0 Y{y} F{speed} + {% endif %} + RESTORE_TOOLHEAD_SETTINGS diff --git a/macros/priming.cfg b/macros/priming.cfg new file mode 100644 index 00000000..45ea0c75 --- /dev/null +++ b/macros/priming.cfg @@ -0,0 +1,420 @@ +[gcode_macro SAVE_PROBE_RESULT] +gcode: + {% set last_z_offset = 9999.9 %} + {% if printer.configfile.settings.beacon is defined %} + {% set current_z = printer.toolhead.position.z|float %} + {% set last_z_offset = printer.beacon.last_sample.dist - current_z %} + {% elif printer.configfile.settings.bltouch is defined %} + {% set config_offset = printer.configfile.settings.bltouch.z_offset|float %} + {% set last_z_offset = printer.probe.last_z_result - config_offset %} + {% elif printer.configfile.settings.probe is defined %} + {% set config_offset = printer.configfile.settings.probe.z_offset|float %} + {% set last_z_offset = printer.probe.last_z_result - config_offset %} + {% endif %} + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Saving offset adjustment of {last_z_offset} in {params.VARIABLE|default('last_z_offset')}" + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE={params.VARIABLE|default('last_z_offset')} VALUE={last_z_offset} + +[gcode_macro PROBE_FOR_PRIMING] +gcode: + {% if printer["gcode_macro RatOS"].nozzle_priming|lower != 'false' %} + SAVE_GCODE_STATE NAME=probe_for_priming_state + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Probing the prime location.." + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # parameter + {% set t = params.TOOLHEAD|default(-1)|int %} + {% set idex_mode = params.IDEX_MODE|default('')|lower %} + + # config + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + {% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max %} + + # calculation + {% if idex_mode == '' %} + # COREXY - HYBRID + {% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %} + {% set x_start = 5 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %} + {% set x_start = printer["gcode_macro RatOS"].printable_x_max - 5 %} + {% else %} + {% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} + {% set y_start = 5 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} + {% set y_start = printable_y_max - 5 %} + {% else %} + {% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %} + {% endif %} + {% else %} + # IDEX + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set center_x = max_x / 2 %} + {% if t == 0 %} + {% set x_start = 5 %} + {% else %} + {% set x_start = max_x - 5 %} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} + {% set y_start = 5 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} + {% set y_start = printable_y_max - 5 %} + {% endif %} + {% endif %} + {% set z = printer.configfile.settings.bed_mesh.horizontal_move_z|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 %} + + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Probing the start of the prime location at {x_start}, {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 + {% if t == 1 %} + SAVE_PROBE_RESULT VARIABLE=probe_for_priming_result_t1 + {% else %} + SAVE_PROBE_RESULT VARIABLE=probe_for_priming_result + {% endif %} + + {% if idex_mode == '' %} + # COREXY - HYBRID + {% set x_end = x_start %} + {% set y_end = y_start + 45 %} + {% else %} + # IDEX + {% if t==1 %} + {% set x_end = x_start - 45 %} + {% else %} + {% set x_end = x_start + 45 %} + {% endif %} + {% set y_end = y_start %} + {% endif %} + + RATOS_ECHO PREFIX="Adaptive Mesh" MSG="Probing the end of the prime location at {x_end}, {y_end}" + G1 X{x_end} Y{y_end} F{speed} + PROBE_CURRENT_POSITION + {% if t == 1 %} + SAVE_PROBE_RESULT VARIABLE=probe_for_priming_end_result_t1 + {% else %} + SAVE_PROBE_RESULT VARIABLE=probe_for_priming_end_result + {% endif %} + + RESTORE_GCODE_STATE NAME=probe_for_priming_state + RESTORE_TOOLHEAD_SETTINGS + {% endif %} + +[gcode_macro RESET_PRIME_PROBE_STATE] +gcode: + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_result VALUE=None + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_end_result VALUE=None + {% if printer["dual_carriage"] is defined %} + # IDEX + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_result_t1 VALUE=None + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=probe_for_priming_end_result_t1 VALUE=None + {% endif %} + +[gcode_macro PROBE_CURRENT_POSITION] +gcode: + SAVE_GCODE_STATE NAME=probe_current_position_state + {% if printer["gcode_macro RatOS"].z_probe|lower == 'stowable' %} + ASSERT_PROBE_DEPLOYED + {% endif %} + PROBE + {% if printer.configfile.settings.beacon is defined %} + BEACON_QUERY + {% else %} + # Only restore state if we're not using a beacon, so we state at scanning height + RESTORE_GCODE_STATE NAME=probe_current_position_state MOVE=1 MOVE_SPEED={printer["gcode_macro RatOS"].macro_z_speed|float} + {% endif %} + +[gcode_macro PRIME_LINE] +description: Prints a primeline, used internally, if configured, as part of the START_PRINT macro. +gcode: + RATOS_ECHO PREFIX="Priming" MSG="Prime line has been discontinued, switching to prime blob.." + PRIME_BLOB INITIAL_TOOLHEAD={params.INITIAL_TOOLHEAD} BOTH_TOOLHEADS={params.BOTH_TOOLHEADS} IDEX_MODE={params.IDEX_MODE} Y1={params.Y1} + +[gcode_macro PRIME_BLOB] +description: Prints a primeblob, used internally, if configured, as part of the START_PRINT macro. +gcode: + RATOS_ECHO PREFIX="Priming" MSG="Priming nozzle with prime blob.." + CACHE_TOOLHEAD_SETTINGS + SET_MACRO_TRAVEL_SETTINGS + + # idex mode + {% set target_idex_mode = '' %} + {% if printer["dual_carriage"] is defined %} + {% if params.IDEX_MODE is defined %} + {% set target_idex_mode = params.IDEX_MODE|default('')|lower %} + {% else %} + { action_raise_error("IDEX_MODE parameter not found for PRIME_BLOB macro. This is likely a bug.") } + {% endif %} + RATOS_ECHO PREFIX="Priming" MSG="Priming in IDEX {target_idex_mode} mode.." + {% set current_idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set current_toolhead = 1 if current_idex_mode=='primary' else 0 %} + {% endif %} + + # save gcode state + # this is the only macro where copy and mirror mode is possibly in use + # SAVE_GCODE_STATE isnt IDEX aware, we have no other chance than to skip it + # klippers built in dual carriage save state is buggy and creates to many side effects + {% if target_idex_mode != "copy" or target_idex_mode != "mirror" %} + SAVE_GCODE_STATE NAME=prime_blob_state + {% endif %} + + # config + {% set bed_margin_x = printer["gcode_macro RatOS"].bed_margin_x %} + {% set bed_margin_y = printer["gcode_macro RatOS"].bed_margin_y %} + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + {% set fan_speed = printer["gcode_macro RatOS"].nozzle_prime_bridge_fan|float %} + {% set nozzle_diameter = printer.configfile.settings.extruder.nozzle_diameter|float %} + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + {% set has_start_offset_t0 = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) != 9999.9 %} + {% if printer["dual_carriage"] is defined %} + {% set has_start_offset_t1 = printer["gcode_macro RatOS"].probe_for_priming_result_t1|float(9999.9) != 9999.9 %} + {% endif %} + + # parameter + {% set initial_toolhead = params.INITIAL_TOOLHEAD|default(default_toolhead)|int %} + {% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %} + + # calculation + {% if target_idex_mode == '' %} + # COREXY - HYBRID + {% set x_factor = 0 %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'min' %} + {% set x_start = 5 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_x|lower == 'max' %} + {% set x_start = printer["gcode_macro RatOS"].printable_x_max - 5 %} + {% else %} + {% set x_start = printer["gcode_macro RatOS"].nozzle_prime_start_x|float %} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} + {% set y_start = 5 %} + {% set y_factor = 1 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} + {% set y_start = printer["gcode_macro RatOS"].printable_y_max - 5 %} + {% set y_factor = -1 %} + {% else %} + {% set y_start = printer["gcode_macro RatOS"].nozzle_prime_start_y|float %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|float < printer["gcode_macro RatOS"].printable_y_max / 2 %} + {% set y_factor = 1 %} + {% else %} + {% set y_factor = -1 %} + {% endif %} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'forwards' %} + {% set y_factor = 1 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_direction|lower == 'backwards' %} + {% set y_factor = -1 %} + {% endif %} + {% set z = printer["gcode_macro RatOS"].start_print_park_z_height|float %} + {% else %} + # IDEX + {% set max_x = printer.configfile.settings.stepper_x.position_max|float %} + {% set max_y = printer.toolhead.axis_maximum.y|float %} + {% set center_x = max_x / 2 %} + {% set center_y = max_y / 2 %} + {% set y_factor = 0 %} + {% if target_idex_mode == 'copy' or target_idex_mode == 'mirror' %} + {% set x_start = center_x / 2 + 5 %} + {% set x_factor = 1 %} + {% else %} + {% if both_toolheads and initial_toolhead != current_toolhead %} + {% if current_toolhead == 0 %} + {% set x_start = 55 %} + {% set x_factor = -1 %} + {% elif current_toolhead == 1 %} + {% set x_start = max_x - 55 %} + {% set x_factor = 1 %} + {% endif %} + {% else %} + {% if current_toolhead == 0 %} + {% set x_start = 5 %} + {% set x_factor = 1 %} + {% elif current_toolhead == 1 %} + {% set x_start = max_x - 5 %} + {% set x_factor = -1 %} + {% endif %} + {% endif %} + {% endif %} + {% if printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'min' %} + {% set y_start = 5 %} + {% elif printer["gcode_macro RatOS"].nozzle_prime_start_y|lower == 'max' %} + {% set y_start = printer.toolhead.axis_maximum.y|float - 5 %} + {% endif %} + {% set z = 10 %} + {% endif %} + + {% set start_z_offset = 0 %} + {% set end_z_offset = 0 %} + {% if has_start_offset_t0 %} + {% set start_z_probe_result_t0 = printer["gcode_macro RatOS"].probe_for_priming_result|float(9999.9) %} + {% set end_z_probe_result_t0 = printer["gcode_macro RatOS"].probe_for_priming_end_result|float(9999.9) %} + {% if printer.configfile.settings.bltouch is not defined and printer.configfile.settings.probe is not defined and printer.configfile.settings.beacon is not defined %} + { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } + {% endif %} + {% if start_z_probe_result_t0 == 9999.9 %} + { action_raise_error("No start probe result found for prime area. This is likely a bug.") } + {% endif %} + {% if end_z_probe_result_t0 == 9999.9 %} + { action_raise_error("No end probe result found for prime area. This is likely a bug.") } + {% endif %} + {% set adjustment_threshold = printer["gcode_macro RatOS"].adaptive_prime_offset_threshold|float %} + {% if start_z_probe_result_t0 < adjustment_threshold %} + { action_raise_error("Abnormal probe offset detected. Needed offset of {start_adjustment} 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.") } + {% endif %} + {% if end_z_probe_result_t0 < adjustment_threshold %} + { action_raise_error("Abnormal probe offset detected. Needed offset of {end_adjustment} 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.") } + {% endif %} + {% set start_z_offset = start_z_probe_result_t0 %} + {% set end_z_offset = end_z_probe_result_t0 %} + {% endif %} + + {% if printer["dual_carriage"] is defined %} + {% if current_toolhead == 1 or both_toolheads or target_idex_mode == "copy" or target_idex_mode == "mirror" %} + {% if has_start_offset_t1 %} + {% set start_z_probe_result_t1 = printer["gcode_macro RatOS"].probe_for_priming_result_t1|float(9999.9) %} + {% set end_z_probe_result_t1 = printer["gcode_macro RatOS"].probe_for_priming_end_result_t1|float(9999.9) %} + {% if printer.configfile.settings.bltouch is not defined and printer.configfile.settings.probe is not defined and printer.configfile.settings.beacon is not defined %} + { action_raise_error("No probe or bltouch section found. Adaptive priming only works with [probe] or [bltouch].") } + {% endif %} + {% if start_z_probe_result_t1 == 9999.9 %} + { action_raise_error("No start probe result found for prime area. This is likely a bug.") } + {% endif %} + {% if end_z_probe_result_t1 == 9999.9 %} + { action_raise_error("No end probe result found for prime area. This is likely a bug.") } + {% endif %} + {% set adjustment_threshold = printer["gcode_macro RatOS"].adaptive_prime_offset_threshold|float %} + {% if start_z_probe_result_t1 < adjustment_threshold %} + { action_raise_error("Abnormal probe offset detected. Needed offset of {start_adjustment} 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.") } + {% endif %} + {% if end_z_probe_result_t1 < adjustment_threshold %} + { action_raise_error("Abnormal probe offset detected. Needed offset of {end_adjustment} 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.") } + {% endif %} + {% set start_z_offset = [start_z_offset, start_z_probe_result_t1]|max %} + {% set end_z_offset = [end_z_offset, start_z_probe_result_t1]|max %} + {% endif %} + {% endif %} + {% if target_idex_mode != 'copy' and target_idex_mode != 'mirror' %} + {% if both_toolheads and initial_toolhead != current_toolhead %} + {% set original_start_z_offset = start_z_offset %} + {% set original_end_z_offset = end_z_offset %} + {% set start_z_offset = original_end_z_offset %} + {% set end_z_offset = original_start_z_offset %} + {% endif %} + {% endif %} + {% endif %} + + DEBUG_ECHO PREFIX="PRIME_BLOB" MSG="x_start: {x_start}, y_start: {y_start}, x_factor: {x_factor}, y_factor: {y_factor}, z: {z}, start_z_offset: {start_z_offset}, end_z_offset: {end_z_offset}" + + # Absolute positioning + G90 + # Relative extrusion + M83 + RATOS_ECHO PREFIX="Priming" MSG="Lifting Z to {z}.." + # Lift to start print Z height + G0 Z{z} F{z_speed} + + # move close to blob position along the edge of the bed + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + RATOS_ECHO PREFIX="Priming" MSG="Moving to {x_start}, {y_start} along the edge of the print area.." + G1 X{x_start} F{speed} + G1 Y{y_start + (15 * y_factor)} F{speed} + {% else %} + # IDEX + G1 Y{y_start + (15 * y_factor)} F{speed} + {% if target_idex_mode=="copy" or target_idex_mode=="mirror" %} + RATOS_ECHO PREFIX="Priming" MSG="Mirroring move to {x_start}, {y_start} along the edge of the print area.." + # we use the same priming procedure for both modes + _IDEX_MIRROR PRIMING=1 + {% else %} + RATOS_ECHO PREFIX="Priming" MSG="Moving to {x_start}, {y_start} along the edge of the print area.." + {% endif %} + G1 X{x_start} F{speed} + {% endif %} + + RATOS_ECHO PREFIX="Priming" MSG="Starting prime blob.." + # Lower to blob extrusion height + G1 Z{0.5 + start_z_offset} F{z_speed} + # Move to final position horizontally + G1 Y{y_start} F{speed} + # Extrude a blob (split in two moves to avoid thresholds) + G1 F300 E{14 / ((0.4 / nozzle_diameter) ** 2)} + G1 F300 E{14 / ((0.4 / nozzle_diameter) ** 2)} + # 40% fan + M106 S{fan_speed} + # Move the extruder up by 5mm while extruding, breaks away from blob + G1 Z5 F100 E5 + RATOS_ECHO PREFIX="Priming" MSG="Bridging with {((fan_speed/255) * 100)|int}% fan speed.." + # Move to wipe position, but keep extruding so the wipe is attached to blob + G1 F3000 X{x_start + (15 * x_factor)} Y{y_start + (15 * y_factor)} E{1 / ((0.4 / nozzle_diameter) ** 2)} + # 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 F3000 X{x_start + (20 * x_factor)} Y{y_start + (20 * y_factor)} Z{3.8 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} + G1 F3000 X{x_start + (34 * x_factor)} Y{y_start + (34 * y_factor)} Z{2.6 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} + G1 F3000 X{x_start + (38 * x_factor)} Y{y_start + (38 * y_factor)} Z{1.4 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} + G1 F3000 X{x_start + (42 * x_factor)} Y{y_start + (42 * y_factor)} Z{0.2 + end_z_offset} E{0.2 / ((0.4 / nozzle_diameter) ** 2)} + # 0% fan + M106 S0 + # small wipe line + G1 F3000 X{x_start + (46 * x_factor)} Y{y_start + (46 * y_factor)} Z{0.2 + end_z_offset} E0.6 + # Break away wipe + G1 F{speed} X{x_start + (50 * x_factor)} Y{y_start + (50 * y_factor)} + + # z-hop after priming + {% if target_idex_mode == "copy" or target_idex_mode == "mirror" %} + G0 Z3 F{z_speed} + {% endif %} + + # reactivate idex copy mode if needed + {% if target_idex_mode == "copy" %} + _IDEX_COPY DANCE=0 Y={params.Y1} + {% endif %} + + # restore gcode state + # this is the only macro where copy and mirror mode is possibly in use + # SAVE_GCODE_STATE isnt IDEX aware, we have no other chance than to skip it + # klippers built in dual carriage save state is buggy and creates to many side effects + {% if target_idex_mode != "copy" or target_idex_mode != "mirror" %} + RESTORE_GCODE_STATE NAME=prime_blob_state + {% endif %} + + RESTORE_TOOLHEAD_SETTINGS + + # Reset extrusion distance + G92 E0 \ No newline at end of file diff --git a/macros/toolheads.cfg b/macros/toolheads.cfg new file mode 100644 index 00000000..15f84e4e --- /dev/null +++ b/macros/toolheads.cfg @@ -0,0 +1,658 @@ +##### +# TOOLHEAD SELECTION +#### +[gcode_macro _SELECT_TOOL] +gcode: + {% if printer["dual_carriage"] is defined %} + {% 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' %} + + RATOS_ECHO PREFIX="IDEX" MSG="Selecting T{new_t}.." + + # reset any speed override from the purge tower + M220 S100 + + # parameters + {% set new_x = params.X|default(-1)|float %} + {% set new_y = params.Y|default(-1)|float %} + {% set z_hop = params.Z|default(0.0)|float %} + {% set toolshift = true if params.TOOLSHIFT|default(1)|int == 1 else false %} + + # deactivate toolshifting if printer is not homed + {% if "xyz" not in printer.toolhead.homed_axes %} + {% set toolshift = false %} + {% endif %} + + # swap part cooling fans + {% set fan_speed = printer["fan_generic part_fan_t%s" % act_t].speed %} + {% set sync_fans = true if printer["gcode_macro RatOS"].toolchange_sync_fans|default(false)|lower == 'true' else false %} + {% if fan_speed > 0 %} + SET_FAN_SPEED FAN=part_fan_t0 SPEED={fan_speed if (new_t == 0 or sync_fans) else 0} + SET_FAN_SPEED FAN=part_fan_t1 SPEED={fan_speed if (new_t == 1 or sync_fans) 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} TOOLSHIFT={toolshift} 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 mainsail UI + 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} + + # this is a very basic sanity check for the klipper idex_mode.py bug + # a randomly apearing bug in idex_mode.py leads to switched modes for the dual carriage state + {% if 'x' in printer.toolhead.homed_axes %} + {% set sanity_check_idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% if new_t == 0 %} + {% if printer.toolhead.extruder == 'extruder' %} + {% if sanity_check_idex_mode == 'primary' %} + { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + {% endif %} + {% endif %} + {% elif new_t == 1 %} + {% if printer.toolhead.extruder == 'extruder1' %} + {% if sanity_check_idex_mode == 'inactive' %} + { action_emergency_stop("Switched states detected in idex_mode.py. Please restart the host controller.") } + {% endif %} + {% endif %} + {% endif %} + {% endif %} + + # absolute positioning + G90 + + {% endif %} + {% endif %} + {% endif %} + {% endif %} + +[gcode_macro _TOOLCHANGE] +gcode: + # parameters + {% set new_t = params.T|default(-1)|int %} + {% set new_x = params.X|default(-1.0)|float %} + {% set new_y = params.Y|default(-1.0)|float %} + {% set z_hop = params.Z_HOP|default(0.0)|float %} + {% set toolshift = true if params.TOOLSHIFT|default(true)|lower == 'true' else false %} + {% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %} + + DEBUG_ECHO PREFIX="_TOOLCHANGE" MSG="T={new_t} X={new_x} Y={new_y} IS_PRINTING_GCODE={is_printing_gcode} TOOLSHIFT={toolshift} Z_HOP={z_hop}" + + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + {% set config_zhop = printer["gcode_macro RatOS"].toolchange_zhop|default(1.0)|float %} + {% set center_x = printer.configfile.settings.stepper_x.position_max|float / 2 %} + {% set acceleration = printer["gcode_macro RatOS"].toolchange_travel_accel %} + {% set parking_position = printer["gcode_macro RatOS"].parking_position %} + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% set act_t = 1 if idex_mode == 'primary' else 0 %} + + # change toolhead + {% if not is_printing_gcode and not toolshift %} + + DEBUG_ECHO PREFIX="_TOOLCHANGE" MSG="Changing tool to T{new_t} without retracting/extruding or moving the toolheads except for parking." + + # park toolhead + {% if "xyz" in printer.toolhead.homed_axes %} + G1 X{parking_position[act_t]} F{speed} + {% endif %} + + # activate new carriage and offset + SET_DUAL_CARRIAGE CARRIAGE={new_t} MODE=PRIMARY + + # set offset + _SET_TOOLHEAD_OFFSET T={new_t} MOVE={1 if "xyz" in printer.toolhead.homed_axes else 0} + + # activate new extruder + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if new_t == 0 else new_t} + + {% else %} + # absolute positioning + G90 + + # set toolchange acceleration + {% set max_accel = printer.toolhead.max_accel|float %} + {% set square_corner_velocity = printer.toolhead.square_corner_velocity|float %} + SET_VELOCITY_LIMIT ACCEL={acceleration} ACCEL_TO_DECEL={acceleration} SQUARE_CORNER_VELOCITY=20 + + # manual tool switching, bring new tool to the printable center + {% if not is_printing_gcode and toolshift and new_x < 0 and new_y < 0 %} + {% set new_x = center_x %} + {% set new_y = printer.gcode_move.gcode_position.y|float %} + {% endif %} + + {% if new_x < 0 or new_y < 0 %} + # park the active toolhead and activate new toolhead without moving it + + # z-hop before parking + DEBUG_ECHO PREFIX="_TOOLCHANGE" MSG="No new X or Y position given, parking the active toolhead and activating the new toolhead without moving it." + _ZHOP_BEFORE_TOOLCHANGE Z_HOP={z_hop + config_zhop} T={new_t} + + # park toolhead + {% if "x" in printer.toolhead.homed_axes %} + G1 X{parking_position[act_t]} F{speed} + {% endif %} + + # # extrude after parking + {% if is_printing_gcode %} + _EXTRUDE T={new_t} + {% endif %} + + # activate new carriage and offset + SET_DUAL_CARRIAGE CARRIAGE={new_t} + _SET_TOOLHEAD_OFFSET T={new_t} MOVE={1 if "xyz" in printer.toolhead.homed_axes else 0} + + # activate new extruder + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if new_t == 0 else new_t} + + {% else %} + {% if "xyz" not in printer.toolhead.homed_axes %} + # printer is not homed + + # activate the new carriage and offset + SET_DUAL_CARRIAGE CARRIAGE={new_t} + _SET_TOOLHEAD_OFFSET T={new_t} + + # activate new extruder + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if new_t == 0 else new_t} + + {% else %} + # shift the toolheads + + # get current z-position + {% set gcode_z = printer.gcode_move.gcode_position.z|float %} + {% set toolhead_z = printer.toolhead.position.z|float %} + + {% if new_t == 0 %} + # get values + {% set t0_act_x = parking_position[0]|float %} + {% set t1_act_x = printer.toolhead.position.x|float %} + {% set t0_new_x = new_x %} + {% set t1_new_x = parking_position[1]|float %} + {% set t0_distance = t0_new_x - t0_act_x %} + {% set t1_distance = t1_new_x - t1_act_x %} + + # calculate needed z-hop + {% set calc_z_hop = z_hop + config_zhop %} + + # z-hop before toolchange + DEBUG_ECHO PREFIX="_TOOLCHANGE" MSG="Shifting to T0." + _ZHOP_BEFORE_TOOLCHANGE Z_HOP={calc_z_hop} T={new_t} SYNC=1 + + # make sure T0 is in its correct parking position + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + G1 X{t0_act_x} F{speed} + + {% if t0_distance >= t1_distance %} + # copy move + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY + G1 X{t0_act_x + (t1_new_x - t1_act_x)} Y{new_y + svv.idex_yoffset} F{speed} + + # move T0 + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + G1 X{t0_new_x + svv.idex_xoffset} F{speed} + + {% elif t0_distance < t1_distance %} + # copy move + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY + G1 X{t0_new_x + svv.idex_xoffset} Y{new_y + svv.idex_yoffset} F{speed} + + # park T1 + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{t1_new_x} F{speed} + + # move T0 + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + G1 X{t0_new_x + svv.idex_xoffset} F{speed} + + {% endif %} + + # Offset move + {% if svv.idex_applied_offset != 0 %} + SET_GCODE_OFFSET X_ADJUST={(svv.idex_xoffset)} Y_ADJUST={(svv.idex_yoffset)} MOVE=0 SPEED={speed} + G1 X{t0_new_x} Y{new_y} F{speed} + SET_GCODE_OFFSET Z_ADJUST={(svv.idex_zoffset)} MOVE=1 SPEED={z_speed} + SAVE_VARIABLE VARIABLE=idex_applied_offset VALUE=0 + RATOS_ECHO PREFIX="IDEX" MSG="Toolhead offset applied for T0: X={svv.idex_xoffset} Y={svv.idex_yoffset} Z={svv.idex_zoffset}" + {% endif %} + + # calculate needed z-drop + {% set calc_z_drop = z_hop + config_zhop %} + + # z-drop after toolchange + _ZDROP_AFTER_TOOLCHANGE Z_DROP={calc_z_drop} T={new_t} SYNC=1 + + {% elif new_t == 1 %} + # get values + {% set t0_act_x = printer.toolhead.position.x|float %} + {% set t1_act_x = parking_position[1]|float %} + {% set t0_new_x = parking_position[0]|float %} + {% set t1_new_x = new_x %} + {% set t0_distance = t0_act_x - t0_new_x %} + {% set t1_distance = t1_act_x - t1_new_x %} + + # calculate needed z-hop + {% set calc_z_hop = z_hop + config_zhop %} + + # z-hop before toolchange + DEBUG_ECHO PREFIX="_TOOLCHANGE" MSG="Shifting to T1." + _ZHOP_BEFORE_TOOLCHANGE Z_HOP={calc_z_hop} T={new_t} SYNC=1 + + # make sure T1 is in its correct parking position + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{t1_act_x} F{speed} + + {% if t0_distance >= t1_distance %} + # copy move + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY + G1 X{t0_act_x - (t1_act_x - t1_new_x) - svv.idex_xoffset} Y{new_y - svv.idex_yoffset} F{speed} + + # park T0 + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + G1 X{t0_new_x - svv.idex_xoffset} F{speed} + + # move T1 + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + + {% elif t0_distance < t1_distance %} + # copy move + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=COPY + G1 X{t0_new_x} Y{new_y - svv.idex_yoffset} F{speed} + + # move T1 + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + G1 X{t1_new_x - svv.idex_xoffset} F{speed} + + {% endif %} + + # offset move + {% if svv.idex_applied_offset != 1 %} + SET_GCODE_OFFSET X_ADJUST={(0-svv.idex_xoffset)} Y_ADJUST={(0-svv.idex_yoffset)} MOVE=0 SPEED={speed} + G1 X{t1_new_x} Y{new_y} F{speed} + SET_GCODE_OFFSET Z_ADJUST={(0-svv.idex_zoffset)} MOVE=1 SPEED={z_speed} + SAVE_VARIABLE VARIABLE=idex_applied_offset VALUE=1 + RATOS_ECHO PREFIX="IDEX" MSG="Toolhead offset applied for T1: X={(0-svv.idex_xoffset)} Y={(0-svv.idex_yoffset)} Z={(0-svv.idex_zoffset)}" + {% endif %} + + # calculate needed z-drop + {% set calc_z_drop = z_hop + config_zhop %} + + # z-drop after toolchange + _ZDROP_AFTER_TOOLCHANGE Z_DROP={calc_z_drop} T={new_t} SYNC=1 + + {% endif %} + + # activate new extruder + ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if new_t == 0 else new_t} + + {% endif %} + {% endif %} + + # reset acceleration + SET_VELOCITY_LIMIT ACCEL={max_accel} ACCEL_TO_DECEL={(max_accel / 2)} SQUARE_CORNER_VELOCITY={square_corner_velocity} + + {% endif %} + +[gcode_macro _ZHOP_BEFORE_TOOLCHANGE] +gcode: + # parameters + {% set t = params.T|int %} + {% set sync = params.SYNC|default(0)|int %} + {% set z_hop = params.Z_HOP|default(0.0)|float %} + {% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %} + + DEBUG_ECHO PREFIX="_ZHOP_BEFORE_TOOLCHANGE" MSG="T={t} SYNC={sync} IS_PRINTING_GCODE={is_printing_gcode} Z_HOP={z_hop}" + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_zspeed|default(15)|float %} + {% set feedrate = printer["gcode_macro RatOS"].toolchange_feedrate %} + {% set combined_zhop = printer["gcode_macro RatOS"].toolchange_combined_zhop|default(0)|int %} + {% set both_toolheads = true if printer["gcode_macro START_PRINT"].both_toolheads|default(true)|lower == 'true' else false %} + {% set m400 = true if printer["gcode_macro RatOS"].toolchange_m400|default(true)|lower == 'true' else false %} + {% set e = printer["gcode_macro RatOS"].toolchange_retraction %} + + G91 # relative positioning + M82 # absolute extrusion + G92 E0 # reset extrusion distance + + # snyc extruders + {% if sync == 1 and t == 0 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder1 + {% endif %} + {% elif sync == 1 and t == 1 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder + {% endif %} + {% endif %} + + # z-hop + {% if combined_zhop == 1 and is_printing_gcode %} + G1 Z+{z_hop} E-{e[t]} F{speed * 60} + {% else %} + G1 Z+{z_hop} F{speed * 60} + {% if is_printing_gcode %} + G1 E-{e[t]} F{feedrate[t]} + {% endif %} + {% endif %} + + # wait for movements + {% if m400 %} + M400 + {% endif %} + + # unsync extruder + {% if sync == 1 and t == 0 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder + {% endif %} + {% elif sync == 1 and t == 1 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder1 + {% endif %} + {% endif %} + + G90 # absolute positioning + G92 E0 # reset extrusion distance + + # Set extrusion mode based on user configuration + {% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %} + M83 + {% else %} + M82 + {% endif %} + +[gcode_macro _ZDROP_AFTER_TOOLCHANGE] +gcode: + # parameters + {% set t = params.T|int %} + {% set sync = params.SYNC|default(0)|int %} + {% set z_drop = params.Z_DROP|default(0.0)|float %} + {% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %} + + DEBUG_ECHO PREFIX="_ZDROP_AFTER_TOOLCHANGE" MSG="T={t} SYNC={sync} IS_PRINTING_GCODE={is_printing_gcode} Z_DROP={z_drop}" + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_zspeed|default(15)|float %} + {% set feedrate = printer["gcode_macro RatOS"].toolchange_feedrate %} + {% set combined_zhop = printer["gcode_macro RatOS"].toolchange_combined_zhop|default(0)|int %} + {% set both_toolheads = true if printer["gcode_macro START_PRINT"].both_toolheads|default(true)|lower == 'true' else false %} + {% set m400 = true if printer["gcode_macro RatOS"].toolchange_m400|default(true)|lower == 'true' else false %} + {% set e = printer["gcode_macro RatOS"].toolchange_extrusion %} + + G91 # relative positioning + M82 # absolute extrusion + G92 E0 # reset extrusion distance + + # snyc extruders + {% if sync == 1 and t == 0 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder1 + {% endif %} + {% elif sync == 1 and t == 1 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder + {% endif %} + {% endif %} + + # z-drop + {% if combined_zhop == 1 and is_printing_gcode %} + G1 Z-{z_drop} E{e[t]} F{speed * 60} + {% else %} + G1 Z-{z_drop} F{speed * 60} + {% if is_printing_gcode %} + G1 E{e[t]} F{feedrate[t]} + {% endif %} + {% endif %} + + # wait for movements + {% if m400 %} + M400 + {% endif %} + + # unsync extruder + {% if sync == 1 and t == 0 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder MOTION_QUEUE=extruder + {% endif %} + {% elif sync == 1 and t == 1 and is_printing_gcode and both_toolheads %} + {% if printer['extruder'].can_extrude|lower == 'true' and printer['extruder1'].can_extrude|lower == 'true' %} + SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder1 + {% endif %} + {% endif %} + + G90 # absolute positioning + G92 E0 # reset extrusion distance + + # Set extrusion mode based on user configuration + {% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %} + M83 + {% else %} + M82 + {% endif %} + +[gcode_macro _EXTRUDE] +gcode: + # parameters + {% set t = params.T|int %} + + # config + {% set e = printer["gcode_macro RatOS"].toolchange_extrusion %} + {% set feedrate = printer["gcode_macro RatOS"].toolchange_feedrate %} + {% set m400 = true if printer["gcode_macro RatOS"].toolchange_m400|default(true)|lower == 'true' else false %} + + # extrude + G91 # relative positioning + M82 # absolute extrusion + G92 E0 # reset extrusion distance + G1 E{e[t]} F{feedrate[t] * 60} # retract + G90 # absolute positioning + G92 E0 # reset extrusion distance + + # wait for movements + {% if m400 %} + M400 + {% endif %} + + # Set extrusion mode based on user configuration + {% if printer["gcode_macro RatOS"].relative_extrusion|lower == 'true' %} + M83 + {% else %} + M82 + {% endif %} + +##### +# TOOLHEAD HELPER +#### + +[delayed_gcode _INIT_TOOLHEADS] +initial_duration: 0.1 +gcode: + {% if printer["dual_carriage"] is defined %} + + # config + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|int %} + + # ratos variables file + {% set svv = printer.save_variables.variables %} + SAVE_VARIABLE VARIABLE=idex_applied_offset VALUE={default_toolhead} + + # activate IDEX default + _IDEX_SINGLE INIT=1 + + # this is brutal, but better than colliding toolheads + # inverted hybrid core-xy bugfix sanity check + {% set inverted = False %} + {% if printer.configfile.settings.ratos_hybrid_corexy is defined and printer.configfile.settings.ratos_hybrid_corexy.inverted is defined %} + {% if printer.configfile.settings.ratos_hybrid_corexy.inverted|lower == 'true' %} + {% set inverted = True %} + {% endif %} + {% endif %} + {% if inverted == False %} + { action_emergency_stop("ratos_hybrid_corexy NOT INVERTED! Inverted hybrid core-xy bugfix not detected.") } + {% endif %} + + # toolhead offsets sanity check + {% if svv.idex_zoffset>0 %} + { action_emergency_stop("Wrong physical toolhead z-offset detected! The secondary toolheads nozzle must be higher then the nozzle from the primary toolhead.") } + {% endif %} + {% if default_toolhead == 0 and svv.idex_xoffset>0 %} + { action_emergency_stop("Wrong physical toolhead x-offset detected! The secondary toolhead T1 x-offset must be negative.") } + {% endif %} + {% if default_toolhead == 1 and svv.idex_xoffset<0 %} + { action_emergency_stop("Wrong physical toolhead x-offset detected! The secondary toolhead T0 x-offset must be positive.") } + {% endif %} + + # dual carriage safe distance sanity check + {% if printer.configfile.settings.dual_carriage.safe_distance is defined %} + {% if printer.configfile.settings.dual_carriage.safe_distance|float < 50 %} + { action_emergency_stop("Dual carriage safe_distance seems to be too low!") } + {% endif %} + {% else %} + { action_emergency_stop("Dual carriage safe_distance not defined!") } + {% endif %} + + # stepper min max position sanity check + {% if printer.configfile.settings.dual_carriage.position_min|float < 0 %} + { action_emergency_stop("dual_carriage position_min too low, set it to 0!") } + {% endif %} + {% if printer.configfile.settings.stepper_x.position_max|float != 200 %} + {% if printer.configfile.settings.stepper_x.position_max|float != 300 %} + {% if printer.configfile.settings.stepper_x.position_max|float != 400 %} + {% if printer.configfile.settings.stepper_x.position_max|float != 500 %} + { action_emergency_stop("stepper_x position_max seems to be wrong, set it to your max print width!") } + {% endif %} + {% endif %} + {% endif %} + {% endif %} + + {% endif %} + +[gcode_macro _SET_TOOLHEAD_OFFSET] +gcode: + # parameters + {% set t = params.T|int %} + {% set move = params.MOVE|default(0)|int %} + + # echo + DEBUG_ECHO PREFIX="_SET_TOOLHEAD_OFFSET" MSG="T={t} MOVE={move}" + + # ratos variables file + {% set svv = printer.save_variables.variables %} + + # config + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %} + {% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %} + + # set offset + {% if "xyz" not in printer.toolhead.homed_axes %} + {% set move = 0 %} + {% endif %} + {% if svv.idex_applied_offset != t %} + {% if t != printer["gcode_macro RatOS"].default_toolhead|int %} + SET_GCODE_OFFSET X_ADJUST={(svv.idex_xoffset)} Y_ADJUST={(svv.idex_yoffset)} MOVE={move} SPEED={speed} + SET_GCODE_OFFSET Z_ADJUST={(svv.idex_zoffset)} MOVE={move} SPEED={z_speed} + {% else %} + SET_GCODE_OFFSET X_ADJUST={(0-svv.idex_xoffset)} Y_ADJUST={(0-svv.idex_yoffset)} MOVE={move} SPEED={speed} + SET_GCODE_OFFSET Z_ADJUST={(0-svv.idex_zoffset)} MOVE={move} SPEED={z_speed} + {% endif %} + SAVE_VARIABLE VARIABLE=idex_applied_offset VALUE={t} + RATOS_ECHO PREFIX="IDEX" MSG="Toolhead offset applied for T{t}: X={svv.idex_xoffset} Y={svv.idex_yoffset} Z={svv.idex_zoffset}" + {% endif %} + +[gcode_macro TOOLCHANGE_CONFIG] +gcode: + {% set svv = printer.save_variables.variables %} + + # {% set oldX = svv.xoffset|float %} + # {% set oldY = svv.yoffset|float %} + # {% set oldZ = svv.zoffset|float %} + + # {% if params.X is defined %} + # SAVE_VARIABLE VARIABLE=xoffset VALUE={ params.X|float } + # {% endif %} + + {% if params.ZHOP is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_zhop VALUE={params.ZHOP|default(1.0)|float} + {% endif %} + {% if params.COMBINED_ZHOP is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_combined_zhop VALUE={params.COMBINED_ZHOP|default(0)|int} + {% endif %} + {% if params.M400 is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_m400 VALUE={true if params.M400 == 1 else false} + {% endif %} + {% if params.EXTRUDE is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_extrusion VALUE={params.EXTRUDE|default('[0.8,0.8]')} + {% endif %} + {% if params.RETRACT is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_retraction VALUE={params.RETRACT|default('[0.8,0.8]')} + {% endif %} + {% if params.FEEDRATE is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_feedrate VALUE={params.FEEDRATE|default('[7200,7200]')} + {% endif %} + {% if params.SPEED is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_travel_speed VALUE={params.SPEED|default(300)} + {% endif %} + {% if params.ACCEL is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_travel_accel VALUE={params.ACCEL|default(5000)} + {% endif %} + {% if params.SYNC_FANS is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_sync_fans VALUE={true if params.SYNC_FANS == 1 else false} + {% endif %} + {% if params.RETRACT is defined %} + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=toolchange_retraction VALUE={params.RETRACT|default('[0.8,0.8]')} + {% endif %} + +# this fixes a superslicer issue +# only the currently active extruders temp got changed after the first layer. +# call this from the slicers change layer custom gcode +[gcode_macro _LAYER_CHANGE] +variable_t: 0 +variable_layer_number: 1 +variable_extruder_other_layer_temp: 0 +variable_extruder_other_layer_temp_1: 0 +gcode: + {% if printer["gcode_macro _LAYER_CHANGE"].layer_number is defined %} + {% set layer_number = printer["gcode_macro _LAYER_CHANGE"].layer_number|int %} + {% if printer["gcode_macro _LAYER_CHANGE"].extruder_other_layer_temp is defined %} + {% if layer_number == 2 %} + {% set t = printer["gcode_macro _LAYER_CHANGE"].t|int %} + {% set both_toolheads = true if printer["gcode_macro START_PRINT"].both_toolheads|default(true)|lower == 'true' else false %} + {% set extruder_other_layer_temp = printer["gcode_macro _LAYER_CHANGE"].extruder_other_layer_temp|float %} + {% set extruder_other_layer_temp_1 = printer["gcode_macro _LAYER_CHANGE"].extruder_other_layer_temp_1|float %} + {% if t == 0 or both_toolheads %} + M104 S{extruder_other_layer_temp} T0 + {% endif %} + {% if t == 1 or both_toolheads %} + M104 S{extruder_other_layer_temp_1} T1 + {% endif %} + {% endif %} + {% endif %} + SET_GCODE_VARIABLE MACRO=_LAYER_CHANGE VARIABLE=layer_number VALUE={layer_number + 1} + {% endif %} diff --git a/macros/user-hooks.cfg b/macros/user-hooks.cfg new file mode 100644 index 00000000..a8366999 --- /dev/null +++ b/macros/user-hooks.cfg @@ -0,0 +1,27 @@ +[gcode_macro _USER_START_PRINT_BEFORE_HOMING] +gcode: + +[gcode_macro _USER_START_PRINT_AFTER_HEATING_BED] +gcode: + +[gcode_macro _USER_START_PRINT_BED_MESH] +gcode: + +[gcode_macro _USER_START_PRINT_PARK] +gcode: + +[gcode_macro _USER_START_PRINT_AFTER_HEATING_EXTRUDER] +gcode: + +[gcode_macro _USER_START_PRINT_HEAT_CHAMBER] +description: Uses the extruder sensor to wait for chamber temp. Override the _START_PRINT_HEAT_CHAMBER macro to implement heated chamber handling. +gcode: + +[gcode_macro _USER_END_PRINT_BEFORE_HEATERS_OFF] +gcode: + +[gcode_macro _USER_END_PRINT_AFTER_HEATERS_OFF] +gcode: + +[gcode_macro _USER_END_PRINT_PARK] +gcode: diff --git a/macros/util.cfg b/macros/util.cfg new file mode 100644 index 00000000..17fc80f0 --- /dev/null +++ b/macros/util.cfg @@ -0,0 +1,196 @@ +##### +# CONFIGURATION VARIABLES +##### + +[gcode_macro ECHO_RATOS_VARS] +description: Echo RatOS variables to the console. +gcode: + {% for var, value in printer["gcode_macro RatOS"].items() %} + {action_respond_info(var ~ ": " ~ value)} + {% endfor %} + +[gcode_macro RatOS] +description: RatOS variable storage macro, will echo variables to the console when run. +# Configuration defaults +# Configuration should exclusively happen in printer.cfg. +variable_relative_extrusion: False +variable_force_absolute_position: False +variable_preheat_extruder: True +variable_preheat_extruder_temp: 150 +variable_calibrate_bed_mesh: True +variable_nozzle_priming: "primeblob" +variable_nozzle_prime_start_x: "max" # min, max or number +variable_nozzle_prime_start_y: "min" # min, max or number +variable_nozzle_prime_direction: "auto" # auto, forwards, backwards +variable_nozzle_prime_bridge_fan: 102 +variable_filament_unload_length: 130 +variable_filament_unload_speed: 5 +variable_filament_load_length: 100 +variable_filament_load_speed: 10 +variable_start_print_park_in: "back" +variable_start_print_park_z_height: 50 +variable_start_print_heat_chamber_bed_temp: 115 +variable_end_print_park_in: "back" +variable_pause_print_park_in: "back" +variable_macro_travel_speed: 150 +variable_macro_travel_accel: 2000 +variable_macro_z_speed: 15 +variable_end_print_park_z_hop: 20 +# Possible values: 'sensorless' or 'endstops'. +variable_homing: "endstops" +variable_sensorless_x_current: 0.6 +variable_sensorless_y_current: 0.9 +# Possible values: 'static' or 'stowable' +variable_z_probe: "static" +# Possible Values: 'middle' or an absolute x coordinate +variable_safe_home_x: "middle" +# Possible Values: 'middle' or an absolute y coordinate +variable_safe_home_y: "middle" +variable_stowable_probe_stop_on_error: False +variable_driver_type_x: "tmc2209" +variable_driver_type_y: "tmc2209" +variable_adaptive_mesh: False +variable_probe_for_priming_result: None +variable_probe_for_priming_end_result: None +variable_adaptive_prime_offset_threshold: -1.0 +variable_bed_margin_x: [0, 0] +variable_bed_margin_y: [0, 0] +variable_printable_x_min: 0 +variable_printable_x_max: 0 +variable_printable_y_min: 0 +variable_printable_y_max: 0 +gcode: + ECHO_RATOS_VARS + +[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 tool = 0 if printer["gcode_macro T0"].active else 1 %} + {% set max_x = printer.toolhead.axis_maximum.x if tool == 0 else printer.toolhead.axis_maximum.x - 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} + DEBUG_ECHO PREFIX="CALCULATE_PRINTABLE_AREA" MSG="Printable area calculated: X: 0,{max_x} Y: 0,{max_y}" + +[gcode_macro CACHE_TOOLHEAD_SETTINGS] +variable_old_accel: 1000 +variable_old_decel: 500 +variable_old_speed: 50 +variable_old_scv: 5 +gcode: + SET_GCODE_VARIABLE MACRO=CACHE_TOOLHEAD_SETTINGS VARIABLE=old_accel VALUE={ printer.toolhead.max_accel } + SET_GCODE_VARIABLE MACRO=CACHE_TOOLHEAD_SETTINGS VARIABLE=old_decel VALUE={ printer.toolhead.max_accel_to_decel } + SET_GCODE_VARIABLE MACRO=CACHE_TOOLHEAD_SETTINGS VARIABLE=old_speed VALUE={ printer.toolhead.max_velocity } + SET_GCODE_VARIABLE MACRO=CACHE_TOOLHEAD_SETTINGS VARIABLE=old_scv VALUE={ printer.toolhead.square_corner_velocity } + DEBUG_ECHO PREFIX="CACHE_TOOLHEAD_SETTINGS" MSG="Toolhead settings cached. ${printer.toolhead.max_accel} accel, ${printer.toolhead.max_accel_to_decel} decel, ${printer.toolhead.max_velocity} velocity, ${printer.toolhead.square_corner_velocity} scv." + +[gcode_macro SET_MACRO_TRAVEL_SETTINGS] +gcode: + {% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %} + {% set accel = printer["gcode_macro RatOS"].macro_travel_accel %} + SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel/2} VELOCITY={speed} SQUARE_CORNER_VELOCITY={5} + DEBUG_ECHO PREFIX="SET_MACRO_TRAVEL_SETTINGS" MSG="Macro travel settings set. ${accel} accel, ${speed} velocity" + +[gcode_macro SET_TOOLCHANGE_TRAVEL_SETTINGS] +gcode: + {% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed|float * 60 %} + {% set accel = printer["gcode_macro RatOS"].toolchange_travel_accel %} + SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel/2} VELOCITY={speed} SQUARE_CORNER_VELOCITY={5} + DEBUG_ECHO PREFIX="SET_TOOLCHANGE_TRAVEL_SETTINGS" MSG="Toolchange travel settings set. ${accel} accel, ${speed} velocity" + +[gcode_macro RESTORE_TOOLHEAD_SETTINGS] +gcode: + {% set old_accel = printer["gcode_macro CACHE_TOOLHEAD_SETTINGS"].old_accel %} + {% set old_decel = printer["gcode_macro CACHE_TOOLHEAD_SETTINGS"].old_decel %} + {% set old_speed = printer["gcode_macro CACHE_TOOLHEAD_SETTINGS"].old_speed %} + {% set old_scv = printer["gcode_macro CACHE_TOOLHEAD_SETTINGS"].old_scv %} + SET_VELOCITY_LIMIT ACCEL={old_accel} ACCEL_TO_DECEL={old_decel} VELOCITY={old_speed} SQUARE_CORNER_VELOCITY={old_scv} + DEBUG_ECHO PREFIX="RESTORE_TOOLHEAD_SETTINGS" MSG="Toolhead settings restored. ${old_accel} accel, ${old_decel} decel, ${old_speed} velocity, ${old_scv} scv." + +[gcode_macro SET_CENTER_KINEMATIC_POSITION] +description: FOR DEBUGGING PURPOSES ONLY. Sets the internal printer kinematic state to the center of all axes regardless of actual physical position. +gcode: + RATOS_ECHO MSG="WARNING: ONLY USE SET_CENTER_KINEMATIC_POSITION FOR DEBUGGING PURPOSES. YOU'RE OVERRIDING THE INTERNAL POSITIONING STATE OF THE PRINTER. PROCEED WITH CAUTION AND DO A PROPER G28 WHEN DONE." + SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=True + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + SET_KINEMATIC_POSITION X={printer["gcode_macro RatOS"].printable_x_max / 2} Y={printer["gcode_macro RatOS"].printable_y_max / 2} Z={printer.toolhead.axis_maximum.z / 2} + {% else %} + # IDEX + IDEX_SET_CENTER_KINEMATIC_POSITION + {% endif %} + +[gcode_macro IDEX_SET_CENTER_KINEMATIC_POSITION] +description: FOR DEBUGGING PURPOSES ONLY. Sets the internal printer kinematic state to the center of all axes regardless of actual physical position. +gcode: + RATOS_ECHO MSG="WARNING: ONLY USE SET_CENTER_KINEMATIC_POSITION FOR DEBUGGING PURPOSES. YOU'RE OVERRIDING THE INTERNAL POSITIONING STATE OF THE PRINTER. PROCEED WITH CAUTION AND DO A PROPER G28 WHEN DONE." + SET_GCODE_VARIABLE MACRO=MAYBE_HOME VARIABLE=is_kinematic_position_overriden VALUE=True + {% set center_x = printer.configfile.settings.stepper_x.position_max|float / 2 %} + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + SET_KINEMATIC_POSITION X={center_x - (center_x / 2)} Y={printer["gcode_macro RatOS"].printable_y_max / 2} Z={printer.toolhead.axis_maximum.z / 2} + SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY + SET_KINEMATIC_POSITION X={center_x + (center_x / 2)} Y={printer["gcode_macro RatOS"].printable_y_max / 2} Z={printer.toolhead.axis_maximum.z / 2} + SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY + +[gcode_macro VERIFY_HYBRID_INVERTED] +gcode: + # inverted hybrid core-xy bugfix sanity check + {% set inverted = False %} + {% if printer.configfile.settings.ratos_hybrid_corexy is defined and printer.configfile.settings.ratos_hybrid_corexy.inverted is defined %} + {% if printer.configfile.settings.ratos_hybrid_corexy.inverted|lower == 'true' %} + {% set inverted = True %} + {% endif %} + {% endif %} + {% if inverted == False %} + { action_emergency_stop("ratos_hybrid_corexy NOT INVERTED! Inverted hybrid core-xy bugfix not detected.") } + {% endif %} + +[gcode_macro RATOS_ECHO] +gcode: + {% set prefix = "RatOS" %} + {% set debug = params.DEBUG|default(0)|int %} + {% if params.PREFIX is defined %} + {% set prefix = prefix ~ " | " ~ params.PREFIX %} + {% endif %} + {% set prefix = prefix ~ ":" %} + {% set msg = "" %} + {% if params.MSG is defined %} + {% set msg = params.MSG %} + {% else %} + {% set msg = "No msg parameter provided (this is a bug or unintended use)." %} + {% endif %} + {% if not debug %} + # Print to display if not a debug message + M117 {prefix} {msg} + {% endif %} + RESPOND PREFIX="{prefix}" MSG="{msg}" + +### DEBUGGING MACROS +[gcode_macro ENABLE_DEBUG] +gcode: + SET_GCODE_VARIABLE MACRO=DEBUG_ECHO VARIABLE=enabled VALUE=True + SET_GCODE_VARIABLE MACRO=DEBUG_ECHO VARIABLE=prefix_filter VALUE="'{params.FILTER|default('')|lower}'" + RATOS_ECHO PREFIX="DEBUG" MSG="Debugging enabled." + +[gcode_macro DISABLE_DEBUG] +gcode: + SET_GCODE_VARIABLE MACRO=DEBUG_ECHO VARIABLE=enabled VALUE=False + RATOS_ECHO PREFIX="DEBUG" MSG="Debugging disabled." + +[gcode_macro DEBUG_ECHO] +variable_enabled: False +variable_prefix_filter: '' +gcode: + {% set prefix = "DEBUG" %} + {% if params.PREFIX is defined %} + {% set prefix = prefix ~ " - " ~ params.PREFIX %} + {% endif %} + {% if enabled and (prefix_filter|lower == '' or prefix_filter|lower in params.PREFIX|lower) %} + RATOS_ECHO PREFIX="{prefix}" MSG="{params.MSG}" DEBUG=1 + {% endif %} diff --git a/printers/base.cfg b/printers/base.cfg index f9e2a782..67290692 100644 --- a/printers/base.cfg +++ b/printers/base.cfg @@ -6,7 +6,7 @@ gcode: {% if printer.webhooks.state|lower == 'ready' %} {% if printer.pause_resume.is_paused|lower == 'false' %} - M117 Idle timeout reached + RATOS_ECHO PREFIX="IDLE" MSG="2 hours since last activity. Powering off heaters and motors.." TURN_OFF_HEATERS M84 {% endif %} diff --git a/printers/caramba-hybrid/macros.cfg b/printers/caramba-hybrid/macros.cfg index c0275c9b..1c00aa64 100644 --- a/printers/caramba-hybrid/macros.cfg +++ b/printers/caramba-hybrid/macros.cfg @@ -2,6 +2,11 @@ # To override settings from this file, you can copy and paste the relevant # sections into your printer.cfg and change it there. +[delayed_gcode _HYBRID_INIT] +initial_duration: 0.1 +gcode: + VERIFY_HYBRID_INVERTED + # Print macros. Call these from your slicer (custom g-code). # You can copy these to printer.cfg and modify them to your liking, or just use them as is. # Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers @@ -10,19 +15,16 @@ gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} - M117 Adjusting Z tilt... - RESPOND MSG="Adjusting Z tilt..." + RATOS_ECHO MSG="Adjusting Z tilt..." # Adjust bed tilt Z_TILT_ADJUST - M117 Rehoming Z after Z tilt adjustment... - RESPOND MSG="Rehoming Z after Z tilt adjustment..." + RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z diff --git a/printers/caramba-idex/macros.cfg b/printers/caramba-idex/macros.cfg index c0275c9b..bfe7b5b3 100644 --- a/printers/caramba-idex/macros.cfg +++ b/printers/caramba-idex/macros.cfg @@ -2,27 +2,59 @@ # To override settings from this file, you can copy and paste the relevant # sections into your printer.cfg and change it there. +##### +# INCLUDE IDEX MACRO FILES +##### +[include ../../macros/idex/*.cfg] + +[delayed_gcode _IDEX_INIT] +initial_duration: 0.1 +gcode: + # ensure IDEX homing order + SET_GCODE_VARIABLE MACRO=RatOS VARIABLE=home_y_first VALUE=True + # ensure inverted hybrid corexy configuration + VERIFY_HYBRID_INVERTED + # Print macros. Call these from your slicer (custom g-code). # You can copy these to printer.cfg and modify them to your liking, or just use them as is. # Read more here: https://rat-rig.github.io/V-CoreOS/#/slicers + + [gcode_macro _START_PRINT_AFTER_HEATING_BED] gcode: - {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} + {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} + {% set t = params.T|default(-1)|int %} + {% set both_toolheads = true if params.BOTH_TOOLHEADS|default(true)|lower=='true' else false %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." - # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. - # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. - M104 S{min_temp} - TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} - {% endif %} - M117 Adjusting Z tilt... - RESPOND MSG="Adjusting Z tilt..." + {% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %} + RATOS_ECHO MSG="Pre-heating extruder..." + # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. + # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. + {% if printer["dual_carriage"] is not defined %} + # COREXY - HYBRID + M104 S{min_temp} + TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} + {% else %} + # IDEX + {% if t==0 or default_toolhead==0 or both_toolheads %} + M104 S{min_temp} T0 + {% endif %} + {% if t==1 or default_toolhead==1 or both_toolheads %} + M104 S{min_temp} T1 + {% endif %} + {% if t==0 or default_toolhead==0 or both_toolheads %} + TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} + {% endif %} + {% if t==1 or default_toolhead==1 or both_toolheads %} + TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp} + {% endif %} + {% endif %} + {% endif %} + RATOS_ECHO MSG="Adjusting Z tilt..." # Adjust bed tilt Z_TILT_ADJUST - M117 Rehoming Z after Z tilt adjustment... - RESPOND MSG="Rehoming Z after Z tilt adjustment..." + RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z @@ -30,10 +62,28 @@ gcode: [gcode_macro Z_TILT_ADJUST] rename_existing: Z_TILT_ADJUST_ORIG gcode: - {% if printer["gcode_macro RatOS"].z_probe == 'stowable' %} - DEPLOY_PROBE - {% endif %} - Z_TILT_ADJUST_ORIG - {% if printer["gcode_macro RatOS"].z_probe == 'stowable' %} - STOW_PROBE - {% endif %} + {% if printer["dual_carriage"] is defined %} + # reset IDEX mode + _IDEX_SINGLE + # select default toolhead + _SELECT_TOOL T={printer["gcode_macro RatOS"].default_toolhead|default(0)|int} TOOLSHIFT=false + {% endif %} + + # Z-Zilt Adjust + {% if printer["gcode_macro RatOS"].z_probe == 'stowable' %} + DEPLOY_PROBE + {% endif %} + Z_TILT_ADJUST_ORIG + {% if printer["gcode_macro RatOS"].z_probe == 'stowable' %} + STOW_PROBE + {% endif %} + + {% if printer["dual_carriage"] is defined %} + # restore IDEX mode + {% set idex_mode = printer["dual_carriage"].carriage_1|lower %} + {% if idex_mode == "copy" %} + _IDEX_COPY + {% elif idex_mode == "mirror" %} + _IDEX_MIRROR + {% endif %} + {% endif %} diff --git a/printers/caramba/macros.cfg b/printers/caramba/macros.cfg index c0275c9b..7a6591f8 100644 --- a/printers/caramba/macros.cfg +++ b/printers/caramba/macros.cfg @@ -10,19 +10,16 @@ gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} - M117 Adjusting Z tilt... - RESPOND MSG="Adjusting Z tilt..." + RATOS_ECHO MSG="Adjusting Z tilt..." # Adjust bed tilt Z_TILT_ADJUST - M117 Rehoming Z after Z tilt adjustment... - RESPOND MSG="Rehoming Z after Z tilt adjustment..." + RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z diff --git a/printers/initial-setup.cfg b/printers/initial-setup.cfg index 241c8650..9976df11 100644 --- a/printers/initial-setup.cfg +++ b/printers/initial-setup.cfg @@ -17,22 +17,22 @@ max_accel: 1 [gcode_macro PAUSE] rename_existing: PAUSE_BASE gcode: - M118 Please setup your printer through the RatOS configurator at /configure + RATOS_ECHO MSG="Please setup your printer through the RatOS configurator at /configure" [gcode_macro RESUME] rename_existing: RESUME_BASE gcode: - M118 Please setup your printer through the RatOS configurator at /configure + RATOS_ECHO MSG="Please setup your printer through the RatOS configurator at /configure" [gcode_macro CANCEL_PRINT] rename_existing: CANCEL_BASE gcode: - M118 Please setup your printer through the RatOS configurator at /configure + RATOS_ECHO MSG="Please setup your printer through the RatOS configurator at /configure" [delayed_gcode INIT] initial_duration: 0.0 gcode: - M118 Welcome to RatOS! - M118 Please setup your printer through the RatOS configurator at /configure + RATOS_ECHO MSG="Welcome to RatOS!" + RATOS_ECHO MSG="Please setup your printer through the RatOS configurator at /configure" [include ../shell-macros.cfg] diff --git a/printers/v-core-3/macros.cfg b/printers/v-core-3/macros.cfg index c0275c9b..7a6591f8 100644 --- a/printers/v-core-3/macros.cfg +++ b/printers/v-core-3/macros.cfg @@ -10,19 +10,16 @@ gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} - M117 Adjusting Z tilt... - RESPOND MSG="Adjusting Z tilt..." + RATOS_ECHO MSG="Adjusting Z tilt..." # Adjust bed tilt Z_TILT_ADJUST - M117 Rehoming Z after Z tilt adjustment... - RESPOND MSG="Rehoming Z after Z tilt adjustment..." + RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z diff --git a/printers/v-core-pro/macros.cfg b/printers/v-core-pro/macros.cfg index 31370bbe..cc20f18b 100644 --- a/printers/v-core-pro/macros.cfg +++ b/printers/v-core-pro/macros.cfg @@ -10,19 +10,16 @@ gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} - M117 Adjusting Z tilt... - RESPOND MSG="Adjusting Z tilt..." + RATOS_ECHO MSG="Adjusting Z tilt..." # Adjust bed tilt Z_TILT_ADJUST - M117 Rehoming Z after Z tilt adjustment... - RESPOND MSG="Rehoming Z after Z tilt adjustment..." + RATOS_ECHO MSG="Rehoming Z after Z tilt adjustment..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z diff --git a/printers/voron-v24/macros.cfg b/printers/voron-v24/macros.cfg index ad505438..8c5ef55d 100644 --- a/printers/voron-v24/macros.cfg +++ b/printers/voron-v24/macros.cfg @@ -10,19 +10,16 @@ gcode: {% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %} {% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %} {% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %} - M117 Pre-heating extruder... - RESPOND MSG="Pre-heating extruder..." + RATOS_ECHO MSG="Pre-heating extruder..." # Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp. # Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle. M104 S{min_temp} TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp} {% endif %} # Adjust bed tilt - M117 Quad gantry leveling... - RESPOND MSG="Quad gantry leveling..." + RATOS_ECHO MSG="Quad gantry leveling..." QUAD_GANTRY_LEVEL - M117 Rehoming Z after quad gantry leveling... - RESPOND MSG="Rehoming Z after quad gantry leveling..." + RATOS_ECHO MSG="Rehoming Z after quad gantry leveling..." # Home again as Z will have changed after tilt adjustment and bed heating. G28 Z diff --git a/scripts/idex-generate-belt-tension-graph.sh b/scripts/idex-generate-belt-tension-graph.sh new file mode 100755 index 00000000..85bea3d5 --- /dev/null +++ b/scripts/idex-generate-belt-tension-graph.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +DISABLE_Y=0 +DISABLE_X=0 + +if [ "$1" == "x" ] +then + DISABLE_Y=1 +fi +if [ "$1" == "y" ] +then + DISABLE_X=1 +fi + +if [ ! -d "/home/pi/printer_data/config/input_shaper" ] +then + mkdir /home/pi/printer_data/config/input_shaper +fi + +T0=1 +T1=1 +T2=0 + +if [ "$2" == "0" ] +then + T1=0 +fi +if [ "$2" == "1" ] +then + T0=0 +fi +if [ "$2" == "2" ] +then + T2=1 +fi + +DATE=$(date +'%Y-%m-%d-%H%M%S') +if [ $DISABLE_Y -eq 0 ] +then + [ -e "/tmp/left_y_belt_tension.csv" ] && rm /tmp/left_y_belt_tension.csv + [ -e "/tmp/right_y_belt_tension.csv" ] && rm /tmp/right_y_belt_tension.csv + [ -e "/tmp/combined_y_belt_tension.csv" ] && rm /tmp/combined_y_belt_tension.csv + + if [ $T2 -eq 1 ] + then + if [ ! -e "/tmp/raw_data_y_toolboard_t0_t2.csv" ] + then + echo "ERROR: No y data found for left toolhead (T0)" + exit 1 + fi + if [ ! -e "/tmp/raw_data_y_toolboard_t1_t2.csv" ] + then + echo "ERROR: No y data found for right toolhead (T1)" + exit 1 + fi + cp /tmp/raw_data_y_toolboard_t0_t2.csv /tmp/left_y_belt_tension.csv + cp /tmp/raw_data_y_toolboard_t1_t2.csv /tmp/right_y_belt_tension.csv + fi + + if [ $T2 -eq 0 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/raw_data_y_toolboard_t0_t0.csv" ] + then + echo "ERROR: No y data found for left toolhead (T0)" + exit 1 + fi + cp /tmp/raw_data_y_toolboard_t0_t0.csv /tmp/left_y_belt_tension.csv + fi + + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/raw_data_y_toolboard_t1_t1.csv" ] + then + echo "ERROR: No y data found for right toolhead (T1)" + exit 1 + fi + cp /tmp/raw_data_y_toolboard_t1_t1.csv /tmp/right_y_belt_tension.csv + fi + fi + + /home/pi/klipper/scripts/graph_accelerometer.py -c /tmp/*_y_belt_tension.csv -o /home/pi/printer_data/config/input_shaper/y_tension_comparison_"$DATE".png +fi +if [ $DISABLE_X -eq 0 ] +then + [ -e "/tmp/left_x_belt_tension.csv" ] && rm /tmp/left_x_belt_tension.csv + [ -e "/tmp/right_x_belt_tension.csv" ] && rm /tmp/right_x_belt_tension.csv + + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/raw_data_x_toolboard_t0_t0.csv" ] + then + echo "ERROR: No x data found for the left toolhead (T0)" + exit 1 + fi + cp /tmp/raw_data_x_toolboard_t0_t0.csv /tmp/left_x_belt_tension.csv + fi + + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/raw_data_x_toolboard_t1_t1.csv" ] + then + echo "ERROR: No x data found for right toolhbead (T1)" + exit 1 + fi + cp /tmp/raw_data_x_toolboard_t1_t1.csv /tmp/right_x_belt_tension.csv + fi + + /home/pi/klipper/scripts/graph_accelerometer.py -c /tmp/*_x_belt_tension.csv -o /home/pi/printer_data/config/input_shaper/x_tension_comparison_"$DATE".png +fi \ No newline at end of file diff --git a/scripts/idex-generate-shaper-graph.sh b/scripts/idex-generate-shaper-graph.sh new file mode 100755 index 00000000..87c09ebf --- /dev/null +++ b/scripts/idex-generate-shaper-graph.sh @@ -0,0 +1,231 @@ +#!/bin/bash + +DISABLE_Y=0 +DISABLE_X=0 + +if [ "$1" = "x" ] +then + DISABLE_Y=1 +fi +if [ "$1" = "y" ] +then + DISABLE_X=1 +fi + +if [ ! -d "/home/pi/printer_data/config/input_shaper" ] +then + mkdir /home/pi/printer_data/config/input_shaper +fi + +T0=1 +T1=1 +IDEX=0 + +if [ "$2" == "0" ] +then + T1=0 +fi +if [ "$2" == "1" ] +then + T0=0 +fi +if [ "$3" == "1" ] +then + IDEX=1 +fi +if [ "$3" == "2" ] +then + IDEX=2 +fi + +DATE=$(date +'%Y-%m-%d-%H%M%S') +if [ $DISABLE_Y -eq 0 ] +then + [ -e "/tmp/t0_y.csv" ] && rm /tmp/t0_y.csv + [ -e "/tmp/t1_y.csv" ] && rm /tmp/t1_y.csv + [ -e "/tmp/t0_copy_y.csv" ] && rm /tmp/t0_copy_y.csv + [ -e "/tmp/t1_copy_y.csv" ] && rm /tmp/t1_copy_y.csv + [ -e "/tmp/t0_mirror_y.csv" ] && rm /tmp/t0_mirror_y.csv + [ -e "/tmp/t1_mirror_y.csv" ] && rm /tmp/t1_mirror_y.csv + + if [ $IDEX -eq 0 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t0.csv" ] + then + echo "ERROR: No y data found for T0" + exit 1 + fi + cp "/tmp/resonances_y_$4_$5_$6_t0.csv" /tmp/t0_y.csv + echo "please wait..." + /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_y.csv -o /home/pi/printer_data/config/input_shaper/t0_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t0.csv" + fi + + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t1.csv" ] + then + echo "ERROR: No y data found for T1" + exit 1 + fi + cp "/tmp/resonances_y_$4_$5_$6_t1.csv" /tmp/t1_y.csv + echo "please wait..." + /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_y.csv -o /home/pi/printer_data/config/input_shaper/t1_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t1.csv" + fi + fi + + if [ $IDEX -eq 1 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t0_copy.csv" ] + then + echo "ERROR: No y data found for T0 copy mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_y_$4_$5_$6_t0_copy.csv" /tmp/t0_copy_y.csv + [ -e "/tmp/t0_copy_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_copy_y.csv -o /home/pi/printer_data/config/input_shaper/t0_copy_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t0_copy.csv" + fi + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t1_copy.csv" ] + then + echo "ERROR: No y data found for T1 copy mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_y_$4_$5_$6_t1_copy.csv" /tmp/t1_copy_y.csv + [ -e "/tmp/t1_copy_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_copy_y.csv -o /home/pi/printer_data/config/input_shaper/t1_copy_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t1_copy.csv" + fi + fi + + if [ $IDEX -eq 2 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t0_mirror.csv" ] + then + echo "ERROR: No y data found for T0 mirror mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_y_$4_$5_$6_t0_mirror.csv" /tmp/t0_mirror_y.csv + [ -e "/tmp/t0_mirror_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_mirror_y.csv -o /home/pi/printer_data/config/input_shaper/t0_mirror_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t0_mirror.csv" + fi + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_y_$4_$5_$6_t1_mirror.csv" ] + then + echo "ERROR: No y data found for T1 mirror mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_y_$4_$5_$6_t1_mirror.csv" /tmp/t1_mirror_y.csv + [ -e "/tmp/t1_mirror_y.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_mirror_y.csv -o /home/pi/printer_data/config/input_shaper/t1_mirror_resonances_y_"$DATE".png + rm "/tmp/resonances_y_$4_$5_$6_t1_mirror.csv" + fi + fi +fi + +if [ $DISABLE_X -eq 0 ] +then + [ -e "/tmp/t0_x.csv" ] && rm /tmp/t0_x.csv + [ -e "/tmp/t1_x.csv" ] && rm /tmp/t1_x.csv + [ -e "/tmp/t0_copy_x.csv" ] && rm /tmp/t0_copy_x.csv + [ -e "/tmp/t1_copy_x.csv" ] && rm /tmp/t1_copy_x.csv + [ -e "/tmp/t0_mirror_x.csv" ] && rm /tmp/t0_mirror_x.csv + [ -e "/tmp/t1_mirror_x.csv" ] && rm /tmp/t1_mirror_x.csv + + if [ $IDEX -eq 0 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t0.csv" ] + then + echo "ERROR: resonances_x_$4_$5_$6_t0.csv" + echo "ERROR: No x data found for T0" + exit 1 + fi + cp "/tmp/resonances_x_$4_$5_$6_t0.csv" /tmp/t0_x.csv + echo "please wait..." + /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_x.csv -o /home/pi/printer_data/config/input_shaper/t0_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t0.csv" + fi + + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t1.csv" ] + then + echo "ERROR: No x data found for T1" + exit 1 + fi + cp "/tmp/resonances_x_$4_$5_$6_t1.csv" /tmp/t1_x.csv + echo "please wait..." + /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_x.csv -o /home/pi/printer_data/config/input_shaper/t1_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t1.csv" + fi + fi + + if [ $IDEX -eq 1 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t0_copy.csv" ] + then + echo "ERROR: No x data found for T0 copy mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_x_$4_$5_$6_t0_copy.csv" /tmp/t0_copy_x.csv + [ -e "/tmp/t0_copy_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_copy_x.csv -o /home/pi/printer_data/config/input_shaper/t0_copy_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t0_copy.csv" + fi + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t1_copy.csv" ] + then + echo "ERROR: No x data found for T1 copy mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_x_$4_$5_$6_t1_copy.csv" /tmp/t1_copy_x.csv + [ -e "/tmp/t1_copy_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_copy_x.csv -o /home/pi/printer_data/config/input_shaper/t1_copy_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t1_copy.csv" + fi + fi + + if [ $IDEX -eq 2 ] + then + if [ $T0 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t0_mirror.csv" ] + then + echo "ERROR: No x data found for T0 mirror mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_x_$4_$5_$6_t0_mirror.csv" /tmp/t0_mirror_x.csv + [ -e "/tmp/t0_mirror_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t0_mirror_x.csv -o /home/pi/printer_data/config/input_shaper/t0_mirror_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t0_mirror.csv" + fi + if [ $T1 -eq 1 ] + then + if [ ! -e "/tmp/resonances_x_$4_$5_$6_t1_mirror.csv" ] + then + echo "ERROR: No x data found for T1 mirror mode" + exit 1 + fi + echo "please wait..." + cp "/tmp/resonances_x_$4_$5_$6_t1_mirror.csv" /tmp/t1_mirror_x.csv + [ -e "/tmp/t1_mirror_x.csv" ] && /home/pi/klipper/scripts/calibrate_shaper.py /tmp/t1_mirror_x.csv -o /home/pi/printer_data/config/input_shaper/t1_mirror_resonances_x_"$DATE".png + rm "/tmp/resonances_x_$4_$5_$6_t1_mirror.csv" + fi + fi +fi \ No newline at end of file diff --git a/sensors/prusa-mini-filament-switch.cfg b/sensors/prusa-mini-filament-switch.cfg index fd888261..9183de1b 100644 --- a/sensors/prusa-mini-filament-switch.cfg +++ b/sensors/prusa-mini-filament-switch.cfg @@ -2,10 +2,10 @@ switch_pin: ^filament_switch_sensor_pin pause_on_runout: True runout_gcode: - M118 Filament Runout Detected + RATOS_ECHO MSG="Filament Runout Detected" M600 insert_gcode: - M118 Filament Load Detected + RATOS_ECHO MSG="Filament Load Detected" LOAD_FILAMENT event_delay: 3.0 pause_delay: 0.01 diff --git a/sensors/prusa-mk3s-filament-switch.cfg b/sensors/prusa-mk3s-filament-switch.cfg index bcd7a87a..597fde99 100644 --- a/sensors/prusa-mk3s-filament-switch.cfg +++ b/sensors/prusa-mk3s-filament-switch.cfg @@ -2,10 +2,10 @@ switch_pin: !filament_switch_sensor_pin pause_on_runout: True runout_gcode: - M118 Filament Runout Detected + RATOS_ECHO MSG="Filament Runout Detected" M600 insert_gcode: - M118 Filament Load Detected + RATOS_ECHO MSG="Filament Load Detected" LOAD_FILAMENT event_delay: 3.0 pause_delay: 0.01 diff --git a/shell-macros.cfg b/shell-macros.cfg index 6e470ef5..c116237c 100644 --- a/shell-macros.cfg +++ b/shell-macros.cfg @@ -20,43 +20,43 @@ timeout: 10. [gcode_macro GENERATE_SHAPER_GRAPHS] description: Genarates input shaper resonances graphs for analysis. Uses the AXIS parameter for if you only want to do one axis at a time, (eg. GENERATE_SHAPER_GRAPHS AXIS=X) gcode: - {% if params.AXIS is defined %} - {% if params.AXIS|lower == 'x' %} - MAYBE_HOME - TEST_RESONANCES AXIS=X - RUN_SHELL_COMMAND CMD=generate_shaper_graph_x - RESPOND MSG="Input shaper graph generated for the X axis. You'll find it in the input_shaper folder in the machine tab!" - {% elif params.AXIS|lower == 'y' %} - MAYBE_HOME - TEST_RESONANCES AXIS=Y - RUN_SHELL_COMMAND CMD=generate_shaper_graph_y - RESPOND MSG="Input shaper graph generated for the Y axis. You'll find it in the input_shaper folder in the machine tab!" - {% else %} - {action_raise_error("Unknown axis specified. Expected X or Y.")} - {% endif %} - {% else %} - MAYBE_HOME - TEST_RESONANCES AXIS=X - TEST_RESONANCES AXIS=Y - RUN_SHELL_COMMAND CMD=generate_shaper_graph_x - RUN_SHELL_COMMAND CMD=generate_shaper_graph_y - RESPOND MSG="Input shaper graphs generated for X and Y. You'll find them in the input_shaper folder in the machine tab!" - {% endif %} + {% if params.AXIS is defined %} + {% if params.AXIS|lower == 'x' %} + MAYBE_HOME + TEST_RESONANCES AXIS=X + RUN_SHELL_COMMAND CMD=generate_shaper_graph_x + RATOS_ECHO MSG="Input shaper graph generated for the X axis. You'll find it in the input_shaper folder in the machine tab!" + {% elif params.AXIS|lower == 'y' %} + MAYBE_HOME + TEST_RESONANCES AXIS=Y + RUN_SHELL_COMMAND CMD=generate_shaper_graph_y + RATOS_ECHO MSG="Input shaper graph generated for the Y axis. You'll find it in the input_shaper folder in the machine tab!" + {% else %} + {action_raise_error("Unknown axis specified. Expected X or Y.")} + {% endif %} + {% else %} + MAYBE_HOME + TEST_RESONANCES AXIS=X + TEST_RESONANCES AXIS=Y + RUN_SHELL_COMMAND CMD=generate_shaper_graph_x + RUN_SHELL_COMMAND CMD=generate_shaper_graph_y + RATOS_ECHO MSG="Input shaper graphs generated for X and Y. You'll find them in the input_shaper folder in the machine tab!" + {% endif %} [gcode_macro MEASURE_COREXY_BELT_TENSION] description: Generates resonance graph used to ensure belts are equally tensioned. gcode: - TEST_RESONANCES AXIS=1,1 OUTPUT=raw_data NAME=belt-tension-upper - TEST_RESONANCES AXIS=1,-1 OUTPUT=raw_data NAME=belt-tension-lower - RUN_SHELL_COMMAND CMD=generate_belt_tension_graph - RESPOND MSG="Belt tension graphs generated. You'll find them in the input_shaper folder in the machine tab!" + TEST_RESONANCES AXIS=1,1 OUTPUT=raw_data NAME=belt-tension-upper + TEST_RESONANCES AXIS=1,-1 OUTPUT=raw_data NAME=belt-tension-lower + RUN_SHELL_COMMAND CMD=generate_belt_tension_graph + RATOS_ECHO MSG="Belt tension graphs generated. You'll find them in the input_shaper folder in the machine tab!" [gcode_macro CHANGE_HOSTNAME] description: Change the hostname of your Raspberry Pi. gcode: - {% if params.HOSTNAME is not defined %} - RESPOND MSG='You have to specify a new hostname with the HOSTNAME parameter. Ex: CHANGE_HOSTNAME HOSTNAME="MY_NEW_HOSTNAME"' - RESPOND MSG="Please note: RFCs mandate that a hostname's labels may contain only the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted." - {% else %} - RUN_SHELL_COMMAND CMD=change_hostname PARAMS={params.HOSTNAME} - {% endif %} + {% if params.HOSTNAME is not defined %} + RESPOND MSG='You have to specify a new hostname with the HOSTNAME parameter. Ex: CHANGE_HOSTNAME HOSTNAME="MY_NEW_HOSTNAME"' + RATOS_ECHO MSG="Please note: RFCs mandate that a hostname's labels may contain only the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted." + {% else %} + RUN_SHELL_COMMAND CMD=change_hostname PARAMS={params.HOSTNAME} + {% endif %}