Skip to content

Commit

Permalink
better ratos integration
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Apr 3, 2024
1 parent b129769 commit 23eff2a
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 292 deletions.
256 changes: 70 additions & 186 deletions klippy/rmmu.py

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ gcode:
{% endif %}
{% endif %}
RMMU_RESET
RMMU_LOAD_TOOL TOOL={initial_tool} TEMP=-1
RMMU_LOAD_TOOL TOOLHEAD={initial_tool} TEMP=-1
RMMU_START_PRINT { rawparams }
{% endif %}

Expand Down Expand Up @@ -728,6 +728,20 @@ gcode:
{% 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 printer["rmmu"] is defined and printer["gcode_macro T0"].loading_position is defined %}
{% set loading_position = printer["gcode_macro T0"].loading_position|float %}
{% if loading_position > 0 %}
{% if printer["gcode_macro RatOS"].toolchange_first_purge is defined %}
{% set toolchange_first_purge = printer["gcode_macro RatOS"].toolchange_first_purge|float %}
{% if toolchange_first_purge > 0 %}
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
_PURGE_FILAMENT TOOLHEAD=0 E={toolchange_first_purge}
_CLEANING_MOVE TOOLHEAD=0
{% endif %}
{% endif %}
{% endif %}
{% endif %}

{% if idex_mode == '' %}
# DEFAULT
_PRIME
Expand Down Expand Up @@ -806,19 +820,6 @@ gcode:
{% endif %}
{% endif %}
{% endif %}
{% if printer["rmmu"] is defined and printer["gcode_macro T0"].loading_position is defined %}
{% set loading_position = printer["gcode_macro T0"].loading_position|float %}
{% if loading_position > 0 %}
{% if printer["gcode_macro RatOS"].toolchange_first_purge is defined %}
{% set toolchange_first_purge = printer["gcode_macro RatOS"].toolchange_first_purge|float %}
{% if toolchange_first_purge > 0 %}
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
_PURGE_FILAMENT TOOLHEAD=0 E={toolchange_first_purge}
_CLEANING_MOVE TOOLHEAD=0
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% if first_x >= 0 and first_y >= 0 %}
G0 X{first_x} Y{first_y} Z{first_z} F{speed}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion macros/load_filament.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ gcode:
# load filament
_MOVE_TO_LOADING_POSITION TOOLHEAD={toolhead}
{% if printer["rmmu"] is defined %}
RMMU_LOAD_TOOL TOOL={toolhead} TEMP={params.TEMP|default(-1)|int}
RMMU_LOAD_TOOL TOOLHEAD={toolhead} TEMP={params.TEMP|default(-1)|int}
{% else %}
_LOAD_FILAMENT_FROM_EXTRUDER_TO_COOLING_ZONE TOOLHEAD={toolhead}
_LOAD_FILAMENT_FROM_COOLING_ZONE_TO_NOZZLE TOOLHEAD={toolhead}
Expand Down
179 changes: 104 additions & 75 deletions macros/rmmu.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#####
# RMMU UNLOAD MACROS
#####
[gcode_macro _RMMU_UNLOAD_FILAMENT_FROM_NOZZLE_TO_COOLING_POSITION]
[gcode_macro _RMMU_UNLOAD_FILAMENT_FROM_NOZZLE_TO_COOLING_ZONE]
gcode:
# parameter
{% set t = params.T|int %}
{% set toolhead = params.TOOLHEAD|int %}

# get current printing mode
{% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %}

DEBUG_ECHO PREFIX="_RMMU_UNLOAD_FILAMENT_FROM_NOZZLE_TO_COOLING_POSITION" MSG="T={t}, is_printing_gcode={is_printing_gcode}"
DEBUG_ECHO PREFIX="_RMMU_UNLOAD_FILAMENT_FROM_NOZZLE_TO_COOLING_ZONE" MSG="TOOLHEAD={toolhead}, is_printing_gcode={is_printing_gcode}"

{% if is_printing_gcode and "xyz" in printer.toolhead.homed_axes and printer["rmmu"].filament_changes|int > 0 %}

# config
{% set purge_before_unload = printer["gcode_macro T%s" % t].purge_before_unload|float %}
{% set purge_before_unload = printer["gcode_macro T%s" % toolhead].purge_before_unload|float %}

# cache current position
{% set pos = printer.toolhead.position %}
Expand All @@ -37,7 +37,7 @@ gcode:

# purge
{% if purge_before_unload > 0 %}
_PURGE_BEFORE_UNLOAD TOOLHEAD={t}
_PURGE_BEFORE_UNLOAD TOOLHEAD={toolhead}
{% else %}
# wait a bit for the filament to melt in case it was a short move
G4 P3000
Expand All @@ -52,6 +52,98 @@ gcode:
M400


#####
# UI EXPOSED FILAMENT MACROS
#####
[gcode_macro HOME_FILAMENT]
gcode:
# parameter
{% set toolhead = params.TOOLHEAD|default(-1)|int %}

