Skip to content

Commit

Permalink
rmmu multi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Apr 27, 2024
1 parent 7441aac commit c5b6d5b
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 48 deletions.
14 changes: 11 additions & 3 deletions klippy/rmmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, config):
self.name = config.get_name().split()[-1]

# rmmu default status
self.in_use = False
self.is_homed = False
self.runout_detected = False
self.initial_filament = -1
Expand Down Expand Up @@ -213,21 +214,23 @@ def get_status(self, eventtime):
return {'name': self.name,
'tool_count': self.tool_count,
'is_homed': self.is_homed,
'in_use': self.in_use,
'initial_filament': self.initial_filament,
'needs_initial_purging': self.needs_initial_purging,
'loaded_filament': self.get_setting(self.name.lower() + self.VARS_LOADED_FILAMENT),
'loaded_filament': self.get_loaded_filament(),
'loaded_filament_temp': self.get_setting(self.name.lower() + self.VARS_LOADED_FILAMENT_TEMP)}

def reset(self):
# default values
self.in_use = False
self.is_homed = False
self.runout_detected = False
self.start_print_param = None
self.initial_filament = -1
self.needs_initial_purging = False

# # update frontend
# loaded_filament = self.get_setting(self.name.lower() + self.VARS_LOADED_FILAMENT)
# loaded_filament = self.get_loaded_filament()
# for i in range(0, self.tool_count):
# if i == loaded_filament:
# self.gcode.run_script_from_command("SET_GCODE_VARIABLE MACRO=T" + str(i) + " VARIABLE=active VALUE=True")
Expand Down Expand Up @@ -1176,7 +1179,7 @@ def on_filament_runout(self, tool, clogged):
if clogged != "true":

# unload filament
loaded_filament = self.get_setting(self.name.lower() + self.VARS_LOADED_FILAMENT)
loaded_filament = self.get_loaded_filament()
if not self.unload_filament(loaded_filament):
# echo
self.ratos_echo("Can not eject filament because it couldnt be unloaded!")
Expand Down Expand Up @@ -1248,6 +1251,11 @@ def query_sensors(self):
#####
# Helper
#####
def get_loaded_filament(self):
if self.is_sensor_triggered(self.toolhead_filament_sensor):
return self.get_setting(self.name.lower() + self.VARS_LOADED_FILAMENT)
return -1

def move_filament(self, tool, move, speed, accel, sync):
# home if needed
if not self.is_homed:
Expand Down
8 changes: 5 additions & 3 deletions klippy/rmmu_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def start_print(self, param):
for physical_toolhead in used_toolheads:
for t in used_tools:
if physical_toolhead == int(self.mapping[str(t)]["TOOLHEAD"]):
self.rmmu[physical_toolhead].in_use = True
self.rmmu[physical_toolhead].initial_filament = t
break
# handle toolhead mapping
Expand All @@ -207,8 +208,9 @@ def start_print(self, param):
if self.rmmu[physical_toolhead].is_sensor_triggered(self.rmmu[physical_toolhead].toolhead_filament_sensor):
loaded_filament = self.rmmu[physical_toolhead].get_status(self.toolhead.get_last_move_time())['loaded_filament']
loaded_filament_temp = self.rmmu[physical_toolhead].get_status(self.toolhead.get_last_move_time())['loaded_filament_temp']
initial_filament = int(self.mapping[str(self.rmmu[physical_toolhead].initial_filament)]["FILAMENT"])
if loaded_filament >=0 and loaded_filament <= self.total_tool_count:
if loaded_filament != self.rmmu[physical_toolhead].initial_filament:
if loaded_filament != initial_filament:
if loaded_filament_temp > self.rmmu[physical_toolhead].heater.min_extrude_temp and loaded_filament_temp < self.rmmu[physical_toolhead].heater.max_temp:
# unloaded the filament that is already loaded
self.ratos_echo("Wrong filament detected in hotend!")
Expand All @@ -220,7 +222,7 @@ def start_print(self, param):