DEBUG_ECHO PREFIX="HOME_FILAMENT" MSG="toolhead={toolhead}"

{% if printer["rmmu"] is defined %}
{% if toolhead >= -1 and toolhead < printer["rmmu"].tool_count %}
RMMU_HOME_FILAMENT TOOLHEAD={toolhead}
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


[gcode_macro MOVE_FILAMENT]
gcode:
# parameter
{% set toolhead = params.TOOLHEAD|default(-1)|int %}
{% set move = params.MOVE|default(50)|int %}
{% set speed = params.SPEED|default(10)|int %}
{% set sync = params.SYNC_EXTRUDER|default(0)|int %}

DEBUG_ECHO PREFIX="MOVE_FILAMENT" MSG="toolhead={toolhead}, move={move}, speed={speed}, sync={sync}"

{% if printer["rmmu"] is defined %}
{% if toolhead >= 0 and toolhead < printer["rmmu"].tool_count %}
{% if printer["rmmu"].is_homed|default('false')|lower != 'true' %}
RMMU_HOME
{% endif %}
RMMU_SELECT_TOOL TOOLHEAD={toolhead}
{% if sync == 0 %}
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0 MOVE={move} SPEED={speed} ACCEL={printer.toolhead.max_accel}
{% else %}
G92 E0
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0 MOVE={move} SPEED={speed} ACCEL={printer.toolhead.max_accel} SYNC=0
G0 E{move} F{(speed * 60)}
MANUAL_STEPPER STEPPER=rmmu_pulley SYNC=1
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0
G92 E0
{% endif %}
RMMU_SELECT_TOOL TOOLHEAD=-1
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


[gcode_macro EJECT_FILAMENT]
gcode:
# parameter
{% set toolhead = params.TOOLHEAD|default(-1)|int %}

DEBUG_ECHO PREFIX="EJECT_FILAMENT" MSG="toolhead={toolhead}"

{% if printer["rmmu"] is defined %}
{% if t >= -1 and t < printer["rmmu"].tool_count %}
RMMU_EJECT_FILAMENT TOOLHEAD={toolhead}
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


#####
# RMMU HOOKS
#####
[gcode_macro _RMMU_BEFORE_TOOL_CHANGE]
gcode:
# parameter
{% set toolhead = params.TOOLHEAD|int %}

DEBUG_ECHO PREFIX="_RMMU_BEFORE_TOOL_CHANGE" MSG="toolhead={toolhead}"

SAVE_GCODE_STATE NAME=PAUSE_state
G92 E0
G0 E-2 F3600
M400


[gcode_macro _RMMU_AFTER_TOOL_CHANGE]
gcode:
# parameter
{% set toolhead = params.TOOLHEAD|int %}

DEBUG_ECHO PREFIX="_RMMU_AFTER_TOOL_CHANGE" MSG="toolhead={toolhead}"


#####
# RMMU EVENTS
#####
Expand All @@ -62,30 +154,29 @@ variable_z: 0
variable_fan_speed: 0
gcode:
# parameter
{% set t = params.T|int %}
{% set toolhead = params.TOOLHEAD|int %}

# get current printing mode
{% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %}

DEBUG_ECHO PREFIX="_RMMU_ON_FILAMENT_HAS_CHANGED" MSG="T={t}, is_printing_gcode={is_printing_gcode}"
DEBUG_ECHO PREFIX="_RMMU_ON_FILAMENT_HAS_CHANGED" MSG="TOOLHEAD={toolhead}, is_printing_gcode={is_printing_gcode}"

{% if is_printing_gcode and "xyz" in printer.toolhead.homed_axes %}

# config
{% set purge_after_load = printer["gcode_macro T%s" % t].purge_after_load|float %}
{% set purge_after_load = printer["gcode_macro T%s" % toolhead].purge_after_load|float %}
{% set speed = printer["gcode_macro RatOS"].macro_travel_speed|float * 60 %}

# Handle toolhead settings
CACHE_TOOLHEAD_SETTINGS
SET_MACRO_TRAVEL_SETTINGS

# purge filament
_PURGE_FILAMENT TOOLHEAD=0 E={purge_after_load}
_PURGE_FILAMENT TOOLHEAD=0 E={purge_after_load} R=2

# retract a bit
G92 E0 # Reset extrusion distance
G0 E-1 F2100 # Purge
G92 E0 # Reset extrusion distance
G0 E-2 F2100 # Purge
M400 # Wait for move to complete

# cleaning move
Expand All @@ -111,6 +202,8 @@ gcode:
# get current printing mode
{% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %}

DEBUG_ECHO PREFIX="_RMMU_ON_FILAMENT_LOADING_ERROR" MSG="is_printing_gcode={is_printing_gcode}"

{% if is_printing_gcode and "xyz" in printer.toolhead.homed_axes %}
SAVE_GCODE_STATE NAME=PAUSE_state
{printer.configfile.settings['gcode_macro pause'].rename_existing}
Expand All @@ -119,70 +212,6 @@ gcode:
{% endif %}


#####
# FILAMENT MACROS
#####
[gcode_macro HOME_FILAMENT]
variable_parameter_TOOL : -1
gcode:
# parameter
{% set t = params.TOOLHEAD|default(-1)|int %}

{% if printer["rmmu"] is defined %}
{% if t >= -1 and t < printer["rmmu"].tool_count %}
RMMU_HOME_FILAMENT TOOL={t}
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


[gcode_macro MOVE_FILAMENT]
gcode:
# parameter
{% set t = params.TOOLHEAD|default(-1)|int %}
{% set move = params.MOVE|default(50)|int %}
{% set speed = params.SPEED|default(10)|int %}
{% set sync = params.SYNC_EXTRUDER|default(0)|int %}

{% if printer["rmmu"] is defined %}
{% if t >= 0 and t < printer["rmmu"].tool_count %}
{% if printer["rmmu"].is_homed|default('false')|lower != 'true' %}
RMMU_HOME
{% endif %}
RMMU_SELECT_TOOL TOOL={t}
{% if sync == 0 %}
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0 MOVE={move} SPEED={speed} ACCEL={printer.toolhead.max_accel}
{% else %}
G92 E0
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0 MOVE={move} SPEED={speed} ACCEL={printer.toolhead.max_accel} SYNC=0
G0 E{move} F{(speed * 60)}
MANUAL_STEPPER STEPPER=rmmu_pulley SYNC=1
MANUAL_STEPPER STEPPER=rmmu_pulley SET_POSITION=0
G92 E0
{% endif %}
RMMU_SELECT_TOOL TOOL=-1
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


[gcode_macro EJECT_FILAMENT]
variable_parameter_TOOL : -1
gcode:
# parameter
{% set t = params.TOOLHEAD|default(-1)|int %}

{% if printer["rmmu"] is defined %}
{% if t >= -1 and t < printer["rmmu"].tool_count %}
RMMU_EJECT_FILAMENT TOOL={t}
{% else %}
RATOS_ECHO MSG="Please select correct toolhead!"
{% endif %}
{% endif %}


#####
# RMMU OVERRIDES
#####
Expand Down
2 changes: 1 addition & 1 deletion macros/toolheads.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gcode:
{% set new_t = params.T|int %}
{% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %}
{% if is_printing_gcode %}
RMMU_CHANGE_TOOL TOOL={new_t}
RMMU_CHANGE_TOOL TOOLHEAD={new_t}
{% endif %}
{% else %}
{% set idex_mode = '' %}
Expand Down
2 changes: 1 addition & 1 deletion macros/unload_filament.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ gcode:
# unload filament
_MOVE_TO_LOADING_POSITION TOOLHEAD={toolhead}
{% if printer["rmmu"] is defined %}
RMMU_UNLOAD_TOOL TOOL={toolhead} TEMP={params.TEMP|default(-1)|int}
RMMU_UNLOAD_TOOL TOOLHEAD={toolhead} TEMP={params.TEMP|default(-1)|int}
{% else %}
_UNLOAD_FILAMENT_FROM_NOZZLE_TO_COOLING_ZONE TOOLHEAD={toolhead}
_UNLOAD_FILAMENT_FROM_COOLING_ZONE_TO_EXTRUDER TOOLHEAD={toolhead}
Expand Down
21 changes: 7 additions & 14 deletions scripts/ratos_rmmu_postprocessor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# /usr/bin/python3

import sys
import re
import argparse
from shutil import ReadError, copy2
from os import path, remove, getenv
Expand Down Expand Up @@ -55,8 +54,7 @@ def process_file(args, sourcefile):
first_y = -1
start_print_line = 0
file_has_changed = False
found_m220 = False
found_layerchange = False
first_layer_override_done = False

for line in range(len(lines)):

Expand Down Expand Up @@ -93,17 +91,12 @@ def process_file(args, sourcefile):
print("line:" + lines[line].rstrip())
sys.exit(1)

# remove wipe tower speed override for the first layer
if start_print_line > 0 and not found_m220:
if not found_layerchange:
if lines[line].rstrip().startswith(";LAYER_CHANGE"):
found_layerchange = True

if found_layerchange:
if lines[line].rstrip().startswith("M220 S"):
file_has_changed = True
found_m220 = True
lines[line] = 'M220 S100\n'
# remove wipe tower speed override for the first layer to ensure first layer adhesion
if slicer == "superslicer":
if start_print_line > 0 and not first_layer_override_done:
if lines[line].rstrip().startswith("; CP TOOLCHANGE WIPE"):
lines[line] = 'M220 S100 ' + lines[line]
first_layer_override_done = True

# add START_PRINT parameters
if start_print_line > 0:
Expand Down

0 comments on commit 23eff2a

Please sign in to comment.