# home printer if needed and move toolhead to its parking position
self.gcode.run_script_from_command('MAYBE_HOME')
if self.rmmu[physical_toolhead].initial_filament >= self.rmmu[0].tool_count:
if initial_filament >= self.rmmu[0].tool_count:
self.gcode.run_script_from_command('_MOVE_TO_LOADING_POSITION TOOLHEAD=1')
else:
self.gcode.run_script_from_command('_MOVE_TO_LOADING_POSITION TOOLHEAD=0')
Expand All @@ -240,7 +242,7 @@ def start_print(self, param):
raise self.printer.command_error("Unknown filament detected in toolhead! Please unload the filament and restart the print.")
else:
# tell RatOS that initial purging is not needed
self.rmmu[physical_toolhead].rmmu[physical_toolhead].needs_initial_purging = False
self.rmmu[physical_toolhead].needs_initial_purging = False
else:
raise self.printer.command_error("Unknown filament detected in toolhead! Please unload the filament and restart the print.")

Expand Down
81 changes: 53 additions & 28 deletions macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -595,42 +595,36 @@ gcode:

# rmmu load initial tool
{% if printer["rmmu_hub"] is defined %}
{% if physical_t0_used and printer["rmmu RMMU_T0"] is defined and printer["rmmu RMMU_T0"].loaded_filament|int != printer["rmmu RMMU_T0"].initial_filament|int %}
RATOS_ECHO MSG="1"
{% if physical_t0_used and printer["rmmu RMMU_T0"] is defined and printer["rmmu RMMU_T0"].loaded_filament|int != printer["rmmu_hub"].mapping["%s" % printer["rmmu RMMU_T0"].initial_filament|int]["FILAMENT"]|int %}
RATOS_ECHO MSG="Load initial RMMU_T0 filament..."
{% if initial_tool == 1 %}
RATOS_ECHO MSG="2"
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder
{% endif %}
RATOS_ECHO MSG="3"
M118 FILAMENT {printer["rmmu RMMU_T0"].initial_filament|int}
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T0"].initial_filament|int}
LOAD_FILAMENT TOOLHEAD={printer["rmmu RMMU_T0"].initial_filament|int}
# RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T0"].initial_filament|int}
{% if printer["dual_carriage"] is defined %}
RATOS_ECHO MSG="4"
PARK_TOOLHEAD
{% endif %}
{% if initial_tool == 1 %}
RATOS_ECHO MSG="5"
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder1
{% endif %}
{% endif %}
{% if physical_t1_used and printer["rmmu RMMU_T1"] is defined and printer["rmmu RMMU_T1"].loaded_filament|int != printer["rmmu RMMU_T1"].initial_filament|int %}
RATOS_ECHO MSG="6"
{% if physical_t1_used and printer["rmmu RMMU_T1"] is defined and printer["rmmu RMMU_T1"].loaded_filament|int != printer["rmmu_hub"].mapping["%s" % printer["rmmu RMMU_T1"].initial_filament|int]["FILAMENT"]|int %}
RATOS_ECHO MSG="Load initial RMMU_T1 filament..."
{% if initial_tool == 0 %}
RATOS_ECHO MSG="7"
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder1
{% endif %}
RATOS_ECHO MSG="8"
M118 FILAMENT {printer["rmmu RMMU_T1"].initial_filament|int}
_MOVE_TO_LOADING_POSITION TOOLHEAD=1
RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T1"].initial_filament|int}
LOAD_FILAMENT TOOLHEAD={printer["rmmu RMMU_T1"].initial_filament|int}
# RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T1"].initial_filament|int}
{% if printer["dual_carriage"] is defined %}
RATOS_ECHO MSG="9"
PARK_TOOLHEAD
{% endif %}
{% if initial_tool == 0 %}
RATOS_ECHO MSG="10"
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder
{% endif %}
Expand Down Expand Up @@ -745,7 +739,11 @@ gcode:
{% if printer["dual_carriage"] is defined %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
M104 S{min_temp} T{default_toolhead}
TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp}
{% if default_toolhead == 0 %}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% else %}
TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp}
{% endif %}
{% else %}
M104 S{min_temp}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
Expand All @@ -771,17 +769,44 @@ 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_hub"] 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 and printer["rmmu RMMU_T%s" % initial_toolhead].needs_initial_purging|lower == "true" %}
{% set toolchange_first_purge = printer["gcode_macro RatOS"].toolchange_first_purge|float %}
{% set toolchange_first_purge_feedrate = printer["gcode_macro RatOS"].toolchange_first_purge_feedrate|float %}
{% if toolchange_first_purge > 0 %}
RATOS_ECHO PREFIX="RMMU" MSG="Initial purging..."
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
_PURGE_FILAMENT TOOLHEAD=0 E={toolchange_first_purge} F={toolchange_first_purge_feedrate}
_CLEANING_MOVE TOOLHEAD=0
{% if printer["rmmu_hub"] is defined %}
{% if printer["gcode_macro RatOS"].toolchange_first_purge is defined %}
{% set toolchange_first_purge = printer["gcode_macro RatOS"].toolchange_first_purge|float %}
{% set toolchange_first_purge_feedrate = printer["gcode_macro RatOS"].toolchange_first_purge_feedrate|float %}
{% if toolchange_first_purge > 0 %}
{% if printer["rmmu RMMU_T0"] is defined and printer["gcode_macro T0"].loading_position is defined %}
{% if printer["rmmu RMMU_T0"].in_use|lower == "true" and printer["rmmu RMMU_T0"].needs_initial_purging|lower == "true" %}
{% if initial_toolhead == 1 %}
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder
{% endif %}
{% set loading_position = printer["gcode_macro T0"].loading_position|float %}
RATOS_ECHO PREFIX="RMMU T0" MSG="Initial purging..."
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
_PURGE_FILAMENT TOOLHEAD=0 E={toolchange_first_purge} F={toolchange_first_purge_feedrate}
_CLEANING_MOVE TOOLHEAD=0
{% if initial_toolhead == 1 %}
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder1
{% endif %}
{% endif %}
{% endif %}
{% if printer["rmmu RMMU_T1"] is defined and printer["gcode_macro T1"].loading_position is defined %}
{% if printer["rmmu RMMU_T1"].in_use|lower == "true" and printer["rmmu RMMU_T1"].needs_initial_purging|lower == "true" %}
{% if initial_toolhead == 0 %}
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder1
{% endif %}
{% set loading_position = printer["gcode_macro T1"].loading_position|float %}
RATOS_ECHO PREFIX="RMMU T1" MSG="Initial purging..."
_MOVE_TO_LOADING_POSITION TOOLHEAD=1
_PURGE_FILAMENT TOOLHEAD=1 E={toolchange_first_purge} F={toolchange_first_purge_feedrate}
_CLEANING_MOVE TOOLHEAD=1
{% if initial_toolhead == 0 %}
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Expand Down
37 changes: 26 additions & 11 deletions macros/toolheads.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,43 @@ gcode:
{% set new_t = printer["rmmu_hub"].mapping["%s" % t]["TOOLHEAD"]|int %}
{% set loaded_filament_t0 = printer["rmmu RMMU_T0"].loaded_filament|int %}
{% set loaded_filament_t1 = printer["rmmu RMMU_T1"].loaded_filament|int %}
{% set mapped_filament = printer["rmmu_hub"].mapping["%s" % t]["FILAMENT"]|int %}

RATOS_ECHO PREFIX="TOOL" MSG="t:{t}, act_t:{act_t}, new_t:{new_t}, loaded_t0:{loaded_filament_t0}, loaded_t1:{loaded_filament_t1}, mapped_filament:{mapped_filament}"

# TOOL: t:4, act_t:0, new_t:1, loaded_t0:1, loaded_t1:3, mapped_filament:0

{% if printer["rmmu_hub"].mode == "multi" %}
{% if act_t == 0 and loaded_filament_t1 == t %}
# T1 has the demanded filament already loaded
_SELECT_TOOL T=1 X={x} Y={y} Z={z} TOOLSHIFT={s}

{% elif act_t == 1 and loaded_filament_t0 == t %}
# T0 has the demanded filament already loaded
_SELECT_TOOL T=0 X={x} Y={y} Z={z} TOOLSHIFT={s}
{% if act_t == new_t %}
# change filament in the active toolhead
RATOS_ECHO PREFIX="TOOL" MSG="change filament in the active toolhead"
PARK_TOOLHEAD
_MOVE_TO_LOADING_POSITION TOOLHEAD={act_t}
RMMU_CHANGE_FILAMENT FILAMENT={t} X={x} Y={y}

{% else %}
{% if act_t == new_t %}
PARK_TOOLHEAD
_MOVE_TO_LOADING_POSITION TOOLHEAD={act_t}
RMMU_CHANGE_FILAMENT FILAMENT={t} X={x} Y={y}
{% if act_t == 0 and loaded_filament_t1 == mapped_filament %}
# T1 has the demanded filament already loaded
RATOS_ECHO PREFIX="TOOL" MSG="T1 has the demanded filament already loaded"
_SELECT_TOOL T=1 X={x} Y={y} Z={z} TOOLSHIFT={s}

{% elif act_t == 1 and loaded_filament_t0 == mapped_filament %}
# T0 has the demanded filament already loaded
RATOS_ECHO PREFIX="TOOL" MSG="T0 has the demanded filament already loaded"
_SELECT_TOOL T=0 X={x} Y={y} Z={z} TOOLSHIFT={s}

{% else %}
# change filament in the inactive toolhead and activate that toolhead
RATOS_ECHO PREFIX="TOOL" MSG="change filament in the inactive toolhead and activate that toolhead"
PARK_TOOLHEAD
SET_DUAL_CARRIAGE CARRIAGE={new_t} MODE=PRIMARY
_SET_TOOLHEAD_OFFSET T={new_t} MOVE={1 if "xyz" in printer.toolhead.homed_axes else 0}
ACTIVATE_EXTRUDER EXTRUDER=extruder{'' if new_t == 0 else 1}
_MOVE_TO_LOADING_POSITION TOOLHEAD={new_t}
RMMU_LOAD_FILAMENT FILAMENT={t}
RMMU_CHANGE_FILAMENT FILAMENT={t} X={x} Y={y}
# RMMU_LOAD_FILAMENT FILAMENT={t}

{% endif %}
{% endif %}

Expand Down
6 changes: 3 additions & 3 deletions scripts/ratos_idex_postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def process_file(args, sourcefile):
if lines[line].rstrip().startswith("START_PRINT") or lines[line].rstrip().startswith("RMMU_START_PRINT"):
start_print_line = line

# count IDEX toolshifts
# count toolshifts
if start_print_line > 0:
if lines[line].rstrip().startswith("T0") or lines[line].rstrip().startswith("T1"):
if lines[line].rstrip().startswith("T") and lines[line].rstrip()[1:].isdigit():
if toolshift_count == 0:
# remove first toolchange
lines[line] = ''
Expand Down Expand Up @@ -212,7 +212,7 @@ def process_file(args, sourcefile):
break

# make toolshift changes
if toolshift_count > 1 and toolchange_line > 0 and move_line > 0:
if toolshift_count > 0 and toolchange_line > 0 and move_line > 0:
file_has_changed = True

if zhop_line > 0:
Expand Down

0 comments on commit c5b6d5b

Please sign in to comment.